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>
6 Distributed under the OSI-approved BSD License (the "License");
7 see accompanying file Copyright.txt for details.
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
16 #include "cmStandardIncludes.h"
17 #include "cmNinjaTypes.h"
18 #include "cmLocalNinjaGenerator.h"
19 #include "cmOSXBundleGenerator.h"
22 class cmGlobalNinjaGenerator;
23 class cmGeneratedFileStream;
24 class cmGeneratorTarget;
27 class cmCustomCommand;
29 class cmNinjaTargetGenerator
32 /// Create a cmNinjaTargetGenerator according to the @a target's type.
33 static cmNinjaTargetGenerator* New(cmTarget* target);
35 /// Build a NinjaTargetGenerator.
36 cmNinjaTargetGenerator(cmTarget* target);
39 virtual ~cmNinjaTargetGenerator();
41 virtual void Generate() = 0;
43 std::string GetTargetName() const;
47 bool SetMsvcTargetPdbVariable(cmNinjaVars&) const;
49 cmGeneratedFileStream& GetBuildFileStream() const;
50 cmGeneratedFileStream& GetRulesFileStream() const;
52 cmTarget* GetTarget() const
53 { return this->Target; }
55 cmGeneratorTarget* GetGeneratorTarget() const
56 { return this->GeneratorTarget; }
58 cmLocalNinjaGenerator* GetLocalGenerator() const
59 { return this->LocalGenerator; }
61 cmGlobalNinjaGenerator* GetGlobalGenerator() const;
63 cmMakefile* GetMakefile() const
64 { return this->Makefile; }
66 const char* GetConfigName() const;
68 std::string LanguageCompilerRule(const std::string& lang) const
69 { return lang + "_COMPILER"; }
71 const char* GetFeature(const char* feature);
72 bool GetFeatureAsBool(const char* feature);
73 void AddFeatureFlags(std::string& flags, const char* lang);
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().
80 std::string ComputeFlagsForObject(cmSourceFile *source,
81 const std::string& language);
83 std::string ComputeDefines(cmSourceFile *source,
84 const std::string& language);
86 std::string ConvertToNinjaPath(const char *path) const {
87 return this->GetLocalGenerator()->ConvertToNinjaPath(path);
89 cmLocalNinjaGenerator::map_to_ninja_path MapToNinjaPath() const {
90 return this->GetLocalGenerator()->MapToNinjaPath();
93 /// @return the list of link dependency for the given target @a target.
94 cmNinjaDeps ComputeLinkDeps() const;
96 /// @return the source file path for the given @a source.
97 std::string GetSourceFilePath(cmSourceFile* source) const;
99 /// @return the object file path for the given @a source.
100 std::string GetObjectFilePath(cmSourceFile* source) const;
102 /// @return the file path where the target named @a name is generated.
103 std::string GetTargetFilePath(const std::string& name) const;
105 /// @return the output path for the target.
106 virtual std::string GetTargetOutputDir() const;
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);
114 cmNinjaDeps GetObjects() const
115 { return this->Objects; }
117 // Helper to add flag for windows .def file.
118 void AddModuleDefinitionFlag(std::string& flags);
120 void EnsureDirectoryExists(const std::string& dir) const;
121 void EnsureParentDirectoryExists(const std::string& path) const;
123 // write rules for Mac OS X Application Bundle content.
124 struct MacOSXContentGeneratorType :
125 cmOSXBundleGenerator::MacOSXContentGeneratorType
127 MacOSXContentGeneratorType(cmNinjaTargetGenerator* g) :
130 void operator()(cmSourceFile& source, const char* pkgloc);
133 cmNinjaTargetGenerator* Generator;
135 friend struct MacOSXContentGeneratorType;
138 MacOSXContentGeneratorType* MacOSXContentGenerator;
139 // Properly initialized by sub-classes.
140 cmOSXBundleGenerator* OSXBundleGenerator;
141 std::set<cmStdString> MacContentFolders;
146 cmGeneratorTarget* GeneratorTarget;
147 cmMakefile* Makefile;
148 cmLocalNinjaGenerator* LocalGenerator;
149 /// List of object files for this target.
152 // The windows module definition source file (.def), if any.
153 std::string ModuleDefinitionFile;
156 #endif // ! cmNinjaTargetGenerator_h