• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1get_source_file_property
2------------------------
3
4Get a property for a source file.
5
6.. code-block:: cmake
7
8  get_source_file_property(<variable> <file>
9                           [DIRECTORY <dir> | TARGET_DIRECTORY <target>]
10                           <property>)
11
12Gets a property from a source file.  The value of the property is
13stored in the specified ``<variable>``.  If the source property is not found,
14the behavior depends on whether it has been defined to be an ``INHERITED``
15property or not (see :command:`define_property`).  Non-inherited properties
16will set ``variable`` to ``NOTFOUND``, whereas inherited properties will search
17the relevant parent scope as described for the :command:`define_property`
18command and if still unable to find the property, ``variable`` will be set to
19an empty string.
20
21By default, the source file's property will be read from the current source
22directory's scope.
23
24.. versionadded:: 3.18
25  Directory scope can be overridden with one of the following sub-options:
26
27  ``DIRECTORY <dir>``
28    The source file property will be read from the ``<dir>`` directory's
29    scope.  CMake must already know about that source directory, either by
30    having added it through a call to :command:`add_subdirectory` or ``<dir>``
31    being the top level source directory.  Relative paths are treated as
32    relative to the current source directory.
33
34  ``TARGET_DIRECTORY <target>``
35    The source file property will be read from the directory scope in which
36    ``<target>`` was created (``<target>`` must therefore already exist).
37
38Use :command:`set_source_files_properties` to set property values.  Source
39file properties usually control how the file is built. One property that is
40always there is :prop_sf:`LOCATION`.
41
42See also the more general :command:`get_property` command.
43
44.. note::
45
46  The :prop_sf:`GENERATED` source file property may be globally visible.
47  See its documentation for details.
48