Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak
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
  )

However, the above syntax is incorrect and CMake complains that SET_TARGET_PROPERTIES was called with incorrect number of arguments. 

So I thought maybe the following will work:

set_target_properties(LibD
  PROPERTIES
    IMPORTED_LINK_INTERFACE_LIBRARIES LibA
    IMPORTED_LINK_INTERFACE_LIBRARIES LibB
  )

Although this time CMake doesn't complaint, only LibB's libraries are linked ultimately, LibA is overwritten. Doing the following, of course, doesn't work because LibA is now an imported library and not exactly a variable that can be used directly:

set_target_properties(LibD
  PROPERTIES
    IMPORTED_LINK_INTERFACE_LIBRARIES "${LibA};${LibB}" # not correct because LibA and LibB are CMake imported libraries, not direct paths to libraries
  )

Is there any way to specify, for an imported target, multiple dependencies on other libraries (and/or dependencies on other imported libraries).

Thanks,
Saad

--

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
Reply | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Craig Scott-3


On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak
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 <[hidden email]> wrote:
On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Petr Kmoch
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 <[hidden email]> 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 <[hidden email]> wrote:
On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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

--

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


--

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
Reply | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

CHEVRIER, Marc
In reply to this post by Saad Khattak

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 <[hidden email]> on behalf of Saad Khattak <[hidden email]>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <[hidden email]>
Cc: Cmake Mailing List <[hidden email]>
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 <[hidden email]> wrote:

On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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


--

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
Reply | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Craig Scott-3


On Thu, Dec 14, 2017 at 7:40 PM, CHEVRIER, Marc <[hidden email]> 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.


You can set multiple properties with set_target_properties() and you are allowed to define your own property names, so CMake could never know for sure if you are defining a list for one property or defining multiple properties.


 

 

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 <[hidden email]> on behalf of Saad Khattak <[hidden email]>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <[hidden email]>
Cc: Cmake Mailing List <[hidden email]>
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 <[hidden email]> wrote:

On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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




--
Craig Scott
Melbourne, Australia

--

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 | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak
In reply to this post by CHEVRIER, Marc
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 <[hidden email]> 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 <[hidden email]> on behalf of Saad Khattak <[hidden email]>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <[hidden email]>
Cc: Cmake Mailing List <[hidden email]>
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 <[hidden email]> wrote:

On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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


--

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 | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

CHEVRIER, Marc

Hi,

 

Your assumption is erroneous. INTERFACE keyword is related to dependencies behavior against target (see target_link_libraries documentation). It do not specify type of target, so IMPORTED libraries will work as well.

 

 

From: Saad Khattak <[hidden email]>
Date: Saturday 16 December 2017 at 00:39
To: "CHEVRIER, Marc" <[hidden email]>
Cc: Craig Scott <[hidden email]>, Cmake Mailing List <[hidden email]>
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 <[hidden email]> 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 <[hidden email]> on behalf of Saad Khattak <[hidden email]>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <[hidden email]>
Cc: Cmake Mailing List <[hidden email]>
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 <[hidden email]> wrote:

On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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


--

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 | Threaded
Open this post in threaded view
|

Re: Using SET_TARGET_PROPERTIES and IMPORTED_LINK_INTERFACE_LIBRARIES

Saad Khattak
Thank you for clearing that up Marc! I'll continue to use target_link_libraries (... INTERFACE ...) for imported libraries.

On Mon, Dec 18, 2017 at 3:06 AM CHEVRIER, Marc <[hidden email]> wrote:

Hi,

 

Your assumption is erroneous. INTERFACE keyword is related to dependencies behavior against target (see target_link_libraries documentation). It do not specify type of target, so IMPORTED libraries will work as well.

 

 

From: Saad Khattak <[hidden email]>
Date: Saturday 16 December 2017 at 00:39
To: "CHEVRIER, Marc" <[hidden email]>
Cc: Craig Scott <[hidden email]>, Cmake Mailing List <[hidden email]>


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 <[hidden email]> 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 <[hidden email]> on behalf of Saad Khattak <[hidden email]>
Date: Thursday 14 December 2017 at 03:20
To: Craig Scott <[hidden email]>
Cc: Cmake Mailing List <[hidden email]>
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 <[hidden email]> wrote:

On Thu, Dec 14, 2017 at 8:22 AM, Saad Khattak <[hidden email]> 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


--

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