[CMake] $<> expressions in include_directories command

Daniel Pfeifer purplekarrot at gmail.com
Tue Jul 12 12:34:24 EDT 2011


Hi fellows of Ryppl and CMake,

we are currently in the process of modularizing the Boost C++
Libraries into small individual components. All these components may
depend upon each other, circular dependencies may occur too. We use
CMake to configure, build, test, package etc. We are quite successful.

Concerning include directories, we make all header files available
from one directory. We do this either with symlinks or with forwading
headers, depending on whether symlinks are possible on that platform
or not. This works, but has several drawbacks:

1. It is slow. Generating forwarding headers for all headers that we
use is a matter of minutes. We can improve the speed by checking the
existence of files or symlinking directories, but then:

2. It is fragile. When we add a file header file in a directory that
is forwarded via a symlink we may accidentally put it into the source
directory.

3. it is not correct. Each component may access all header files. It
should be able to access the headers of its dependency tree only.


For a fast, stable, and correct solution, we want to add the right set
of include directories directly, without forwarding anything. However,
the right set of include directories is unknown until all components
have been processed.

Example: We have the components A, B, C. A depends on B, B depends on
C. Therefore, A should be using the include directories of B and C.
This information however is unknown until the components B and C have
been processed. The include directories cannot be declared while
processing A.


The ideal solution for us would be the following:

> include_directories($<FOOBAR_DIRS>)
> ...
> set(FOOBAR_DIRS /usr/include/foo)

The generator expression $<FOOBAR_DIRS> is evaluated in the final pass
of the include_directories command. It is possible to 'use' the value
FOOBAR_LIBS before it has been set.

I already implemented the functionality above. The generator
expressions are expanded incrementally and recursive expansion is
taken care of. See: https://github.com/purpleKarrot/CMake/commit/5f73bcf40fe8b9150bf61afaa3783b56be9e8270

Can we get this functionality upstream?

cheers, Daniel


More information about the CMake mailing list