From 1d2796baed09a92781d9b116397813b4dac73b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 31 Oct 2023 16:24:00 +0100 Subject: [PATCH] CMake: avoid installed Magnum headers being picked over local ones. If Magnum and Corrade get installed into the same directory, target_include_directories() or target_link_libraries() with Corrade before Magnum will result in the (usually stale) installed Magnum headers being picked over the local ones. Which is unwanted, so try to always put the local Magnum include path first. Tested manually by installing to an arbitrary location and editing configure.h to contain an #error. That failed for the Text library, and with these changes it now doesn't fail anymore, but that's not a guarantee that I managed to fix all such cases. --- src/Magnum/Audio/CMakeLists.txt | 8 ++++++-- src/Magnum/GL/CMakeLists.txt | 6 ++++-- src/Magnum/Text/CMakeLists.txt | 11 ++++++++--- src/Magnum/Trade/CMakeLists.txt | 2 ++ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Magnum/Audio/CMakeLists.txt b/src/Magnum/Audio/CMakeLists.txt index 293f89c80..14428988f 100644 --- a/src/Magnum/Audio/CMakeLists.txt +++ b/src/Magnum/Audio/CMakeLists.txt @@ -75,8 +75,10 @@ add_library(MagnumAudioObjects OBJECT ${MagnumAudio_SRCS} ${MagnumAudio_HEADERS}) target_include_directories(MagnumAudioObjects PUBLIC - $ $ + # Include dependencies after Magnum itself, to avoid stale installed Magnum + # headers being preferred over the project-local ones + $ $) if(NOT MAGNUM_BUILD_STATIC) target_compile_definitions(MagnumAudioObjects PRIVATE "MagnumAudioObjects_EXPORTS") @@ -178,7 +180,6 @@ if(MAGNUM_BUILD_TESTS) ${MagnumAudio_GracefulAssert_SRCS}) target_compile_definitions(MagnumAudioTestLib PRIVATE "CORRADE_GRACEFUL_ASSERT" "MagnumAudio_EXPORTS") - target_include_directories(MagnumAudioTestLib PUBLIC ${OPENAL_INCLUDE_DIR}) set_target_properties(MagnumAudioTestLib PROPERTIES DEBUG_POSTFIX "-d") if(MAGNUM_BUILD_STATIC_PIC) set_target_properties(MagnumAudioTestLib PROPERTIES POSITION_INDEPENDENT_CODE ON) @@ -187,6 +188,9 @@ if(MAGNUM_BUILD_TESTS) Magnum Corrade::PluginManager OpenAL::OpenAL) + # Include dependencies after Magnum itself, to avoid stale installed Magnum + # headers being preferred over the project-local ones + target_include_directories(MagnumAudioTestLib PUBLIC ${OPENAL_INCLUDE_DIR}) if(MAGNUM_WITH_SCENEGRAPH) target_link_libraries(MagnumAudioTestLib PUBLIC MagnumSceneGraph) endif() diff --git a/src/Magnum/GL/CMakeLists.txt b/src/Magnum/GL/CMakeLists.txt index bdee9c60f..5d9ec947c 100644 --- a/src/Magnum/GL/CMakeLists.txt +++ b/src/Magnum/GL/CMakeLists.txt @@ -264,9 +264,11 @@ if(MAGNUM_WITH_OPENGLTESTER) # Assuming that PIC is not needed because the Tester lib is always linked # to the executable and not to any intermediate shared lib target_include_directories(MagnumOpenGLTesterObjects PUBLIC - $ $ - $) + $ + # Include dependencies after Magnum itself, to avoid stale installed + # headers being preferred over the project-local ones + $) add_library(MagnumOpenGLTester STATIC $ diff --git a/src/Magnum/Text/CMakeLists.txt b/src/Magnum/Text/CMakeLists.txt index 6e593b9f6..914d756a9 100644 --- a/src/Magnum/Text/CMakeLists.txt +++ b/src/Magnum/Text/CMakeLists.txt @@ -85,11 +85,14 @@ add_library(MagnumTextObjects OBJECT ${MagnumText_HEADERS} ${MagnumText_PRIVATE_HEADERS}) target_include_directories(MagnumTextObjects PUBLIC - $ $) if(MAGNUM_TARGET_GL) target_include_directories(MagnumTextObjects PUBLIC $) endif() +# Include dependencies after Magnum itself, to avoid stale installed Magnum +# headers being preferred over the project-local ones +target_include_directories(MagnumTextObjects PUBLIC + $) if(NOT MAGNUM_BUILD_STATIC) target_compile_definitions(MagnumTextObjects PRIVATE "MagnumTextObjects_EXPORTS") endif() @@ -109,11 +112,13 @@ elseif(MAGNUM_BUILD_STATIC_PIC) endif() target_link_libraries(MagnumText PUBLIC Magnum - MagnumTextureTools - Corrade::PluginManager) + MagnumTextureTools) if(MAGNUM_TARGET_GL) target_link_libraries(MagnumText PUBLIC MagnumGL) endif() +# Include dependencies after Magnum itself, to avoid stale installed Magnum +# headers being preferred over the project-local ones +target_link_libraries(MagnumText PUBLIC Corrade::PluginManager) install(TARGETS MagnumText RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} diff --git a/src/Magnum/Trade/CMakeLists.txt b/src/Magnum/Trade/CMakeLists.txt index 124615509..e480079dd 100644 --- a/src/Magnum/Trade/CMakeLists.txt +++ b/src/Magnum/Trade/CMakeLists.txt @@ -123,6 +123,8 @@ add_library(MagnumTradeObjects OBJECT ${MagnumTrade_PRIVATE_HEADERS}) target_include_directories(MagnumTradeObjects PUBLIC $ + # Include dependencies after Magnum itself, to avoid stale installed + # headers being preferred over the project-local ones $) if(NOT MAGNUM_BUILD_STATIC) target_compile_definitions(MagnumTradeObjects PRIVATE "MagnumTradeObjects_EXPORTS")