Skip to content

Commit 59be314

Browse files
committed
CMake: fix static linkage of SDL2 and use static SDL2 by default
1 parent eb3e7aa commit 59be314

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

CMake/Dependencies.cmake

+21-7
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ if(OGRE_BUILD_DEPENDENCIES AND NOT EXISTS ${OGREDEPS_PATH})
189189
execute_process(COMMAND ${CMAKE_COMMAND}
190190
-E make_directory ${PROJECT_BINARY_DIR}/SDL2-build)
191191
execute_process(COMMAND ${BUILD_COMMAND_COMMON}
192-
-DSDL_STATIC=FALSE
192+
-DSDL_STATIC=TRUE
193+
-DSDL_STATIC_PIC=TRUE
194+
-DSDL_SHARED=FALSE
193195
${PROJECT_BINARY_DIR}/SDL2-2.0.14
194196
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/SDL2-build)
195197
execute_process(COMMAND ${CMAKE_COMMAND}
@@ -336,12 +338,24 @@ if(NOT ANDROID AND NOT EMSCRIPTEN)
336338
# find script does not work in cross compilation environment
337339
find_package(SDL2 QUIET)
338340
macro_log_feature(SDL2_FOUND "SDL2" "Simple DirectMedia Library needed for input handling in samples" "https://www.libsdl.org/" FALSE "" "")
339-
if(SDL2_FOUND AND NOT TARGET SDL2::SDL2)
340-
add_library(SDL2::SDL2 INTERFACE IMPORTED)
341-
set_target_properties(SDL2::SDL2 PROPERTIES
342-
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
343-
INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}"
344-
)
341+
if(SDL2_FOUND)
342+
if(TARGET SDL2::SDL2-static)
343+
set_target_properties(SDL2::SDL2-static PROPERTIES IMPORTED_GLOBAL TRUE)
344+
add_library(SDL2::SDL2 ALIAS SDL2::SDL2-static)
345+
if(UNIX)
346+
# leaks -Wl,--no-undefined
347+
set_target_properties(SDL2::SDL2-static PROPERTIES
348+
IMPORTED_LINK_INTERFACE_LIBRARIES_RELWITHDEBINFO ""
349+
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG ""
350+
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE "")
351+
endif()
352+
elseif(NOT TARGET SDL2::SDL2)
353+
add_library(SDL2::SDL2 INTERFACE IMPORTED)
354+
set_target_properties(SDL2::SDL2 PROPERTIES
355+
INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}"
356+
INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}"
357+
)
358+
endif()
345359
endif()
346360

347361
find_package(Qt5 COMPONENTS Core Gui QUIET)

0 commit comments

Comments
 (0)