CMake: Finding zlib dependency broken since v1.14.5: ZLib support in HDF5 was enabled but not found
Describe the bug
The following CMake file snippet works with v1.14.4.3, but fails with v1.14.5 and 1.14.6 where the configuration warning: "ZLib support in HDF5 was enabled but not found" is stated which later on results in run-time exceptions.
project(MyProject CXX)
include(FetchContent)
FetchContent_Declare(
zlib
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.3.1
GIT_SHALLOW TRUE
)
FetchContent_Declare(
hdf5
GIT_REPOSITORY https://github.com/HDFGroup/hdf5.git
# GIT_TAG hdf5_1.14.4.3 # works
GIT_TAG hdf5_1.14.5 #fails
GIT_SHALLOW TRUE
)
set(ZLIB_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(INSTALL_BIN_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "" FORCE)
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "" FORCE)
set(SKIP_INSTALL_ALL OFF CACHE BOOL "" FORCE)
set(SKIP_INSTALL_FILES ON CACHE BOOL "" FORCE)
set(SKIP_INSTALL_HEADERS ON CACHE BOOL "" FORCE)
set(ZLIB_FOUND ON)
set(ZLIB_USE_EXTERNAL ON)
set(HDF5_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_HL_LIB OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_PARALLEL_TOOLS OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_UTILS OFF CACHE BOOL "" FORCE)
set(HDF5_DISABLE_COMPILER_WARNINGS ON CACHE BOOL "" FORCE)
set(HDF5_ENABLE_ALL_WARNINGS OFF CACHE BOOL "" FORCE)
set(HDF5_ENABLE_DEPRECATED_SYMBOLS OFF CACHE BOOL "" FORCE)
set(HDF5_ENABLE_NONSTANDARD_FEATURES OFF CACHE BOOL "" FORCE)
set(HDF5_ENABLE_SZIP_SUPPORT OFF CACHE BOOL "" FORCE)
set(HDF5_ENABLE_WARNINGS_AS_ERRORS OFF CACHE BOOL "" FORCE)
set(HDF5_ENABLE_Z_LIB_SUPPORT ON CACHE BOOL "" FORCE)
set(HDF5_EXPORTED_TARGETS)
set(HDF5_EXTERNALLY_CONFIGURED ON CACHE BOOL "" FORCE)
set(HDF5_INSTALL_NO_DEVELOPMENT ON CACHE BOOL "" FORCE)
set(HDF5_INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "" FORCE)
set(HDF5_LIB_DEPENDENCIES zlib)
set(HDF5_TEST_CPP OFF CACHE BOOL "" FORCE)
set(HDF5_TEST_EXAMPLES OFF CACHE BOOL "" FORCE)
set(HDF5_TEST_SERIAL OFF CACHE BOOL "" FORCE)
set(HDF5_TEST_SWMR OFF CACHE BOOL "" FORCE)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(zlib)
set(ZLIB_INCLUDE_DIR ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
set(ZLIB_INCLUDE_DIRS ${zlib_SOURCE_DIR} ${zlib_BINARY_DIR})
FetchContent_MakeAvailable(hdf5)
set(HDF5_INCLUDE_DIR "${hdf5_SOURCE_DIR}/src" "${hdf5_SOURCE_DIR}/src/H5FDsubfiling" "${hdf5_BINARY_DIR}/src")
Expected behavior A minor release must not break the build scripts of downstream users.
Platform (please complete the following information)
- HDF5 version: v1.14.5 and v1.14.6
- OS and version: any
- Compiler and version: any
- Build system (e.g. CMake, Autotools) and version: CMake (any current version)
Additional context Add any other context about the problem here.
why are you setting; set(ZLIB_FOUND ON)
Also, to use an installed zlib, hdf5 needs: ZLIB_USE_EXTERNAL:BOOL=OFF Yes, the name is confusing but the description is: Use External Library Building for ZLIB This controls wether the zlib is built-in (ON) or found on the system (OFF)
Thanks for the reply.
After removing set(ZLIB_FOUND ON) and ZLIB_USE_EXTERNAL negated to set(ZLIB_USE_EXTERNAL OFF) hdf5 configure finds the system zlib On Ubuntu and nothing on Win. The intent is to use the user-provided zlib instead.
The FindZLIB.cmake module usually works best with setting the ENV(ZLIB_ROOT) to where zlib is installed. If that doesn't work and the zlib was built with CMake and provides zlib-config.cmake file, HDF5_MODULE_MODE_ZLIB:BOOL=OFF might help.
I don't get hdf5 configured with zlib dependency as expected. This is just to much trial and error. Do you have a working proposal based on the example CMake code? Thanks again for your support!
Unfortunately, I had to resort to this CMake option: Note that if there is a problem finding the libraries, try adding the CMake variable CMAKE_FIND_DEBUG_MODE:BOOL=ON to the command line.
Given my knowledge and the high number of option combinations I have to admit that I do not have the endurance to run the tests repeatedly via CI. Obviously it is not trivial at all to update a working build script (yes, probably based on workarounds or shortcuts) from 1.14.4 to 1.14.5 or 1.14.6.
If you are curious, the whole workflow is taken from https://github.com/tbeu/ModelicaTableAdditions/blob/main/ModelicaTableAdditions/Resources/BuildProjects/CMake/test.cmake
Given that zlib compression is consistent across versions and that hdf5 does not expose the zlib APIs - I would recommend that the settings let hdf5 build a private version of zlib to use. This should avoid the error. Finding a pre-built zlib needs to be careful with getting all the variables correct in a complicated set of find_package calls. This would be the case with libaec as well.
Thanks for the reply. I am not sure what this actually means to my setup. Currently I am locked to v1.14.4 without hope to migrate any time soon.
Yes, I can relate to the confusion. To put it bluntly, this use case is beyond our resources to maintain. My suggestion was to simplify the settings and let hdf5 build the compression libraries within its own build environment.