[CMake] OBJECT libraries and dependencies

Leif Walsh leif.walsh at gmail.com
Tue Mar 4 16:51:48 EST 2014


Hi all,

I'm dealing with an annoying problem with the linker, that I realize is
non-standard usage but I'm hoping CMake can help.

The main question is, is there any way in CMake to use OBJECT libraries but
still represent dependency graph information?

I have a bunch of global variables with constructors that have important
side-effects (I know...), and for build graph sanity, these get linked into
static libraries which depend on each other.  When we link executables,
some object files get excluded because they only have global variables that
aren't referenced anywhere else (because their constructors are supposed to
"register" them), and then of course that code just doesn't make it in to
the executable.

It looks like I have three options:

1. Manually insert a reference to each object file in the compilation unit
containing main().  This means manually maintaining this list and possibly
forgetting to add things in the future.

2. Use -Wl,-whole-archive.  This approach is at odds with CMake's helpful
static library dependency (and mutual dependency) tracking and resolution,
and can result in multiple definition errors as often as it results in
forgetting to include object files.

2.5. It's possible to use -Wl,-whole-archive just on some libraries, not
the depended-on ones, but this has a similar problem to options 1 and 3, in
that we need to manually maintain a list of "important" libraries.

3. Make every library an OBJECT library.  AFAICT this requires listing
every library in the dependency graph in the add_executable() directive,
and not having dependency information tracked locally to the library that
has the dependency.  There also may be ordering issues I haven't discovered
yet.

What would be wonderful is if CMake could track dependencies for OBJECT
libraries the same way it tracks them for STATIC libraries.  Is this
planned somewhere?  Does it already exist in a property I haven't seen yet?

-- 
Cheers,
Leif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20140304/4b40866b/attachment.html>


More information about the CMake mailing list