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