[CMake] How to exclude linking from add_subdirectory?

Eric Noulard eric.noulard at gmail.com
Sat Mar 25 05:06:24 EDT 2017


You should check the options PUBLIC, PRIVATE, of the
target_link_librairies.
See: https://cmake.org/cmake/help/v3.7/command/target_link_libraries.html

transitive linking is achieved through PUBLIC or INTERFACE whereas PRIVATE
does not propagate.
AFAIU your shared lib should PRIVATEly target_link_librairies to your
shared lib.
Moreover the way you describe it suggest that your static libs may well be
OBJECT libraries:
https://cmake.org/cmake/help/v3.7/command/add_library.html#object-libraries

Next time, posting some excerpt of your CMakeLists.txt would make it easier
to answer with example.
Eric

Le 25 mars 2017 6:14 AM, "kipade" <kipade at 163.com> a écrit :

> In my cmake project, there are some subdirectories within it, and some of
> them have to build as completed
> static or shared libraries.
> 1. The top project is executable
> 2. a subdirectory is a shared project, which also have some subdirectoy
> compile as static libraries which
>    of course should ONLY link into their parent shared library
> I add link options to linking the shared library produced by its
> subdirectory(which linked as a shared library),
> but I found the all sub-static library with the shared library project(the
> subdirectory) also double linked into
> the top executable project. Of course I only want to link the shared
> library. How to resolve such problem
> for the top CMakeLists.txt?
>
>
>
>
> --
>
> 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/opensou
> rce/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/20170325/136c4c10/attachment.html>


More information about the CMake mailing list