[CMake] how to inherit includes from other directories

Victor Yankee victor.whiskey.yankee at gmail.com
Fri Sep 2 13:27:02 EDT 2011


Hello,

I have the cmake book and have not found how to do what I need, if it is
possible.
I have a large project that must compile for both Linux and Windows. The
project is mostly header-only (except for unit tests) and categorized and
organized into subdirectories. Something like this:

build/
src/
      utils
              a
                     A.h
                     unittest_a.cpp

              b
                     B.h   // needs a.h
                     unittest_b.cpp

      common
              c
                    C.h      // needs A.h and B.h
                    testit.cpp   // needs C.h, B.h and A.h


The directory src/utils/a has a header file A.h. Likewise src/utils/b has a
header file B.h that #includes a.h.
Finally, c has a header file C.h that #includes a.h and b.h.


This is just a short example of my large project. In reality there are other
directories and levels of subdirectories.

What can I do in the local CMakeLists.txt files so that the directories
where the header files live are automatically made part of the others as
needed,
so I do not have to keep remembering all of them for every header-only
library all the way down the dependency chain?

I tried using add_custom_target(...) to create a header-only library target
for "a" and "b", then tried add_dependencies() for b (which needs a) and for
c(which needs b and by extension also needs a). This fails and in the build
directory if I do "cmake .." followed by "VERBOSE=1" make it fails in
src/common/c because there is no -Ia -Ib in the compile line.

I have attached this small example to this email though I don't know if the
mailman can handle attachments.

I hope all is clear.

Thanks for your kind assistance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110902/c8f4a8ac/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cmakeHeaderOnly.zip
Type: application/zip
Size: 5908 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110902/c8f4a8ac/attachment.zip>


More information about the CMake mailing list