CMake system include search path

cmake

Solution

you can use include_directories(..) to set directories that will be used for all targets, or add include directories only to a specific target with `target_include_directories` or `set_property`:

set(foo_INCLUDE_DIRS
    ${CMAKE_SOURCE_DIR}/foo
    ${CMAKE_SOURCE_DIR}/whatever)

set_property(TARGET YourTarget PROPERTY INCLUDE_DIRECTORIES ${foo_INCLUDE_DIRS})

target_include_directories(<target> [SYSTEM] [BEFORE <INTERFACE|PUBLIC|PRIVATE> [items1...]

#or
include_directories([AFTER|BEFORE] [SYSTEM] ${foo_INCLUDE_DIRS})

Problem

I'm wondering how I would go about adding an include directory to the system search path for a CMake project. Particularly, I've some source that I'm trying to build a CMake project for. The source is not mine, and so I don't really want to modify it. The source has the following include directive: ``` #include <foo/bar.h> ``` So I need to add the directory containing foo to my search path. Is this something I can set within the CMakeLists.txt?

Original source