# CMake: zlib dependency not properly propagted by hdf5 targets

**URL:** <https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149>\
**Category:** HDF5 Library\
**Created:** [December 6, 2018, 10:01am UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149 "2018-12-06T10:01:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![neumann](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@neumann](https://forum.hdfgroup.org/u/neumann)\
**Post date:** [December 6, 2018, 10:01am UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/1 "2018-12-06T10:01:17Z")

</div>

see [https://github.com/Microsoft/vcpkg/issues/4895](https://github.com/Microsoft/vcpkg/issues/4895)

---

<div class="post-metadata">

**Author:** ![byrn](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@byrn](https://forum.hdfgroup.org/u/byrn)\
**Post date:** [December 6, 2018, 2:06pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/2 "2018-12-06T14:06:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![neumann](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@neumann](https://forum.hdfgroup.org/u/neumann)\
**Post date:** [December 7, 2018, 6:59am UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/3 "2018-12-07T06:59:56Z")

</div>

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. )

---

<div class="post-metadata">

**Author:** ![chitty\_cloud](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/c/f6c823/32.png) [@chitty\_cloud](https://forum.hdfgroup.org/u/chitty_cloud)\
**Post date:** [January 6, 2019, 7:23pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/4 "2019-01-06T19:23:05Z")

</div>

Any progress on this issue ?

---

<div class="post-metadata">

**Author:** ![byrn](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@byrn](https://forum.hdfgroup.org/u/byrn)\
**Post date:** [February 26, 2019, 3:10pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/5 "2019-02-26T15:10:41Z")

</div>

Unfortunately, I don’t think I’ve gotten this correct yet. Although, all the dependent links now show:

> INTERFACE\_LINK\_LIBRARIES  
> “$\<$\<C\_COMPILER\_ID:MSVC\>:\>;$\<$\<CXX\_COMPILER\_ID:MSVC\>:\>;  
> $\<LINK\_ONLY:zlib-static\>;$\<LINK\_ONLY:szip-static\>;  
> $\<LINK\_ONLY:$\<$BOOL:OFF:\>\>;$\<$\<NOT:$\<PLATFORM\_ID:Windows\>\>:\>”

Allen

---

<div class="post-metadata">

**Author:** ![neumann](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@neumann](https://forum.hdfgroup.org/u/neumann)\
**Post date:** [March 7, 2019, 1:57pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/6 "2019-03-07T13:57:12Z")

</div>

~~I think the problem lies with szip and how it defines the target. with only szip-static cmake things it its a library and not an imported target. So szip should define targest SZIP::szip-static and SZIP::szip-shared so that cmake has a chance to figure out that szip-static and szip-shared are targets and not libraries.~~

screw that: The real problem is that hdf5-config.cmake does never reach the code:  
`include (${PACKAGE_PREFIX_DIR}/share/SZIP/SZIP-targets.cmake)`  
thus not including the szip-targets and failing to link against szip.

the code is guarded by:  
`if (NOT TARGET "hdf5")`  
`if (${HDF5_PACKAGE_NAME}_ENABLE_SZIP_SUPPORT AND ${HDF5_PACKAGE_NAME}_PACKAGE_EXTLIBS AND NOT TARGET "szip")`

Maybe the last `AND` should be an `OR`?

concerning the zlib release/debug issue. I found a comment in the vtk port of vcpkg:

> For VTK `vcpkg_fixup_cmake_targets` is not enough:  
> Files for system third party dependencies are written to modules that  
> are located in the paths `share/vtk/Modules` and `debug/share/vtk/Modules`.  
> In the release folder, only the release libraries are referenced (e.g. “C:/vcpkg/installed/x64-windows/lib/zlib.lib”).  
> But in the debug folder both libraries (e.g. “optimized;C:/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/vcpkg/installed/x64-windows/debug/lib/zlibd.lib”)  
> or only the debug library (e.g. “C:/vcpkg/installed/x64-windows/debug/lib/hdf5\_D.lib”) is referenced.  
> This is because VCPKG appends only the release library prefix (…/x64-windows/lib)  
> when configuring release but both (…/x64-windows/lib and …/x64-windows/debug/lib)  
> when configuring debug.

so the zlib issue is not an hdf5 issue but an vcpkg issue

---

<div class="post-metadata">

**Author:** ![byrn](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@byrn](https://forum.hdfgroup.org/u/byrn)\
**Post date:** [March 7, 2019, 4:42pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/7 "2019-03-07T16:42:56Z")

</div>

I will take a look and try some things - maybe we can get a solution for the next release of hdf5.  
Also maybe the AND NOT TARGET “zlib/szip” should just be deleted?

Allen

---

<div class="post-metadata">

**Author:** ![neumann](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/n/50afbb/32.png) [@neumann](https://forum.hdfgroup.org/u/neumann)\
**Post date:** [March 9, 2019, 9:42pm UTC](https://forum.hdfgroup.org/t/cmake-zlib-dependency-not-properly-propagted-by-hdf5-targets/5149/8 "2019-03-09T21:42:17Z")

</div>

Ok I think I figured this one out:

The problem is that vcpkg builds without HDF5\_PACKAGE\_EXTLIBS=ON so the szip target file is not included in hdf5config.cmake. On the other hand hdf5config.cmake is missing a find\_package(SZIP) call if HDF5\_PACKAGE\_EXTLIBS=OFF and the target szip is not yet defined!

The part in the config should look like:

> if (${HDF5\_PACKAGE\_NAME}\_ENABLE\_SZIP\_SUPPORT AND NOT TARGET “szip”)  
> if(${HDF5\_PACKAGE\_NAME}\_PACKAGE\_EXTLIBS)  
> include (${PACKAGE\_PREFIX\_DIR}/share/SZIP/SZIP-targets.cmake)  
> else()  
> find\_package(SZIP REQUIRED)  
> endif()  
> endif()

the same for zlib (although currently zlib does not define targets and as such the full paths to the libs is embedded by cmake within hdf5-targets.cmake )
