set_property.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. ``SOURCE``
  32. Scope may name zero or more source files. By default, source file properties
  33. are only visible to targets added in the same directory (``CMakeLists.txt``).
  34. .. versionadded:: 3.18
  35. Visibility can be set in other directory scopes using one or both of the
  36. following sub-options:
  37. ``DIRECTORY <dirs>...``
  38. The source file property will be set in each of the ``<dirs>``
  39. directories' scopes. CMake must already know about
  40. each of these directories, either by having added them through a call to
  41. :command:`add_subdirectory` or it being the top level source directory.
  42. Relative paths are treated as relative to the current source directory.
  43. .. versionadded:: 3.19
  44. ``<dirs>`` may reference a binary directory.
  45. ``TARGET_DIRECTORY <targets>...``
  46. The source file property will be set in each of the directory scopes
  47. where any of the specified ``<targets>`` were created (the ``<targets>``
  48. must therefore already exist).
  49. See also the :command:`set_source_files_properties` command.
  50. ``INSTALL``
  51. .. versionadded:: 3.1
  52. Scope may name zero or more installed file paths.
  53. These are made available to CPack to influence deployment.
  54. Both the property key and value may use generator expressions.
  55. Specific properties may apply to installed files and/or directories.
  56. Path components have to be separated by forward slashes,
  57. must be normalized and are case sensitive.
  58. To reference the installation prefix itself with a relative path use ``.``.
  59. Currently installed file properties are only defined for
  60. the WIX generator where the given paths are relative
  61. to the installation prefix.
  62. ``TEST``
  63. Scope may name zero or more existing tests.
  64. See also the :command:`set_tests_properties` command.
  65. ``CACHE``
  66. Scope must name zero or more cache existing entries.
  67. The required ``PROPERTY`` option is immediately followed by the name of
  68. the property to set. Remaining arguments are used to compose the
  69. property value in the form of a semicolon-separated list.
  70. If the ``APPEND`` option is given the list is appended to any existing
  71. property value (except that empty values are ignored and not appended).
  72. If the ``APPEND_STRING`` option is given the string is
  73. appended to any existing property value as string, i.e. it results in a
  74. longer string and not a list of strings. When using ``APPEND`` or
  75. ``APPEND_STRING`` with a property defined to support ``INHERITED``
  76. behavior (see :command:`define_property`), no inheriting occurs when
  77. finding the initial value to append to. If the property is not already
  78. directly set in the nominated scope, the command will behave as though
  79. ``APPEND`` or ``APPEND_STRING`` had not been given.
  80. See the :manual:`cmake-properties(7)` manual for a list of properties
  81. in each scope.
  82. .. note::
  83. The :prop_sf:`GENERATED` source file property may be globally visible.
  84. See its documentation for details.