[CMake] ADD_SUBDIRECTORY() with a higher level directory

Daniel Dekkers d.dekkers at cthrough.nl
Thu Nov 3 16:10:35 EDT 2011


Hi,

We are creating a directory structure for distribution of an open-source
library with examples included.
It looks something like this:

+ library <- the root directory
  CMakeLists.txt <- create context for building (only) the library
  + src <- contains the sources of the library
    CMakeLists.txt <- actually add sources for (only) the library
  + examples
    CMakeLists.txt <- create context for building all the examples (and the
library, once)
    + example0
      CMakeLists.txt <- create context for building example0 (and the
library)
      + src
        CMakeLists.txt <- add sources for example0
      + rsrc
    + example1
      CMakeLists.txt <- create context for building example1 (and the
library)
      + src
        CMakeLists.txt <- add sources for example1 
      + rsrc
    + ...

The CMakeLists.txt in library, library/examples and
library/examples/example0 and library/examples/example1 should all be
possible entry points for a build. Maybe you want to build only the library,
maybe you want to build the whole example suite, or maybe an individual
example.

Of course, the CMakeLists.txt in examples (or example0 and example1) depends
on the actual library, so, from that level, we would like to call
ADD_SUBDIRECTORY() to the *higher level* library directory... which is
unacceptable for ADD_SUBDIRECTORY() (and probably conflicts with the whole
CMake structure).

If we would move examples "up" the hierarchy there wouldn't be a problem,
but that doesn't give a nice distribution package.

Any hints on a proper way to do this?

Kind Regards,

Daniel Dekkers



More information about the CMake mailing list