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 cmLocalNinjaGenerator_h
14 # define cmLocalNinjaGenerator_h
16 # include "cmLocalGenerator.h"
17 # include "cmNinjaTypes.h"
19 class cmGlobalNinjaGenerator;
20 class cmGeneratedFileStream;
24 * \class cmLocalNinjaGenerator
25 * \brief Write a local build.ninja file.
27 * cmLocalNinjaGenerator produces a local build.ninja file from its
30 class cmLocalNinjaGenerator : public cmLocalGenerator
33 /// Default constructor.
34 cmLocalNinjaGenerator();
37 virtual ~cmLocalNinjaGenerator();
39 /// Overloaded methods. @see cmLocalGenerator::Generate()
40 virtual void Generate();
42 /// Overloaded methods. @see cmLocalGenerator::Configure()
43 virtual void Configure();
45 /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
46 virtual std::string GetTargetDirectory(cmTarget const& target) const;
48 const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
49 cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
52 * Shortcut to get the cmake instance throw the global generator.
53 * @return an instance of the cmake object.
55 const cmake* GetCMakeInstance() const;
56 cmake* GetCMakeInstance();
58 const char* GetConfigName() const
59 { return this->ConfigName.c_str(); }
61 /// @return whether we are processing the top CMakeLists.txt file.
62 bool isRootMakefile() const;
64 /// @returns the relative path between the HomeOutputDirectory and this
65 /// local generators StartOutputDirectory.
66 std::string GetHomeRelativeOutputPath() const
67 { return this->HomeRelativeOutputPath; }
69 std::string ConvertToNinjaPath(const char *path);
71 struct map_to_ninja_path {
72 cmLocalNinjaGenerator *LocalGenerator;
73 map_to_ninja_path(cmLocalNinjaGenerator *LocalGen)
74 : LocalGenerator(LocalGen) {}
75 std::string operator()(const std::string &path) {
76 return LocalGenerator->ConvertToNinjaPath(path.c_str());
80 map_to_ninja_path MapToNinjaPath() {
81 return map_to_ninja_path(this);
84 void ExpandRuleVariables(std::string& string,
85 const RuleVariables& replaceValues) {
86 cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
89 std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
91 void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
92 void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
94 void AddCustomCommandTarget(cmCustomCommand const* cc, cmTarget* target);
95 void AppendCustomCommandLines(const cmCustomCommand *cc,
96 std::vector<std::string> &cmdLines);
97 void AppendCustomCommandDeps(const cmCustomCommand *cc,
98 cmNinjaDeps &ninjaDeps);
100 virtual std::string ConvertToLinkReference(std::string const& lib);
104 virtual std::string ConvertToIncludeReference(std::string const& path);
108 cmGeneratedFileStream& GetBuildFileStream() const;
109 cmGeneratedFileStream& GetRulesFileStream() const;
111 void WriteBuildFileTop();
112 void WriteProjectHeader(std::ostream& os);
113 void WriteNinjaFilesInclusion(std::ostream& os);
114 void WriteProcessedMakefile(std::ostream& os);
116 void SetConfigName();
118 void WriteCustomCommandRule();
119 void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
120 const cmNinjaDeps& orderOnlyDeps);
122 void WriteCustomCommandBuildStatements();
125 std::string ConfigName;
126 std::string HomeRelativeOutputPath;
128 typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
129 CustomCommandTargetMap;
130 CustomCommandTargetMap CustomCommandTargets;
133 #endif // ! cmLocalNinjaGenerator_h