target_include_directories.rst 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. target_include_directories
  2. --------------------------
  3. Add include directories to a target.
  4. ::
  5. target_include_directories(<target> [SYSTEM] [BEFORE]
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specify 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. If ``BEFORE`` is specified, the content will be prepended to the property
  13. instead of being appended.
  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. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  20. The following arguments specify include directories.
  21. Specified include directories may be absolute paths or relative paths.
  22. Repeated calls for the same <target> append items in the order called. If
  23. ``SYSTEM`` is specified, the compiler will be told the
  24. directories are meant as system include directories on some platforms
  25. (signalling this setting might achieve effects such as the compiler
  26. skipping warnings, or these fixed-install system files not being
  27. considered in dependency calculations - see compiler docs). If ``SYSTEM``
  28. is used together with ``PUBLIC`` or ``INTERFACE``, the
  29. :prop_tgt:`INTERFACE_SYSTEM_INCLUDE_DIRECTORIES` target property will be
  30. populated with the specified directories.
  31. Arguments to ``target_include_directories`` may use "generator expressions"
  32. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  33. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  34. manual for more on defining buildsystem properties.
  35. Include directories usage requirements commonly differ between the build-tree
  36. and the install-tree. The ``BUILD_INTERFACE`` and ``INSTALL_INTERFACE``
  37. generator expressions can be used to describe separate usage requirements
  38. based on the usage location. Relative paths are allowed within the
  39. ``INSTALL_INTERFACE`` expression and are interpreted relative to the
  40. installation prefix. For example:
  41. .. code-block:: cmake
  42. target_include_directories(mylib PUBLIC
  43. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/mylib>
  44. $<INSTALL_INTERFACE:include/mylib> # <prefix>/include/mylib
  45. )
  46. Creating Relocatable Packages
  47. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  48. .. |INTERFACE_PROPERTY_LINK| replace:: :prop_tgt:`INTERFACE_INCLUDE_DIRECTORIES`
  49. .. include:: /include/INTERFACE_INCLUDE_DIRECTORIES_WARNING.txt