set_property.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. set_property
  2. ------------
  3. Set a named property in a given scope.
  4. .. code-block:: cmake
  5. set_property(<GLOBAL |
  6. DIRECTORY [<dir>] |
  7. TARGET [<target1> ...] |
  8. SOURCE [<src1> ...]
  9. [DIRECTORY <dirs> ...]
  10. [TARGET_DIRECTORY <targets> ...] |
  11. INSTALL [<file1> ...] |
  12. TEST [<test1> ...]
  13. [DIRECTORY <dir>] |
  14. CACHE [<entry1> ...] >
  15. [APPEND] [APPEND_STRING]
  16. PROPERTY <name> [<value1> ...])
  17. Sets one property on zero or more objects of a scope.
  18. The first argument determines the scope in which the property is set.
  19. It must be one of the following:
  20. ``GLOBAL``
  21. Scope is unique and does not accept a name.
  22. ``DIRECTORY``
  23. Scope defaults to the current directory but other directories
  24. (already processed by CMake) may be named by full or relative path.
  25. Relative paths are treated as relative to the current source directory.
  26. See also the :command:`set_directory_properties` command.
  27. .. versionadded:: 3.19
  28. ``<dir>`` may reference a binary directory.
  29. ``TARGET``
  30. Scope may name zero or more existing targets.
  31. See also the :command:`set_target_properties` command.
  32. :ref:`Alias Targets` do not support setting target properties.
  33. ``SOURCE``
  34. Scope may name zero or more source files. By default, source file properties
  35. are only visible to targets added in the same directory (``CMakeLists.txt``).
  36. .. versionadded:: 3.18
  37. Visibility can be set in other directory scopes using one or both of the
  38. following sub-options:
  39. ``DIRECTORY <dirs>...``
  40. The source file property will be set in each of the ``<dirs>``
  41. directories' scopes. CMake must already know about
  42. each of these directories, either by having added them through a call to
  43. :command:`add_subdirectory` or it being the top level source directory.
  44. Relative paths are treated as relative to the current source directory.
  45. .. versionadded:: 3.19
  46. ``<dirs>`` may reference a binary directory.
  47. ``TARGET_DIRECTORY <targets>...``
  48. The source file property will be set in each of the directory scopes
  49. where any of the specified ``<targets>`` were created (the ``<targets>``
  50. must therefore already exist).
  51. See also the :command:`set_source_files_properties` command.
  52. ``INSTALL``
  53. .. versionadded:: 3.1
  54. Scope may name zero or more installed file paths.
  55. These are made available to CPack to influence deployment.
  56. Both the property key and value may use generator expressions.
  57. Specific properties may apply to installed files and/or directories.
  58. Path components have to be separated by forward slashes,
  59. must be normalized and are case sensitive.
  60. To reference the installation prefix itself with a relative path use ``.``.
  61. Currently installed file properties are only defined for
  62. the WIX generator where the given paths are relative
  63. to the installation prefix.
  64. ``TEST``
  65. Scope is limited to the directory the command is called in. It may name zero
  66. or more existing tests. See also command :command:`set_tests_properties`.
  67. Test property values may be specified using
  68. :manual:`generator expressions <cmake-generator-expressions(7)>`
  69. for tests created by the :command:`add_test(NAME)` signature.
  70. .. versionadded:: 3.28
  71. Visibility can be set in other directory scopes using the following sub-option:
  72. ``DIRECTORY <dir>``
  73. The test property will be set in the ``<dir>`` directory's scope. CMake must
  74. already know about this directory, either by having added it through a call
  75. to :command:`add_subdirectory` or it being the top level source directory.
  76. Relative paths are treated as relative to the current source directory.
  77. ``<dir>`` may reference a binary directory.
  78. ``CACHE``
  79. Scope must name zero or more existing cache entries.
  80. The required ``PROPERTY`` option is immediately followed by the name of
  81. the property to set. Remaining arguments are used to compose the
  82. property value in the form of a semicolon-separated list.
  83. If the ``APPEND`` option is given the list is appended to any existing
  84. property value (except that empty values are ignored and not appended).
  85. If the ``APPEND_STRING`` option is given the string is
  86. appended to any existing property value as string, i.e. it results in a
  87. longer string and not a list of strings. When using ``APPEND`` or
  88. ``APPEND_STRING`` with a property defined to support ``INHERITED``
  89. behavior (see :command:`define_property`), no inheriting occurs when
  90. finding the initial value to append to. If the property is not already
  91. directly set in the nominated scope, the command will behave as though
  92. ``APPEND`` or ``APPEND_STRING`` had not been given.
  93. .. note::
  94. The :prop_sf:`GENERATED` source file property may be globally visible.
  95. See its documentation for details.
  96. See Also
  97. ^^^^^^^^
  98. * :command:`define_property`
  99. * :command:`get_property`
  100. * The :manual:`cmake-properties(7)` manual for a list of properties
  101. in each scope.