[compiler-rt] 9f4dfcb - [CMake] Clean up old code for handling MSVC runtime setting the old way

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 19 01:25:41 PDT 2023


Author: Martin Storsjö
Date: 2023-07-19T11:25:28+03:00
New Revision: 9f4dfcb795bb0ecf9944553f49371164801cd83f

URL: https://github.com/llvm/llvm-project/commit/9f4dfcb795bb0ecf9944553f49371164801cd83f
DIFF: https://github.com/llvm/llvm-project/commit/9f4dfcb795bb0ecf9944553f49371164801cd83f.diff

LOG: [CMake] Clean up old code for handling MSVC runtime setting the old way

This was left in place to reduce the risk of breaking anything,
and to keep the diff smaller, in D155233.

Differential Revision: https://reviews.llvm.org/D155431

Added: 
    

Modified: 
    compiler-rt/CMakeLists.txt
    llvm/cmake/modules/ChooseMSVCCRT.cmake

Removed: 
    


################################################################################
diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index fd0430e76c7e14..1545340aa8a81f 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -389,17 +389,6 @@ 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.
-  # 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/llvm/cmake/modules/ChooseMSVCCRT.cmake b/llvm/cmake/modules/ChooseMSVCCRT.cmake
index 0305b620998540..6d52ac97bac209 100644
--- a/llvm/cmake/modules/ChooseMSVCCRT.cmake
+++ b/llvm/cmake/modules/ChooseMSVCCRT.cmake
@@ -4,52 +4,14 @@
 #
 # The macro is invoked at the end of the file.
 #
-# CMake already sets CRT flags in the CMAKE_CXX_FLAGS_* and
-# CMAKE_C_FLAGS_* variables by default. To let the user
-# override that for each build type:
-# 1. Detect which CRT is already selected, and reflect this in
-# LLVM_USE_CRT_* so the user can have a better idea of what
-# changes they're making.
-# 2. Replace the flags in both variables with the new flag via a regex.
-# 3. set() the variables back into the cache so the changes
-# are user-visible.
-
-### Helper macros: ###
-macro(make_crt_regex regex crts)
-  set(${regex} "")
-  foreach(crt ${${crts}})
-    # Trying to match the beginning or end of the string with stuff
-    # like [ ^]+ didn't work, so use a bunch of parentheses instead.
-    set(${regex} "${${regex}}|(^| +)/${crt}($| +)")
-  endforeach(crt)
-  string(REGEX REPLACE "^\\|" "" ${regex} "${${regex}}")
-endmacro(make_crt_regex)
-
-macro(get_current_crt crt_current regex flagsvar)
-  # Find the selected-by-CMake CRT for each build type, if any.
-  # Strip off the leading slash and any whitespace.
-  string(REGEX MATCH "${${regex}}" ${crt_current} "${${flagsvar}}")
-  string(REPLACE "/" " " ${crt_current} "${${crt_current}}")
-  string(STRIP "${${crt_current}}" ${crt_current})
-endmacro(get_current_crt)
-
-# Replaces or adds a flag to a variable.
-# Expects 'flag' to be padded with spaces.
-macro(set_flag_in_var flagsvar regex flag)
-  string(REGEX MATCH "${${regex}}" current_flag "${${flagsvar}}")
-  if("${current_flag}" STREQUAL "")
-    set(${flagsvar} "${${flagsvar}}${${flag}}")
-  else()
-    string(REGEX REPLACE "${${regex}}" "${${flag}}" ${flagsvar} "${${flagsvar}}")
-  endif()
-  string(STRIP "${${flagsvar}}" ${flagsvar})
-  # Make sure this change gets reflected in the cache/gui.
-  # CMake requires the docstring parameter whenever set() touches the cache,
-  # so get the existing docstring and re-use that.
-  get_property(flagsvar_docs CACHE ${flagsvar} PROPERTY HELPSTRING)
-  set(${flagsvar} "${${flagsvar}}" CACHE STRING "${flagsvar_docs}" FORCE)
-endmacro(set_flag_in_var)
-
+# This mechanism is deprecated, but kept for transitioning users.
+#
+# This reads the LLVM_USE_CRT_<CONFIG> options and sets
+# CMAKE_MSVC_RUNTIME_LIBRARY accordingly. The previous mechanism allowed
+# setting 
diff erent choices for 
diff erent build configurations (for
+# multi-config generators), but translating multiple 
diff ering choices to
+# the corresponding CMAKE_MSVC_RUNTIME_LIBRARY generator expression isn't
+# supported by this transitional helper.
 
 macro(choose_msvc_crt MSVC_CRT)
   if(LLVM_USE_CRT)
@@ -58,8 +20,6 @@ macro(choose_msvc_crt MSVC_CRT)
 variables (LLVM_USE_CRT_DEBUG, etc) instead.")
   endif()
 
-  make_crt_regex(MSVC_CRT_REGEX ${MSVC_CRT})
-
   foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
     string(TOUPPER "${build_type}" build)
     if (NOT "${LLVM_USE_CRT_${build}}" STREQUAL "")
@@ -83,12 +43,6 @@ variables (LLVM_USE_CRT_DEBUG, etc) instead.")
       message(STATUS "Using VC++ CRT: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
       set(runtime_library_set 1)
     endif()
-    foreach(lang C CXX)
-      # Clear any potentially manually set options from these variables.
-      # Kept as temporary backwards compat (unsure if necessary).
-      # TODO: We probably should remove it.
-      set_flag_in_var(CMAKE_${lang}_FLAGS_${build} MSVC_CRT_REGEX "")
-    endforeach(lang)
   endforeach(build_type)
 endmacro(choose_msvc_crt MSVC_CRT)
 


        


More information about the llvm-commits mailing list