cmScriptGenerator.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 char* config_var,
  46. std::vector<std::string> const& configurations);
  47. virtual ~cmScriptGenerator();
  48. void Generate(std::ostream& os, const char* config,
  49. std::vector<std::string> const& configurationTypes);
  50. const std::vector<std::string>& GetConfigurations() const
  51. { return this->Configurations; }
  52. protected:
  53. typedef cmScriptGeneratorIndent Indent;
  54. virtual void GenerateScript(std::ostream& os);
  55. virtual void GenerateScriptConfigs(std::ostream& os, Indent const& indent);
  56. virtual void GenerateScriptActions(std::ostream& os, Indent const& indent);
  57. virtual void GenerateScriptForConfig(std::ostream& os,
  58. const char* config,
  59. Indent const& indent);
  60. // Test if this generator does something for a given configuration.
  61. bool GeneratesForConfig(const char*);
  62. std::string CreateConfigTest(const char* 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. const char* 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