[CMake] Conditional transitive link libraries

Daniel Wirtz daniel.wirtz at simtech.uni-stuttgart.de
Mon Jun 1 05:03:53 EDT 2015


Hello all,

I'm struggling with the CMake "Config"-based package description when 
using two depending packages where the upstream package has optional 
link libraries.

Suppose you have libA that optionally uses zip functionality (say by 
some option USE_ZLIB in libA's CMakeLists.txt). This means libA will 
optionally have -lz in its INTERFACE_LINK_LIBRARIES (exported into 
liba-config.cmake).
Now, if you have a libB using libA via find_package(libA), how do you 
know if libA has been built with or without zlib support when both 
libraries are installed and exported with CMake's package config system?

I know that the link library information is treated transitively and 
will be propagated to the link libraries of libB, hence -lz will appear 
whenever linking against libB. However, the PATH to libz is nowhere 
included; consequently, the link fails with "could not find library z" 
unless you magically knew that libz is a dependent link library of libA 
and where to include it from. Including the absolute path to libz in 
libA's config is also not the way to go, as it ruins the portability 
over different systems.

Is there a "native" CMake way?

Thanks!

-- 
Dr. Daniel Wirtz
Dipl. Math. Dipl. Inf.
SRC SimTech
Pfaffenwaldring 5a
+49 711 685 60044



More information about the CMake mailing list