From a9174def9b9149c9bd55d90c8ba23452b83b88ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 18 Oct 2023 21:19:09 +0200 Subject: [PATCH] modules: update Magnum Find modules. --- modules/FindCorrade.cmake | 5 +++-- modules/FindEGL.cmake | 8 ++++---- modules/FindMagnum.cmake | 37 ++++++++++++++++++++++++------------- modules/FindOpenGLES2.cmake | 2 +- modules/FindOpenGLES3.cmake | 2 +- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/modules/FindCorrade.cmake b/modules/FindCorrade.cmake index 969c68c..7d2e725 100644 --- a/modules/FindCorrade.cmake +++ b/modules/FindCorrade.cmake @@ -474,8 +474,9 @@ foreach(_component ${Corrade_FIND_COMPONENTS}) # Interconnect library if(_component STREQUAL Interconnect) # Disable /OPT:ICF on MSVC, which merges functions with identical - # contents and thus breaks signal comparison - if(CORRADE_TARGET_WINDOWS AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # contents and thus breaks signal comparison. Same case is for + # clang-cl which uses the MSVC linker by default. + if(CORRADE_TARGET_WINDOWS AND (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) if(CMAKE_VERSION VERSION_LESS 3.13) set_property(TARGET Corrade::${_component} PROPERTY INTERFACE_LINK_LIBRARIES "-OPT:NOICF,REF") diff --git a/modules/FindEGL.cmake b/modules/FindEGL.cmake index eda9a29..66a4c54 100644 --- a/modules/FindEGL.cmake +++ b/modules/FindEGL.cmake @@ -38,10 +38,10 @@ # DEALINGS IN THE SOFTWARE. # -# Under Emscripten, GL is linked implicitly. With MINIMAL_RUNTIME you need to -# specify -lGL. Simply set the library name to that. +# Under Emscripten, EGL is linked implicitly. With MINIMAL_RUNTIME you need to +# specify -lEGL. Simply set the library name to that. if(CORRADE_TARGET_EMSCRIPTEN) - set(EGL_LIBRARY GL CACHE STRING "Path to a library." FORCE) + set(EGL_LIBRARY EGL CACHE STRING "Path to a library." FORCE) else() find_library(EGL_LIBRARY NAMES EGL @@ -69,7 +69,7 @@ if(NOT TARGET EGL::EGL) # Work around BUGGY framework support on macOS. Do this also in case of # Emscripten, since there we don't have a location either. # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if((APPLE AND ${EGL_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) + if((APPLE AND EGL_LIBRARY MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(EGL::EGL INTERFACE IMPORTED) set_property(TARGET EGL::EGL APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${EGL_LIBRARY}) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index c8c5e87..5662389 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -227,6 +227,15 @@ # 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 set(_MAGNUM_CORRADE_DEPENDENCIES ) foreach(_magnum_component ${Magnum_FIND_COMPONENTS}) @@ -309,14 +318,6 @@ if(MAGNUM_BUILD_DEPRECATED) 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 if(NOT TARGET Magnum::Magnum) add_library(Magnum::Magnum UNKNOWN IMPORTED) @@ -726,7 +727,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) INTERFACE_LINK_LIBRARIES ${CMAKE_DL_LIBS}) endif() - # With GLVND (since CMake 3.11) we need to explicitly link to + # With GLVND (since CMake 3.10) we need to explicitly link to # GLX/EGL because libOpenGL doesn't provide it. For EGL we have # our own EGL find module, which makes things simpler. The # upstream FindOpenGL is anything but simple. Also can't use @@ -773,7 +774,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) INTERFACE_LINK_LIBRARIES "--js-library ${MAGNUM_PLATFORM_JS}") endif() - # With GLVND (since CMake 3.11) we need to explicitly link to + # With GLVND (since CMake 3.10) we need to explicitly link to # GLX/EGL because libOpenGL doesn't provide it. For EGL we have # our own EGL find module, which makes things simpler. The # upstream FindOpenGL is anything but simple. Also can't use @@ -803,12 +804,19 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) set_property(TARGET Magnum::${_component} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${X11_LIBRARIES}) - # With GLVND (since CMake 3.11) we need to explicitly link to + # With GLVND (since CMake 3.10) 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. 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_GLES and MAGNUM_TARGET_EGL is set, these + # applications can be built only if GLVND is available as + # otherwise there would be a conflict between libGL and + # libGLES. Thus, if GLVND is not available, it won't link + # libGLX here, but that shouldn't be a problem since the + # application library won't exist either. find_package(OpenGL) if(OPENGL_opengl_LIBRARY AND OpenGL_GL_PREFERENCE STREQUAL GLVND) set_property(TARGET Magnum::${_component} APPEND PROPERTY @@ -851,7 +859,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) # GLX context dependencies if(_component STREQUAL GlxContext) - # With GLVND (since CMake 3.11) we need to explicitly link to + # With GLVND (since CMake 3.10) 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. Also @@ -890,7 +898,7 @@ foreach(_component ${Magnum_FIND_COMPONENTS}) # GL library elseif(_component STREQUAL GL) if(NOT MAGNUM_TARGET_GLES OR (MAGNUM_TARGET_GLES AND NOT MAGNUM_TARGET_EGL AND NOT CORRADE_TARGET_IOS)) - # If the GLVND library (CMake 3.11+) was found, link to the + # If the GLVND library (CMake 3.10+) 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 @@ -1292,3 +1300,6 @@ if(MAGNUM_PLUGINS_RELEASE_DIR) set(MAGNUM_PLUGINS_SCENECONVERTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/sceneconverters) set(MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_DIR ${MAGNUM_PLUGINS_RELEASE_DIR}/audioimporters) endif() + +# Resets CMake policies set at the top of the file to not affect other code. +cmake_policy(POP) diff --git a/modules/FindOpenGLES2.cmake b/modules/FindOpenGLES2.cmake index e3d022c..ef1da66 100644 --- a/modules/FindOpenGLES2.cmake +++ b/modules/FindOpenGLES2.cmake @@ -64,7 +64,7 @@ if(NOT TARGET OpenGLES2::OpenGLES2) # Work around BUGGY framework support on macOS. Do this also in case of # Emscripten, since there we don't have a location either. # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if((CORRADE_TARGET_APPLE AND ${OPENGLES2_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) + if((CORRADE_TARGET_APPLE AND OPENGLES2_LIBRARY MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(OpenGLES2::OpenGLES2 INTERFACE IMPORTED) set_property(TARGET OpenGLES2::OpenGLES2 APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${OPENGLES2_LIBRARY}) diff --git a/modules/FindOpenGLES3.cmake b/modules/FindOpenGLES3.cmake index 5c41acc..4d79aff 100644 --- a/modules/FindOpenGLES3.cmake +++ b/modules/FindOpenGLES3.cmake @@ -69,7 +69,7 @@ if(NOT TARGET OpenGLES3::OpenGLES3) # Work around BUGGY framework support on macOS. Do this also in case of # Emscripten, since there we don't have a location either. # http://public.kitware.com/pipermail/cmake/2016-April/063179.html - if((CORRADE_TARGET_APPLE AND ${OPENGLES3_LIBRARY} MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) + if((CORRADE_TARGET_APPLE AND OPENGLES3_LIBRARY MATCHES "\\.framework$") OR CORRADE_TARGET_EMSCRIPTEN) add_library(OpenGLES3::OpenGLES3 INTERFACE IMPORTED) set_property(TARGET OpenGLES3::OpenGLES3 APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${OPENGLES3_LIBRARY})