CMake: Generic check for desktop GL and EGL on Linux systems

This commit is contained in:
Nicolas Caramelli 2021-05-06 15:43:16 +02:00 committed by Sam Lantinga
parent fd121b5ec0
commit 6a2af48ad7
2 changed files with 55 additions and 73 deletions

View file

@ -1202,14 +1202,14 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS)
CheckRPI() CheckRPI()
CheckX11() CheckX11()
CheckDirectFB() CheckDirectFB()
CheckOpenGLX11() # Need to check for EGL first because KMSDRM and Wayland depends on it.
CheckOpenGLESX11() CheckEGL()
CheckKMSDRM()
CheckGLX()
CheckOpenGL()
CheckOpenGLES()
CheckWayland() CheckWayland()
CheckVivante() CheckVivante()
# Need to check EGL before checking KMSDRM because KMSDRM depends on it.
CheckEGLKMSDRM()
CheckKMSDRM()
CheckOpenGLKMSDRM()
endif() endif()
if(UNIX) if(UNIX)

View file

@ -593,6 +593,10 @@ macro(CheckX11)
set(CMAKE_REQUIRED_LIBRARIES) set(CMAKE_REQUIRED_LIBRARIES)
endif() endif()
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() endmacro()
macro(WaylandProtocolGen _SCANNER _CODE_MODE _XML _PROTL) 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 wayland-client wayland-scanner wayland-egl wayland-cursor egl xkbcommon)
pkg_check_modules(WAYLAND_SCANNER_1_15 "wayland-scanner>=1.15") pkg_check_modules(WAYLAND_SCANNER_1_15 "wayland-scanner>=1.15")
if(WAYLAND_FOUND) if(WAYLAND_FOUND AND HAVE_VIDEO_OPENGL_EGL)
execute_process( execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=wayland_scanner wayland-scanner
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
@ -777,36 +781,15 @@ macro(CheckVivante)
endif(VIDEO_VIVANTE) endif(VIDEO_VIVANTE)
endmacro(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: # Requires:
# - nada # - nada
macro(CheckOpenGLX11) macro(CheckGLX)
if(VIDEO_OPENGL) if(VIDEO_OPENGL)
check_c_source_compiles(" check_c_source_compiles("
#include <GL/gl.h>
#include <GL/glx.h> #include <GL/glx.h>
int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL) int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL_GLX)
if(HAVE_VIDEO_OPENGL_GLX)
if(HAVE_VIDEO_OPENGL)
set(HAVE_VIDEO_OPENGL TRUE)
set(SDL_VIDEO_OPENGL 1)
set(SDL_VIDEO_OPENGL_GLX 1) set(SDL_VIDEO_OPENGL_GLX 1)
set(SDL_VIDEO_RENDER_OGL 1)
endif() endif()
endif() endif()
endmacro() endmacro()
@ -814,15 +797,9 @@ endmacro()
# Requires: # Requires:
# - PkgCheckModules # - PkgCheckModules
macro(CheckEGL) macro(CheckEGL)
if (VIDEO_OPENGL OR VIDEO_OPENGLES)
pkg_check_modules(EGL egl) pkg_check_modules(EGL egl)
string(REPLACE "-D_THREAD_SAFE;" "-D_THREAD_SAFE=1;" EGL_CFLAGS "${EGL_CFLAGS}") 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()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}")
check_c_source_compiles(" check_c_source_compiles("
#define EGL_API_FB #define EGL_API_FB
@ -838,18 +815,24 @@ macro(CheckEGLKMSDRM)
endmacro() endmacro()
# Requires: # Requires:
# - PkgCheckModules # - nada
macro(CheckOpenGLESX11) macro(CheckOpenGL)
CheckEGL() if(VIDEO_OPENGL)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${EGL_CFLAGS}")
if(VIDEO_OPENGLES)
check_c_source_compiles(" check_c_source_compiles("
#define EGL_API_FB #include <GL/gl.h>
#include <EGL/egl.h> #include <GL/glext.h>
int main (int argc, char** argv) {}" HAVE_VIDEO_OPENGL_EGL) int main(int argc, char** argv) {}" HAVE_VIDEO_OPENGL)
if(HAVE_VIDEO_OPENGL_EGL) if(HAVE_VIDEO_OPENGL)
set(SDL_VIDEO_OPENGL_EGL 1) set(SDL_VIDEO_OPENGL 1)
set(SDL_VIDEO_RENDER_OGL 1)
endif() endif()
endif()
endmacro()
# Requires:
# - nada
macro(CheckOpenGLES)
if(VIDEO_OPENGLES)
check_c_source_compiles(" check_c_source_compiles("
#include <GLES/gl.h> #include <GLES/gl.h>
#include <GLES/glext.h> #include <GLES/glext.h>
@ -868,7 +851,6 @@ macro(CheckOpenGLESX11)
set(SDL_VIDEO_OPENGL_ES2 1) set(SDL_VIDEO_OPENGL_ES2 1)
set(SDL_VIDEO_RENDER_OGL_ES2 1) set(SDL_VIDEO_RENDER_OGL_ES2 1)
endif() endif()
endif() endif()
endmacro() endmacro()