• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1target_include_directories
2--------------------------
3
4Add include directories to a target.
5
6.. code-block:: cmake
7
8  target_include_directories(<target> [SYSTEM] [AFTER|BEFORE]
9    <INTERFACE|PUBLIC|PRIVATE> [items1...]
10    [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
11
12Specifies include directories to use when compiling a given target.
13The named ``<target>`` must have been created by a command such
14as :command:`add_executable` or :command:`add_library` and must not be an
15:ref:`ALIAS target <Alias Targets>`.
16
17By using ``AFTER`` or ``BEFORE`` explicitly, you can select between appending
18and prepending, independent of the default.
19
20The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to specify
21the scope of the following arguments.  ``PRIVATE`` and ``PUBLIC`` items will
22populate the :prop_tgt:`INCLUDE_DIRECTORIES` property of ``<target>``.
23``PUBLIC`` and ``INTERFACE`` items will populate the
24:prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES` property of ``<target>``.
25The following arguments specify include directories.
26
27.. versionadded:: 3.11
28  Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
29
30Specified include directories may be absolute paths or relative paths.
31Repeated calls for the same <target> append items in the order called.  If
32``SYSTEM`` is specified, the compiler will be told the
33directories are meant as system include directories on some platforms
34(signalling this setting might achieve effects such as the compiler
35skipping warnings, or these fixed-install system files not being
36considered in dependency calculations - see compiler docs).  If ``SYSTEM``
37is used together with ``PUBLIC`` or ``INTERFACE``, the
38:prop_tgt:`INTERFACE_SYSTEM_INCLUDE_DIRECTORIES` target property will be
39populated with the specified directories.
40
41Arguments to ``target_include_directories`` may use "generator expressions"
42with the syntax ``$<...>``.  See the :manual:`cmake-generator-expressions(7)`
43manual for available expressions.  See the :manual:`cmake-buildsystem(7)`
44manual for more on defining buildsystem properties.
45
46Include directories usage requirements commonly differ between the build-tree
47and the install-tree.  The ``BUILD_INTERFACE`` and ``INSTALL_INTERFACE``
48generator expressions can be used to describe separate usage requirements
49based on the usage location.  Relative paths are allowed within the
50``INSTALL_INTERFACE`` expression and are interpreted relative to the
51installation prefix.  For example:
52
53.. code-block:: cmake
54
55  target_include_directories(mylib PUBLIC
56    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
57    $<INSTALL_INTERFACE:include/mylib>  # <prefix>/include/mylib
58  )
59
60Creating Relocatable Packages
61^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62
63.. |INTERFACE_PROPERTY_LINK| replace:: :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
64.. include:: /include/INTERFACE_INCLUDE_DIRECTORIES_WARNING.txt
65