From b10f02091306e8b05d6baeb5d7b536c75d681766 Mon Sep 17 00:00:00 2001 From: Pavel Rojtberg Date: Thu, 18 Mar 2021 23:14:43 +0100 Subject: [PATCH] CMake: fix static linkage of SDL2 and use static SDL2 by default --- CMake/Dependencies.cmake | 28 +++++++++++++++++++++------- PlugIns/Assimp/CMakeLists.txt | 6 +++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 138a22561eb..4ed7045ab78 100644 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -189,7 +189,9 @@ if(OGRE_BUILD_DEPENDENCIES AND NOT EXISTS ${OGREDEPS_PATH}) execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/SDL2-build) execute_process(COMMAND ${BUILD_COMMAND_COMMON} - -DSDL_STATIC=FALSE + -DSDL_STATIC=TRUE + -DSDL_STATIC_PIC=TRUE + -DSDL_SHARED=FALSE ${PROJECT_BINARY_DIR}/SDL2-2.0.14 WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/SDL2-build) execute_process(COMMAND ${CMAKE_COMMAND} @@ -336,12 +338,24 @@ if(NOT ANDROID AND NOT EMSCRIPTEN) # find script does not work in cross compilation environment find_package(SDL2 QUIET) macro_log_feature(SDL2_FOUND "SDL2" "Simple DirectMedia Library needed for input handling in samples" "https://www.libsdl.org/" FALSE "" "") - if(SDL2_FOUND AND NOT TARGET SDL2::SDL2) - add_library(SDL2::SDL2 INTERFACE IMPORTED) - set_target_properties(SDL2::SDL2 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" - INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}" - ) + if(SDL2_FOUND) + if(TARGET SDL2::SDL2-static) + set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE) + add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static) + if(UNIX) + # leaks -Wl,--no-undefined + set_target_properties(SDL2::SDL2-static PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES_RELWITHDEBINFO "" + IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG "" + IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "") + endif() + elseif(NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 INTERFACE IMPORTED) + set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}" + ) + endif() endif() find_package(Qt5 COMPONENTS Core Gui QUIET) diff --git a/PlugIns/Assimp/CMakeLists.txt b/PlugIns/Assimp/CMakeLists.txt index 99082440c34..01f34211853 100644 --- a/PlugIns/Assimp/CMakeLists.txt +++ b/PlugIns/Assimp/CMakeLists.txt @@ -8,7 +8,11 @@ target_include_directories(Codec_Assimp PUBLIC target_link_libraries(Codec_Assimp PUBLIC OgreMain PRIVATE fix::assimp) if(OGRE_BUILD_DEPENDENCIES) # hack to get our CI build going, despite horribly broken assimp cmake - target_link_libraries(Codec_Assimp PRIVATE ZLIB::ZLIB ${OGREDEPS_PATH}/lib/IrrXML.lib) + if(UNIX) + target_link_libraries(Codec_Assimp PUBLIC ${OGREDEPS_PATH}/lib/libIrrXML.a) + else() + target_link_libraries(Codec_Assimp PRIVATE ZLIB::ZLIB ${OGREDEPS_PATH}/lib/IrrXML.lib) + endif() endif() ogre_config_framework(Codec_Assimp)