From 7d7826d7a58b7543078095a05821af23ccb87130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Hrdli=C4=8Dka?= Date: Mon, 10 Jan 2022 22:45:52 +0100 Subject: [PATCH] Set static build properly on non-Windows vcpkg targets --- CMakeLists.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index da97bc03d..8df5d4378 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,26 +32,26 @@ include(CPack) include(CMakeDependentOption) # Basic build options -if(WIN32) - if(VCPKG_TOOLCHAIN) - # For vcpkg builds we have to respect the linking method used by the - # specified triplet. - set(NO_STATIC_OPTION ON) - if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$") - # `-static` triplet, use static linking - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - set(STATIC_BUILD ON) - elseif(VCPKG_TARGET_TRIPLET MATCHES "-windows-static-md$") - # `-static-md` triplet, use static linking with dynamic CRT - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set(STATIC_BUILD ON) - elseif() - # Regular triplet, use dynamic linking - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") - set(STATIC_BUILD OFF) - endif() +if(VCPKG_TOOLCHAIN) + # For vcpkg builds we have to respect the linking method used by the + # specified triplet. + set(NO_STATIC_OPTION ON) + if(VCPKG_TARGET_TRIPLET MATCHES "-static$") + # `-static` triplet, use static linking + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + set(STATIC_BUILD ON) + elseif(VCPKG_TARGET_TRIPLET MATCHES "-static-md$") + # `-static-md` triplet, use static linking with dynamic CRT + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set(STATIC_BUILD ON) + elseif() + # Regular triplet, use dynamic linking + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + set(STATIC_BUILD OFF) endif() +endif() +if(WIN32) # Prefer static builds on Windows set(PREFER_STATIC ON)