[CMake] Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak saadrustam at gmail.com
Wed Dec 13 21:19:58 EST 2017


Thanks Craig for your reply.

The issue is that both "LibA" and "LibB" have been set using
"add_library(LibA STATIC IMPORTED)" and "add_library(LibB IMPORTED)" and
both have some properties that are being set.

Ultimately, CMake recognizes LibA and LibB as CMake library projects, and
they have their own include and link directories and other library
dependencies.

The nice thing about using LibA directly is then LibD inherits all the
include and link directories of LibA and LibB which then get inherited by
any library or executable that includes LibD (and ultimately, the whole
point of modern CMake):

set_target_properties(LibD
  PROPERTIES
    IMPORTED_LINK_INTERFACE_LIBRARIES LibA #cmake recognizes LibA as
IMPORTED CMake libraries
)

If I use "LibA;LibB" then first, I have to manually extract the library
names of the imported CMake libraries LibA and LibB. Then, I have to call
"target_include_directories" and "target_link_libraries" for all
dependencies of LibA and LibB, even though these dependencies were defined
in their own respective CMake files when calling "add_library(LibA STATIC
IMPORTED)"

set_target_properties(LibD
  PROPERTIES
    IMPORTED_LINK_INTERFACE_LIBRARIES "LibA;LibB" #cmake no longer
recognizes LibA and LibB as IMPORTED CMake libraries
)

Regards,
Saad

On Wed, Dec 13, 2017 at 4:32 PM Craig Scott <craig.scott at crascit.com> wrote:

> On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <saadrustam at gmail.com>
> wrote:
>
>> Hi,
>>
>> I have several imported libraries:
>>
>> LibA
>> LibB
>> LibC
>>
>> Where each imported library has been populated by (where ${LIB_NAME} is
>> either LibA, LibB or LibC):
>>
>> add_library(${LIB_NAME} STATIC IMPORTED)
>>
>> And each library has the properties IMPORT_LOCATION_${CONFIGURATION} set
>> properly:
>>
>> set_target_properties(${LIB_NAME}
>>     PROPERTIES IMPORTED_LOCATION_DEBUG # same for release
>>    "location/of/library.lib"
>>     )
>>
>> Now let's say I have another imported library LibD that depends on LibA
>> and LibB such that any executable that uses LibD must also link with LibA
>> and LibB. To do that, I use:
>>
>> set_target_properties(LibD
>>   PROPERTIES
>>     IMPORTED_LINK_INTERFACE_LIBRARIES LibA LibB
>>   )
>>
>
> You probably want this instead:
>
> set_target_properties(LibD
>   PROPERTIES
>     IMPORTED_LINK_INTERFACE_LIBRARIES "LibA;LibB"
> )
>
>
> Note that if the property value is a list, you have to provide it as a
> single string (i.e. "LibA;LibB" rather than LibA LibB)
>
>
>
> --
> Craig Scott
> Melbourne, Australia
> https://crascit.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171214/5bb078ce/attachment.html>


More information about the CMake mailing list