From 6b2e6cfd53a6ccb84cc1c261f968c5e7d223d8f3 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 10 Dec 2020 11:01:12 +0200 Subject: [PATCH] Prevent EGL headers from including Xlib headers One of the annoying things about EGL headers is that they include platform headers by default, e.g. on X11, it's Xlib.h, etc. The problem with Xlib.h is that it uses the define compiler directive to declare constants and those constants have very generic names, e.g. 'None', which typically conflict with enums, etc. In order to work around bad things coming from Xlib.h, we include fixx11.h file that contains some workarounds to redefine some Xlib's types. There's a flag or rather two flags (EGL_NO_PLATFORM_SPECIFIC_TYPES and EGL_NO_X11) that are cross-vendor and they can be used to prevent EGL headers from including platform specific headers, such as Xlib.h [1] The benefit of setting those two flags is that you can simply include EGL/egl.h or epoxy/egl.h and the world won't explode due to Xlib.h MESA_EGL_NO_X11_HEADERS is set to support older versions of Mesa. [1] https://github.com/KhronosGroup/EGL-Registry/pull/111 --- CMakeLists.txt | 5 +++++ platform.h | 1 - platformsupport/scenes/opengl/abstract_egl_backend.h | 1 - plugins/platforms/drm/drm_gpu.h | 1 - plugins/qpa/backingstore.h | 1 - plugins/qpa/eglhelpers.h | 1 - plugins/qpa/eglplatformcontext.h | 2 +- plugins/qpa/integration.h | 1 - plugins/qpa/offscreensurface.h | 1 - plugins/qpa/window.h | 1 - plugins/screencast/eglnativefence.h | 3 ++- 11 files changed, 8 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03f33f57b4..369ffa5998 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,11 @@ include(ECMConfiguredInstall) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0 -DQT_USE_QSTRINGBUILDER -DQT_NO_URL_CAST_FROM_STRING) +# Prevent EGL headers from including platform headers, in particular Xlib.h. +add_definitions(-DMESA_EGL_NO_X11_HEADERS) +add_definitions(-DEGL_NO_X11) +add_definitions(-DEGL_NO_PLATFORM_SPECIFIC_TYPES) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/platform.h b/platform.h index ba41343a1a..03fbf838db 100644 --- a/platform.h +++ b/platform.h @@ -11,7 +11,6 @@ #include #include #include -#include #include "fixqopengl.h" #include "input.h" diff --git a/platformsupport/scenes/opengl/abstract_egl_backend.h b/platformsupport/scenes/opengl/abstract_egl_backend.h index b72c362317..6f0babb9a2 100644 --- a/platformsupport/scenes/opengl/abstract_egl_backend.h +++ b/platformsupport/scenes/opengl/abstract_egl_backend.h @@ -13,7 +13,6 @@ #include #include -#include class QOpenGLFramebufferObject; diff --git a/plugins/platforms/drm/drm_gpu.h b/plugins/platforms/drm/drm_gpu.h index 078c87e8d8..ca8c0c6f6d 100644 --- a/plugins/platforms/drm/drm_gpu.h +++ b/plugins/platforms/drm/drm_gpu.h @@ -14,7 +14,6 @@ #include #include -#include #include "drm_buffer.h" diff --git a/plugins/qpa/backingstore.h b/plugins/qpa/backingstore.h index 51741a8800..d8df8db5cc 100644 --- a/plugins/qpa/backingstore.h +++ b/plugins/qpa/backingstore.h @@ -12,7 +12,6 @@ #include #include "fixqopengl.h" -#include #include diff --git a/plugins/qpa/eglhelpers.h b/plugins/qpa/eglhelpers.h index 80f633b9d3..1db82c349d 100644 --- a/plugins/qpa/eglhelpers.h +++ b/plugins/qpa/eglhelpers.h @@ -11,7 +11,6 @@ #include #include "fixqopengl.h" -#include #include diff --git a/plugins/qpa/eglplatformcontext.h b/plugins/qpa/eglplatformcontext.h index 07ae3e3a36..9d5986def3 100644 --- a/plugins/qpa/eglplatformcontext.h +++ b/plugins/qpa/eglplatformcontext.h @@ -12,7 +12,7 @@ #include #include "fixqopengl.h" -#include + #include namespace KWin diff --git a/plugins/qpa/integration.h b/plugins/qpa/integration.h index 5d31ab6e10..daba012844 100644 --- a/plugins/qpa/integration.h +++ b/plugins/qpa/integration.h @@ -13,7 +13,6 @@ #include #include "fixqopengl.h" -#include #include #include diff --git a/plugins/qpa/offscreensurface.h b/plugins/qpa/offscreensurface.h index 9a17e0e2e5..0bf192e21b 100644 --- a/plugins/qpa/offscreensurface.h +++ b/plugins/qpa/offscreensurface.h @@ -11,7 +11,6 @@ #include #include "fixqopengl.h" -#include #include diff --git a/plugins/qpa/window.h b/plugins/qpa/window.h index c1a7e75a35..f1270e1821 100644 --- a/plugins/qpa/window.h +++ b/plugins/qpa/window.h @@ -12,7 +12,6 @@ #include #include "fixqopengl.h" -#include #include #include diff --git a/plugins/screencast/eglnativefence.h b/plugins/screencast/eglnativefence.h index c8dfd278a0..15886eae39 100644 --- a/plugins/screencast/eglnativefence.h +++ b/plugins/screencast/eglnativefence.h @@ -6,8 +6,9 @@ #pragma once +#include + #include -#include namespace KWin {