cmScriptGenerator.h 3.1 KB

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