aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2023-07-12 12:40:37 +0000
committerMartin Storsjö <martin@martin.st>2023-07-17 09:59:05 +0300
commitc6bd873403a8ac6538a3fe3b3c2fe39c16b146a6 (patch)
treed640f6e4cbe17b31642488103969b875e21c8783 /compiler-rt
parentf69a9f3974ea6d6f556783dfbe202a06d6d3398b (diff)
downloadllvm-c6bd873403a8ac6538a3fe3b3c2fe39c16b146a6.zip
llvm-c6bd873403a8ac6538a3fe3b3c2fe39c16b146a6.tar.gz
llvm-c6bd873403a8ac6538a3fe3b3c2fe39c16b146a6.tar.bz2
[CMake] Switch the CMP0091 policy (MSVC_RUNTIME_LIBRARY) to the new behaviour
With the new behaviour, the /MD or similar options aren't added to e.g. CMAKE_CXX_FLAGS_RELEASE, but are added separately by CMake. They can be changed by the cmake variable CMAKE_MSVC_RUNTIME_LIBRARY or with the target property MSVC_RUNTIME_LIBRARY. LLVM has had its own custom CMake flags, e.g. LLVM_USE_CRT_RELEASE, which affects which CRT is used for release mode builds. Deprecate these and direct users to use CMAKE_MSVC_RUNTIME_LIBRARY directly instead (and do a best effort attempt at setting CMAKE_MSVC_RUNTIME_LIBRARY based on the existing LLVM_USE_CRT_ flags). This only handles the simple cases, it doesn't handle multi-config generators with different LLVM_USE_CRT_* variables for different configs though, but that's probably fine - we should move over to the new upstream CMake mechanism anyway, and push users towards that. Change code in compiler-rt, that previously tried to override the CRT choice to /MT, to set CMAKE_MSVC_RUNTIME_LIBRARY instead of meddling in the old variables. This resolves the policy issue in https://github.com/llvm/llvm-project/issues/63286, and should handle the issues that were observed originally when the minimum CMake version was bumped, in https://github.com/llvm/llvm-project/issues/62719 and https://github.com/llvm/llvm-project/issues/62739. Differential Revision: https://reviews.llvm.org/D155233
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/CMakeLists.txt25
-rw-r--r--compiler-rt/lib/orc/CMakeLists.txt2
2 files changed, 13 insertions, 14 deletions
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index d004474..fd0430e 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -387,20 +387,19 @@ if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "s390x")
endif()
if(MSVC)
- # Replace the /M[DT][d] flags with /MT, and strip any definitions of _DEBUG,
- # which cause definition mismatches at link time.
# FIXME: In fact, sanitizers should support both /MT and /MD, see PR20214.
- if(COMPILER_RT_HAS_MT_FLAG)
- 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" "/MT" ${flag_var} "${${flag_var}}")
- string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
- string(REGEX REPLACE "/D_DEBUG" "" ${flag_var} "${${flag_var}}")
- endforeach()
- endif()
+ set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded)
+ # Remove any /M[DT][d] flags, and strip any definitions of _DEBUG.
+ # TODO: We probably could remove this altogether.
+ 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)
diff --git a/compiler-rt/lib/orc/CMakeLists.txt b/compiler-rt/lib/orc/CMakeLists.txt
index 7943f3f..38dd233 100644
--- a/compiler-rt/lib/orc/CMakeLists.txt
+++ b/compiler-rt/lib/orc/CMakeLists.txt
@@ -131,7 +131,7 @@ else() # not Apple
)
if (MSVC)
- set(ORC_CFLAGS "${ORC_CFLAGS} /MD")
+ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
else()
set(ORC_BUILD_TYPE STATIC)