[CMake] how to inherit includes from other directories

Raymond Wan r.wan at aist.go.jp
Thu Sep 8 01:00:47 EDT 2011


Hi Glenn,


On Wed, Sep 7, 2011 at 20:36, Glenn Coombs <glenn.coombs at gmail.com> wrote:
> Could you not create a file in each subdirectory called something like
> header-deps.cmake ?  This file would contain the include_directory()
> commands necessary for using this module, plus include() commands of other
> modules that it depends on.  So for your example:
>
> # utils/b/header-deps.cmake
> include_directories(...)
> include(${CMAKE_SOURCE_DIR)/utils/a/header-deps.cmake)
>
> # utils/a/header-deps.cmake
> include_directories(${CMAKE_SOURCE_DIR}/common/foo)
>
> Then you can just do include(${CMAKE_SOURCE_DIR}/utils/b/header-deps.cmake)
> and it will add everything that B needs including all its dependencies.


My understanding of Victor's question is that he would like (and I
agree, it would be nice) for these dependencies to be determined by
CMake auto-magically.  So, whether we add include_directories () to
the CMake file or have a header-deps.cmake file is perhaps not as
important (though, your suggestion would reduce the amount of clutter
in the CMakeLists.txt file).

Perhaps a script is more suitable for this task?  That is, it would
walk through the directories and update each directories'
header-deps.cmake.  Surely, if a script is used, it would be less
error-prone to have the script update an external file than the
CMakeLists.txt file itself.

Fortunately for me, the depth of my directories is not as deep as
Victor's, so I'm not quite there yet.  But perhaps later...

Ray


More information about the CMake mailing list