HDFGroup / HDFGroup/hdf5

unnecessary calls to `find_dependency(ZLIB)` when depending on hdf5-shared

Open
#6,347 12 comments 0 reactions 1 assignee Claimed by @jhendersonHDF View on GitHub
Component - Build
Dominant language
C
Stars
988
Forks
355
Avg merge
4d 2h
Merged PRs (30d)
12

Description

**Describe the bug**

`find_dependency(ZLIB)` is called in `hdf5-config.cmake` even though hdf5 links zlib internally, which means it is not relevant when linking to hdf5 as a shared library.

I believe the same issue applies to SZIP.

**Expected behavior**

I can link hdf5 as a shared library even when zlib development files are not available, as worked fine with 1.14.6. Specifically, `find_dependency` is only called on dependencies required to link hdf5.

**Platform (please complete the following information)**
- HDF5 version 2.1.0
- OS and version linux (alma9)
- Compiler and version: gcc 14
- Build system (e.g. CMake version) and generator (e.g. XCode, Ninja) CMake 4.3
- Any configure options you specified:
```
cmake ${CMAKE_ARGS} -LAH -G "Ninja" \
-DHDF5_ENABLE_ZLIB_SUPPORT=ON \
-DHDF5_ENABLE_SZIP_SUPPORT=ON \
-DHDF5_BUILD_CPP_LIB=ON \
-DHDF5_BUILD_HL_LIB=ON \
-DHDF5_BUILD_FORTRAN=ON \
-DHDF5_BUILD_EXAMPLES=OFF \
-DHDF5_H5CC_C_COMPILER=`basename ${CC}` \
-DHDF5_H5CC_CXX_COMPILER=`basename ${CXX}` \
-DHDF5_H5CC_Fortran_COMPILER=`basename ${FC}` \
-DH5_DEFAULT_PLUGINDIR="${PREFIX}/lib/hdf5/plugin" \
-DHDF5_ENABLE_THREADSAFE=ON \
-DHDF5_ALLOW_UNSUPPORTED=ON \
-DHDF5_ENABLE_ROS3_VFD=ON \
-DHDF5_ENABLE_NONSTANDARD_FEATURES=OFF \
-DBUILD_STATIC_LIBS=OFF \
-B build .
```
- MPI library and version (parallel HDF5) none

**Additional context**

This is coming up on conda-forge, where the zlib development package (containing headers, cmake files, etc.) is a new requirement to build against hdf5, where it wasn't before, only needing the actual runtime library. zlib is not linked at any point in this process, so this produces an incorrect direct dependency on zlib for packages that only link hdf5.

Related issues:

- similar discussion in #6279
- these calls were added in #5547 to address https://github.com/CGNS/CGNS/pull/834 which I think is specific to hdf5-static, and not applicable to a shared library build

**Suggested solution**

Add an appropriate conditional [here](https://github.com/HDFGroup/hdf5/blob/5c96f3ba48f8327f96c99a6b139d4712c1b501aa/config/install/hdf5-config.cmake.in#L127-L144) so that `find_dependency` is only called on transitive dependencies when they are needed to link to hdf5, which I _think_ would only be static builds. It's possible that this is just adding `AND @BUILD_STATIC_LIBS@`, but it may be more complex than that.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.