From f506169f80760e39f1b96da3991778ed0ac1b92a Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Sat, 4 Nov 2023 23:51:30 +0300 Subject: [PATCH] Fixed MSVC issues with /MT(d) flag propagation --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5a361b1e..febd1efed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,12 +16,15 @@ # dwarfs. If not, see . # +cmake_minimum_required(VERSION 3.25.0) + +# Enable CMAKE_MSVC_RUNTIME_LIBRARY +cmake_policy(SET CMP0091 NEW) + project(dwarfs) include(ExternalProject) -cmake_minimum_required(VERSION 3.25.0) - include(CheckCXXSourceCompiles) option(WITH_TESTS "build with tests" OFF) @@ -95,6 +98,8 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") add_compile_options(/Zc:__cplusplus /utf-8 /wd4267 /wd4244 /wd5219) + # Apply /MT or /MTd (multithread, static version of the run-time library) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") @@ -244,7 +249,6 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") foreach(CompilerFlag CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) - string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") string(REPLACE "/RTC1" "" ${CompilerFlag} "${${CompilerFlag}}") endforeach()