Add hybrid CRT link for Windows binaries (#40890)
JohnMcPMS committed
Aug 24, 2026 at 11:52 UTC
4e41274b9add3a2a5a9edf7598ec8e7242d7dfe3
1 file changed
+9
CMakeLists.txt
+9
@@ -350,6 +350,15 @@ if (${TARGET_PLATFORM} STREQUAL "x64")
350
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /CETCOMPAT")
351
endif()
352
353
+# Hybrid CRT: static-link the C++ runtime and STL (/MT|/MTd from CMAKE_MSVC_RUNTIME_LIBRARY),
354
+# but dynamic-link the Universal CRT (ucrt.dll) which is an OS component on Windows 10+.
355
+# This eliminates the VCRUNTIME/MSVCP redistributable dependency while avoiding the size
356
+# cost of statically linking the UCRT. See https://aka.ms/hybridcrt for details.
357
+set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /defaultlib:ucrt.lib")
358
+set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /NODEFAULTLIB:libucrt.lib /defaultlib:ucrt.lib")
359
+set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libucrtd.lib /defaultlib:ucrtd.lib")
360
+set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:libucrtd.lib /defaultlib:ucrtd.lib")
361
+
362
# Common link libraries
363
link_directories(${WSLDEPS_SOURCE_DIR}/lib/)
364
set(COMMON_LINK_LIBRARIES