-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[zlib] Add cmake wrapper #18914
[zlib] Add cmake wrapper #18914
Conversation
ports/zlib/vcpkg-cmake-wrapper.cmake
Outdated
if(NOT ZLIB_ROOT OR ZLIB_ROOT STREQUAL "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") | ||
set(ZLIB_ROOT "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") | ||
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS "${ZLIB_ROOT}/include" NO_DEFAULT_PATH) | ||
find_library(ZLIB_LIBRARY_RELEASE NAMES zlib z PATHS "${ZLIB_ROOT}/lib" NO_DEFAULT_PATH) | ||
find_library(ZLIB_LIBRARY_DEBUG NAMES zlibd z PATHS "${ZLIB_ROOT}/debug/lib" NO_DEFAULT_PATH) | ||
if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY_RELEASE OR (NOT ZLIB_LIBRARY_DEBUG AND EXISTS "${ZLIB_ROOT}/debug/lib")) | ||
message("Broken installation of vcpkg port zlib") | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS 3.4) | ||
find_package(SelectLibraryConfigurations) | ||
select_library_configurations(ZLIB) | ||
unset(ZLIB_FOUND) | ||
endif() | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why so complicated? If the wrapper is installed and called you can automatically assume that you are wanting zlib from vcpkg (because otherwise the wrapper would not be installed).
if(NOT ZLIB_ROOT OR ZLIB_ROOT STREQUAL "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") | |
set(ZLIB_ROOT "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") | |
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS "${ZLIB_ROOT}/include" NO_DEFAULT_PATH) | |
find_library(ZLIB_LIBRARY_RELEASE NAMES zlib z PATHS "${ZLIB_ROOT}/lib" NO_DEFAULT_PATH) | |
find_library(ZLIB_LIBRARY_DEBUG NAMES zlibd z PATHS "${ZLIB_ROOT}/debug/lib" NO_DEFAULT_PATH) | |
if(NOT ZLIB_INCLUDE_DIR OR NOT ZLIB_LIBRARY_RELEASE OR (NOT ZLIB_LIBRARY_DEBUG AND EXISTS "${ZLIB_ROOT}/debug/lib")) | |
message("Broken installation of vcpkg port zlib") | |
endif() | |
if(CMAKE_VERSION VERSION_LESS 3.4) | |
find_package(SelectLibraryConfigurations) | |
select_library_configurations(ZLIB) | |
unset(ZLIB_FOUND) | |
endif() | |
endif() | |
set(ZLIB_ROOT "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") | |
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS "${ZLIB_ROOT}/include" NO_DEFAULT_PATH) | |
find_library(ZLIB_LIBRARY_RELEASE NAMES zlib z PATHS "${ZLIB_ROOT}/lib" NO_DEFAULT_PATH) | |
find_library(ZLIB_LIBRARY_DEBUG NAMES zlibd z PATHS "${ZLIB_ROOT}/debug/lib" NO_DEFAULT_PATH) |
the rest should be handled by the find_package
call (e.g. select_library_configurations and stuff).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really tried to minimize what is called complicated now. The purpose of the code is:
- Ensure that the libraries are not looked up in another path if not found in vcpkg. You may perhaps rely on zlib.h, but no so much on the libs: Most platforms come with some version of zlib. The library names vary with the platform. The community triplets are not even tested by CI. If the module does its own search, it may find a libary in a different place, so that a configuration failure would go unnoticed.
- But do not break release-only triplets.
- Ensure that configuration is done correctly even in CMake 3.1 ... 3.3. where the module does not call select_library_configurations.
Of course, things might be more compact with a standardized vcpkg_find_libraries
which would encapsulate the vcpkg paths and the checks for existance:
vcpkg_find_libraries(ZLIB
HEADER zlib.h
LIBRARY_NAMES_RELEASE zlib z
LIBRARY_NAMES_DEBUG zlibd z
)
(Leaving the select_library_configurations
as proposed.)
ports/zlib/vcpkg-cmake-wrapper.cmake
Outdated
@@ -0,0 +1,15 @@ | |||
if(NOT ZLIB_ROOT OR ZLIB_ROOT STREQUAL "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of the VCPKG variables, this could use ${CMAKE_CURRENT_LIST_DIR}/../..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... but ${CMAKE_CURRENT_LIST_DIR}/../..
would not work well for comparing with a user-defined VCPKG_ROOT
.
The question if a user-defined VCPKG_ROOT
is acceptable for a vcpkg build system. For ABI consistency, the user would need an overlay port for zlib, thus turning of the wrapper anyway.
python-3:x64-osx: Seems unrelated:
sentry-native:x64-osx: Gotcha, stumbles over cmake's optimized/debug variant configurations for zlib:
|
try adding |
Port sentry-native builds crashpad as a git submodule (i.e. it doesn't use (and depend on) the vcpkg port). Port sentry-native submodule crashpad may use zlib as a submodule (default mode for MSVC!), but otherwise has it is own "processing" of zlib linking options (https://github.com/getsentry/crashpad/blob/5cf3032b2281cf0928acc8bccf69f91ccf26b939/third_party/zlib/CMakeLists.txt). But port sentry-native doesn't depend on port zlib, so build results are ... a lottery? |
ports/zlib/vcpkg-cmake-wrapper.cmake
Outdated
message("Broken installation of vcpkg port zlib") | ||
endif() | ||
if(CMAKE_VERSION VERSION_LESS 3.4) | ||
find_package(SelectLibraryConfigurations) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this script is not a module. Why find_package it and not include?
also, why only for cmake version less than 3.4?
sorry for the questions, but it's the first time i see something like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right about find_package
. I was just typing too many find_package
calls recently ;-)
The version 3.4 thing is because CMake's find_module isn't handling select_library_configurations
before CMake 3.4. vcpkg claims to support CMake 3.1 for user projects (but doesn't not notice when it breaks), and zlib seems to popular to have a higher requirement than vcpkg.cmake
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vcpkg claims to support CMake 3.1 for user projects
"claims" let us just assume the quotes and don't care about anything less then 3.7 ;)
Even if a project does
cmake_minimum_required (VERSION 3.1)
if it is configured with a newer version the modules won't be downgraded with it. The reason vcpkg.cmake
needs to assume 3.1 is due to policy stuff otherwise not working correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version 3.4 thing is because CMake's find_module isn't handling select_library_configurations before CMake 3.4.
any sources for that, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok sorry it's a thing specific for this module. I was under the impression that it was meant to be true in general in cmake
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason vcpkg.cmake needs to assume 3.1 is due to policy stuff otherwise not working correctly.
I would be fine with that, but this is not what I take out from the statements by @strega-nil-ms, just 14 days ago: [1] [2]
"we really do support CMake version back to CMake 3.1 in vcpkg.cmake. There are extra features that require more recent versions, but we do support back to CMake 3.1 (or there's a bug.)"
"All we need is that, if a port supports CMake 3.1, and the user uses 3.1 for their build, it works."
Now I could get away with saying the port zlib doesn't support CMake < 3.4. But if CMake 3.1 isn't enough evev for port zlib, which other port would support that version?
(I'm not arguing for staying with cmake 3.1. I just want to know in advance how to prepare my PRs.)
What is wrong with arm64-windows now? Both zlib:x64-windows (I assume host) and zlib:arm64-windows complain that the "files are already installed in D:/installed/arm64-windows and are in conflict with" the files from the fresh installation (x64) / build (arm64) of the package. |
a port that’s installing his own third party dependencies instead of reusing those provided by vcpkg? it happened and might have happened again |
some CI bug where the /installed/ folder is not correctly cleaned up probably. Also saw it in some of my PRs with qt.... |
We still don't know why this file was used by another process. |
Sure, just see sentry-native in this PR. |
I don't see support for CMake < 3.4 coming back, so this block could be removed. |
This PR will be reviewed these days. |
What does your PR fix?
This PR adds a cmake wrapper for zlib which ensures that
ZLIB::ZLIB
andZLIB_LIBRARIES
are actually properly configured for release (optimized) and debug variant. It fixes inaccurate passing of captured libraries as reported (and attempted to fix) in [hdf5] Link zlib using the ZLIB::ZLIB target #18905.Which triplets are supported/not supported? Have you updated the CI baseline?
all, no
Does your PR follow the maintainer guide?
Changes limited to adding the wrapper.
If you have added/updated a port: Have you run
./vcpkg x-add-version --all
and committed the result?yes.
Tested with local cmake project.
Not tested with cmake < 3.15 due to #18898.
CC @Neumann-A who pointed out the issue's with CMake's FindZLIB module in #18905.