Browse Source

CMake: set a CMake policy instead of setting OpenGL_GL_PREFERENCE.

The policy makes it work for all find_package(OpenGL) calls,
possibly even in subprojects, without having to copypaste the same
OpenGL_GL_PREFERENCE override code to each.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
19f9ba10ad
  1. 13
      CMakeLists.txt
  2. 20
      modules/FindMagnum.cmake

13
CMakeLists.txt

@ -50,6 +50,12 @@ endif()
if(POLICY CMP0144) if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW) cmake_policy(SET CMP0144 NEW)
endif() endif()
# Prefer GLVND when finding OpenGL. If this causes problems (known to fail with
# NVidia drivers in Debian Buster, reported on 2019-04-09), users can override
# this by setting OpenGL_GL_PREFERENCE to LEGACY.
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
# Superprojects can use just set(MAGNUM_WITH_BLAH ON) without FORCE CACHE on # Superprojects can use just set(MAGNUM_WITH_BLAH ON) without FORCE CACHE on
# 3.13+ # 3.13+
if(POLICY CMP0077) if(POLICY CMP0077)
@ -563,13 +569,6 @@ endif()
# Check dependencies # Check dependencies
if(MAGNUM_WITH_GL) if(MAGNUM_WITH_GL)
if(NOT MAGNUM_TARGET_GLES OR (MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_EGL AND NOT CORRADE_TARGET_IOS)) if(NOT MAGNUM_TARGET_GLES OR (MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_EGL AND NOT CORRADE_TARGET_IOS))
# 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) find_package(OpenGL REQUIRED)
elseif(MAGNUM_TARGET_GLES2) elseif(MAGNUM_TARGET_GLES2)
find_package(OpenGLES2 REQUIRED) find_package(OpenGLES2 REQUIRED)

20
modules/FindMagnum.cmake

@ -227,6 +227,15 @@
# DEALINGS IN THE SOFTWARE. # DEALINGS IN THE SOFTWARE.
# #
# CMake policies used by FindMagnum are popped again at the end.
cmake_policy(PUSH)
# Prefer GLVND when finding OpenGL. If this causes problems (known to fail with
# NVidia drivers in Debian Buster, reported on 2019-04-09), users can override
# this by setting OpenGL_GL_PREFERENCE to LEGACY.
if(POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif()
# Corrade library dependencies # Corrade library dependencies
set(_MAGNUM_CORRADE_DEPENDENCIES ) set(_MAGNUM_CORRADE_DEPENDENCIES )
foreach(_magnum_component ${Magnum_FIND_COMPONENTS}) foreach(_magnum_component ${Magnum_FIND_COMPONENTS})
@ -309,14 +318,6 @@ if(MAGNUM_BUILD_DEPRECATED)
endif() endif()
endif() endif()
# 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 # Base Magnum library
if(NOT TARGET Magnum::Magnum) if(NOT TARGET Magnum::Magnum)
add_library(Magnum::Magnum UNKNOWN IMPORTED) add_library(Magnum::Magnum UNKNOWN IMPORTED)
@ -1292,3 +1293,6 @@ if(MAGNUM_PLUGINS_RELEASE_DIR)
set(MAGNUM_PLUGINS_SCENECONVERTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/sceneconverters) set(MAGNUM_PLUGINS_SCENECONVERTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/sceneconverters)
set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/audioimporters) set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/audioimporters)
endif() endif()
# Resets CMake policies set at the top of the file to not affect other code.
cmake_policy(POP)

Loading…
Cancel
Save