target_include_directories.rst 2.8 KB

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