get_source_file_property.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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, but this can be overridden with one of the following
  18. sub-options:
  19. ``DIRECTORY <dir>``
  20. The source file property will be read from the ``<dir>`` directory's
  21. scope. CMake must already know about that source directory, either by
  22. having added it through a call to :command:`add_subdirectory` or ``<dir>``
  23. being the top level source directory. Relative paths are treated as
  24. relative to the current source directory.
  25. ``TARGET_DIRECTORY <target>``
  26. The source file property will be read from the directory scope in which
  27. ``<target>`` was created (``<target>`` must therefore already exist).
  28. Use :command:`set_source_files_properties` to set property values. Source
  29. file properties usually control how the file is built. One property that is
  30. always there is :prop_sf:`LOCATION`.
  31. See also the more general :command:`get_property` command.