HDF5 finds the wrong zlib #4904
Labels
Component - Build
CMake, Autotools
Priority - 2. Medium ⏹
It would be nice to have this in the next release
Type - Task
Actions that don't fit into any other type category
Describe the bug
HDF5 uses
find_package(ZLIB ... COMPONENTS ...)
before it falls back tofind_package(ZLIB)
in CMakeFilters.cmake. The former call scans the system for a CMake config file (due toCOMPONENTS
). The latter call uses the builtin FindZLIB.cmake module.Calling
find_package
twice is problematic because it messes up the search order: if a user configures HDF5 withCMAKE_PREFIX_PATH=/path/to/my/zlib
, and this zlib does not have an associated CMake config file, HDF5 will ignore it and pick up a system zlib if it has a config file.The problem happens for example on Fedora 40 after
dnf install zlib-devel
, which installs the filewhich is picked up by the first
find_package
call. The secondfind_package
call which would have found the intended zlib in the higher priority search directory is then ignored.Expected behavior
As a user, if I pass
-DCMAKE_PREFIX_PATH=/path/to/zlib
(without cmake config file), HDF5 should use this zlib, not system zlib (with cmake config file).Further, I would not expect HDF5 to prefer CMake config files at all, given that the promoted build system for zlib is their configure script, which obviously does not create a CMake config file.
I would strongly suggest to use one and only one
find_package
call, and useZLIB_USE_STATIC_LIBS
introduced in CMake 3.24 instead of rolling your own.Platform (please complete the following information)
zlib-devel
installedAdditional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: