packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmLocalNinjaGenerator.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 cmLocalNinjaGenerator_h
14 #  define cmLocalNinjaGenerator_h
15
16 #  include "cmLocalGenerator.h"
17 #  include "cmNinjaTypes.h"
18
19 class cmGlobalNinjaGenerator;
20 class cmGeneratedFileStream;
21 class cmake;
22
23 /**
24  * \class cmLocalNinjaGenerator
25  * \brief Write a local build.ninja file.
26  *
27  * cmLocalNinjaGenerator produces a local build.ninja file from its
28  * member Makefile.
29  */
30 class cmLocalNinjaGenerator : public cmLocalGenerator
31 {
32 public:
33   /// Default constructor.
34   cmLocalNinjaGenerator();
35
36   /// Destructor.
37   virtual ~cmLocalNinjaGenerator();
38
39   /// Overloaded methods. @see cmLocalGenerator::Generate()
40   virtual void Generate();
41
42   /// Overloaded methods. @see cmLocalGenerator::Configure()
43   virtual void Configure();
44
45   /// Overloaded methods. @see cmLocalGenerator::GetTargetDirectory()
46   virtual std::string GetTargetDirectory(cmTarget const& target) const;
47
48   const cmGlobalNinjaGenerator* GetGlobalNinjaGenerator() const;
49   cmGlobalNinjaGenerator* GetGlobalNinjaGenerator();
50
51   /**
52    * Shortcut to get the cmake instance throw the global generator.
53    * @return an instance of the cmake object.
54    */
55   const cmake* GetCMakeInstance() const;
56   cmake* GetCMakeInstance();
57
58   const char* GetConfigName() const
59   { return this->ConfigName.c_str(); }
60
61   /// @return whether we are processing the top CMakeLists.txt file.
62   bool isRootMakefile() const;
63
64   /// @returns the relative path between the HomeOutputDirectory and this
65   /// local generators StartOutputDirectory.
66   std::string GetHomeRelativeOutputPath() const
67   { return this->HomeRelativeOutputPath; }
68
69   std::string ConvertToNinjaPath(const char *path);
70
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());
77     }
78   };
79
80   map_to_ninja_path MapToNinjaPath() {
81     return map_to_ninja_path(this);
82   }
83
84   void ExpandRuleVariables(std::string& string,
85                            const RuleVariables& replaceValues) {
86     cmLocalGenerator::ExpandRuleVariables(string, replaceValues);
87   }
88
89   std::string BuildCommandLine(const std::vector<std::string> &cmdLines);
90
91   void AppendTargetOutputs(cmTarget* target, cmNinjaDeps& outputs);
92   void AppendTargetDepends(cmTarget* target, cmNinjaDeps& outputs);
93
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);
99
100   virtual std::string ConvertToLinkReference(std::string const& lib);
101
102
103 protected:
104   virtual std::string ConvertToIncludeReference(std::string const& path);
105
106
107 private:
108   cmGeneratedFileStream& GetBuildFileStream() const;
109   cmGeneratedFileStream& GetRulesFileStream() const;
110
111   void WriteBuildFileTop();
112   void WriteProjectHeader(std::ostream& os);
113   void WriteNinjaFilesInclusion(std::ostream& os);
114   void WriteProcessedMakefile(std::ostream& os);
115
116   void SetConfigName();
117
118   void WriteCustomCommandRule();
119   void WriteCustomCommandBuildStatement(cmCustomCommand const *cc,
120                                         const cmNinjaDeps& orderOnlyDeps);
121
122   void WriteCustomCommandBuildStatements();
123
124
125   std::string ConfigName;
126   std::string HomeRelativeOutputPath;
127
128   typedef std::map<cmCustomCommand const*, std::set<cmTarget*> >
129     CustomCommandTargetMap;
130   CustomCommandTargetMap CustomCommandTargets;
131 };
132
133 #endif // ! cmLocalNinjaGenerator_h