[CMake] running CMake from different parts of the tree

Andreas Pakulat apaku at gmx.de
Thu Mar 12 06:38:28 EDT 2009


On 11.03.09 16:15:02, Tyler Roscoe wrote:
> 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?

Yes.

> What causes it?

Because you're using two different builddirs. Each builddir is completely
standalone, it doesn't know anything about any other builddirectories on
your disk. So in fact for the productcli/build the baselib did change. If
you look into that builddir you'll see that it builds its own copy of
baselib and that needed to be updated because its not touched by anything
from baselib/build.

If you want to avoid that, you'll need to either:

- have a common base sourcedir containing a CMakeLists.txt that adds the
  baselib and productcli subdirs and create a builddir for that common base
- or build+install your baselib as shared or static library and let
  productcli find and link against that installed version of the library.

Andreas

-- 
"Life, loathe it or ignore it, you can't like it."
		-- Marvin, "Hitchhiker's Guide to the Galaxy"


More information about the CMake mailing list