cmCommand.h 2.6 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. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <memory>
  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. cmMakefile* GetMakefile() { return this->Makefile; }
  38. void SetExecutionStatus(cmExecutionStatus* s);
  39. cmExecutionStatus* GetExecutionStatus() { return this->Status; }
  40. /**
  41. * This is called by the cmMakefile when the command is first
  42. * encountered in the CMakeLists.txt file. It expands the command's
  43. * arguments and then invokes the InitialPass.
  44. */
  45. bool InvokeInitialPass(const std::vector<cmListFileArgument>& args,
  46. cmExecutionStatus& status);
  47. /**
  48. * This is called when the command is first encountered in
  49. * the CMakeLists.txt file.
  50. */
  51. virtual bool InitialPass(std::vector<std::string> const& args,
  52. cmExecutionStatus&) = 0;
  53. /**
  54. * This is a virtual constructor for the command.
  55. */
  56. virtual std::unique_ptr<cmCommand> Clone() = 0;
  57. /**
  58. * Set the error message
  59. */
  60. void SetError(const std::string& e);
  61. protected:
  62. cmMakefile* Makefile = nullptr;
  63. private:
  64. cmExecutionStatus* Status = nullptr;
  65. };
  66. class cmLegacyCommandWrapper
  67. {
  68. public:
  69. explicit cmLegacyCommandWrapper(std::unique_ptr<cmCommand> cmd);
  70. cmLegacyCommandWrapper(cmLegacyCommandWrapper const& other);
  71. cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper const& other);
  72. cmLegacyCommandWrapper(cmLegacyCommandWrapper&&) = default;
  73. cmLegacyCommandWrapper& operator=(cmLegacyCommandWrapper&&) = default;
  74. bool operator()(std::vector<cmListFileArgument> const& args,
  75. cmExecutionStatus& status) const;
  76. private:
  77. std::unique_ptr<cmCommand> Command;
  78. };