1 get_cmake_property(ENABLED_LANGUAGES ENABLED_LANGUAGES)
2 include(CheckCXXCompilerFlag)
3 include(CheckCCompilerFlag)
5 if(NOT CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL .lib)
6 list(FIND ENABLED_LANGUAGES C index)
7 if(${index} GREATER -1)
8 check_c_compiler_flag(-static-libgcc ld-static-libgcc)
13 if(NOT CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL .lib)
14 list(FIND ENABLED_LANGUAGES CXX index)
15 if(${index} GREATER -1)
16 check_cxx_compiler_flag(-static-libstdc++ ld-static-libstdcxx)
21 function(string_append var)
23 string(FIND "${${var}}" "${arg}" index)
25 string(STRIP "${${var}} ${arg}" ${var})
28 set(${var} "${${var}}" PARENT_SCOPE)
31 function(target_link_static_3_13)
32 foreach(target ${ARGN})
34 get_property(LINK_FLAGS TARGET ${target} PROPERTY LINK_FLAGS)
36 string_append(LINK_FLAGS -static-libgcc)
38 if(ld-static-libstdcxx)
39 string_append(LINK_FLAGS -static-libstdc++)
41 set_property(TARGET ${target} PROPERTY LINK_FLAGS "${LINK_FLAGS}")
46 function(target_link_static_3_15)
47 foreach(target ${ARGN})
49 set_property(TARGET ${target} PROPERTY
50 MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>"
56 function(target_link_static)
57 if(CMAKE_VERSION VERSION_LESS 3.13)
58 target_link_static_3_13(${ARGN})
61 if(NOT CMAKE_VERSION VERSION_LESS 3.15)
62 target_link_static_3_15(${ARGN})
65 foreach(target ${ARGN})
66 if(target MATCHES "^INTERFACE|PUBLIC|PRIVATE")
71 target_link_options(${target} ${scope} -static-libgcc)
73 if(ld-static-libstdcxx)
74 target_link_options(${target} ${scope} $<$<COMPILE_LANGUAGE:CXX>:-static-libstdc++>)