target_sources.rst 1.5 KB

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