[clang] [CMake]Remove LLVM_USE_CRT* (PR #66850)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 19 19:38:50 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

[Ref](https://discourse.llvm.org/t/fixing-crt-allocator-support-on-windows/73525)

# Notes
- ``ChooseMSVCCRT.cmake`` is the automatic translation layer that's been completely removed
- The old implementation seems to support MultiConfiguration generators that I personally don't use , so some guidance from the reviewer on that topic would help
- The CRT allocator code has already been fixed to not use LLVM_USE_CRT

---
Full diff: https://github.com/llvm/llvm-project/pull/66850.diff


7 Files Affected:

- (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (-1) 
- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (-1) 
- (modified) clang/cmake/caches/Fuchsia.cmake (-4) 
- (removed) llvm/cmake/modules/ChooseMSVCCRT.cmake (-58) 
- (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (+1-2) 
- (modified) llvm/cmake/modules/LLVMConfig.cmake.in (+1-4) 
- (modified) llvm/docs/CMake.rst (-6) 


``````````diff
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake
index e6f5650eac4668f..bbb4b9e71be2d3d 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -95,7 +95,6 @@ set(CLANG_DEFAULT_LINKER                    "lld" CACHE STRING "")
 
 if(WIN32)
   set(CMAKE_MSVC_RUNTIME_LIBRARY            "MultiThreaded" CACHE STRING "")
-  set(LLVM_USE_CRT_RELEASE                  "MT" CACHE STRING "")
 endif()
 
 # Set up RPATH for the target runtime/builtin libraries.
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index bc4d9f1462b1814..803d41a2c87179a 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -30,7 +30,6 @@ set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
 set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")
 
 if(WIN32)
-  set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
   set(FUCHSIA_DISABLE_DRIVER_BUILD ON)
 endif()
 
diff --git a/clang/cmake/caches/Fuchsia.cmake b/clang/cmake/caches/Fuchsia.cmake
index c599f141f9e5b1b..9c68be0bfe54b69 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -70,10 +70,6 @@ foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
   endif()
 endforeach()
 
-if(WIN32)
-  set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
-endif()
-
 set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
diff --git a/llvm/cmake/modules/ChooseMSVCCRT.cmake b/llvm/cmake/modules/ChooseMSVCCRT.cmake
deleted file mode 100644
index 6d52ac97bac2092..000000000000000
--- a/llvm/cmake/modules/ChooseMSVCCRT.cmake
+++ /dev/null
@@ -1,58 +0,0 @@
-# The macro choose_msvc_crt() takes a list of possible
-# C runtimes to choose from, in the form of compiler flags,
-# to present to the user. (MTd for /MTd, etc)
-#
-# The macro is invoked at the end of the file.
-#
-# 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 different choices for different build configurations (for
-# multi-config generators), but translating multiple differing 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)
-    message(FATAL_ERROR
-      "LLVM_USE_CRT is deprecated. Use the CMAKE_BUILD_TYPE-specific
-variables (LLVM_USE_CRT_DEBUG, etc) instead.")
-  endif()
-
-  foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
-    string(TOUPPER "${build_type}" build)
-    if (NOT "${LLVM_USE_CRT_${build}}" STREQUAL "")
-      if (NOT ${LLVM_USE_CRT_${build}} IN_LIST ${MSVC_CRT})
-        message(FATAL_ERROR
-          "Invalid value for LLVM_USE_CRT_${build}: ${LLVM_USE_CRT_${build}}. Valid options are one of: ${${MSVC_CRT}}")
-      endif()
-      set(library "MultiThreaded")
-      if ("${LLVM_USE_CRT_${build}}" MATCHES "d$")
-        set(library "${library}Debug")
-      endif()
-      if ("${LLVM_USE_CRT_${build}}" MATCHES "^MD")
-        set(library "${library}DLL")
-      endif()
-      if(${runtime_library_set})
-        message(WARNING "Conflicting LLVM_USE_CRT_* options")
-      else()
-        message(WARNING "The LLVM_USE_CRT_* options are deprecated, use the CMake provided CMAKE_MSVC_RUNTIME_LIBRARY setting instead")
-      endif()
-      set(CMAKE_MSVC_RUNTIME_LIBRARY "${library}" CACHE STRING "" FORCE)
-      message(STATUS "Using VC++ CRT: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
-      set(runtime_library_set 1)
-    endif()
-  endforeach(build_type)
-endmacro(choose_msvc_crt MSVC_CRT)
-
-
-# List of valid CRTs for MSVC
-set(MSVC_CRT
-  MD
-  MDd
-  MT
-  MTd)
-
-choose_msvc_crt(MSVC_CRT)
-
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 4e87c6d1c3eb868..f72c41aaffb5061 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -470,7 +470,6 @@ endif()
 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
 
 if( MSVC )
-  include(ChooseMSVCCRT)
 
   # Add definitions that make MSVC much less annoying.
   add_compile_definitions(
@@ -951,7 +950,7 @@ if(LLVM_USE_SANITIZER)
       endif()
       # Prepare ASAN runtime if needed
       if (LLVM_USE_SANITIZER MATCHES ".*Address.*")
-        if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
+        if (${CMAKE_MSVC_RUNTIME_LIBRARY} MATCHES "^(MultiThreaded|MultiThreadedDebug)$")
           append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
             CMAKE_EXE_LINKER_FLAGS)
           append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib"
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index 42dfd607f7e651a..5465e981f235545 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -14,10 +14,7 @@ set(LLVM_PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@)
 
 set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@)
 
-set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@)
-set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@)
-set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@)
-set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@)
+set(CMAKE_MSVC_RUNTIME_LIBRARY @CMAKE_MSVC_RUNTIME_LIBRARY@)
 
 set(LLVM_USE_SPLIT_DWARF @LLVM_USE_SPLIT_DWARF@)
 
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 67f740447ed7bfb..4d894212fb11d47 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -777,12 +777,6 @@ enabled sub-projects. Nearly all of these variable names begin with
   ``LLVM_USE_SANITIZER`` contains ``Undefined``. This can be used to override
   the default set of UBSan flags.
 
-**LLVM_USE_CRT_{target}**:STRING
-  On Windows, tells which version of the C runtime library (CRT) should be used.
-  For example, -DLLVM_USE_CRT_RELEASE=MT would statically link the CRT into the
-  LLVM tools and library. This is deprecated; use ``CMAKE_MSVC_RUNTIME_LIBRARY``
-  instead.
-
 **LLVM_USE_INTEL_JITEVENTS**:BOOL
   Enable building support for Intel JIT Events API. Defaults to OFF.
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/66850


More information about the cfe-commits mailing list