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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to