target_sources.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. target_sources
  2. --------------
  3. .. versionadded:: 3.1
  4. Add sources to a target.
  5. .. code-block:: cmake
  6. target_sources(<target>
  7. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  8. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  9. Specifies sources to use when building a target and/or its dependents.
  10. The named ``<target>`` must have been created by a command such as
  11. :command:`add_executable` or :command:`add_library` or
  12. :command:`add_custom_target` and must not be an
  13. :ref:`ALIAS target <Alias Targets>`.
  14. .. versionchanged:: 3.13
  15. Relative source file paths are interpreted as being relative to the current
  16. source directory (i.e. :variable:`CMAKE_CURRENT_SOURCE_DIR`).
  17. See policy :policy:`CMP0076`.
  18. .. versionadded:: 3.20
  19. ``<target>`` can be a custom target.
  20. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  21. specify the scope of the items following them. ``PRIVATE`` and ``PUBLIC``
  22. items will populate the :prop_tgt:`SOURCES` property of
  23. ``<target>``, which are used when building the target itself.
  24. ``PUBLIC`` and ``INTERFACE`` items will populate the
  25. :prop_tgt:`INTERFACE_SOURCES` property of ``<target>``, which are used
  26. when building dependents.
  27. The following arguments specify sources. Repeated calls for the same
  28. ``<target>`` append items in the order called. The targets created by
  29. :command:`add_custom_target` can only have ``PRIVATE`` scope.
  30. .. versionadded:: 3.3
  31. Allow exporting targets with :prop_tgt:`INTERFACE_SOURCES`.
  32. .. versionadded:: 3.11
  33. Allow setting ``INTERFACE`` items on :ref:`IMPORTED targets <Imported Targets>`.
  34. Arguments to ``target_sources`` may use "generator expressions"
  35. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  36. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  37. manual for more on defining buildsystem properties.