Skip to content
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

CMake: Finding zlib dependency broken since v1.14.5: ZLib support in HDF5 was enabled but not found #5303

Open
tbeu opened this issue Feb 7, 2025 · 7 comments

Comments

@tbeu
Copy link
Contributor

tbeu commented Feb 7, 2025

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.

@byrnHDF
Copy link
Contributor

byrnHDF commented Feb 10, 2025

why are you setting;
set(ZLIB_FOUND ON)

@byrnHDF
Copy link
Contributor

byrnHDF commented Feb 10, 2025

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)

@tbeu
Copy link
Contributor Author

tbeu commented Feb 10, 2025

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.

@byrnHDF
Copy link
Contributor

byrnHDF commented Feb 11, 2025

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.

@tbeu
Copy link
Contributor Author

tbeu commented Feb 11, 2025

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!

@byrnHDF
Copy link
Contributor

byrnHDF commented Feb 11, 2025

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.

@tbeu
Copy link
Contributor Author

tbeu commented Feb 15, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants