Skip to content

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

@minrk

Description

@minrk

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:

Suggested solution

Add an appropriate conditional here 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.

Metadata

Metadata

Assignees

Type

Projects

Status

On-Deck

Relationships

None yet

Development

No branches or pull requests

Issue actions