get_property.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. [DIRECTORY <dir>] |
  14. CACHE <entry> |
  15. VARIABLE >
  16. PROPERTY <name>
  17. [SET | DEFINED | BRIEF_DOCS | FULL_DOCS])
  18. Gets one property from one object in a scope.
  19. The first argument specifies the variable in which to store the result.
  20. The second argument determines the scope from which to get the property.
  21. It must be one of the following:
  22. ``GLOBAL``
  23. Scope is unique and does not accept a name.
  24. ``DIRECTORY``
  25. Scope defaults to the current directory, but another
  26. directory (already processed by CMake) may be named by the
  27. full or relative path ``<dir>``.
  28. Relative paths are treated as relative to the current source directory.
  29. See also the :command:`get_directory_property` command.
  30. .. versionadded:: 3.19
  31. ``<dir>`` may reference a binary directory.
  32. ``TARGET``
  33. Scope must name one existing target.
  34. See also the :command:`get_target_property` command.
  35. ``SOURCE``
  36. Scope must name one source file. By default, the source file's property
  37. will be read from the current source directory's scope.
  38. .. versionadded:: 3.18
  39. Directory scope can be overridden with one of the following sub-options:
  40. ``DIRECTORY <dir>``
  41. The source file property will be read from the ``<dir>`` directory's
  42. scope. CMake must already know about
  43. the directory, either by having added it through a call
  44. to :command:`add_subdirectory` or ``<dir>`` being the top level directory.
  45. Relative paths are treated as relative to the current source directory.
  46. .. versionadded:: 3.19
  47. ``<dir>`` may reference a binary directory.
  48. ``TARGET_DIRECTORY <target>``
  49. The source file property will be read from the directory scope in which
  50. ``<target>`` was created (``<target>`` must therefore already exist).
  51. See also the :command:`get_source_file_property` command.
  52. ``INSTALL``
  53. .. versionadded:: 3.1
  54. Scope must name one installed file path.
  55. ``TEST``
  56. Scope must name one existing test.
  57. See also the :command:`get_test_property` command.
  58. .. versionadded:: 3.28
  59. Directory scope can be overridden with the following sub-option:
  60. ``DIRECTORY <dir>``
  61. The test property will be read from the ``<dir>`` directory's
  62. scope. CMake must already know about the directory, either by having
  63. added it through a call to :command:`add_subdirectory` or ``<dir>`` being
  64. the top level directory. Relative paths are treated as relative to the
  65. current source directory. ``<dir>`` may reference a binary directory.
  66. ``CACHE``
  67. Scope must name one cache entry.
  68. ``VARIABLE``
  69. Scope is unique and does not accept a name.
  70. The required ``PROPERTY`` option is immediately followed by the name of
  71. the property to get. If the property is not set, the named ``<variable>``
  72. will be unset in the calling scope upon return, although some properties
  73. support inheriting from a parent scope if defined to behave that way
  74. (see :command:`define_property`).
  75. If the ``SET`` option is given, the variable is set to a boolean
  76. value indicating whether the property has been set. If the ``DEFINED``
  77. option is given, the variable is set to a boolean value indicating
  78. whether the property has been defined, such as with the
  79. :command:`define_property` command.
  80. If ``BRIEF_DOCS`` or ``FULL_DOCS`` is given, then the variable is set to a
  81. string containing documentation for the requested property. If
  82. documentation is requested for a property that has not been defined,
  83. ``NOTFOUND`` is returned.
  84. .. note::
  85. The :prop_sf:`GENERATED` source file property may be globally visible.
  86. See its documentation for details.
  87. See Also
  88. ^^^^^^^^
  89. * :command:`define_property`
  90. * :command:`set_property`