[CMake] Transitive link question

Michael Hertling mhertling at online.de
Thu Dec 15 05:19:41 EST 2011


On 12/13/2011 11:00 PM, Biddiscombe, John A. wrote:
>>
> Sure, when project A is loaded into project B it either needs to search and load the hdf5 cmake file or require that to be done in project B before loading project A. Then the hdf5 target will be known in project B too and linking will work fine.
> <
> 
> Using find_package in project B is an option, but what I was really trying to ask is if there's a way to make the transitive link get the correct library on its own. Since I have a number of different versions of the hdf5 package installed, there's a chance that project B will use the wrong one (ok, not when I'm doing it because I know, but if a third party needs to do the same). Since project A knows the correct library and name/lib other target properties, I would like it to make it available to project B/C/D etc

If A is linked against HDF5, and "hdf5" is an imported target, the
latter will appear among A's transitive link dependencies with its
symbolic name instead of a full path to the library. In fact, this
separation of target names and library paths is the basic idea of
imported targets, and what you're asking for is rather the opposite.

If you really want to have HDF5's debug library mentioned explicitly
among A's prerequisites, you might query the IMPORTED_LOCATION_DEBUG
property of "hdf5" and link A against that value. However, in this
way, you lose the flexibility w.r.t. choosing libraries in link
command lines based on the build/configuration type.

Generally, IMO, the best bet is to provide a full-featured config file
AConfig.cmake which includes the appropriate file(s) provided by HDF5,
so any of A's clients can issue FIND_PACKAGE(A) and receives complete
information about A and its prerequisites. This is the most powerful
solution, and you might even parameterize AConfig.cmake in a manner
so that the client can choose which HDF5 installation the config
file should look for, e.g. via an HDF5_ROOT variable.

Regards,

Michael


More information about the CMake mailing list