cmVariableWatchCommand.h 2.8 KB

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