Hi,

Your assumption is erroneous. INTERFACE keyword is related to dependencies 
behavior against target (see 
target_link_libraries<https://cmake.org/cmake/help/git-master/command/target_link_libraries.html>
 documentation). It do not specify type of target, so IMPORTED libraries will 
work as well.


From: Saad Khattak <saadrus...@gmail.com>
Date: Saturday 16 December 2017 at 00:39
To: "CHEVRIER, Marc" <marc.chevr...@sap.com>
Cc: Craig Scott <craig.sc...@crascit.com>, Cmake Mailing List <cmake@cmake.org>
Subject: Re: [CMake] Using SET_TARGET_PROPERTIES and 
IMPORTED_LINK_INTERFACE_LIBRARIES

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.chevr...@sap.com<mailto:marc.chevr...@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-boun...@cmake.org<mailto:cmake-boun...@cmake.org>> on behalf 
of Saad Khattak <saadrus...@gmail.com<mailto:saadrus...@gmail.com>>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <craig.sc...@crascit.com<mailto:craig.sc...@crascit.com>>
Cc: Cmake Mailing List <cmake@cmake.org<mailto:cmake@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.sc...@crascit.com<mailto:craig.sc...@crascit.com>> wrote:
On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak 
<saadrus...@gmail.com<mailto:saadrus...@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:
https://cmake.org/mailman/listinfo/cmake

Reply via email to