cmCommand.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 cmCommand_h
  14. #define cmCommand_h
  15. #include "cmObject.h"
  16. #include "cmListFileCache.h"
  17. #include "cmMakefile.h"
  18. /** \class cmCommand
  19. * \brief Superclass for all commands in CMake.
  20. *
  21. * cmCommand is the base class for all commands in CMake. A command
  22. * manifests as an entry in CMakeLists.txt and produces one or
  23. * more makefile rules. Commands are associated with a particular
  24. * makefile. This base class cmCommand defines the API for commands
  25. * to support such features as enable/disable, inheritance,
  26. * documentation, and construction.
  27. */
  28. class cmCommand : public cmObject
  29. {
  30. public:
  31. cmTypeMacro(cmCommand, cmObject);
  32. /**
  33. * Construct the command. By default it is enabled with no makefile.
  34. */
  35. cmCommand()
  36. {this->Makefile = 0; this->Enabled = true;}
  37. /**
  38. * Need virtual destructor to destroy real command type.
  39. */
  40. virtual ~cmCommand() {}
  41. /**
  42. * Specify the makefile.
  43. */
  44. void SetMakefile(cmMakefile*m)
  45. {this->Makefile = m; }
  46. cmMakefile* GetMakefile() { return this->Makefile; }
  47. /**
  48. * This is called by the cmMakefile when the command is first
  49. * encountered in the CMakeLists.txt file. It expands the command's
  50. * arguments and then invokes the InitialPass.
  51. */
  52. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args)
  53. {
  54. std::vector<std::string> expandedArguments;
  55. this->Makefile->ExpandArguments(args, expandedArguments);
  56. return this->InitialPass(expandedArguments);
  57. }
  58. /**
  59. * This is called when the command is first encountered in
  60. * the CMakeLists.txt file.
  61. */
  62. virtual bool InitialPass(std::vector<std::string> const& args) = 0;
  63. /**
  64. * This is called at the end after all the information
  65. * specified by the command is accumulated. Most commands do
  66. * not implement this method. At this point, reading and
  67. * writing to the cache can be done.
  68. */
  69. virtual void FinalPass() {};
  70. /**
  71. * This is a virtual constructor for the command.
  72. */
  73. virtual cmCommand* Clone() = 0;
  74. /**
  75. * This determines if the command is invoked when in script mode.
  76. */
  77. virtual bool IsScriptable()
  78. {
  79. return false;
  80. }
  81. /**
  82. * This determines if the method is deprecated or not.
  83. */
  84. virtual bool IsDeprecated(int /*major*/, int /*minor*/)
  85. {
  86. return false;
  87. }
  88. /**
  89. * This determines if usage of the method is discouraged or not.
  90. * This is currently only used for generating the documentation.
  91. */
  92. virtual bool IsDiscouraged()
  93. {
  94. return false;
  95. }
  96. /**
  97. * The name of the command as specified in CMakeList.txt.
  98. */
  99. virtual const char* GetName() = 0;
  100. /**
  101. * Succinct documentation.
  102. */
  103. virtual const char* GetTerseDocumentation() = 0;
  104. /**
  105. * More documentation.
  106. */
  107. virtual const char* GetFullDocumentation() = 0;
  108. /**
  109. * Enable the command.
  110. */
  111. void EnabledOn()
  112. {this->Enabled = true;}
  113. /**
  114. * Disable the command.
  115. */
  116. void EnabledOff()
  117. {this->Enabled = false;}
  118. /**
  119. * Query whether the command is enabled.
  120. */
  121. bool GetEnabled()
  122. {return this->Enabled;}
  123. /**
  124. * Disable or enable the command.
  125. */
  126. void SetEnabled(bool enabled)
  127. {this->Enabled = enabled;}
  128. /**
  129. * Return the last error string.
  130. */
  131. const char* GetError()
  132. {
  133. if(this->Error.length() == 0)
  134. {
  135. this->Error = this->GetName();
  136. this->Error += " unknown error.";
  137. }
  138. return this->Error.c_str();
  139. }
  140. /**
  141. * Set the error message
  142. */
  143. void SetError(const char* e)
  144. {
  145. this->Error = this->GetName();
  146. this->Error += " ";
  147. this->Error += e;
  148. }
  149. protected:
  150. cmMakefile* Makefile;
  151. private:
  152. bool Enabled;
  153. std::string Error;
  154. };
  155. #endif