[CMake] how to inherit includes from other directories

Andreas Mohr andi at lisas.de
Wed Sep 7 01:57:06 EDT 2011


Hi,

On Tue, Sep 06, 2011 at 04:50:30PM -0400, cmake-request at cmake.org wrote:
> Date: Tue, 6 Sep 2011 16:50:28 -0400
> From: David Cole <david.cole at kitware.com>

> CMake does not track dependencies of header-only "libraries". It only
> tracks actual library dependencies given by target_link_libraries
> commands.
> 
> You will have to come up with your own way to manage your projects
> interconnections.
> 
> CMake provides the include_directories command so that you can say
> where your header files are. If Z depends on A and B's header files
> then Z is going to have to have include_directories commands for A and
> B's include directories.
> 
> Sorry there's no magic bullet here.

Hmm, but surely the Config file mechanism (as used e.g. within a common
build tree) may be a useful/more suitable way to do it
rather than doing a manual open-coded include_directories()?

Just to mention, AFAIR it's done like that:
- libxxx/CMakeLists.txt defines (header location, build defines, ...) variables
- that file then does a configure_file() on a libxxxConfig.cmake.in
  which thus encodes these settings
- other projects within the build tree then include(libxxxConfig.cmake)
  (more or less specifically or implicitly pathed)
(or alternatively include a Use file which _both_ includes Config file
_and_ then activates these include paths for the local project)

Or, more specifically, Z would somehow make sure to evaluate
AConfig.cmake and BConfig.cmake.

Andreas Mohr


More information about the CMake mailing list