-
-
Notifications
You must be signed in to change notification settings - Fork 469
cmake: better zlib-ng / zlib handling #886
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
Conversation
Instead of assuming zlib-ng preference over zlib as a dependency, let the user decide. New cmake variable MZ_ZLIB_FLAVOR can be set to auto | zlib-ng | zlib defaults to auto.
I tested against a system wide zlib-ng 2.2.4, zlib 1.3.1 and vcpkg zlib 1.3.1 |
I was running into the same problem, so am happy to see that it's being worked on :) The proposed fix improves things for me but there are still some wrinkles. My use case is to make a local installation of minizip-ng built against zlib-ng, and then build a project against that. Starting from
where minizip-ng is at sgoth:zlib-ng-fixes (57d1e28), I run
A couple of observations:
Now that zlib-ng provides zlib-ng-config.cmake, is FindZLIB-NG.cmake still needed? In most cases I think it's preferable to rely on the config file provided by the dependency (e.g., zlib-ng) rather than implementing a find script in the consumer (e.g., minizip-ng), because
In my case, the inconsistency in 1 and the issue in 2 can be fixed by removing FindZLIB-NG.cmake and replacing the lines
by
This links ${MINIZIP_TARGET} against the zlib-ng::zlib target, which adds both include directories and link libraries. (I'm not familiar with the CMake conventions of minizip-ng, so I don't know whether MINIZIP_LIB is the right variable to use for CMake targets, as opposed to just library names.) Note that zlib-ng-config.cmake was added in zlib-ng 2.1.7, so if it's important for minizip-ng to be compatible with earlier versions, FindZLIB-NG.cmake would still be needed (perhaps only used as a fallback for that case). Of course, there may also be other reasons for keeping FindZLIB-NG.cmake that I'm not aware of. |
Thanks for testing!
That's totally fine - as long as both ways find the same things it doesn't really matter.
FindZLIB-NG sounds just broken for Windows then...
I'd second that. Could replace 1176a22 but the other change would stay the same. To just disable zlib-ng usage i ended up using |
In short: yes
For Windows, building minizip-ng against zlib-ng doesn't seem to work at all. That is unchanged by this PR. If it were my project i'd merge this and treat the rest as separate issues. |
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.
Sorry for the delay, I have not been in the best of health.
@@ -39,6 +39,16 @@ message(STATUS "Using CMake version ${CMAKE_VERSION}") | |||
option(MZ_COMPAT "Enables compatibility layer" ON) | |||
# Compression library options | |||
option(MZ_ZLIB "Enables ZLIB compression" ON) | |||
|
|||
# Controls to select either zlib-ng or zlib | |||
set(MZ_ZLIB_FLAVOR "auto" CACHE STRING "Select the preferred zlib flavor - auto searches for zlib-ng then zlib") |
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.
Is it possible to use option() here?
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.
Should the README be updated to include the new option?
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.
yes, updating the readme for that is a good idea
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.
Is it possible to use option() here?
option is boolean - it could be framed as MZ_ZLIB_PREFER_ZLIB-NG
or something like that.
Not sure if that's any better but i can do that if you provide the name 😅
With MZ_SANITIZER we already do it with a string "option".
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.
Should the README be updated to include the new option?
Done
Contains two changes around how zlib-ng/zlib is handled in cmake.
Fixes minizip-ng-config.cmake relies on non-existant zlib-ng-config.cmake #722 by renaming FindZLIBNG to FindZLIB-NG (and all internal naming for consistency)
It works with ZLIBNG to build minizip-ng itself but leads cmake to put a call to
find_dependency(ZLIBNG REQUIRED)
that searches for zlibng-config.cmake in its generated minizip-ng-config.cmake when the actual config is called zlib-ng-config.cmakeAdds a new MZ_ZLIB_FLAVOR cmake variable that allows either auto|zlib-ng|zlib defaulting to auto (unchanged behavior).
This puts users in control of the used zlib implementation should both be available.
Especially via package managers the old situation leads to "silently" linking the wrong library if the package manager provides zlib but zlib-ng is still found as a system wide installation.
Let me know if i should split these into 2 PRs.