packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmMakefileTargetGenerator.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 cmMakefileTargetGenerator_h
13 #define cmMakefileTargetGenerator_h
14
15 #include "cmLocalUnixMakefileGenerator3.h"
16 #include "cmOSXBundleGenerator.h"
17
18 class cmCustomCommand;
19 class cmDependInformation;
20 class cmDepends;
21 class cmGeneratorTarget;
22 class cmGeneratedFileStream;
23 class cmGlobalUnixMakefileGenerator3;
24 class cmLocalUnixMakefileGenerator3;
25 class cmMakefile;
26 class cmTarget;
27 class cmSourceFile;
28
29 /** \class cmMakefileTargetGenerator
30  * \brief Support Routines for writing makefiles
31  *
32  */
33 class cmMakefileTargetGenerator
34 {
35 public:
36   // constructor to set the ivars
37   cmMakefileTargetGenerator(cmTarget* target);
38   virtual ~cmMakefileTargetGenerator();
39
40   // construct using this factory call
41   static cmMakefileTargetGenerator *New(cmTarget *tgt);
42
43   /* the main entry point for this class. Writes the Makefiles associated
44      with this target */
45   virtual void WriteRuleFiles() = 0;
46
47   /* return the number of actions that have progress reporting on them */
48   virtual unsigned long GetNumberOfProgressActions() {
49     return this->NumberOfProgressActions;}
50   std::string GetProgressFileNameFull()
51     { return this->ProgressFileNameFull; }
52
53   cmTarget* GetTarget() { return this->Target;}
54
55 protected:
56
57   // create the file and directory etc
58   void CreateRuleFile();
59
60   // outputs the rules for object files and custom commands used by
61   // this target
62   void WriteTargetBuildRules();
63
64   // write some common code at the top of build.make
65   void WriteCommonCodeRules();
66   void WriteTargetLanguageFlags();
67
68   // write the provide require rules for this target
69   void WriteTargetRequiresRules();
70
71   // write the clean rules for this target
72   void WriteTargetCleanRules();
73
74   // write the depend rules for this target
75   void WriteTargetDependRules();
76
77   // write rules for Mac OS X Application Bundle content.
78   struct MacOSXContentGeneratorType :
79     cmOSXBundleGenerator::MacOSXContentGeneratorType
80   {
81     MacOSXContentGeneratorType(cmMakefileTargetGenerator* gen) :
82       Generator(gen) {}
83
84     void operator()(cmSourceFile& source, const char* pkgloc);
85
86   private:
87     cmMakefileTargetGenerator* Generator;
88   };
89   friend struct MacOSXContentGeneratorType;
90
91   // write the rules for an object
92   void WriteObjectRuleFiles(cmSourceFile& source);
93
94   // write the build rule for an object
95   void WriteObjectBuildFile(std::string &obj,
96                             const char *lang,
97                             cmSourceFile& source,
98                             std::vector<std::string>& depends);
99
100   // write the depend.make file for an object
101   void WriteObjectDependRules(cmSourceFile& source,
102                               std::vector<std::string>& depends);
103
104   // write the build rule for a custom command
105   void GenerateCustomRuleFile(const cmCustomCommand& cc);
106
107   // write a rule to drive building of more than one output from
108   // another rule
109   void GenerateExtraOutput(const char* out, const char* in,
110                            bool symbolic = false);
111
112   void AppendProgress(std::vector<std::string>& commands);
113
114   // write out the variable that lists the objects for this target
115   void WriteObjectsVariable(std::string& variableName,
116                             std::string& variableNameExternal);
117   void WriteObjectsString(std::string& buildObjs);
118   void WriteObjectsStrings(std::vector<std::string>& objStrings,
119                            std::string::size_type limit = std::string::npos);
120
121   // write the driver rule to build target outputs
122   void WriteTargetDriverRule(const char* main_output, bool relink);
123
124   void DriveCustomCommands(std::vector<std::string>& depends);
125
126   // Return the a string with -F flags on apple
127   std::string GetFrameworkFlags();
128
129   void AppendFortranFormatFlags(std::string& flags, cmSourceFile& source);
130
131   // append intertarget dependencies
132   void AppendTargetDepends(std::vector<std::string>& depends);
133
134   // Append object file dependencies.
135   void AppendObjectDepends(std::vector<std::string>& depends);
136
137   // Append link rule dependencies (objects, etc.).
138   void AppendLinkDepends(std::vector<std::string>& depends);
139
140   // Lookup the link rule for this target.
141   std::string GetLinkRule(const char* linkRuleVar);
142
143   /** In order to support parallel builds for custom commands with
144       multiple outputs the outputs are given a serial order, and only
145       the first output actually has the build rule.  Other outputs
146       just depend on the first one.  The check-build-system step must
147       remove a dependee if the depender is missing to make sure both
148       are regenerated properly.  This method is used by the local
149       makefile generators to register such pairs.  */
150   void AddMultipleOutputPair(const char* depender, const char* dependee);
151
152   /** Create a script to hold link rules and a command to invoke the
153       script at build time.  */
154   void CreateLinkScript(const char* name,
155                         std::vector<std::string> const& link_commands,
156                         std::vector<std::string>& makefile_commands,
157                         std::vector<std::string>& makefile_depends);
158
159   /** Create a response file with the given set of options.  Returns
160       the relative path from the target build working directory to the
161       response file name.  */
162   std::string CreateResponseFile(const char* name,
163                                  std::string const& options,
164                                  std::vector<std::string>& makefile_depends);
165
166   /** Create lists of object files for linking and cleaning.  */
167   void CreateObjectLists(bool useLinkScript, bool useArchiveRules,
168                          bool useResponseFile, std::string& buildObjs,
169                          std::vector<std::string>& makefile_depends);
170
171   void AddIncludeFlags(std::string& flags, const char* lang);
172
173   virtual void CloseFileStreams();
174   void RemoveForbiddenFlags(const char* flagVar, const char* linkLang,
175                             std::string& linkFlags);
176   cmTarget *Target;
177   cmGeneratorTarget* GeneratorTarget;
178   cmLocalUnixMakefileGenerator3 *LocalGenerator;
179   cmGlobalUnixMakefileGenerator3 *GlobalGenerator;
180   cmMakefile *Makefile;
181   const char *ConfigName;
182
183   enum CustomCommandDriveType { OnBuild, OnDepends, OnUtility };
184   CustomCommandDriveType CustomCommandDriver;
185
186   // the full path to the build file
187   std::string BuildFileName;
188   std::string BuildFileNameFull;
189
190   // the full path to the progress file
191   std::string ProgressFileNameFull;
192   unsigned long NumberOfProgressActions;
193   bool NoRuleMessages;
194
195   // the path to the directory the build file is in
196   std::string TargetBuildDirectory;
197   std::string TargetBuildDirectoryFull;
198
199   // the stream for the build file
200   cmGeneratedFileStream *BuildFileStream;
201
202   // the stream for the flag file
203   std::string FlagFileNameFull;
204   cmGeneratedFileStream *FlagFileStream;
205   class StringList: public std::vector<std::string> {};
206   std::map<cmStdString, StringList> FlagFileDepends;
207
208   // the stream for the info file
209   std::string InfoFileNameFull;
210   cmGeneratedFileStream *InfoFileStream;
211
212   // files to clean
213   std::vector<std::string> CleanFiles;
214
215   // objects used by this target
216   std::vector<std::string> Objects;
217   std::vector<std::string> ExternalObjects;
218
219   // Set of object file names that will be built in this directory.
220   std::set<cmStdString> ObjectFiles;
221
222   // Set of extra output files to be driven by the build.
223   std::set<cmStdString> ExtraFiles;
224
225   typedef std::map<cmStdString, cmStdString> MultipleOutputPairsType;
226   MultipleOutputPairsType MultipleOutputPairs;
227
228   // Target name info.
229   std::string TargetNameOut;
230   std::string TargetNameSO;
231   std::string TargetNameReal;
232   std::string TargetNameImport;
233   std::string TargetNamePDB;
234
235   // Mac OS X content info.
236   std::set<cmStdString> MacContentFolders;
237   cmOSXBundleGenerator* OSXBundleGenerator;
238   MacOSXContentGeneratorType* MacOSXContentGenerator;
239
240   typedef std::map<cmStdString, cmStdString> ByLanguageMap;
241   std::string GetFlags(const std::string &l);
242   ByLanguageMap FlagsByLanguage;
243   std::string GetDefines(const std::string &l);
244   ByLanguageMap DefinesByLanguage;
245
246   // Target-wide Fortran module output directory.
247   bool FortranModuleDirectoryComputed;
248   std::string FortranModuleDirectory;
249   const char* GetFortranModuleDirectory();
250
251   // Compute target-specific Fortran language flags.
252   void AddFortranFlags(std::string& flags);
253
254   // Helper to add flag for windows .def file.
255   void AddModuleDefinitionFlag(std::string& flags);
256
257   // Add language feature flags.
258   void AddFeatureFlags(std::string& flags, const char* lang);
259
260   // Feature query methods.
261   const char* GetFeature(const char* feature);
262   bool GetFeatureAsBool(const char* feature);
263
264   //==================================================================
265   // Convenience routines that do nothing more than forward to
266   // implementaitons
267   std::string Convert(const char* source,
268                       cmLocalGenerator::RelativeRoot relative,
269                       cmLocalGenerator::OutputFormat output =
270                       cmLocalGenerator::UNCHANGED,
271                       bool optional = false)
272   {
273     return this->LocalGenerator->Convert(source, relative, output, optional);
274   }
275
276 };
277
278 #endif