Search code examples
cmakeinclude

Cmake and includes in a tree of source directories


The CMake documentation contains the following:

include_directories: Add include directories to the build.
include_directories([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...) Add the given directories to those the compiler uses to search for include files. Relative paths are interpreted as relative to the current source directory.

Need clarification: does "current source directory" refer to the directory containing this CMakeLists.txt file, or to the directory containing the source file momentarily being built? Experiment would suggest the former, but I'd appreciate confirmation.

I'm converting an old project from Xcode, and this is the directory structure:

  A (contains CMakeLists.txt and some headers)
 / \
B   C (each contain sources and headers)

In Xcode (and it also works in Visual Studio) I can say "Find include files in the project directory and all subdirectories recursively." Is there any way to do that here? If not, what is the most graceful syntax to say what I need? I have source files in B that reference headers in A, and some that reference headers in C


Solution

  • It refers to the directory which contains CMakelists.txt (not a *.cmake script) that is currently being executed.

    That path is stored in CMAKE_CURRENT_SOURCE_DIR variable.