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

Ben Boeckel ben.boeckel at kitware.com
Wed Feb 25 14:49:03 EST 2015


On Mon, Feb 23, 2015 at 13:44:13 -0500, Ben Boeckel wrote:
<snip>

After discussion with Brad here, the current, tentative, plan is as
follows:

  - When creating $<LINK_ONLY> generator expressions, if the name is a
    target, add $<TARGET_NAME> as well. This will help the exporter find
    targets which need exporting from the build.
  - When exporting, if $<LINK_ONLY:$<TARGET_NAME:ifacelib>> is found and
    ifacelib has no link interface, remove the entire expression. This
    will address bug #15415 so that interface libraries linked with
    PRIVATE can stay unexported.

This will at least allow the INTERFACE-for-OBJECT use case work for
PRIVATE usage of them.

For the OBJECT library half of this:

  - Add support for tll(objlib foo) and tll(foo objlib); tll(objlib1
    objlib2) will be unsupported for now; implementation for it can come
    later as there are could be other issues with that case.
  - Use $<LINK_ONLY> for PRIVATE libraries in the INTERFACE of object
    libraries (will use the same code path as static libraries here).
  - When exporting, if an OBJECT library is found to be referenced such
    that it also needs to be exported, add it to the current export set
    as an INTERFACE library with all of the interface properties of the
    object library.
      * The above check for stripping LINK_ONLY will also do so for
        object libraries.
      * Targets exported this way will be placed in the same export set
        as the target which triggered it and will share a namespace,
        export set, etc. The name will be mangled as it is purely an
        implementation detail.
      * Manually exporting object libraries will still be disallowed.

Things that crossed my mind since the discussion (or were mentioned
before but not resolved completely):

  - Make it an error to use a non-empty INTERFACE_SOURCES for object
    libraries (a new policy).
  - When exporting the object library's interface, empty
    INTERFACE_SOURCES regardless of the above policy ($<TARGET_OBJECTS>
    will only cause errors on the now-INTERFACE library). Stripping it
    in the common case is possible, but it could be deep in genex
    conditions and not able to be found.

Another, much lower priority, branch (only tangentially related to
either of the above) would be to make the following work as one would
expect:

    add_library(A OBJECT a.c)
    add_library(B OBJECT b.c $<TARGET_OBJECTS:A>)
    add_library(C SHARED c.c $<TARGET_OBJECTS:B>)

Where $<TARGET_OBJECTS:B> would bring in $<TARGET_OBJECTS:A> as well
(currently OBJECT libraries may not have TARGET_OBJECTS as sources). I
have a patch for the implementation of this already if anyone else would
like to add the tests and docs for it before I get around to it.

Thoughts?

--Ben


More information about the cmake-developers mailing list