Set static build properly on non-Windows vcpkg targets

This commit is contained in:
David Hrdlička
2022-01-10 22:45:52 +01:00
parent bb25829dbc
commit 7d7826d7a5

View File

@@ -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$<$<CONFIG:Debug>: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$<$<CONFIG:Debug>:Debug>DLL")
set(STATIC_BUILD ON)
elseif()
# Regular triplet, use dynamic linking
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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$<$<CONFIG:Debug>: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$<$<CONFIG:Debug>:Debug>DLL")
set(STATIC_BUILD ON)
elseif()
# Regular triplet, use dynamic linking
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(STATIC_BUILD OFF)
endif()
endif()
if(WIN32)
# Prefer static builds on Windows
set(PREFER_STATIC ON)