Added missing SFML_USE_STATIC_STD_LIBS checks to CMake configuration.

This commit is contained in:
binary1248 2023-10-03 05:52:40 +02:00 committed by Lukas Dürrenberger
parent 5d0996906b
commit 8c9c5c5b99
3 changed files with 23 additions and 13 deletions

View File

@ -20,11 +20,17 @@ endmacro()
# example: sfml_set_stdlib(sfml-system) # example: sfml_set_stdlib(sfml-system)
function(sfml_set_stdlib target) function(sfml_set_stdlib target)
# for gcc on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled # for gcc on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC) if(SFML_OS_WINDOWS)
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM) if(SFML_COMPILER_GCC)
target_link_libraries(${target} PRIVATE "-static-libgcc" "-static-libstdc++") if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM) target_link_libraries(${target} PRIVATE "-static-libgcc" "-static-libstdc++")
target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++") elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++")
endif()
elseif(SFML_COMPILER_MSVC)
if(SFML_USE_STATIC_STD_LIBS)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif() endif()
endif() endif()
endfunction() endfunction()
@ -134,10 +140,6 @@ macro(sfml_add_library module)
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s) set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s) set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
set_target_properties(${target} PROPERTIES RELWITHDEBINFO_POSTFIX -s) set_target_properties(${target} PROPERTIES RELWITHDEBINFO_POSTFIX -s)
if(SFML_USE_STATIC_STD_LIBS)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
endif() endif()
# set the version and soversion of the target (for compatible systems -- mostly Linuxes) # set the version and soversion of the target (for compatible systems -- mostly Linuxes)
@ -289,10 +291,6 @@ macro(sfml_add_example target)
add_executable(${target} ${target_input}) add_executable(${target} ${target_input})
endif() endif()
if(SFML_USE_STATIC_STD_LIBS)
set_property(TARGET ${target} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# enable precompiled headers # enable precompiled headers
if (SFML_ENABLE_PCH) if (SFML_ENABLE_PCH)
message(VERBOSE "enabling PCH for SFML example '${target}'") message(VERBOSE "enabling PCH for SFML example '${target}'")
@ -349,6 +347,9 @@ function(sfml_add_test target SOURCES DEPENDS)
# set the target's folder (for IDEs that support it, e.g. Visual Studio) # set the target's folder (for IDEs that support it, e.g. Visual Studio)
set_target_properties(${target} PROPERTIES FOLDER "Tests") set_target_properties(${target} PROPERTIES FOLDER "Tests")
# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib(${target})
# link the target to its SFML dependencies # link the target to its SFML dependencies
target_link_libraries(${target} PRIVATE ${DEPENDS} sfml-test-main) target_link_libraries(${target} PRIVATE ${DEPENDS} sfml-test-main)

View File

@ -33,6 +33,11 @@ target_include_directories(sfml-test-main PUBLIC TestUtilities)
target_link_libraries(sfml-test-main PUBLIC SFML::System Catch2::Catch2WithMain) target_link_libraries(sfml-test-main PUBLIC SFML::System Catch2::Catch2WithMain)
set_target_warnings(sfml-test-main) set_target_warnings(sfml-test-main)
# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib(Catch2)
sfml_set_stdlib(Catch2WithMain)
sfml_set_stdlib(sfml-test-main)
sfml_set_option(SFML_RUN_DISPLAY_TESTS ON BOOL "TRUE to run tests that require a display, FALSE to ignore it") sfml_set_option(SFML_RUN_DISPLAY_TESTS ON BOOL "TRUE to run tests that require a display, FALSE to ignore it")
if(SFML_RUN_DISPLAY_TESTS) if(SFML_RUN_DISPLAY_TESTS)
target_compile_definitions(sfml-test-main PRIVATE SFML_RUN_DISPLAY_TESTS) target_compile_definitions(sfml-test-main PRIVATE SFML_RUN_DISPLAY_TESTS)

View File

@ -18,3 +18,7 @@ endif()
add_executable(test-sfml-install Install.cpp) add_executable(test-sfml-install Install.cpp)
target_link_libraries(test-sfml-install PRIVATE SFML::Graphics SFML::Network SFML::Audio) target_link_libraries(test-sfml-install PRIVATE SFML::Graphics SFML::Network SFML::Audio)
if(SFML_USE_STATIC_STD_LIBS)
set_target_properties(test-sfml-install PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()