From fe687dfcd808350f55ba5851d19b48712766f3f5 Mon Sep 17 00:00:00 2001 From: Ludvig Michaelsson Date: Fri, 1 Sep 2023 11:34:48 +0200 Subject: [PATCH] windows: set CMAKE_MSVC_RUNTIME_LIBRARY for zlib Since v1.3, zlib advertises compatibility with CMake 3.15 which added the MSVC_RUNTIME_LIBRARY [1] property, defaulting to the dynamically-linked runtime library. This seems to overrides our selection of MSVC runtime library passed through CMAKE_C_FLAGS_. Ultimately, this results in a linker error when trying to link libfido2 and zlib. The generator expression used is the same as the default generator expression in CMake, with the exception of using the statically linked runtime library for static builds of libfido2. [1] https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html --- windows/build.ps1 | 1 + windows/const.ps1 | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/windows/build.ps1 b/windows/build.ps1 index 52a1d669..ff43d8b8 100644 --- a/windows/build.ps1 +++ b/windows/build.ps1 @@ -183,6 +183,7 @@ try { -DBUILD_SHARED_LIBS="${SHARED}" ` -DCMAKE_C_FLAGS_DEBUG="${CFLAGS_DEBUG}" ` -DCMAKE_C_FLAGS_RELEASE="${CFLAGS_RELEASE}" ` + -DCMAKE_MSVC_RUNTIME_LIBRARY="${CMAKE_MSVC_RUNTIME_LIBRARY}" ` -DCMAKE_INSTALL_PREFIX="${PREFIX}" "${CMAKE_SYSTEM_VERSION}"; ` ExitOnError & $CMake --build . --config ${Config} --verbose; ExitOnError diff --git a/windows/const.ps1 b/windows/const.ps1 index 41092268..03ea34d2 100644 --- a/windows/const.ps1 +++ b/windows/const.ps1 @@ -34,9 +34,13 @@ New-Variable -Name 'PREFIX' -Value "${OUTPUT}\${Arch}\${Type}" -Option Constant if ("${Type}" -eq "dynamic") { New-Variable -Name 'RUNTIME' -Value '/MD' -Option Constant New-Variable -Name 'SHARED' -Value 'ON' -Option Constant + New-Variable -Name 'CMAKE_MSVC_RUNTIME_LIBRARY' -Option Constant ` + -Value 'MultiThreaded$<$:Debug>DLL' } else { New-Variable -Name 'RUNTIME' -Value '/MT' -Option Constant New-Variable -Name 'SHARED' -Value 'OFF' -Option Constant + New-Variable -Name 'CMAKE_MSVC_RUNTIME_LIBRARY' -Option Constant ` + -Value 'MultiThreaded$<$:Debug>' } New-Variable -Name 'CFLAGS_DEBUG' -Value "${RUNTIME}d /Zi /guard:cf /sdl" ` -Option Constant