[CMake] [2.8.12.1] Bug in Xcode generation of STATIC from OBJECT libraries

Paul Smith paul at mad-scientist.net
Thu Jan 23 11:36:34 EST 2014


On Thu, 2014-01-23 at 10:22 -0500, Brad King wrote:
> On Thu, Jan 23, 2014 at 8:03 AM, Paul Smith <paul at mad-scientist.net> wrote:
> >   add_library(mylib STATIC $<TARGET_OBJECTS:mylib_OBJECTS>)
> [snip]
> > The Makefile generators work fine
> >
> > For Xcode, though, the link fails:
> 
> This is a known limitation.  From the add_library documentation:
> 
>  http://www.cmake.org/cmake/help/v2.8.12/cmake.html#command:add_library
>  "Some native build systems may not like targets that have only object files,
>   so consider adding at least one real source file"

I see.  That's a shame :-(.

I have lots of these libraries and so I was trying to write a macro that
would do all this stuff for me (create the OBJECT library then the
STATIC library, plus it does a few other things I need done like set
certain properties).

Then later in one CMakeLists.txt file I would collect all the OBJECT
libraries into a single SHARED library, like:

  set(SO_OBJECTS)
  foreach(LIB lib1 lib2 lib3 lib4)
      list(APPEND SO_OBJECTS $<TARGET_OBJECTS:${LIB}_OBJECTS>)
  endforeach()

That worked great--for makefile generators.

If I have to exclude one of the source files from the OBJECT library so
I can include it directly into the STATIC library, now somehow I have to
also remember that extra source file so it can be included in the SHARED
library as well.

Also, doesn't that mean that I'll be compiling those source files which
are omitted from the OBJECT library twice, once for shared and once for
static?

Kind of unpleasant.  Anyone have any ideas?



More information about the CMake mailing list