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