Static Libraries and target_link_libraries

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

Static Libraries and target_link_libraries

Andrew Bell

When creating a static library, you can still use the function "target_link_libraries" even though the static library is never linked, as such.  What you're doing is creating a dependency record for cmake so that target_link_libraries of a static library are included in a link of some other target which depends on the static library.  What seems confusing is that target_link_libraries accepts the keywords PUBLIC and PRIVATE as well as INTERFACE when used with a static library, since only INTERFACE really makes sense in this context.

Would it be beneficial to issue a warning when someone uses PUBLIC or PRIVATE with target_link_libraries on a static library to make it clear that they may not be understanding what's going on?
 
--
Andrew Bell
[hidden email]

--

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: Static Libraries and target_link_libraries

Marc CHEVRIER
It is quite inexact because a target can store many information like include directories or preprocessor definitions for example (through properties like INCLUDE_DIRECTORIES or COMPILE_DEFINITIONS).

So it make sense to enable to specify link libraries to a static library using PRIVATE or PUBLIC to ensure various settings are propagated to the static library compilation step. 
Le 25 janv. 2019 à 15:46 +0100, Andrew Bell <[hidden email]>, a écrit :

When creating a static library, you can still use the function "target_link_libraries" even though the static library is never linked, as such.  What you're doing is creating a dependency record for cmake so that target_link_libraries of a static library are included in a link of some other target which depends on the static library.  What seems confusing is that target_link_libraries accepts the keywords PUBLIC and PRIVATE as well as INTERFACE when used with a static library, since only INTERFACE really makes sense in this context.

Would it be beneficial to issue a warning when someone uses PUBLIC or PRIVATE with target_link_libraries on a static library to make it clear that they may not be understanding what's going on?
 
--
Andrew Bell
[hidden email]
--

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

--

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: Static Libraries and target_link_libraries

Kevin Puetz

I often hit this, particularly with header-only INTERFACE libraries where I just want to pick up their defines/include paths, and then CMake ends up treating the target_link_libraries(PRIVATE as public anyway). So it would definitely be helpful to have a warning that this doesn’t do what you’d expect, and maybe a pointer to $<BUILD_INTERFACE:header_library> which seems to be the only way to actually have a private (not listed in the exported <project-config.cmake> dependency while building a static library.

 

From: CMake [mailto:[hidden email]] On Behalf Of Marc CHEVRIER
Sent: Friday, January 25, 2019 8:54 AM
To: Cmake Mailing List <[hidden email]>; Andrew Bell <[hidden email]>
Subject: Re: [CMake] Static Libraries and target_link_libraries

 

It is quite inexact because a target can store many information like include directories or preprocessor definitions for example (through properties like INCLUDE_DIRECTORIES or COMPILE_DEFINITIONS).

 

So it make sense to enable to specify link libraries to a static library using PRIVATE or PUBLIC to ensure various settings are propagated to the static library compilation step. 

Le 25 janv. 2019 à 15:46 +0100, Andrew Bell <[hidden email]>, a écrit :

 

When creating a static library, you can still use the function "target_link_libraries" even though the static library is never linked, as such.  What you're doing is creating a dependency record for cmake so that target_link_libraries of a static library are included in a link of some other target which depends on the static library.  What seems confusing is that target_link_libraries accepts the keywords PUBLIC and PRIVATE as well as INTERFACE when used with a static library, since only INTERFACE really makes sense in this context.

 

Would it be beneficial to issue a warning when someone uses PUBLIC or PRIVATE with target_link_libraries on a static library to make it clear that they may not be understanding what's going on?

 
--

Andrew Bell
[hidden email]

--

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


--

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