define_property.rst 2.5 KB

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