From cd7df53a72625424b985ee15c121828a967e5957 Mon Sep 17 00:00:00 2001 From: eyhn Date: Tue, 15 Mar 2022 14:46:30 +0800 Subject: [PATCH] Add USE_STATIC_CRT option --- CMakeLists.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cbbfef2c..f48391edf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,27 @@ IF (WIN32) # Multibyte character set is deprecated since at least MSVC2015 (possibly earlier) ADD_DEFINITIONS( -DUNICODE -D_UNICODE ) ENDIF() + + # Link statically against c/c++ lib to avoid missing redistriburable such as + # "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users + # a choice to opt for the shared runtime if they want. + option(USE_STATIC_CRT "Link against the static runtime libraries." OFF) + + # The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative + # global method here: + if (${USE_STATIC_CRT}) + add_compile_options( + $<$:/MT> + $<$:/MTd> + $<$:/MT> + ) + else() + add_compile_options( + $<$:/MD> + $<$:/MDd> + $<$:/MD> + ) + endif() ENDIF() ENDIF()