[CMake] Transitive include and link libraries on imported targets ?

David Jobet david.jobet at free.fr
Mon Apr 10 04:25:42 EDT 2017


Hello,

After googling a bit I found this post which I think describe exactly what I'm facing : https://cmake.org/pipermail/cmake/2016-August/064100.html

However I fail to understand the answers. Maybe I'm expecting too much.

Basically, I have 2 imported static targets (A and B with B that needs A to compile and link) that I'd like to treat them as "first class cmake citizen".
What I mean by that is that if one of my project lib depends on B, then I want both B and A's include directories to be added to my lib's include directories and I want both A and B's lib to be linked against my lib.

So far I can use INTERFACE_LINK_LIBRARIES on B to add A's lib, and I guess I can use INTERFACE_INCLUDE_DIRECTORIES to add A's includes, but that won't pull transitive dependencies of A into B.

I can use target_link_libraries on an interface of B to add A as described in my first email : that will properly pull any transitive include or libs but that won't make sure that link order is preserved.

Please help.

David

Le 7 avril 2017 15:27:23 GMT+01:00, David Jobet <david.jobet at free.fr> a écrit :
>INTERFACE_LINK_LIBRARIES won't work since it won't pull out include
>path for dependants.
>
>Using target_link_libraries() on the imported lib does not work because
>"it is not built".
>
>So the question remains open : how to represent include and link
>dependencies between 2 imported libs ?
>
>With regards,
>
>David
>
>PS : as to why I had to have 2 stages (A_imported and A), this is
>because I wanted to add an alias which is not possible on an imported
>target
>
>Le 7 avril 2017 12:32:52 GMT+01:00, David Jobet <david.jobet at free.fr> a
>écrit :
>>Well not quite.
>>I tried that, but my current definition is rather
>>Target_link_libraries(B interface B_imported)
>>
>>I don't remember for which reason I had to do it in 2 stages like that
>>(the A/A_imported and B/B_imported versions)
>>
>>If I add A in the list to read :
>>Target_link_libraries(B interface B_imported A)
>>
>>Then linking against B does add B_imported and A, but it does not keep
>>the link order and might put B_imported before A on the command line.
>>
>>I'll try with property INTERFACE_LINK_LIBRARIES instead, and will also
>>try to remove those 2 stages...
>>
>>With regards
>>
>>David
>>
>>Le 6 avril 2017 05:11:46 GMT+01:00, Dvir Yitzchaki
>><Dvir.Yitzchaki at ceva-dsp.com> a écrit :
>>>target_link_libraries(B INTERFACE A)
>>>
>>>Regards,
>>>Dvir
>>>
>>>From: CMake [mailto:cmake-bounces at cmake.org] On Behalf Of David Jobet
>>>Sent: Wednesday, April 5, 2017 18:34
>>>To: cmake at cmake.org
>>>Subject: [CMake] Transitive include and link libraries on imported
>>>targets ?
>>>
>>>Hello,
>>>
>>>Let's say I build some external libs A and B with B depending on A.
>>>B and A do not use cmake, so I build them and install them in a
>>>3rdparty directory. I now have access to includes and libs.
>>>I then create some cmake file to describe those libs so I can use
>them
>>>in my project :
>>>Add_library(A_imported STATIC imported)
>>>Set_property(TARGET A_imported APPEND PROPERTY
>>>INTERFACE_INCLUDE_DIRECTORIES 3rdparty/include/A)
>>>Set_property(TARGET A_imported APPEND PROPERTY IMPORTED_LOCATION
>>>3rdparty/libs/libA.a)
>>>Add_library(A INTERFACE)
>>>Target_link_library(A INTERFACE A_imported)
>>>
>>>Same thing for B
>>>
>>>Now let's say I create a top-level target T that depends on B.
>>>Compilation might fail because B might include files from A and A is
>>>currently not a dependency of T.
>>>
>>>I can fix it in 2 ways :
>>>1- add A as a dependency of T, but I will need to do it on all my Ts
>>>2- somehow make B have transitive dependencies for include and link
>on
>>>A. That would be my prefered choice... But I don't know how to do it.
>>>
>>>Is it possible ? How ?
>>>
>>>Tx for your help.
>>>
>>>David
>>
>>-- 
>>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez
>excuser
>>ma brièveté.
>
>-- 
>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser
>ma brièveté.

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170410/9994ee16/attachment.html>


More information about the CMake mailing list