Raymond, I appreciate your detailed reply.
But apparently include_directories do not propagate UP, only down into subdirectories. The project has many such subdirectories each with its own headers. I think my example was therefore misleading and too simple :( 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. 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. 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. -Victor On Sun, Sep 4, 2011 at 8:15 AM, Raymond Wan <[email protected]> wrote: > Hi Victor, > > > On Sat, Sep 3, 2011 at 02:27, Victor Yankee > <[email protected]> wrote: > > 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'm not much of a CMake expert, but it sounds like something I've done > and I think the INCLUDE_DIRECTORIES command is all you need: > > > http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:include_directories > > So in each of: > > src/utils/a > src/utils/b > src/common/c > src/ > > you would have a CMakeLists.txt . The first 3 performs the unit > testing. And the top-level one in src/ is the one that builds your > executable. In the CMakeLists.txt that refers to the header file in > another directory, you would put INCLUDE_DIRECTORIES. > > You would then tie up their dependencies using ADD_DEPENDENCIES so > that an executable is made once something else is made: > > > http://www.cmake.org/cmake/help/cmake-2-8-docs.html#command:add_dependencies > > I *think* that is all you need. I've also used ADD_SUBDIRECTORY but > I'm not too sure if you need it too in your situation. > > Hope this helps! > > Ray >
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
