[CMake] ADD_SUBDIRECTORY() with a higher level directory

Dan Kegel dank at kegel.com
Sun Nov 6 10:47:12 EST 2011


On Sun, Nov 6, 2011 at 7:27 AM, Daniel Dekkers <d.dekkers at cthrough.nl> wrote:
> This "template" stuff should really be in the documentation, it would have
> helped me a lot.
> More than http://www.cmake.org/cmake/help/examples.html. A library called
> "Hello", really?

FWIW, I'm gathering more examples at
http://code.google.com/p/winezeug/source/browse/#svn/trunk/cmake_examples

I'm also facing questions of how to organize cmake builds for
existing software, but haven't added any examples about that yet;
the examples I have are simple things (how to use gtest, how
to use eclipse, etc.)

In my case, the existing software consists of a bunch of
libraries and programs currently living in their own versioned svn
directories, e.g.
   libfoo/releases/1.1/src/...
   libbar/trunk/src/...
   baz/releases/1.0/src/...
and all the developers check those directories out into unversioned
directories on local disk, e.g.
   libfoo/src/...
   libbar/src/...
   baz/src/...
There's simply no top level directory where one could put an enclosing
CMakeLists.txt!
I can't reorganize the source tree on the developers,
so I'm making do by putting the enclosing CMakeLists.txt next to all
the projects:
   toplevel/trunk/CMakeLists.txt
which is checked out to
   toplevel/CMakeLists.txt
It does
   add_subdirectory(../libfoo libfoo)
   add_subdirectory(../libbar libbar)
   add_subdirectory(../baz baz)

This has the possible advantage that one can have multiple
"top levels" (say, one for server code, and one for client).

I don't know how many shops suffer from this svn layout, but I'll probably
add an example covering it anyway for completeness once I'm sure
it doesn't explode in practice.
- Dan


More information about the CMake mailing list