[CMake] Difference between PRIVATE and PUBLIC with target_link_libraries

iosif neitzke iosif.neitzke+cmake at gmail.com
Thu May 12 09:47:33 EDT 2016


My reading of your examples:

exe1 gets linked to lib2, and lib2/bin is included.  exe1 probably
won't link ultimately because lib2 may need symbols from lib1.
Depends on the structure of the C code between lib2 and lib1.   See
John Lakos for further information on that.

exe2 gets linked to lib3, and gets lib3/bin included because lib3 has
PUBLIC in its own target_include_directories command.  Because exe2
gets lib3, it also gets lib1 and lib1/tmp.

On Thu, May 12, 2016 at 8:19 AM, Patrick Boettcher
<patrick.boettcher at posteo.de> wrote:
> On Wed, 11 May 2016 21:58:34 +1000
> Craig Scott <craig.scott at crascit.com> wrote:
>
> [..]
>> If you were paying careful attention, you would have noticed that
>> when A links in B as PRIVATE, the include directories of B never
>> propagate to something linking to A, but if A is a static library,
>> then the *linking* of B behaves as though the relationship was
>> PUBLIC. This PRIVATE-becomes-PUBLIC behaviour for static libraries
>> only applies to the *linking*, not to the other dependencies
>> (compiler options/flags and include search paths). The upshot of all
>> this is that if you select PRIVATE, PUBLIC or INTERFACE based on the
>> explanations in the dot points above, then CMake will ensure
>> dependencies propagate through to where they are required, regardless
>> of whether libraries are static or shared. This does, of course, rely
>> on you the developer not missing any dependencies or specifying the
>> wrong PRIVATE/PUBLIC/INTERFACE relationship.
>
> Thank you for you long explanation. It was exactly my understanding.
>
> So cmake 3.5.0 has a bug then because I don't see the behavior you
> describe. Have you seen my example I sent in my first mail?
>
> http://public.kitware.com/pipermail/cmake/2016-May/063382.html
>
> Include-dirs from B are propagated to C which links to A which itself
> linked privately to B.
>
> Should I file a bug?
>
> regards,
> --
> Patrick.
>
>
>
>
>
>
>
>


More information about the CMake mailing list