[CMake] Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Petr Kmoch petr.kmoch at gmail.com
Thu Dec 14 03:34:50 EST 2017


Hi Saad,

have you read the docs on IMPORTED_LINK_INTERFACE_LIBRARIES? (
https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_LINK_INTERFACE_LIBRARIES.html
):

  "This property is deprecated. Use INTERFACE_LINK_LIBRARIES instead."

Setting INTERFACE_LINK_LIBRARIES to "LibA;LibB" should do exactly what you
want.

As a side note, the shorthand funciton set_target_properties() and friends
are best suited when multiple properties to one value each. When setting a
list, it's usually more convenient to use the general set_property():

set_property(
  TARGET LibD
  PROPERTY INTERFACE_LINK_LIBRARIES
  LibA LibB
)

Petr


On 14 December 2017 at 03:19, Saad Khattak <saadrustam at gmail.com> wrote:

> 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
>>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171214/c0328b4f/attachment-0001.html>


More information about the CMake mailing list