define_property.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. define_property
  2. ---------------
  3. Define and document custom properties.
  4. .. code-block:: cmake
  5. define_property(<GLOBAL | DIRECTORY | TARGET | SOURCE |
  6. TEST | VARIABLE | CACHED_VARIABLE>
  7. PROPERTY <name> [INHERITED]
  8. [BRIEF_DOCS <brief-doc> [docs...]]
  9. [FULL_DOCS <full-doc> [docs...]]
  10. [INITIALIZE_FROM_VARIABLE <variable>])
  11. Defines one property in a scope for use with the :command:`set_property` and
  12. :command:`get_property` commands. This is primarily useful to associate
  13. documentation with property names that may be retrieved with the
  14. :command:`get_property` command. The first argument determines the kind of
  15. scope in which the property should be used. It must be one of the
  16. following:
  17. ::
  18. GLOBAL = associated with the global namespace
  19. DIRECTORY = associated with one directory
  20. TARGET = associated with one target
  21. SOURCE = associated with one source file
  22. TEST = associated with a test named with add_test
  23. VARIABLE = documents a CMake language variable
  24. CACHED_VARIABLE = documents a CMake cache variable
  25. Note that unlike :command:`set_property` and :command:`get_property` no
  26. actual scope needs to be given; only the kind of scope is important.
  27. The required ``PROPERTY`` option is immediately followed by the name of
  28. the property being defined.
  29. If the ``INHERITED`` option is given, then the :command:`get_property` command
  30. will chain up to the next higher scope when the requested property is not set
  31. in the scope given to the command.
  32. * ``DIRECTORY`` scope chains to its parent directory's scope, continuing the
  33. walk up parent directories until a directory has the property set or there
  34. are no more parents. If still not found at the top level directory, it
  35. chains to the ``GLOBAL`` scope.
  36. * ``TARGET``, ``SOURCE`` and ``TEST`` properties chain to ``DIRECTORY`` scope,
  37. including further chaining up the directories, etc. as needed.
  38. Note that this scope chaining behavior only applies to calls to
  39. :command:`get_property`, :command:`get_directory_property`,
  40. :command:`get_target_property`, :command:`get_source_file_property` and
  41. :command:`get_test_property`. There is no inheriting behavior when *setting*
  42. properties, so using ``APPEND`` or ``APPEND_STRING`` with the
  43. :command:`set_property` command will not consider inherited values when working
  44. out the contents to append to.
  45. The ``BRIEF_DOCS`` and ``FULL_DOCS`` options are followed by strings to be
  46. associated with the property as its brief and full documentation.
  47. Corresponding options to the :command:`get_property` command will retrieve
  48. the documentation.
  49. .. versionchanged:: 3.23
  50. The ``BRIEF_DOCS`` and ``FULL_DOCS`` options are optional.
  51. The ``INITIALIZE_FROM_VARIABLE`` option is followed by the name of a variable
  52. from which to initialize the property. The variable name must end with the
  53. property name, must have a prefix before the property name, and must not begin
  54. with ``CMAKE_`` or ``_CMAKE_``.