cmCommand.h 4.5 KB

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