CMake: zlib dependency not properly propagted by hdf5 targets


#1

see https://github.com/Microsoft/vcpkg/issues/4895


#2

zlib in hdf5 is private and static because zlib is used internally and hdf5 does not have a requirement to expose the zlib interface.
The requirement for zlib linking should be then under downstream application control.

Allen


#3

So i found the real culprit. I don’t know if this is a HDF5 or a CMake issue.

The problem is within hdf5-targets.cmake which is different between debug and release builds.

E.g.:
In debug it contains:

set_target_properties(hdf5::hdf5-static PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "\$<IF:\$<CONFIG:Debug>,DEBUG,NDEBUG>"
  INTERFACE_INCLUDE_DIRECTORIES "G:/MPINew/mpi_vcpkg/buildtrees/hdf5/x64-windows-dbg/src;G:/MPINew/mpi_vcpkg/buildtrees/hdf5/src/CMake-hdf5-1.10.4/hdf5-1.10.4/src"
  INTERFACE_LINK_LIBRARIES "\$<\$<C_COMPILER_ID:MSVC>:>;\$<\$<CXX_COMPILER_ID:MSVC>:>;\$<\$<NOT:\$<CONFIG:DEBUG>>:G:/MPINew/mpi_vcpkg/installed/x64-windows/lib/zlib.lib>;\$<\$<CONFIG:DEBUG>:G:/MPINew/mpi_vcpkg/installed/x64-windows/debug/lib/zlibd.lib>;\$<LINK_ONLY:szip-static>;\$<LINK_ONLY:\$<\$<BOOL:OFF>:>>;\$<\$<NOT:\$<PLATFORM_ID:Windows>>:>"
)

the important part here is:

$<$<NOT:$CONFIG:DEBUG>:G:/MPINew/mpi_vcpkg/installed/x64-windows/lib/zlib.lib>;$<$CONFIG:DEBUG:G:/MPINew/mpi_vcpkg/installed/x64-windows/debug/lib/zlibd.lib>;

while in Release:

set_target_properties(hdf5::hdf5-static PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "\$<IF:\$<CONFIG:Debug>,DEBUG,NDEBUG>"
  INTERFACE_INCLUDE_DIRECTORIES "G:/MPINew/mpi_vcpkg/buildtrees/hdf5/x64-windows-rel/src;G:/MPINew/mpi_vcpkg/buildtrees/hdf5/src/CMake-hdf5-1.10.4/hdf5-1.10.4/src"
  INTERFACE_LINK_LIBRARIES "\$<\$<C_COMPILER_ID:MSVC>:>;\$<\$<CXX_COMPILER_ID:MSVC>:>;G:/MPINew/mpi_vcpkg/installed/x64-windows/lib/zlib.lib;\$<LINK_ONLY:szip-static>;\$<LINK_ONLY:\$<\$<BOOL:OFF>:>>;\$<\$<NOT:\$<PLATFORM_ID:Windows>>:>"
)

the important part here:

G:/MPINew/mpi_vcpkg/installed/x64-windows/lib/zlib.lib;

so the release version contains less information.
So my question now would be: Is HDF5 generating the two different files or is this a CMake issue?

(also the LINK_ONLY:szip-static will not work. )