Browse Source

CMake: make OpenGL_GL_PREFERENCE settable from outside.

pull/335/head
Vladimír Vondruš 7 years ago
parent
commit
687496fccb
  1. 8
      CMakeLists.txt
  2. 4
      doc/changelog.dox
  3. 43
      modules/FindMagnum.cmake
  4. 12
      src/Magnum/GL/CMakeLists.txt
  5. 6
      src/Magnum/Platform/CMakeLists.txt

8
CMakeLists.txt

@ -212,7 +212,13 @@ endif()
# Check dependencies
if(WITH_GL)
if(NOT TARGET_GLES OR TARGET_DESKTOP_GLES)
set(OpenGL_GL_PREFERENCE GLVND) # since CMake 3.11
# OpenGL library preference. Prefer to use GLVND, since that's the
# better approach nowadays, but allow the users to override it from
# outside in case it is broken for some reason (Nvidia drivers in
# Debian's testing (Buster) -- reported on 2019-04-09).
if(NOT CMAKE_VERSION VERSION_LESS 3.10 AND NOT OpenGL_GL_PREFERENCE)
set(OpenGL_GL_PREFERENCE GLVND)
endif()
find_package(OpenGL REQUIRED)
elseif(TARGET_GLES2)
find_package(OpenGLES2 REQUIRED)

4
doc/changelog.dox

@ -267,6 +267,10 @@ See also:
- Updated bundled GL headers to properly define the `GL_VERSION_*` macros to
avoid conflicting `GLintptr` and `GLsizeiptr` type definitions on Windows
when using Magnum together with Qt
- It's now possible to override CMake's
[OpenGL_GL_PREFERENCE](https://cmake.org/cmake/help/v3.11/module/FindOpenGL.html#linux-specific)
from outside on systems where GLVND doesn't work properly (before the build
scripts and `FindMagnum.cmake` always forced GLVND)
@subsection changelog-latest-bugfixes Bug fixes

43
modules/FindMagnum.cmake

@ -260,6 +260,14 @@ foreach(_magnumFlag ${_magnumFlags})
endif()
endforeach()
# OpenGL library preference. Prefer to use GLVND, since that's the better
# approach nowadays, but allow the users to override it from outside in case
# it is broken for some reason (Nvidia drivers in Debian's testing (Buster) --
# reported on 2019-04-09).
if(NOT CMAKE_VERSION VERSION_LESS 3.10 AND NOT OpenGL_GL_PREFERENCE)
set(OpenGL_GL_PREFERENCE GLVND)
endif()
# Base Magnum library
if(NOT TARGET Magnum::Magnum)
add_library(Magnum::Magnum UNKNOWN IMPORTED)
@ -618,12 +626,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# our own EGL find module, which makes things simpler. The
# upstream FindOpenGL is anything but simple. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
if(MAGNUM_TARGET_GL)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES))
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
@ -656,12 +665,13 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# our own EGL find module, which makes things simpler. The
# upstream FindOpenGL is anything but simple. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
if(MAGNUM_TARGET_GL)
if(CORRADE_TARGET_UNIX AND NOT CORRADE_TARGET_APPLE AND (NOT MAGNUM_TARGET_GLES OR MAGNUM_TARGET_DESKTOP_GLES))
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND
PROPERTY INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
@ -683,10 +693,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# With GLVND (since CMake 3.11) we need to explicitly link to
# GLX because libOpenGL doesn't provide it. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::GLX)
endif()
@ -736,10 +747,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# With GLVND (since CMake 3.11) we need to explicitly link to
# GLX because libOpenGL doesn't provide it. Also can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. If GLVND is not used, link to X11 instead.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. If GLVND is not used, link to X11 instead. Also
# can't just check for OPENGL_opengl_LIBRARY because that's set
# even if OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::GLX)
else()
@ -780,10 +792,11 @@ foreach(_component ${Magnum_FIND_COMPONENTS})
# imported target. Otherwise (and also on all systems except
# Linux) link to the classic libGL. Can't use
# OpenGL_OpenGL_FOUND, because that one is set also if GLVND is
# *not* found. WTF.
set(OpenGL_GL_PREFERENCE GLVND)
# *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if
# OpenGL_GL_PREFERENCE is explicitly set to LEGACY.
find_package(OpenGL REQUIRED)
if(OPENGL_opengl_LIBRARY)
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set_property(TARGET Magnum::${_component} APPEND PROPERTY
INTERFACE_LINK_LIBRARIES OpenGL::OpenGL)
else()

12
src/Magnum/GL/CMakeLists.txt

@ -220,8 +220,10 @@ if(NOT TARGET_GLES OR TARGET_DESKTOP_GLES)
# If the GLVND library (CMake 3.11+) was found, link to the imported
# target. Otherwise (and also on all systems except Linux) link to the
# classic libGL. Can't use OpenGL_OpenGL_FOUND, because that one is set
# also if GLVND is *not* found. WTF.
if(OPENGL_opengl_LIBRARY)
# also if GLVND is *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if OpenGL_GL_PREFERENCE is
# explicitly set to LEGACY.
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
target_link_libraries(MagnumGL PUBLIC OpenGL::OpenGL)
else()
target_link_libraries(MagnumGL PUBLIC ${OPENGL_gl_LIBRARY})
@ -308,8 +310,10 @@ if(BUILD_TESTS)
# If the GLVND library (CMake 3.11+) was found, link to the imported
# target. Otherwise (and also on all systems except Linux) link to the
# classic libGL. Can't use OpenGL_OpenGL_FOUND, because that one is set
# also if GLVND is *not* found. WTF.
if(OPENGL_opengl_LIBRARY)
# also if GLVND is *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if OpenGL_GL_PREFERENCE
# is explicitly set to LEGACY.
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
target_link_libraries(MagnumGLTestLib PUBLIC OpenGL::OpenGL)
else()
target_link_libraries(MagnumGLTestLib PUBLIC ${OPENGL_gl_LIBRARY})

6
src/Magnum/Platform/CMakeLists.txt

@ -106,8 +106,10 @@ if((WITH_GLFWAPPLICATION OR WITH_SDL2APPLICATION) AND TARGET_GL)
# to link to GLX explicitly. Otherwise (and also on all systems except
# Linux) the transitive dependency to classic GL lib from MagnumGL is
# enough. Can't use OpenGL_OpenGL_FOUND, because that one is set also
# if GLVND is *not* found. WTF.
if(OPENGL_opengl_LIBRARY)
# if GLVND is *not* found. WTF. Also can't just check for
# OPENGL_opengl_LIBRARY because that's set even if OpenGL_GL_PREFERENCE
# is explicitly set to LEGACY.
if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND)
set(MagnumSomeContext_LIBRARY OpenGL::GLX)
endif()
elseif(MAGNUM_TARGET_GLES AND NOT CORRADE_TARGET_EMSCRIPTEN)

Loading…
Cancel
Save