From e5ed33b91b8e279c67d2fc3f4d035a3039ecf4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Fri, 17 Dec 2021 07:20:21 +0100 Subject: [PATCH] Determine the value of `CMAKE_MSVC_RUNTIME_LIBRARY` properly --- CMakeLists.txt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2070e3a50..73ac6a37c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,16 +18,22 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0091 NEW) cmake_policy(SET CMP0079 NEW) -if(VCPKG_TOOLCHAIN AND VCPKG_TARGET_TRIPLET MATCHES "static") - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") -endif() - project(86Box VERSION 3.1 DESCRIPTION "Emulator of x86-based systems" HOMEPAGE_URL "https://86box.net" LANGUAGES C CXX) +if(WIN32 AND VCPKG_TOOLCHAIN) + if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$") + # `-static` triplet, use the statically linked CRT + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + # Regular triplet (or `-static-md`), use the dynamically linked CRT + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() +endif() + # Detect the target architecture by trying to compile `src/arch_detect.c` try_compile(RESULT_VAR ${CMAKE_BINARY_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/src/arch_detect.c" OUTPUT_VARIABLE ARCH) string(REGEX MATCH "ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}")