cmVariableWatchCommand.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmVariableWatchCommand_h
  11. #define cmVariableWatchCommand_h
  12. #include "cmCommand.h"
  13. class cmVariableWatchCommandHandler
  14. {
  15. public:
  16. typedef std::vector<std::string> VectorOfCommands;
  17. VectorOfCommands Commands;
  18. };
  19. /** \class cmVariableWatchCommand
  20. * \brief Watch when the variable changes and invoke command
  21. *
  22. */
  23. class cmVariableWatchCommand : public cmCommand
  24. {
  25. public:
  26. /**
  27. * This is a virtual constructor for the command.
  28. */
  29. virtual cmCommand* Clone()
  30. {
  31. return new cmVariableWatchCommand;
  32. }
  33. //! Default constructor
  34. cmVariableWatchCommand();
  35. /**
  36. * This is called when the command is first encountered in
  37. * the CMakeLists.txt file.
  38. */
  39. virtual bool InitialPass(std::vector<std::string> const& args,
  40. cmExecutionStatus &status);
  41. /**
  42. * This determines if the command is invoked when in script mode.
  43. */
  44. virtual bool IsScriptable() { return true; }
  45. /** This command does not really have a final pass but it needs to
  46. stay alive since it owns variable watch callback information. */
  47. virtual bool HasFinalPass() const { return true; }
  48. /**
  49. * The name of the command as specified in CMakeList.txt.
  50. */
  51. virtual const char* GetName() { return "variable_watch";}
  52. /**
  53. * Succinct documentation.
  54. */
  55. virtual const char* GetTerseDocumentation()
  56. {
  57. return "Watch the CMake variable for change.";
  58. }
  59. /**
  60. * More documentation.
  61. */
  62. virtual const char* GetFullDocumentation()
  63. {
  64. return
  65. " variable_watch(<variable name> [<command to execute>])\n"
  66. "If the specified variable changes, the message will be printed about "
  67. "the variable being changed. If the command is specified, the command "
  68. "will be executed. The command will receive the following arguments:"
  69. " COMMAND(<variable> <access> <value> <current list file> <stack>)";
  70. }
  71. cmTypeMacro(cmVariableWatchCommand, cmCommand);
  72. void VariableAccessed(const std::string& variable, int access_type,
  73. const char* newValue, const cmMakefile* mf);
  74. protected:
  75. std::map<std::string, cmVariableWatchCommandHandler> Handlers;
  76. bool InCallback;
  77. };
  78. #endif