packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmNinjaTargetGenerator.h
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2011 Peter Collingbourne <peter@pcc.me.uk>
4   Copyright 2011 Nicolas Despres <nicolas.despres@gmail.com>
5
6   Distributed under the OSI-approved BSD License (the "License");
7   see accompanying file Copyright.txt for details.
8
9   This software is distributed WITHOUT ANY WARRANTY; without even the
10   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11   See the License for more information.
12 ============================================================================*/
13 #ifndef cmNinjaTargetGenerator_h
14 #define cmNinjaTargetGenerator_h
15
16 #include "cmStandardIncludes.h"
17 #include "cmNinjaTypes.h"
18 #include "cmLocalNinjaGenerator.h"
19 #include "cmOSXBundleGenerator.h"
20
21 class cmTarget;
22 class cmGlobalNinjaGenerator;
23 class cmGeneratedFileStream;
24 class cmGeneratorTarget;
25 class cmMakefile;
26 class cmSourceFile;
27 class cmCustomCommand;
28
29 class cmNinjaTargetGenerator
30 {
31 public:
32   /// Create a cmNinjaTargetGenerator according to the @a target's type.
33   static cmNinjaTargetGenerator* New(cmTarget* target);
34
35   /// Build a NinjaTargetGenerator.
36   cmNinjaTargetGenerator(cmTarget* target);
37
38   /// Destructor.
39   virtual ~cmNinjaTargetGenerator();
40
41   virtual void Generate() = 0;
42
43   std::string GetTargetName() const;
44
45 protected:
46
47   bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
48
49   cmGeneratedFileStream& GetBuildFileStream() const;
50   cmGeneratedFileStream& GetRulesFileStream() const;
51
52   cmTarget* GetTarget() const
53   { return this->Target; }
54
55   cmGeneratorTarget* GetGeneratorTarget() const
56   { return this->GeneratorTarget; }
57
58   cmLocalNinjaGenerator* GetLocalGenerator() const
59   { return this->LocalGenerator; }
60
61   cmGlobalNinjaGenerator* GetGlobalGenerator() const;
62
63   cmMakefile* GetMakefile() const
64   { return this->Makefile; }
65
66   const char* GetConfigName() const;
67
68   std::string LanguageCompilerRule(const std::string& lang) const
69   { return lang + "_COMPILER"; }
70
71   const char* GetFeature(const char* feature);
72   bool GetFeatureAsBool(const char* feature);
73   void AddFeatureFlags(std::string& flags, const char* lang);
74
75   /**
76    * Compute the flags for compilation of object files for a given @a language.
77    * @note Generally it is the value of the variable whose name is computed
78    *       by LanguageFlagsVarName().
79    */
80   std::string ComputeFlagsForObject(cmSourceFile *source,
81                                     const std::string& language);
82
83   std::string ComputeDefines(cmSourceFile *source,
84                              const std::string& language);
85
86   std::string ConvertToNinjaPath(const char *path) const {
87     return this->GetLocalGenerator()->ConvertToNinjaPath(path);
88   }
89   cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
90     return this->GetLocalGenerator()->MapToNinjaPath();
91   }
92
93   /// @return the list of link dependency for the given target @a target.
94   cmNinjaDeps ComputeLinkDeps() const;
95
96   /// @return the source file path for the given @a source.
97   std::string GetSourceFilePath(cmSourceFile* source) const;
98
99   /// @return the object file path for the given @a source.
100   std::string GetObjectFilePath(cmSourceFile* source) const;
101
102   /// @return the file path where the target named @a name is generated.
103   std::string GetTargetFilePath(const std::string& name) const;
104
105   /// @return the output path for the target.
106   virtual std::string GetTargetOutputDir() const;
107
108   void WriteLanguageRules(const std::string& language);
109   void WriteCompileRule(const std::string& language);
110   void WriteObjectBuildStatements();
111   void WriteObjectBuildStatement(cmSourceFile* source);
112   void WriteCustomCommandBuildStatement(cmCustomCommand *cc);
113
114   cmNinjaDeps GetObjects() const
115   { return this->Objects; }
116
117   // Helper to add flag for windows .def file.
118   void AddModuleDefinitionFlag(std::string& flags);
119
120   void EnsureDirectoryExists(const std::string& dir) const;
121   void EnsureParentDirectoryExists(const std::string& path) const;
122
123   // write rules for Mac OS X Application Bundle content.
124   struct MacOSXContentGeneratorType :
125     cmOSXBundleGenerator::MacOSXContentGeneratorType
126   {
127     MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
128       Generator(g)  {}
129
130     void operator()(cmSourceFile& source, const char* pkgloc);
131
132   private:
133     cmNinjaTargetGenerator* Generator;
134   };
135   friend struct MacOSXContentGeneratorType;
136
137 protected:
138   MacOSXContentGeneratorType* MacOSXContentGenerator;
139   // Properly initialized by sub-classes.
140   cmOSXBundleGenerator* OSXBundleGenerator;
141   std::set<cmStdString> MacContentFolders;
142
143
144 private:
145   cmTarget* Target;
146   cmGeneratorTarget* GeneratorTarget;
147   cmMakefile* Makefile;
148   cmLocalNinjaGenerator* LocalGenerator;
149   /// List of object files for this target.
150   cmNinjaDeps Objects;
151
152   // The windows module definition source file (.def), if any.
153   std::string ModuleDefinitionFile;
154 };
155
156 #endif // ! cmNinjaTargetGenerator_h