From e3095cc31e62d71552510fb2ba09da2721162804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 24 Mar 2026 20:46:05 +0100 Subject: [PATCH] CMake: adjustments to make find_package(Magnum OPTIONAL) work better. Right now, without find_package(Magnum REQUIRED), FindMagnum just continued after the FPHSA call even if the configure file wasn't found, leading to another error right below at file(READ). There's also a CMake policy push/pop and the newly added early return() would cause a PUSH happen without a corresponding POP. Move that below to fix this. --- modules/FindMagnum.cmake | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index b46263bfa..5c7f7a017 100644 --- a/modules/FindMagnum.cmake +++ b/modules/FindMagnum.cmake @@ -228,15 +228,6 @@ # 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}) @@ -279,6 +270,19 @@ if(NOT MAGNUM_INCLUDE_DIR) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Magnum REQUIRED_VARS MAGNUM_INCLUDE_DIR _MAGNUM_CONFIGURE_FILE) + # FPHSA may continue if find_package(Magnum) wasn't called with REQUIRED, + # exit here to avoid another error right at file(READ) below. + return() +endif() + +# CMake policies used by FindMagnum are popped again at the end. The PUSH is +# done only after the return() above to avoid exiting early without a POP. +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() # Read flags from configuration