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