target_sources.rst 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. target_sources
  2. --------------
  3. Add sources to a target.
  4. .. code-block:: cmake
  5. target_sources(<target>
  6. <INTERFACE|PUBLIC|PRIVATE> [items1...]
  7. [<INTERFACE|PUBLIC|PRIVATE> [items2...] ...])
  8. Specifies sources to use when compiling a given target. Relative
  9. source file paths are interpreted as being relative to the current
  10. source directory (i.e. :variable:`CMAKE_CURRENT_SOURCE_DIR`). The
  11. named ``<target>`` must have been created by a command such as
  12. :command:`add_executable` or :command:`add_library` and must not be an
  13. :ref:`ALIAS target <Alias Targets>`.
  14. The ``INTERFACE``, ``PUBLIC`` and ``PRIVATE`` keywords are required to
  15. specify the scope of the following arguments. ``PRIVATE`` and ``PUBLIC``
  16. items will populate the :prop_tgt:`SOURCES` property of
  17. ``<target>``. ``PUBLIC`` and ``INTERFACE`` items will populate the
  18. :prop_tgt:`INTERFACE_SOURCES` property of ``<target>``.
  19. (:ref:`IMPORTED targets <Imported Targets>` only support ``INTERFACE`` items.)
  20. The following arguments specify sources. Repeated calls for the same
  21. ``<target>`` append items in the order called.
  22. Arguments to ``target_sources`` may use "generator expressions"
  23. with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
  24. manual for available expressions. See the :manual:`cmake-buildsystem(7)`
  25. manual for more on defining buildsystem properties.
  26. See also the :policy:`CMP0076` policy for older behavior related to the
  27. handling of relative source file paths.