Skip to content

Commit

Permalink
windows: set CMAKE_MSVC_RUNTIME_LIBRARY for zlib
Browse files Browse the repository at this point in the history
Since v1.3, zlib advertises compatibility with CMake 3.15 which prefers
to leave the MSVC runtime library selection flags out of the default
CMAKE_<LANG>_FLAGS_<CONFIG> values and instead offer a first-class
abstraction.

The CMAKE_MSVC_RUNTIME_LIBRARY variable and MSVC_RUNTIME_LIBRARY target
property may be set to select the MSVC runtime library. If they are not
set then CMake uses the default value

    MultiThreaded$<$<CONFIG:Debug>:Debug>DLL

which is equivalent to the flags for dynamic linking. This causes
linking errors when building the statically linked Win32 version of
libfido2. Adjust the default depending on our target build type to also
allow for static linking.

[1] https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
  • Loading branch information
LDVG committed Sep 1, 2023
1 parent 2705342 commit 88d72b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions windows/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions windows/const.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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$<$<CONFIG:Debug>: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$<$<CONFIG:Debug>:Debug>'
}
New-Variable -Name 'CFLAGS_DEBUG' -Value "${RUNTIME}d /Zi /guard:cf /sdl" `
-Option Constant
Expand Down

0 comments on commit 88d72b5

Please sign in to comment.