[CMake] running CMake from different parts of the tree

Tyler Roscoe tyler at cryptio.net
Wed Mar 11 19:15:02 EDT 2009


Let's say I have two components baselib and productlib. baselib has a
CMakeLists and knows how to build itself. productlib has a CMakeLists,
has add_subdirectory() and add_dependencies() and target_link_libs()
calls to baselib, and knows how to build baselib and then itself.

As a developer, I'm making some changes in baselib. I cd into
baselib/build, run cmake .., and run make every once in a while to check
my changes.

Now I'm done so I want to make sure that productlib still works. So I cd
into productli/build and run cmake ... When I run make, I am surprised
to see that baselib recompiles and relinks even though there have been
no changes (other than running cmake from a different directory).

Is this expected? What causes it? I see that the generated Makefile gets
rewritten with some different paths -- is that what triggers the
rebuild, or is it something else?

Do your developers accept this as a fact of life, or do they have
workarounds, or do they simply not work in this way (preferring to do
something like always run make from the same top-level build directory
no matter where in the tree they are working)? Am I crazy for wanting
the ability to work with each component both on its own and as part of
the larger system?

Is there a way to avoid this behavior through careful writing of
CMakeLists? Through some other hacks?

Thanks,
tyler


More information about the CMake mailing list