get_property.rst 3.5 KB

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