[cmake-developers] target sources property (was: Linking to OBJECT libraries?)

Brad King brad.king at kitware.com
Thu Jun 6 10:52:19 EDT 2013


On 06/06/2013 10:41 AM, Stephen Kelly wrote:
> Brad King wrote:
>> Instead let's consider introducing a usage requirement that can bring
>> in object libraries, external objects, or even source files.  That
>> would solve this and be pretty cool too.
> 
> There's no existing API for manipulating the source items of a target after 
> its creation, so I thought that would be disallowed for some reason.
> 
> So, what we're talking about is something like a target property 
> SOURCE_ITEMS?
> 
>  # Only appending to this property allowed:
>  set_property(TARGET foo APPEND PROPERTY 
>    SOURCE_ITEMS
>      $<TARGET_OBJECTS:bar>
>      somefile.cpp
>      somecompileobject.o
>  )
> 
> and a corresponding INTERFACE_SOURCE_ITEMS which gets consumed from the link 
> interface?

Yes, something like this is what I had in mind.  I do not think we
need the "append only" requirement.  Instead we have two options:

(1) Name the property "EXTRA_SOURCES" and do not expose the
original sources at all so editing is not a problem.

(2) Name the property "SOURCES" and allow projects to edit it.
Having access to the list of sources for both reading and writing
has been requested occasionally.  It is not safe to edit after
reading the LOCATION property or something else that computes
the linker language, but we already document such undefined
behavior for LINKER_LANGUAGE and other properties.

I think I prefer option (2) because it is more general.

Either way we will have a chicken-and-egg problem of things like
$<LINK_LANGUAGE> affecting this usage requirement which could
bring in sources that affect the link language.  IIRC you have
a similar problem for the WIN32_EXECUTABLE property.

Also it may be tricky due to the way $<TARGET_SOURCES:...> is
currently handled up front.

-Brad



More information about the cmake-developers mailing list