[CMake] Setting include directories on a target, not directory.

Robert Dailey rcdailey at gmail.com
Mon Mar 30 16:24:03 EDT 2009


Hi,
I realize there's another post on the list where another user was asking
relatively the same question, but this specific issue was never addressed.

What I'm trying to do is specify include directories on a per-project basis.
I'm avoiding the monolithic shared include directories approach, where a
manually managed list of include directories are provided in a call to
include_directories() at the root source level (CMAKE_SOURCE_DIR).

Instead, I'm assigning include directories returned by find_package() to
each project. Furthermore, the include directories of any dependent projects
must be included in this list. As you can see, this is recursive.

For example, let's assume I have 3 projects named A, B, and C. Project A
depends on B, and B depends on C.

A includes -> C:\foo
B includes -> C:\bar
C includes -> C:\baz

When I process the includes for project A, I flatten the hierarchical list
of includes into a list:
C:\foo;C:\bar;C:\baz

These become my include directories for A. I do this because A may be using
header files from project B, and in B's header files may be including
headers from C:\bar. For this reason, this is required in order for A to
compile.

The issue is that I cannot do this as I process each project. This is
because A is processed before B, and I cannot obtain B's include directories
from A until B has been processed. So this obviously has to have 2 passes.

The first pass involves creating all of the projects and defining internal
cache variables for each project that define their dependencies and
includes. So project A would have a cache variable that looks like this:

A_INCLUDE_DIRS = C:\foo;B

The list has 2 types of items in it. First we list the include directories
for A. At the end, we append the list of targets that A depends on. In this
case, it's B. Project B's variable looks like this:

B_INCLUDE_DIRS = C:\bar;C

You get the picture now...

This allows me to recursively process the dependencies for A.

The first pass involves all of these cache variables getting defined. Once
they're all defined, we now have all the information prepared and we can now
perform the recursion to obtain the dependencies for A. The problem is, I
can't set the dependencies for A now that we're no longer processing A's
CMakeLists.txt file. Pass 2 takes place in the root CMakeLists after all of
the add_subdirectory() calls have been made. If there were only a way for me
to call set_target_properties( INCLUDE_DIRECTORIES ) of some sort, this
could be done. However, INCLUDE_DIRECTORIES property is read-only according
to the documentation. In addition, the INCLUDE_DIRECTORIES property is a
directory specific property and not a property for targets, which further
complicates this process.

What do you guys recommend? I like my approach to solving this problem, it's
just that I can't do the steps required in my 2nd pass (Post-processing
phase) in order to set the include directories on my projects (targets).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090330/106d0928/attachment.htm>


More information about the CMake mailing list