[cmake-developers] New OBJECT library feature

Brad King brad.king at kitware.com
Mon Mar 19 13:46:46 EDT 2012


Hi Folks,

I've just pushed a new 'object-library' topic and merged to 'next'
for testing.  David Cole and I have been working on it for a couple
of weeks.  The following documentation added to the add_library
command explains:

--------------------------------------------------------------------------
  The signature

    add_library(<name> OBJECT <src>...)

  creates a special "object library" target.  An object library compiles
  source files but does not archive or link their object files into a
  library.  Instead other targets created by add_library or
  add_executable may reference the objects using an expression of the
  form $<TARGET_OBJECTS:objlib> as a source, where "objlib" is the
  object library name.  For example:

    add_library(... $<TARGET_OBJECTS:objlib> ...)
    add_executable(... $<TARGET_OBJECTS:objlib> ...)

  will include objlib's object files in a library and an executable
  along with those compiled from their own sources.  Object libraries
  may contain only sources (and headers) that compile to object files.
  They may contain custom commands generating such sources, but not
  PRE_BUILD, PRE_LINK, or POST_BUILD commands.  Object libraries cannot
  be imported, exported, installed, or linked.
--------------------------------------------------------------------------

Many of the documented restrictions are temporary until meaningful
behavior can be defined and implemented for them in a future version.
It is easiest to simply disallow all but the basic use case for now.

This feature plays a role similar to autotools convenience libraries
but works with all toolchains and under VS and Xcode.  We've updated
all primary generators to support object libraries including the Ninja
generator.  Until this goes into master watch out for conflicts when
making changes to the other generators.

We are still missing support in the "Extra" generators to present
OBJECT libraries in the project files.  They need to appear much like
STATIC libraries but have no library/archive file.  We request help
from the contributors of Extra generators to handle them.

Thanks,
-Brad


More information about the cmake-developers mailing list