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
 
meaning
 
project uses
 
LIB A,
LIB B
 
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)
 
here LIB B = HDF5_LIBRARY
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
 
<Lib>
<AdditionalOptions>%(AdditionalOptions) /machine:x64</AdditionalOptions>
<AdditionalDependencies>I:\nco\cmake\zlib\build\Debug\zlibstaticd.lib;I:\nco\cmake\szip\build\bin\Debug\libszip_D.lib</AdditionalDependencies>
</Lib
 
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
clone.bat
bld.bat
 
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
 
thanks
 
 
----------------------
Pedro Vicente
http://www.space-research.org/
 
 
 
 
 
 
 

--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

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

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake