include library dependencies in static lib for Visual Studio

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

include library dependencies in static lib for Visual Studio

Pedro Vicente
I have a project with a chain of external libraries and some of the dependencies depend on each other as options
project uses
LIB B can use as option LIB C
my project then needs to inquire LIB B to see if LIB C was included (to link with LIB C)
I do this like this
message("-- Detecting if HDF5 library ${HDF5_LIBRARY} needs the ZLIB library...")
check_library_exists(${HDF5_LIBRARY} H5Z_DEFLATE "" NEED_ZLIB)
LIB C = the zlib library
this works with no problems in Linux.
However in Visual Studio , this detection only works if I manually set in the generated project
the option
"Link Library Dependencies"
to include LIB C (the zlib library)
these lines get added to the generated Visual Studio project
<AdditionalOptions>%(AdditionalOptions) /machine:x64</AdditionalOptions>
Is there a way that I can set this in the CMake script?
these comments show the problem
#HDF5 can be optionally linked with the SZIP library (Science Data Lossless Compression Program) and ZLIB
#Symbol to detect in ZLIB can be only H5Z_DEFLATE, a structure only defined in H5Zdeflate.c if the filter is enabled
#For SZIP the structure can be only H5Z_SZIP, defined in H5Zszip.c if the filter is enabled
#check_library_exists() tries to link a temporary program with these symbols
#On MSVC for this detection to work, the HDF5 library MUST HAVE as additional dependencies the ZLIB and SZIP libraries,
#which is not a requirement for the library to build successfully
to reproduce the problem, this is the project
on a windows Win64 developer shell
cd cmake
this will git clone and build dependencies, but there will be linking errors because the ZLIB (and SZIP) libraries
were not correctly identified as needed
Pedro Vicente


Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: