set_property.rst 4.0 KB

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