[cmake-developers] Setting the link interface and dependencies in one command

Alexander Neundorf neundorf at kde.org
Sun Oct 9 11:35:29 EDT 2011


On Thursday 06 October 2011, Brad King wrote:
> On 10/5/2011 9:47 AM, Stephen Kelly wrote:
> > Thanks for all of your explanations. It seems that introducing a way to
> > do this with one command has some support.
> > 
> > So if SOME_FEATURE is true,
> > 
> > target_link_libraries(foo bar SOME_KEYWORD baz)
> > if (SOME_FEATURE)
> > 
> >    target_link_libraries(foo mar SOME_KEYWORD maz)
> > 
> > endif()
> > 
> > would have to result in bar and mar not being part of the link interface,
> > and baz and maz being part of the link interface.
> > 
> > How do we decide on a keyword there? LINK_INTERFACE_DEPENDENCIES perhaps?
> 
> One possible problem with making it a keyword is that the name could appear
> in a list of libraries and invisibly transform a target_link_libraries
> call. What we need is a pair of keywords to switch between link+interface
> and link-only dependencies.  We allow the keywords only if one of the two
> is the second argument to the command after the target name.  For example,
> they can be called "LINK_INTERFACE" for link+interface and "LINK_DEPENDS"
> for link-only:
> 
>    target_link_libraries(foo LINK_INTERFACE bar LINK_DEPENDS baz)
>    if(SOME_FEATURE)
>      target_link_libraries(foo LINK_INTERFACE mar LINK_DEPENDS maz)
>    endif()
> 
> Other possible names?  Perhaps LINK_PUBLIC and LINK_PRIVATE?


But doesn't this still have the same problem ?

I mean, if "LINK_PUBLIC" is at the end of a ${FOO_LIBS} variable, everything 
put after it will be PUBLIC:
target_link_libraries(Foo LINK_PRIVATE lib1 lib2 ${FOO_LIBS} lib3)

with FOO_LIBS being e.g. "LINK_PRIVATE libA LINK_PUBLIC libB".
Or isn't that what you meant ?

Alex



More information about the cmake-developers mailing list