[cmake-developers] Exporting an imported target not supported?
Brad King
brad.king at kitware.com
Fri Mar 8 14:14:33 EST 2019
On 3/8/19 1:11 AM, Lassi Niemistö wrote:
> Am I just missing something and should be able to install the export
> of “extlib” without installing the target itself? Any reasoning why
> imported targets should not be possible to export? Any other solution
> ideas for passing the custom link dir of imported lib nicely from tree to tree?
For your use case, CMake does have logic to generate -rpath-link flags
to find dependencies of linked shared libraries, but it needs to know
about these dependencies.
Here is how to handle this:
* Tree1 creates an imported target `extlib`.
It is *not* installed or exported.
* Tree1 creates, exports, and installs, `lib1.so` with a dependency
on `libextlib.so.1`. This creates a `Tree1Targets.cmake` file.
Tree1 should also provide a `Tree1Config.cmake` file that includes
the targets file. See
https://cmake.org/cmake/help/v3.14/manual/cmake-packages.7.html#creating-a-package-configuration-file
* Tree1Config.cmake *also* creates imported target `extlib`.
This will be loaded in the context of dependents.
* Tree2 does `find_package(Tree1)`. This loads `Tree1Config.cmake`
which brings in both `extlib` and `lib1`. Now the -rpath_link flag
can be created by CMake.
-Brad
More information about the cmake-developers
mailing list