cmScriptGenerator.h 3.1 KB

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