variable_watch.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. variable_watch
  2. --------------
  3. Watch the CMake variable for change.
  4. .. code-block:: cmake
  5. variable_watch(<variable> [<command>])
  6. If the specified ``<variable>`` changes and no ``<command>`` is given,
  7. a message will be printed to inform about the change.
  8. If ``<command>`` is given, this command will be executed instead.
  9. The command will receive the following arguments:
  10. ``COMMAND(<variable> <access> <value> <current_list_file> <stack>)``
  11. ``<variable>``
  12. Name of the variable being accessed.
  13. ``<access>``
  14. One of ``READ_ACCESS``, ``UNKNOWN_READ_ACCESS``, ``MODIFIED_ACCESS``,
  15. ``UNKNOWN_MODIFIED_ACCESS``, or ``REMOVED_ACCESS``. The ``UNKNOWN_``
  16. values are only used when the variable has never been set. Once set,
  17. they are never used again during the same CMake run, even if the
  18. variable is later unset.
  19. ``<value>``
  20. The value of the variable. On a modification, this is the new
  21. (modified) value of the variable. On removal, the value is empty.
  22. ``<current_list_file>``
  23. Full path to the file doing the access.
  24. ``<stack>``
  25. List of absolute paths of all files currently on the stack of file
  26. inclusion, with the bottom-most file first and the currently
  27. processed file (that is, ``current_list_file``) last.
  28. Note that for some accesses such as :command:`list(APPEND)`, the watcher
  29. is executed twice, first with a read access and then with a write one.
  30. Also note that an :command:`if(DEFINED)` query on the variable does not
  31. register as an access and the watcher is not executed.
  32. Only non-cache variables can be watched using this command. Access to
  33. cache variables is never watched. However, the existence of a cache
  34. variable ``var`` causes accesses to the non-cache variable ``var`` to
  35. not use the ``UNKNOWN_`` prefix, even if a non-cache variable ``var``
  36. has never existed.