]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
build: Enable static runtime linking for MSVC (#1069)
authorCristian Adam <cristian.adam@gmail.com>
Mon, 23 May 2022 16:18:29 +0000 (18:18 +0200)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 16:18:29 +0000 (18:18 +0200)
CMakeLists.txt

index 2f810287a7e0d06b909f31af6087c5773c358083..4cb1aa532bccda9b10f0ce6b207ecee4237c51c6 100644 (file)
@@ -1,5 +1,9 @@
 cmake_minimum_required(VERSION 3.10)
 
+if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
+  cmake_policy(SET CMP0091 NEW) # Needed by CMAKE_MSVC_RUNTIME_LIBRARY
+endif()
+
 project(ccache LANGUAGES C CXX ASM ASM_MASM)
 if(MSVC)
   enable_language(ASM_MASM)
@@ -83,6 +87,18 @@ include(GNUInstallDirs)
 include(GenerateConfigurationFile)
 include(GenerateVersionFile)
 
+#
+# Static link configuration
+#
+
+if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
+  option(STATIC_LINK "Link statically with system libraries" ON)
+endif()
+
+if(MSVC AND STATIC_LINK)
+  set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
+endif()
+
 #
 # Third party
 #
@@ -113,10 +129,6 @@ endif()
 include(CodeAnalysis)
 option(ENABLE_TRACING "Enable possibility to use internal ccache tracing" OFF)
 
-if(WIN32 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-  option(STATIC_LINK "Link statically with system libraries" ON)
-endif()
-
 #
 # Source code
 #