From: Cristian Adam Date: Mon, 23 May 2022 16:18:29 +0000 (+0200) Subject: build: Enable static runtime linking for MSVC (#1069) X-Git-Tag: v4.7~231 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef7a5ac68a829ff81c28326134d3a3485b97d426;p=thirdparty%2Fccache.git build: Enable static runtime linking for MSVC (#1069) --- 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 #