get_source_file_property.rst 2.0 KB

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