The CMake situation in frameworks

Alexander Neundorf neundorf at kde.org
Tue Nov 29 17:41:25 UTC 2011


On Monday 28 November 2011, Ingo Klöcker wrote:
> On Saturday 26 November 2011, Stephen Kelly wrote:
> > > target_link_libraries(foo
> > > 
> > >    LINK_PUBLIC
> > >    ${QT_QTCORE_LIBRARIES}
> > >    LINK_PRIVATE
> > >    ${QT_QTSCRIPT_LIBRARIES}
> > > 
> > > )
> > 
> > Only this or
> > 
> > target_link_libraries(foo
> > 
> >    LINK_PRIVATE
> >    ${QT_QTSCRIPT_LIBRARIES}
> >    LINK_PUBLIC
> >    ${QT_QTCORE_LIBRARIES}
> > 
> > )
> > 
> > would work. I don't remember why. It might make sense to allow
> > specifying only one of them, so that the below would be equivalent
> > to the above.
> > 
> > target_link_libraries(foo
> > 
> >    ${QT_QTSCRIPT_LIBRARIES}
> >    LINK_PUBLIC
> >    ${QT_QTCORE_LIBRARIES}
> > 
> > )
> > 
> > target_link_libraries(foo
> > 
> >    ${QT_QTCORE_LIBRARIES}
> >    LINK_PRIVATE
> >    ${QT_QTSCRIPT_LIBRARIES}
> > 
> > )
> > 
> > But I guess the cmake devs would have to agree to it.
> 
> If anything then target_link_libraries() should have one well-defined
> default and everything else should have to be specified explicitly.
> Everything else is just confusing and error-prone. In C++ it was done
> right for classes (and structs): A well-defined default combined with an
> easy to understand way to change it explicitly.

Finally I actually had a look at the docs.
Here is what the docs say:

target_link_libraries(<target> [item1 [item2 [...]]]
                      [[debug|optimized|general] <item>] ...)
...
    Library dependencies are transitive by default.
    When this target is linked into another target then the libraries
    linked to this target will appear on the link line for the other
    target too.
    See the LINK_INTERFACE_LIBRARIES target property to override the
    set of transitive link dependencies for a target.

...
target_link_libraries(<target>
                      <LINK_PRIVATE|LINK_PUBLIC>
                      [[debug|optimized|general] <lib>] ...
                      [<LINK_PRIVATE|LINK_PUBLIC>
                      [[debug|optimized|general] <lib>] ...] )
    The LINK_PUBLIC and LINK_PRIVATE modes can be used to specify both
    the link dependencies and the link interface in one command.
    Libraries and targets following LINK_PUBLIC are linked to, and are
    made part of the LINK_INTERFACE_LIBRARIES. Libraries and targets
    following LINK_PRIVATE are linked to, but are not made part of the
    LINK_INTERFACE_LIBRARIES. 


So, either you don't use LINK_PUBLIC or LINK_PRIVATE, then all libs are 
considered LINK_PUBLIC, or you use it, then it must follow directly after the 
target name, i.e. there is no room for any libraries where a default would 
match.

Alex


More information about the Kde-buildsystem mailing list