cmScriptGenerator.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 cmScriptGenerator_h
  4. #define cmScriptGenerator_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <ostream>
  7. #include <string>
  8. #include <vector>
  9. class cmScriptGeneratorIndent
  10. {
  11. public:
  12. cmScriptGeneratorIndent() {}
  13. cmScriptGeneratorIndent(int level)
  14. : Level(level)
  15. {
  16. }
  17. void Write(std::ostream& os) const
  18. {
  19. for (int i = 0; i < this->Level; ++i) {
  20. os << " ";
  21. }
  22. }
  23. cmScriptGeneratorIndent Next(int step = 2) const
  24. {
  25. return cmScriptGeneratorIndent(this->Level + step);
  26. }
  27. private:
  28. int Level = 0;
  29. };
  30. inline std::ostream& operator<<(std::ostream& os,
  31. cmScriptGeneratorIndent indent)
  32. {
  33. indent.Write(os);
  34. return os;
  35. }
  36. /** \class cmScriptGenerator
  37. * \brief Support class for generating install and test scripts.
  38. *
  39. */
  40. class cmScriptGenerator
  41. {
  42. CM_DISABLE_COPY(cmScriptGenerator)
  43. public:
  44. cmScriptGenerator(std::string config_var,
  45. std::vector<std::string> configurations);
  46. virtual ~cmScriptGenerator();
  47. void Generate(std::ostream& os, const std::string& config,
  48. std::vector<std::string> const& configurationTypes);
  49. protected:
  50. typedef cmScriptGeneratorIndent Indent;
  51. virtual void GenerateScript(std::ostream& os);
  52. virtual void GenerateScriptConfigs(std::ostream& os, Indent indent);
  53. virtual void GenerateScriptActions(std::ostream& os, Indent indent);
  54. virtual void GenerateScriptForConfig(std::ostream& os,
  55. const std::string& config,
  56. Indent indent);
  57. virtual void GenerateScriptNoConfig(std::ostream&, Indent) {}
  58. virtual bool NeedsScriptNoConfig() const { return false; }
  59. // Test if this generator does something for a given configuration.
  60. bool GeneratesForConfig(const std::string&);
  61. std::string CreateConfigTest(const std::string& config);
  62. std::string CreateConfigTest(std::vector<std::string> const& configs);
  63. std::string CreateComponentTest(const char* component);
  64. // Information shared by most generator types.
  65. std::string RuntimeConfigVariable;
  66. std::vector<std::string> const Configurations;
  67. // Information used during generation.
  68. std::string ConfigurationName;
  69. std::vector<std::string> const* ConfigurationTypes;
  70. // True if the subclass needs to generate an explicit rule for each
  71. // configuration. False if the subclass only generates one rule for
  72. // all enabled configurations.
  73. bool ActionsPerConfig;
  74. private:
  75. void GenerateScriptActionsOnce(std::ostream& os, Indent indent);
  76. void GenerateScriptActionsPerConfig(std::ostream& os, Indent indent);
  77. };
  78. #endif