summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/CMakeLists.txt19
1 files changed, 19 insertions, 0 deletions
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 1545340aa8a8..cfa97023d281 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -389,6 +389,25 @@ endif()
if(MSVC)
# FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
+
+ # Remove any /M[DT][d] flags, and strip any definitions of _DEBUG.
+ # Since we're using CMAKE_MSVC_RUNTIME_LIBRARY (CMP0091 set to NEW),
+ # these options shouldn't be included in these flags variables. However,
+ # package managers that don't know which mechanism is used for passing
+ # CRT choice flags might be passing them both ways - which leads to
+ # duplicate CRT choice options. Thus make sure to strip out these flags
+ # from these variables, when we're forcing a CRT choice other than what
+ # the user requested here.
+ 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)
+ string(REGEX REPLACE "[/-]M[DT]d" "" ${flag_var} "${${flag_var}}")
+ string(REGEX REPLACE "[/-]MD" "" ${flag_var} "${${flag_var}}")
+ string(REGEX REPLACE "[/-]D_DEBUG" "" ${flag_var} "${${flag_var}}")
+ endforeach()
+
append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)