set_property.rst 4.5 KB

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