cmVariableWatchCommand.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  44. * This determines if the command is invoked when in script mode.
  45. */
  46. virtual bool IsScriptable() { return true; }
  47. /**
  48. * The name of the command as specified in CMakeList.txt.
  49. */
  50. virtual const char* GetName() { return "VARIABLE_WATCH";}
  51. /**
  52. * Succinct documentation.
  53. */
  54. virtual const char* GetTerseDocumentation()
  55. {
  56. return "Watch the CMake variable for change.";
  57. }
  58. /**
  59. * More documentation.
  60. */
  61. virtual const char* GetFullDocumentation()
  62. {
  63. return
  64. " VARIABLE_WATCH(<variable name> [<command to execute>])\n"
  65. "If the specified variable changes, the message will be printed about "
  66. "the variable being changed. If the command is spceified, the command "
  67. "will be executed. The command will receive the following arguments:"
  68. " COMMAND(<variable> <access> <value> <current list file> <stack>)";
  69. }
  70. cmTypeMacro(cmVariableWatchCommand, cmCommand);
  71. void VariableAccessed(const std::string& variable, int access_type,
  72. const char* newValue, const cmMakefile* mf);
  73. protected:
  74. std::map<std::string, cmVariableWatchCommandHandler> Handlers;
  75. bool InCallback;
  76. };
  77. #endif