Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGlobalUnixMakefileGenerator3.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 cmGlobalUnixMakefileGenerator3_h
13 #define cmGlobalUnixMakefileGenerator3_h
14
15 #include "cmGlobalGenerator.h"
16 #include "cmGlobalGeneratorFactory.h"
17
18 class cmGeneratedFileStream;
19 class cmMakefileTargetGenerator;
20 class cmLocalUnixMakefileGenerator3;
21
22 /** \class cmGlobalUnixMakefileGenerator3
23  * \brief Write a Unix makefiles.
24  *
25  * cmGlobalUnixMakefileGenerator3 manages UNIX build process for a tree
26
27
28  The basic approach of this generator is to produce Makefiles that will all
29  be run with the current working directory set to the Home Output
30  directory. The one exception to this is the subdirectory Makefiles which are
31  created as a convenience and just cd up to the Home Output directory and
32  invoke the main Makefiles.
33
34  The make process starts with Makefile. Makefile should only contain the
35  targets the user is likely to invoke directly from a make command line. No
36  internal targets should be in this file. Makefile2 contains the internal
37  targets that are required to make the process work.
38
39  Makefile2 in turn will recursively make targets in the correct order. Each
40  target has its own directory \<target\>.dir and its own makefile build.make in
41  that directory. Also in that directory is a couple makefiles per source file
42  used by the target. Typically these are named source.obj.build.make and
43  source.obj.build.depend.make. The source.obj.build.make contains the rules
44  for building, cleaning, and computing dependencies for the given source
45  file. The build.depend.make contains additional dependencies that were
46  computed during dependency scanning. An additional file called
47  source.obj.depend is used as a marker to indicate when dependencies must be
48  rescanned.
49
50  Rules for custom commands follow the same model as rules for source files.
51
52  */
53
54 class cmGlobalUnixMakefileGenerator3 : public cmGlobalGenerator
55 {
56 public:
57   cmGlobalUnixMakefileGenerator3();
58   static cmGlobalGeneratorFactory* NewFactory() {
59     return new cmGlobalGeneratorSimpleFactory
60       <cmGlobalUnixMakefileGenerator3>(); }
61
62   ///! Get the name for the generator.
63   virtual const char* GetName() const {
64     return cmGlobalUnixMakefileGenerator3::GetActualName();}
65   static const char* GetActualName() {return "Unix Makefiles";}
66
67   /** Get the documentation entry for this generator.  */
68   static void GetDocumentation(cmDocumentationEntry& entry);
69
70   ///! Create a local generator appropriate to this Global Generator3
71   virtual cmLocalGenerator *CreateLocalGenerator();
72
73   /**
74    * Try to determine system infomation such as shared library
75    * extension, pthreads, byte order etc.
76    */
77   virtual void EnableLanguage(std::vector<std::string>const& languages,
78                               cmMakefile *, bool optional);
79
80   /**
81    * Generate the all required files for building this project/tree. This
82    * basically creates a series of LocalGenerators for each directory and
83    * requests that they Generate.
84    */
85   virtual void Generate();
86
87
88   void WriteMainCMakefileLanguageRules(cmGeneratedFileStream& cmakefileStream,
89                                        std::vector<cmLocalGenerator *> &);
90
91   // write out the help rule listing the valid targets
92   void WriteHelpRule(std::ostream& ruleFileStream,
93                      cmLocalUnixMakefileGenerator3 *);
94
95   // write the top level target rules
96   void WriteConvenienceRules(std::ostream& ruleFileStream,
97                              std::set<cmStdString> &emitted);
98
99   /** Get the command to use for a target that has no rule.  This is
100       used for multiple output dependencies and for cmake_force.  */
101   std::string GetEmptyRuleHackCommand() { return this->EmptyRuleHackCommand; }
102
103   /** Get the fake dependency to use when a rule has no real commands
104       or dependencies.  */
105   std::string GetEmptyRuleHackDepends() { return this->EmptyRuleHackDepends; }
106
107   // change the build command for speed
108   virtual std::string GenerateBuildCommand
109   (const char* makeProgram,
110    const char *projectName, const char *projectDir,
111    const char* additionalOptions,
112    const char *targetName,
113    const char* config, bool ignoreErrors, bool fast);
114
115   /** Record per-target progress information.  */
116   void RecordTargetProgress(cmMakefileTargetGenerator* tg);
117
118   void AddCXXCompileCommand(const std::string &sourceFile,
119                             const std::string &workingDirectory,
120                             const std::string &compileCommand);
121
122 protected:
123   void WriteMainMakefile2();
124   void WriteMainCMakefile();
125
126   void WriteConvenienceRules2(std::ostream& ruleFileStream,
127                               cmLocalUnixMakefileGenerator3*);
128
129   void WriteDirectoryRule2(std::ostream& ruleFileStream,
130                            cmLocalUnixMakefileGenerator3* lg,
131                            const char* pass, bool check_all,
132                            bool check_relink);
133   void WriteDirectoryRules2(std::ostream& ruleFileStream,
134                             cmLocalUnixMakefileGenerator3* lg);
135
136   void AppendGlobalTargetDepends(std::vector<std::string>& depends,
137                                  cmTarget& target);
138
139   // does this generator need a requires step for any of its targets
140   bool NeedRequiresStep(cmTarget const&);
141
142   // Target name hooks for superclass.
143   const char* GetAllTargetName()           const { return "all"; }
144   const char* GetInstallTargetName()       const { return "install"; }
145   const char* GetInstallLocalTargetName()  const { return "install/local"; }
146   const char* GetInstallStripTargetName()  const { return "install/strip"; }
147   const char* GetPreinstallTargetName()    const { return "preinstall"; }
148   const char* GetTestTargetName()          const { return "test"; }
149   const char* GetPackageTargetName()       const { return "package"; }
150   const char* GetPackageSourceTargetName() const { return "package_source"; }
151   const char* GetEditCacheTargetName()     const { return "edit_cache"; }
152   const char* GetRebuildCacheTargetName()  const { return "rebuild_cache"; }
153   const char* GetCleanTargetName()         const { return "clean"; }
154
155   virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS() { return true; }
156
157   // Some make programs (Borland) do not keep a rule if there are no
158   // dependencies or commands.  This is a problem for creating rules
159   // that might not do anything but might have other dependencies
160   // added later.  If non-empty this variable holds a fake dependency
161   // that can be added.
162   std::string EmptyRuleHackDepends;
163
164   // Some make programs (Watcom) do not like rules with no commands.
165   // If non-empty this variable holds a bogus command that may be put
166   // in the rule to satisfy the make program.
167   std::string EmptyRuleHackCommand;
168
169   // Store per-target progress counters.
170   struct TargetProgress
171   {
172     TargetProgress(): NumberOfActions(0) {}
173     unsigned long NumberOfActions;
174     std::string VariableFile;
175     std::vector<unsigned long> Marks;
176     void WriteProgressVariables(unsigned long total, unsigned long& current);
177   };
178   struct ProgressMapCompare { bool operator()(cmTarget*,cmTarget*) const; };
179   typedef std::map<cmTarget*, TargetProgress,
180                    ProgressMapCompare> ProgressMapType;
181   ProgressMapType ProgressMap;
182
183   size_t CountProgressMarksInTarget(cmTarget* target,
184                                     std::set<cmTarget*>& emitted);
185   size_t CountProgressMarksInAll(cmLocalUnixMakefileGenerator3* lg);
186
187   cmGeneratedFileStream *CommandDatabase;
188 private:
189   virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
190 };
191
192 #endif