Skip to content

Commit

Permalink
actions: bump zlib to v1.3, set CMAKE_MSVC_RUNTIME_LIBRARY
Browse files Browse the repository at this point in the history
Since v1.3, zlib advertises compatibility with CMake 3.15 which
introduced policy CMP0091 [1]. The NEW behavior is to to leave
the MSVC runtime library selection flags out of the default
CMAKE_<LANG>_FLAGS_<CONFIG> values and instead offer a first-class
abstraction: MSVC_RUNTIME_LIBRARY [2].

CMP0091 is documented to default to the OLD behavior and not warn when
unset. The zlib CMakeLists.txt does not set this policy. However, when
building libfido2 as a static library targeting Win32, linking fails
because our runtime selection flags for zlib have been replaced from
under our feet (the MSVC_RUNTIME_LIBRARY property defaults to the
dynamically linked runtime).

Setting -DCMAKE_POLICY_DEFAULT_CMP0091=OLD [3] on the command line has
no effect and CMake instead warns that the variable has been ignored.
Manually modifying zlib's CMakeLists.txt to set the policy to OLD issues
a deprecation warning but fixes our linking issues.

The only remaining possibility that does not modify external files,
is to explicitly set -DCMAKE_MSVC_RUNTIME_LIBRARY=... [4] on the
command line. Setting it to an empty value does not work (Visual Studio
generators may supposedly also override with _another_ default). Setting
it to one of the allowed values corresponding to the selected build type
resolves our linking issues.

[1] https://cmake.org/cmake/help/latest/policy/CMP0091.html
[2] https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html
[3] https://cmake.org/cmake/help/latest/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.html
[4] https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
  • Loading branch information
LDVG committed Sep 7, 2023
1 parent 79fd7bd commit 7a49148
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .actions/build-linux-i686-w64-mingw32-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sudo make install_sw
cd ..

# Build and install zlib.
git clone --depth=1 https://github.com/madler/zlib -b v1.2.13
git clone --depth=1 https://github.com/madler/zlib -b v1.3
cd zlib
make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32-
sudo make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32- DESTDIR=/fakeroot \
Expand Down
2 changes: 1 addition & 1 deletion .actions/build-linux-openssl3-i686-w64-mingw32-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sudo make install_sw
cd ..

# Build and install zlib.
git clone --depth=1 https://github.com/madler/zlib -b v1.2.13
git clone --depth=1 https://github.com/madler/zlib -b v1.3
cd zlib
make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32-
sudo make -fwin32/Makefile.gcc PREFIX=i686-w64-mingw32- DESTDIR=/fakeroot \
Expand Down
2 changes: 1 addition & 1 deletion .actions/fuzz-linux
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LIBCBOR_MSAN="memory"
OPENSSL_URL="https://github.com/openssl/openssl"
OPENSSL_TAG="openssl-3.0.9"
ZLIB_URL="https://github.com/madler/zlib"
ZLIB_TAG="v1.2.13"
ZLIB_TAG="v1.3"
ZLIB_ASAN="address alignment bounds undefined"
ZLIB_MSAN="memory"
FIDO2_ASAN="address bounds fuzzer-no-link implicit-conversion leak"
Expand Down
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
8 changes: 6 additions & 2 deletions windows/const.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ New-Variable -Name 'LIBCBOR_GIT' -Value 'https://github.com/pjk/libcbor' `
-Option Constant

# zlib coordinates.
New-Variable -Name 'ZLIB' -Value 'zlib-1.2.13' -Option Constant
New-Variable -Name 'ZLIB_BRANCH' -Value 'v1.2.13' -Option Constant
New-Variable -Name 'ZLIB' -Value 'zlib-1.3' -Option Constant
New-Variable -Name 'ZLIB_BRANCH' -Value 'v1.3' -Option Constant
New-Variable -Name 'ZLIB_GIT' -Value 'https://github.com/madler/zlib' `
-Option Constant

Expand All @@ -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 7a49148

Please sign in to comment.