Skip to content

Commit 0a2d7da

Browse files
mstorsjotru
authored andcommitted
[compiler-rt] Reinstate removal of CRT choice flags from CMAKE_*_FLAGS* (#67935)
This reverts one part of commit 9f4dfcb, with a modified comment added about the code. Ideally, this would only be reinstated temporarily - but given the situation in vcpkg, it looks likely that they would keep passing the duplicate options for quite some time. The conflicting CRT choice usually are benign but only would cause warnings about one option overriding the other, if passing e.g. "/MDd /MT". However when vcpkg currently sets these options in CMAKE_*_FLAGS_DEBUG, it passes the redundant option /D_DEBUG; thus the compiler finally ends up with e.g. "/D_DEBUG /MDd /MT", which has the effect of defining _DEBUG while using a release mode CRT, which allegedly breaks the build. There's a PR up for removing this redundant /D_DEBUG option in vcpkg in microsoft/vcpkg#34123. With that in place, this change wouldn't be strictly needed. (cherry picked from commit 7bc09a4)
1 parent 098e653 commit 0a2d7da

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,25 @@ endif()
389389
if(MSVC)
390390
# FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
391391
set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
392+
393+
# Remove any /M[DT][d] flags, and strip any definitions of _DEBUG.
394+
# Since we're using CMAKE_MSVC_RUNTIME_LIBRARY (CMP0091 set to NEW),
395+
# these options shouldn't be included in these flags variables. However,
396+
# package managers that don't know which mechanism is used for passing
397+
# CRT choice flags might be passing them both ways - which leads to
398+
# duplicate CRT choice options. Thus make sure to strip out these flags
399+
# from these variables, when we're forcing a CRT choice other than what
400+
# the user requested here.
401+
foreach(flag_var
402+
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
403+
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
404+
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
405+
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
406+
string(REGEX REPLACE "[/-]M[DT]d" "" ${flag_var} "${${flag_var}}")
407+
string(REGEX REPLACE "[/-]MD" "" ${flag_var} "${${flag_var}}")
408+
string(REGEX REPLACE "[/-]D_DEBUG" "" ${flag_var} "${${flag_var}}")
409+
endforeach()
410+
392411
append_list_if(COMPILER_RT_HAS_Oy_FLAG /Oy- SANITIZER_COMMON_CFLAGS)
393412
append_list_if(COMPILER_RT_HAS_GS_FLAG /GS- SANITIZER_COMMON_CFLAGS)
394413

0 commit comments

Comments
 (0)