From 57742cb02b04ea973ff702b42a7e380decd4048f Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 11 Jul 2024 19:52:44 +0800 Subject: [PATCH] Statically link MSVC runtime (#4613) * Statically link MSVC runtime * Statically link MSVC runtime for llvm --- CMakeLists.txt | 1 + CMakePresets.json | 5 ++++- external/build-llvm.sh | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 415343050d..1dd289a8dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.25") cmake_policy(SET CMP0141 NEW) endif() +cmake_policy(SET CMP0091 NEW) # Don't use absolute paths to the build tree in RPATH, this makes the build # tree relocatable diff --git a/CMakePresets.json b/CMakePresets.json index 7e0697afbe..08f85a37fb 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -10,7 +10,10 @@ "name": "default", "description": "Default build using Ninja Multi-Config generator", "generator": "Ninja Multi-Config", - "binaryDir": "${sourceDir}/build" + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>" + } }, { "name": "msvc-base", diff --git a/external/build-llvm.sh b/external/build-llvm.sh index 142d30ee2f..95302a742b 100755 --- a/external/build-llvm.sh +++ b/external/build-llvm.sh @@ -109,6 +109,10 @@ cmake_arguments_for_slang=( -DLLVM_ENABLE_PROJECTS=clang "-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64" -DLLVM_BUILD_TOOLS=0 + # Get LLVM to use the static linked version of the msvc runtime + "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$:Debug>" + "-DLLVM_USE_CRT_RELEASE=MT" + "-DLLVM_USE_CRT_DEBUG=MTd" ) build_dir=$source_dir/build mkdir -p "$build_dir"