CMake: Generic check for desktop GL and EGL on Linux systems
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ec6b7a7..92ed799 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1202,14 +1202,14 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
CheckRPI()
CheckX11()
CheckDirectFB()
- CheckOpenGLX11()
- CheckOpenGLESX11()
+ # Need to check for EGL first because KMSDRM and Wayland depends on it.
+ CheckEGL()
+ CheckKMSDRM()
+ CheckGLX()
+ CheckOpenGL()
+ CheckOpenGLES()
CheckWayland()
CheckVivante()
- # Need to check EGL before checking KMSDRM because KMSDRM depends on it.
- CheckEGLKMSDRM()
- CheckKMSDRM()
- CheckOpenGLKMSDRM()
endif()
if(UNIX)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index f21a900..d3f6cec 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -593,6 +593,10 @@ macro(CheckX11)
set(CMAKE_REQUIRED_LIBRARIES)
endif()
endif()
+ if(NOT HAVE_VIDEO_X11)
+ # Prevent Mesa from including X11 headers
+ list(APPEND EXTRA_CFLAGS "-DMESA_EGL_NO_X11_HEADERS -DEGL_NO_X11")
+ endif()
endmacro()
macro(WaylandProtocolGen _SCANNER _CODE_MODE _XML _PROTL)
@@ -627,7 +631,7 @@ macro(CheckWayland)
pkg_check_modules(WAYLAND wayland-client wayland-scanner wayland-egl wayland-cursor egl xkbcommon)
pkg_check_modules(WAYLAND_SCANNER_1_15 "wayland-scanner>=1.15")
- if(WAYLAND_FOUND)
+ if(WAYLAND_FOUND AND HAVE_VIDEO_OPENGL_EGL)
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
@@ -778,35 +782,14 @@ macro(CheckVivante)
endmacro(CheckVivante)
# Requires:
-# - libglvnd
-macro(CheckOpenGLKMSDRM)
- if(VIDEO_OPENGL AND HAVE_VIDEO_KMSDRM)
- check_c_source_compiles("
- #include <GL/gl.h>
- int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
-
- if(HAVE_VIDEO_OPENGL)
- set(HAVE_VIDEO_OPENGL TRUE)
- set(SDL_VIDEO_OPENGL 1)
- set(SDL_VIDEO_RENDER_OGL 1)
- endif()
- endif()
-endmacro()
-
-# Requires:
# - nada
-macro(CheckOpenGLX11)
+macro(CheckGLX)
if(VIDEO_OPENGL)
check_c_source_compiles("
- #include <GL/gl.h>
#include <GL/glx.h>
- int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
-
- if(HAVE_VIDEO_OPENGL)
- set(HAVE_VIDEO_OPENGL TRUE)
- set(SDL_VIDEO_OPENGL 1)
+ int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL_GLX)
+ if(HAVE_VIDEO_OPENGL_GLX)
set(SDL_VIDEO_OPENGL_GLX 1)
- set(SDL_VIDEO_RENDER_OGL 1)
endif()
endif()
endmacro()
@@ -814,61 +797,60 @@ endmacro()
# Requires:
# - PkgCheckModules
macro(CheckEGL)
- pkg_check_modules(EGL egl)
- string(REPLACE "-D_THREAD_SAFE;" "-D_THREAD_SAFE=1;" EGL_CFLAGS "${EGL_CFLAGS}")
-endmacro()
-
-# Requires:
-# - PkgCheckModules
-macro(CheckEGLKMSDRM)
- if (HAVE_VIDEO_OPENGLES OR HAVE_VIDEO_OPENGL)
- CheckEGL()
+ if (VIDEO_OPENGL OR VIDEO_OPENGLES)
+ pkg_check_modules(EGL egl)
+ string(REPLACE "-D_THREAD_SAFE;" "-D_THREAD_SAFE=1;" EGL_CFLAGS "${EGL_CFLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}")
check_c_source_compiles("
- #define EGL_API_FB
- #define MESA_EGL_NO_X11_HEADERS
- #define EGL_NO_X11
- #include <EGL/egl.h>
- #include <EGL/eglext.h>
- int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
+ #define EGL_API_FB
+ #define MESA_EGL_NO_X11_HEADERS
+ #define EGL_NO_X11
+ #include <EGL/egl.h>
+ #include <EGL/eglext.h>
+ int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
if(HAVE_VIDEO_OPENGL_EGL)
- set(SDL_VIDEO_OPENGL_EGL 1)
+ set(SDL_VIDEO_OPENGL_EGL 1)
endif()
endif()
endmacro()
# Requires:
-# - PkgCheckModules
-macro(CheckOpenGLESX11)
- CheckEGL()
- set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}")
- if(VIDEO_OPENGLES)
+# - nada
+macro(CheckOpenGL)
+ if(VIDEO_OPENGL)
check_c_source_compiles("
- #define EGL_API_FB
- #include <EGL/egl.h>
- int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL)
- if(HAVE_VIDEO_OPENGL_EGL)
- set(SDL_VIDEO_OPENGL_EGL 1)
+ #include <GL/gl.h>
+ #include <GL/glext.h>
+ int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
+ if(HAVE_VIDEO_OPENGL)
+ set(SDL_VIDEO_OPENGL 1)
+ set(SDL_VIDEO_RENDER_OGL 1)
endif()
+ endif()
+endmacro()
+
+# Requires:
+# - nada
+macro(CheckOpenGLES)
+ if(VIDEO_OPENGLES)
check_c_source_compiles("
- #include <GLES/gl.h>
- #include <GLES/glext.h>
- int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
+ #include <GLES/gl.h>
+ #include <GLES/glext.h>
+ int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V1)
if(HAVE_VIDEO_OPENGLES_V1)
set(HAVE_VIDEO_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES 1)
set(SDL_VIDEO_RENDER_OGL_ES 1)
endif()
check_c_source_compiles("
- #include <GLES2/gl2.h>
- #include <GLES2/gl2ext.h>
- int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
+ #include <GLES2/gl2.h>
+ #include <GLES2/gl2ext.h>
+ int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGLES_V2)
if(HAVE_VIDEO_OPENGLES_V2)
set(HAVE_VIDEO_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES2 1)
set(SDL_VIDEO_RENDER_OGL_ES2 1)
endif()
-
endif()
endmacro()