[cmake-developers] Object library linking (and a bit about INTERFACE_SOURCES)

Brad King brad.king at kitware.com
Tue Feb 24 15:34:39 EST 2015


On 02/23/2015 07:50 PM, Ben Boeckel wrote:
> We could also lift the restriction then. I'm fine with just dropping the
> patch. Basically without it, all it blocks is
> add_custom_{command,target} from using $<TARGET_OBJECTS>…which could be
> useful for some obscure linker target CMake doesn't understand. So maybe
> just lifting all such restrictions on $<TARGET_OBJECTS> is the thing to
> do.

Some restrictions are there because we cannot safely evaluate the
$<TARGET_OBJECTS> in general for all generators.  See the code
using EvaluateForBuildsystem.

>> I had imagined other cases which were easy to reason about (and probably 
>> more common to need) such as:
>>
>>  target_sources(a INTERFACE 
>>    $<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>sym1.c>
>>  )
>>
>> So that it would just 'pass through' any intermediate libraries.
> 
> That works for that case, but doesn't work when it needs to land in a
> specific shared or static library (though I suppose STREQUAL +
> TARGET_NAME could work there too, but that doesn't feel clean to me and
> also feels like the tail wagging the dog).

The author of the target_sources call likely has no idea what consumer
really wants the sources.  At most one could do something like:

 target_sources(someLib INTERFACE
  $<$<BOOL:$<TARGET_PROPERTY:GIVE_ME_someLib_SOURCES>>:someLib.c>)

with current functionality.

Until that problem is solved we cannot make object libraries
implicitly offer their objects just through tll().  That is
the reason I chose to use explicit $<TARGET_OBJECTS> in sources
in the first place.  It avoids the transitive multiple-use problem.
The transitivity problem is also the reason I disallowed linking
to/from object libraries originally.

>> I thought about denying INTERFACE_SOURCES to objlibs altogether
>> but decided against it since the same thing can be done with
>> other libraries anyways.

We should either solve this problem now or disallow the
INTERFACE_SOURCES of object libraries.  Then we will have the
freedom in the future to allow it with whatever semantics make sense
when the problem is eventually solved.  The difference between object
libraries and other library types is that the former have no usage
requirements yet so this is all new behavior for them anyway.  When
the problem is solved then we can activate INTERFACE_SOURCES for
object libraries and allow addition of $<TARGET_OBJECTS:self> to
it.

-Brad



More information about the cmake-developers mailing list