get_property.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. get_property
  2. ------------
  3. Get a property.
  4. .. code-block:: cmake
  5. get_property(<variable>
  6. <GLOBAL |
  7. DIRECTORY [<dir>] |
  8. TARGET <target> |
  9. SOURCE <source> |
  10. [DIRECTORY <dir> | TARGET_DIRECTORY <target>] |
  11. INSTALL <file> |
  12. TEST <test> |
  13. CACHE <entry> |
  14. VARIABLE >
  15. PROPERTY <name>
  16. [SET | DEFINED | BRIEF_DOCS | FULL_DOCS])
  17. Gets one property from one object in a scope.
  18. The first argument specifies the variable in which to store the result.
  19. The second argument determines the scope from which to get the property.
  20. It must be one of the following:
  21. ``GLOBAL``
  22. Scope is unique and does not accept a name.
  23. ``DIRECTORY``
  24. Scope defaults to the current directory but another
  25. directory (already processed by CMake) may be named by the
  26. full or relative path ``<dir>``. The ``<dir>`` may reference either a
  27. source directory, or since CMake 3.19, a binary directory.
  28. Relative paths are treated as relative to the current source directory.
  29. See also the :command:`get_directory_property` command.
  30. ``TARGET``
  31. Scope must name one existing target.
  32. See also the :command:`get_target_property` command.
  33. ``SOURCE``
  34. Scope must name one source file. By default, the source file's property
  35. will be read from the current source directory's scope, but this can be
  36. overridden with one of the following sub-options:
  37. ``DIRECTORY <dir>``
  38. The source file property will be read from the ``<dir>`` directory's
  39. scope. The ``<dir>`` may reference either a source directory, or
  40. since CMake 3.19, a binary directory. CMake must already know about
  41. the directory, either by having added it through a call
  42. to :command:`add_subdirectory` or ``<dir>`` being the top level directory.
  43. Relative paths are treated as relative to the current source directory.
  44. ``TARGET_DIRECTORY <target>``
  45. The source file property will be read from the directory scope in which
  46. ``<target>`` was created (``<target>`` must therefore already exist).
  47. See also the :command:`get_source_file_property` command.
  48. ``INSTALL``
  49. Scope must name one installed file path.
  50. ``TEST``
  51. Scope must name one existing test.
  52. See also the :command:`get_test_property` command.
  53. ``CACHE``
  54. Scope must name one cache entry.
  55. ``VARIABLE``
  56. Scope is unique and does not accept a name.
  57. The required ``PROPERTY`` option is immediately followed by the name of
  58. the property to get. If the property is not set an empty value is
  59. returned, although some properties support inheriting from a parent scope
  60. if defined to behave that way (see :command:`define_property`).
  61. If the ``SET`` option is given the variable is set to a boolean
  62. value indicating whether the property has been set. If the ``DEFINED``
  63. option is given the variable is set to a boolean value indicating
  64. whether the property has been defined such as with the
  65. :command:`define_property` command.
  66. If ``BRIEF_DOCS`` or ``FULL_DOCS`` is given then the variable is set to a
  67. string containing documentation for the requested property. If
  68. documentation is requested for a property that has not been defined
  69. ``NOTFOUND`` is returned.