From d5186b088bebf3a39be8a429c3b8c3f963bde6e0 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Thu, 14 May 2026 02:44:11 +0200 Subject: [PATCH] Link against (non-debug) MSVC runtime statically --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c056d6c..f3630ac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,15 @@ include(CMakeDependentOption) option(SANITIZERS "Build with sanitizers enabled" OFF) cmake_dependent_option(MORE_WARNINGS "Turn on more warnings" OFF "NOT MSVC" OFF) +if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) # Allow this to be overridden from the CLI easily. + # We link against the Microsoft C++ runtime libs statically, except the debug-mode one. + # This is because Microsoft's license terms (through some indirection) allow us to redistribute + # the runtime lib code *except* the debug-mode libs'. + # Since we want to remain able to not think too hard about debug executables, we link against + # the debug libs dynamically, shifting the burden of obtaining them onto the recipient. + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:DebugDLL>") +endif() + if(SANITIZERS) if(MSVC) message(STATUS "ASan enabled")