cmCommand.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. public:
  24. /**
  25. * Construct the command. By default it has no makefile.
  26. */
  27. cmCommand() = default;
  28. /**
  29. * Need virtual destructor to destroy real command type.
  30. */
  31. virtual ~cmCommand() = default;
  32. cmCommand(cmCommand const&) = delete;
  33. cmCommand& operator=(cmCommand const&) = delete;
  34. /**
  35. * Specify the makefile.
  36. */
  37. void SetMakefile(cmMakefile* m) { this->Makefile = m; }
  38. cmMakefile* GetMakefile() { return this->Makefile; }
  39. /**
  40. * This is called by the cmMakefile when the command is first
  41. * encountered in the CMakeLists.txt file. It expands the command's
  42. * arguments and then invokes the InitialPass.
  43. */
  44. virtual bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  45. cmExecutionStatus& status);
  46. /**
  47. * This is called when the command is first encountered in
  48. * the CMakeLists.txt file.
  49. */
  50. virtual bool InitialPass(std::vector<std::string> const& args,
  51. cmExecutionStatus&) = 0;
  52. /**
  53. * This is called at the end after all the information
  54. * specified by the command is accumulated. Most commands do
  55. * not implement this method. At this point, reading and
  56. * writing to the cache can be done.
  57. */
  58. virtual void FinalPass() {}
  59. /**
  60. * Does this command have a final pass? Query after InitialPass.
  61. */
  62. virtual bool HasFinalPass() const { return false; }
  63. /**
  64. * This is a virtual constructor for the command.
  65. */
  66. virtual cmCommand* Clone() = 0;
  67. /**
  68. * Return the last error string.
  69. */
  70. const char* GetError();
  71. /**
  72. * Set the error message
  73. */
  74. void SetError(const std::string& e);
  75. protected:
  76. cmMakefile* Makefile = nullptr;
  77. private:
  78. std::string Error;
  79. };
  80. #endif