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) include(CMakeDependentOption)
# Basic build options # Basic build options
if(WIN32) if(VCPKG_TOOLCHAIN)
if(VCPKG_TOOLCHAIN) # For vcpkg builds we have to respect the linking method used by the
# For vcpkg builds we have to respect the linking method used by the # specified triplet.
# specified triplet. set(NO_STATIC_OPTION ON)
set(NO_STATIC_OPTION ON) if(VCPKG_TARGET_TRIPLET MATCHES "-static$")
if(VCPKG_TARGET_TRIPLET MATCHES "-windows-static$") # `-static` triplet, use static linking
# `-static` triplet, use static linking set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") set(STATIC_BUILD ON)
set(STATIC_BUILD ON) elseif(VCPKG_TARGET_TRIPLET MATCHES "-static-md$")
elseif(VCPKG_TARGET_TRIPLET MATCHES "-windows-static-md$") # `-static-md` triplet, use static linking with dynamic CRT
# `-static-md` triplet, use static linking with dynamic CRT set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") set(STATIC_BUILD ON)
set(STATIC_BUILD ON) elseif()
elseif() # Regular triplet, use dynamic linking
# Regular triplet, use dynamic linking set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL") set(STATIC_BUILD OFF)
set(STATIC_BUILD OFF)
endif()
endif() endif()
endif()
if(WIN32)
# Prefer static builds on Windows # Prefer static builds on Windows
set(PREFER_STATIC ON) set(PREFER_STATIC ON)