2018-02-08 00:15:47 +08:00
|
|
|
# Use statically or dynamically linked CRT?
|
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
if(NOT MSVC)
|
2012-02-03 20:33:48 +08:00
|
|
|
message(FATAL_ERROR "CRT options are available only for MSVC")
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|
|
|
|
|
2015-02-21 00:47:45 +08:00
|
|
|
# Removing LNK4075 warnings for debug WinRT builds
|
|
|
|
# "LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification"
|
|
|
|
# "LNK4075: ignoring '/INCREMENTAL' due to '/OPT:REF' specification"
|
|
|
|
if(MSVC AND WINRT)
|
|
|
|
# Optional verification checks since we don't know existing contents of variables below
|
|
|
|
string(REPLACE "/OPT:ICF " "/OPT:NOICF " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/OPT:REF " "/OPT:NOREF " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/INCREMENTAL:YES " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
|
|
|
|
|
|
|
|
string(REPLACE "/OPT:ICF " "/OPT:NOICF " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
|
2018-02-13 22:34:40 +08:00
|
|
|
string(REPLACE "/OPT:REF " "/OPT:NOREF" CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
|
2015-02-21 00:47:45 +08:00
|
|
|
string(REPLACE "/INCREMENTAL:YES " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG}")
|
|
|
|
|
|
|
|
string(REPLACE "/OPT:ICF " "/OPT:NOICF " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/OPT:REF " "/OPT:NOREF " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/INCREMENTAL:YES " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
|
|
|
string(REPLACE "/INCREMENTAL " "/INCREMENTAL:NO " CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}")
|
|
|
|
|
|
|
|
# Mandatory
|
|
|
|
set(CMAKE_MODULE_LINKER_FLAGS_DEBUG "${CMAKE_MODULE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
|
2013-08-15 21:01:38 +08:00
|
|
|
endif()
|
2013-07-19 17:43:05 +08:00
|
|
|
|
2017-03-25 06:28:43 +08:00
|
|
|
# Ignore warning: This object file does not define any previously undefined public symbols, ...
|
|
|
|
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /IGNORE:4221")
|
|
|
|
|
2022-11-29 14:25:26 +08:00
|
|
|
if(POLICY CMP0091)
|
|
|
|
cmake_policy(GET CMP0091 MSVC_RUNTIME_SET_BY_ABSTRACTION)
|
|
|
|
endif()
|
|
|
|
|
2012-02-03 19:26:49 +08:00
|
|
|
if(NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)
|
2022-11-29 14:25:26 +08:00
|
|
|
if(MSVC_RUNTIME_SET_BY_ABSTRACTION STREQUAL "NEW")
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
else()
|
|
|
|
foreach(flag_var
|
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
|
|
if(${flag_var} MATCHES "/MD")
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
|
|
|
|
endif()
|
|
|
|
if(${flag_var} MATCHES "/MDd")
|
|
|
|
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
|
|
|
|
endif()
|
|
|
|
endforeach(flag_var)
|
|
|
|
endif()
|
2012-02-03 19:26:49 +08:00
|
|
|
|
2017-03-25 06:28:43 +08:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /NODEFAULTLIB:atlthunk.lib")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib")
|
2012-02-03 19:26:49 +08:00
|
|
|
else()
|
2022-11-29 14:25:26 +08:00
|
|
|
if(NOT MSVC_RUNTIME_SET_BY_ABSTRACTION STREQUAL "NEW")
|
|
|
|
foreach(flag_var
|
|
|
|
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
|
|
if(${flag_var} MATCHES "/MT")
|
|
|
|
string(REGEX REPLACE "/MT" "/MD" ${flag_var} "${${flag_var}}")
|
|
|
|
endif()
|
|
|
|
if(${flag_var} MATCHES "/MTd")
|
|
|
|
string(REGEX REPLACE "/MTd" "/MDd" ${flag_var} "${${flag_var}}")
|
|
|
|
endif()
|
|
|
|
endforeach(flag_var)
|
|
|
|
endif()
|
2012-02-03 19:26:49 +08:00
|
|
|
endif()
|