cmCommand.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCommand_h
  4. #define cmCommand_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <vector>
  8. class cmExecutionStatus;
  9. class cmMakefile;
  10. struct cmListFileArgument;
  11. /** \class cmCommand
  12. * \brief Superclass for all commands in CMake.
  13. *
  14. * cmCommand is the base class for all commands in CMake. A command
  15. * manifests as an entry in CMakeLists.txt and produces one or
  16. * more makefile rules. Commands are associated with a particular
  17. * makefile. This base class cmCommand defines the API for commands
  18. * to support such features as enable/disable, inheritance,
  19. * documentation, and construction.
  20. */
  21. class cmCommand
  22. {
  23. CM_DISABLE_COPY(cmCommand)
  24. public:
  25. /**
  26. * Construct the command. By default it has no makefile.
  27. */
  28. cmCommand()
  29. : Makefile(nullptr)
  30. {
  31. }
  32. /**
  33. * Need virtual destructor to destroy real command type.
  34. */
  35. virtual ~cmCommand() {}
  36. /**
  37. * Specify the makefile.
  38. */
  39. void SetMakefile(cmMakefile* m) { this->Makefile = m; }
  40. cmMakefile* GetMakefile() { return this->Makefile; }
  41. /**
  42. * This is called by the cmMakefile when the command is first
  43. * encountered in the CMakeLists.txt file. It expands the command's
  44. * arguments and then invokes the InitialPass.
  45. */
  46. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  47. cmExecutionStatus& status);
  48. /**
  49. * This is called when the command is first encountered in
  50. * the CMakeLists.txt file.
  51. */
  52. virtual bool InitialPass(std::vector<std::string> const& args,
  53. cmExecutionStatus&) = 0;
  54. /**
  55. * This is called at the end after all the information
  56. * specified by the command is accumulated. Most commands do
  57. * not implement this method. At this point, reading and
  58. * writing to the cache can be done.
  59. */
  60. virtual void FinalPass() {}
  61. /**
  62. * Does this command have a final pass? Query after InitialPass.
  63. */
  64. virtual bool HasFinalPass() const { return false; }
  65. /**
  66. * This is a virtual constructor for the command.
  67. */
  68. virtual cmCommand* Clone() = 0;
  69. /**
  70. * Return the last error string.
  71. */
  72. const char* GetError();
  73. /**
  74. * Set the error message
  75. */
  76. void SetError(const std::string& e);
  77. protected:
  78. cmMakefile* Makefile;
  79. private:
  80. std::string Error;
  81. };
  82. #endif