[CMake] Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak saadrustam at gmail.com
Fri Dec 15 18:39:27 EST 2017


Thank you Marc. I found that the following also works:

target_link_libraries(LibD INTERFACE LibA LibB)

However, my guess is that in the future the above may break as it is
assuming LibD is an INTERFACE instead of an IMPORTED library. I'll switch
to your version instead as it seems to be more correct.

On Thu, Dec 14, 2017 at 3:40 AM CHEVRIER, Marc <marc.chevrier at sap.com>
wrote:

> I think you can fill a bug about erroneous behaviour when a list is
> specified with command set_target_properties for property
> IMPORTED_LINK_INTERFACE_LIBRARIES.
>
>
>
> Another way to specify the property is to use command set_property which
> supports multiple values for a property:
>
> set_property(TARGET LibD PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES LibA
> LibB)
>
>
>
>
>
> *From: *CMake <cmake-bounces at cmake.org> on behalf of Saad Khattak <
> saadrustam at gmail.com>
> *Date: *Thursday 14 December 2017 at 03:20
> *To: *Craig Scott <craig.scott at crascit.com>
> *Cc: *Cmake Mailing List <cmake at cmake.org>
> *Subject: *Re: [CMake] Using SET_TARGET_PROPERTIES and
> IMPORTED_LINK_INTERFACE_LIBRARIES
>
>
>
> 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://cmake.org/pipermail/cmake/attachments/20171215/4c4b1d08/attachment.html>


More information about the CMake mailing list