Raymond,<br><br>I appreciate your detailed reply.<br><br>But apparently include_directories do not propagate UP, only down into subdirectories.<br>The project has many such subdirectories each with its own headers. I think my example<br>
was therefore misleading and too simple :(<br><br>There may 3 or 4 levels. At the top level, I would very much like to avoid needing to know all the dependencies at all the lower levels and exhaustively listing each one in an 'include_directories()' command.<br>
<br>If utils/B.h needs utils/A.h which needs foo/Z.h, then in my top-level directory (that only needs to know about B.h) what does its CMakeLists.txt look like? I would like to just be add_includes(utils/B) and have cmake figure out it also needs utils/A and foo.<br>
<br>I have somewhat succeeded by using a global variable called "my_includes" and using PARENT_SCOPE in all the low-level cmakelist files. But then I basically end up including all of the subdirectories all of the time.<br>
<br><br>-Victor<br><br><br><br><br><div class="gmail_quote">On Sun, Sep 4, 2011 at 8:15 AM, Raymond Wan <span dir="ltr"><<a href="mailto:r.wan@aist.go.jp">r.wan@aist.go.jp</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Victor,<br>
<br>
<br>
On Sat, Sep 3, 2011 at 02:27, Victor Yankee<br>
<<a href="mailto:victor.whiskey.yankee@gmail.com">victor.whiskey.yankee@gmail.com</a>> wrote:<br>
> build/<br>
> src/<br>
> utils<br>
> a<br>
> A.h<br>
> unittest_a.cpp<br>
><br>
> b<br>
> B.h // needs a.h<br>
><br>
> unittest_b.cpp<br>
><br>
> common<br>
> c<br>
> C.h // needs A.h and B.h<br>
> testit.cpp // needs C.h, B.h and A.h<br>
><br>
><br>
> The directory src/utils/a has a header file A.h. Likewise src/utils/b has a<br>
><br>
> header file B.h that #includes a.h.<br>
> Finally, c has a header file C.h that #includes a.h and b.h.<br>
><br>
><br>
> This is just a short example of my large project. In reality there are other<br>
> directories and levels of subdirectories.<br>
><br>
><br>
> What can I do in the local CMakeLists.txt files so that the directories<br>
> where the header files live are automatically made part of the others as<br>
> needed,<br>
> so I do not have to keep remembering all of them for every header-only<br>
><br>
> library all the way down the dependency chain?<br>
<br>
<br>
<br>
I'm not much of a CMake expert, but it sounds like something I've done<br>
and I think the INCLUDE_DIRECTORIES command is all you need:<br>
<br>
<a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories" target="_blank">http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories</a><br>
<br>
So in each of:<br>
<br>
src/utils/a<br>
src/utils/b<br>
src/common/c<br>
src/<br>
<br>
you would have a CMakeLists.txt . The first 3 performs the unit<br>
testing. And the top-level one in src/ is the one that builds your<br>
executable. In the CMakeLists.txt that refers to the header file in<br>
another directory, you would put INCLUDE_DIRECTORIES.<br>
<br>
You would then tie up their dependencies using ADD_DEPENDENCIES so<br>
that an executable is made once something else is made:<br>
<br>
<a href="http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies" target="_blank">http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies</a><br>
<br>
I *think* that is all you need. I've also used ADD_SUBDIRECTORY but<br>
I'm not too sure if you need it too in your situation.<br>
<br>
Hope this helps!<br>
<br>
Ray<br>
</blockquote></div><br>