[CMake] How to create transitive include dirs and preprocessor defs

Marcel Loose loose at astron.nl
Wed Apr 22 04:03:53 EDT 2009


Hi all,

I'm currently converting a medium-sized project from Autotools to CMake.
In that project we used the concept of "packages", where we defined a
package as a directory containing sources (and header files) that
together form a logical unit and are translated into a object library.
These packages are interdependent (no cyclic dependencies are allowed).

To mimic this structure I decided to use CMake projects. So, a toy
project would look something like this:

bigproject
  projectA
    subA1
    subA2
  projectB
    subB1

where each sub* project will produce (at least) one library and zero or
more executable programs. For simplicity, lets assume that the library
names are the lowercase version of the project names. So, project subA1
will produce the library libsuba1.a

Now suppose, that subA2 depends on subA1, and that subA1 depends on some
external package ext1. It's not difficult to have subA2 pick up its
dependency on ext1's library, because transitive library dependencies
are properly handled by CMake. But what about include directories and
preprocessor variables that are used by subA1 when its sources are
compiled against ext1? 

Suppose that one of subA1's header files includes a header file from
ext1. I can specify this in subA1 CMakeLists file by using
include_directories(). However, subA2 will fail to compile when it
includes this header file, because the compiler cannot find ext1's
header file. More or less the same can be said about preprocessor
variables; you would like to "inherit" the preprocessor variables from
the project that you depend upon.

So, what is the right way to handle transitive dependencies on include
directories and preprocessor variables? 

Best regards,
Marcel Loose.




More information about the CMake mailing list