[cmake-developers] Exporting an imported target not supported?

Lassi Niemistö lassi.niemisto at wapice.com
Fri Mar 8 01:11:46 EST 2019


Hello,

Related to my recent crash report and its fix https://gitlab.kitware.com/cmake/cmake/merge_requests/3071 I struggle with exporting an imported target and according to the commit message it seems I will not be able to do that.

Use case:

·         Tree1 needs an external lib libextlib.so from /path/to/lib which is not a system path. Thus Tree1 creates an imported target "extlib" of it

·         Tree1 provides a library "lib1", links it to "extlib" and installs+exports "lib1"

·         Tree2 imports Tree1 export file and tries to make "myexe" which would link to "lib1". Which is fine.

·         Problem: linker for "myexe" needs to link to the soname of "extlib", e.g. libextlib.so.1 and it cannot find it because it is not in a system path

·         Solution1: Add /path/to/lib as a link_directory in Tree2. I dislike the solution as Tree2 should not need to know this

·         Solution2: Try to get /path/to/lib inherited in target properties all the way from "extlib" -> "lib1" -> "myexe" using target_link_directories. This fails due to those directories passed to linker via -L which is not used to find library _dependencies_

·         Solution3: Add -rpath-link /path/to/lib with target_link_options to "extlib" in Tree1 so that it would get inherited all the way to "myexe". It does not seem to inherit if "lib1" links to "extlib" in PRIVATE mode. Thus I need to link it "PUBLIC" which would require me to export the imported target "extlib".

o   If I do not install the target "extlib", I see no way to place it in the "export set" which makes the install of "lib1" to fail due to their PUBLIC linkage

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?

-Lassi Niemistö



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake-developers/attachments/20190308/6c48eda1/attachment.html>


More information about the cmake-developers mailing list