[cmake-developers] New INTERFACE_LINK_LIBRARIES policy approach

Brad King brad.king at kitware.com
Thu Jan 3 16:28:58 EST 2013


On 12/26/2012 06:04 AM, Stephen Kelly wrote:
> Brad King wrote:
>> For STATIC libraries we can
>> define that the PUBLIC/PRIVATE/INTERFACE keys are ignored for
>> linking and that it always populates both LINK_LIBRARIES
>> LINK_INTERFACE_LIBRARIES.
> 
> That also means that one can do this:
> 
>  add_library(libstatic STATIC ${srcs})
>  set_property(TARGET libstatic APPEND PROPERTY LINK_LIBRARIES foo)
>  # Warning: foo is not in the 'link interface' of libstatic.
> 
> It's quite a footgun. The existing semantic in CMake is 'for static 
> libraries, the link implementation is the link interface'. 

Yes, but we also don't expose the link implementation as a property.

> I don't see the reason to change that semantic. Exporting the link 
> implementation as the link interface is not that complicated. I'd also worry 
> that there are other code-complications of trying to treat the link 
> implementation as the link interface if it does not come from the property, 
> and not otherwise.

I think it would be simpler.  The link interface would now come from
INTERFACE_LINK_LIBRARIES for all target types.  We just need to make
sure it gets populated correctly by tll.  It should be straightforward
if we disallow LINK_PRIVATE for static libs.

> I'd rather not change it. Why do you think it's important to try to change? 
> You wrote that it allows projects to 'deal with the link interface for all 
> targets the same way'. Can you post some code showing that benefit?

It will simplify code for projects that want to process the link
interfaces of targets by reading their properties, which will be
more likely now that everything is specified by properties.

Right now one can read the link interface for any IMPORTED static
library from IMPORTED_LINK_INTERFACE_LIBRARIES, but the in-project
targets LINK_INTERFACE_LIBRARIES property has no meaning on static
libraries.

We have a chance to address this inconsistency when transitioning to
the new properties.  I'm proposing that in the new approach we say
"LINK_LIBRARIES is for building a target, INTERFACE_LINK_LIBRARIES
is for using a target".  The latter should be available as a property
on both imported and builtin targets, static or not.

-Brad



More information about the cmake-developers mailing list