From ef7a5ac68a829ff81c28326134d3a3485b97d426 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 23 May 2022 18:18:29 +0200 Subject: [PATCH] build: Enable static runtime linking for MSVC (#1069) --- CMakeLists.txt | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f810287a..4cb1aa532 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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$<$: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 # -- 2.47.3