cmScriptGenerator.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmScriptGenerator_h
  11. #define cmScriptGenerator_h
  12. #include <cmConfigure.h>
  13. #include "cmStandardIncludes.h"
  14. class cmScriptGeneratorIndent
  15. {
  16. public:
  17. cmScriptGeneratorIndent()
  18. : Level(0)
  19. {
  20. }
  21. cmScriptGeneratorIndent(int level)
  22. : Level(level)
  23. {
  24. }
  25. void Write(std::ostream& os) const
  26. {
  27. for (int i = 0; i < this->Level; ++i) {
  28. os << " ";
  29. }
  30. }
  31. cmScriptGeneratorIndent Next(int step = 2) const
  32. {
  33. return cmScriptGeneratorIndent(this->Level + step);
  34. }
  35. private:
  36. int Level;
  37. };
  38. inline std::ostream& operator<<(std::ostream& os,
  39. cmScriptGeneratorIndent const& indent)
  40. {
  41. indent.Write(os);
  42. return os;
  43. }
  44. /** \class cmScriptGenerator
  45. * \brief Support class for generating install and test scripts.
  46. *
  47. */
  48. class cmScriptGenerator
  49. {
  50. public:
  51. cmScriptGenerator(const std::string& config_var,
  52. std::vector<std::string> const& configurations);
  53. virtual ~cmScriptGenerator();
  54. void Generate(std::ostream& os, const std::string& config,
  55. std::vector<std::string> const& configurationTypes);
  56. protected:
  57. typedef cmScriptGeneratorIndent Indent;
  58. virtual void GenerateScript(std::ostream& os);
  59. virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
  60. virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
  61. virtual void GenerateScriptForConfig(std::ostream& os,
  62. const std::string& config,
  63. Indent const& indent);
  64. virtual void GenerateScriptNoConfig(std::ostream&, Indent const&) {}
  65. virtual bool NeedsScriptNoConfig() const { return false; }
  66. // Test if this generator does something for a given configuration.
  67. bool GeneratesForConfig(const std::string&);
  68. std::string CreateConfigTest(const std::string& config);
  69. std::string CreateConfigTest(std::vector<std::string> const& configs);
  70. std::string CreateComponentTest(const char* component);
  71. // Information shared by most generator types.
  72. std::string RuntimeConfigVariable;
  73. std::vector<std::string> const Configurations;
  74. // Information used during generation.
  75. std::string ConfigurationName;
  76. std::vector<std::string> const* ConfigurationTypes;
  77. // True if the subclass needs to generate an explicit rule for each
  78. // configuration. False if the subclass only generates one rule for
  79. // all enabled configurations.
  80. bool ActionsPerConfig;
  81. private:
  82. void GenerateScriptActionsOnce(std::ostream& os, Indent const& indent);
  83. void GenerateScriptActionsPerConfig(std::ostream& os, Indent const& indent);
  84. };
  85. #endif