Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmLocalUnixMakefileGenerator3.h
blob847d9c72f55d0884b8d3a1c80fa880aabc43670e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalUnixMakefileGenerator3.h,v $
5 Language: C++
6 Date: $Date: 2009-02-10 13:51:13 $
7 Version: $Revision: 1.88 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmLocalUnixMakefileGenerator3_h
18 #define cmLocalUnixMakefileGenerator3_h
20 #include "cmLocalGenerator.h"
22 class cmCustomCommand;
23 class cmDependInformation;
24 class cmDepends;
25 class cmMakefileTargetGenerator;
26 class cmTarget;
27 class cmSourceFile;
29 /** \class cmLocalUnixMakefileGenerator3
30 * \brief Write a LocalUnix makefiles.
32 * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
33 * member Makefile.
35 class cmLocalUnixMakefileGenerator3 : public cmLocalGenerator
37 public:
38 cmLocalUnixMakefileGenerator3();
39 virtual ~cmLocalUnixMakefileGenerator3();
41 /**
42 * Process the CMakeLists files for this directory to fill in the
43 * Makefile ivar
45 virtual void Configure();
47 /**
48 * Generate the makefile for this directory.
50 virtual void Generate();
53 // this returns the relative path between the HomeOutputDirectory and this
54 // local generators StartOutputDirectory
55 const std::string &GetHomeRelativeOutputPath();
57 // Write out a make rule
58 void WriteMakeRule(std::ostream& os,
59 const char* comment,
60 const char* target,
61 const std::vector<std::string>& depends,
62 const std::vector<std::string>& commands,
63 bool symbolic,
64 bool in_help = false);
66 // write the main variables used by the makefiles
67 void WriteMakeVariables(std::ostream& makefileStream);
69 // write the progress variables used by the makefiles
70 void WriteProgressVariables(unsigned long total, unsigned long &current);
71 void WriteAllProgressVariable();
73 /**
74 * If true, then explicitly pass MAKEFLAGS on the make all target for makes
75 * that do not use environment variables.
78 void SetPassMakeflags(bool s){this->PassMakeflags = s;}
79 bool GetPassMakeflags() { return this->PassMakeflags; }
81 /**
82 * Set the flag used to keep the make program silent.
84 void SetMakeSilentFlag(const char* s) { this->MakeSilentFlag = s; }
85 std::string &GetMakeSilentFlag() { return this->MakeSilentFlag; }
87 /**
88 * Set to true if the shell being used is the windows shell.
89 * This controls if statements in the makefile and the SHELL variable.
90 * The default is false.
92 void SetWindowsShell(bool v) {this->WindowsShell = v;}
94 /**
95 * Set to true if the make tool being used is Watcom WMake.
97 void SetWatcomWMake(bool v) {this->WatcomWMake = v;}
99 /**
100 * Set to true if the make tool being used is MinGW Make.
102 void SetMinGWMake(bool v) {this->MinGWMake = v;}
105 * Set to true if the make tool being used is NMake.
107 void SetNMake(bool v) {this->NMake = v;}
110 * Set to true if the shell being used is the MSYS shell.
111 * This controls if statements in the makefile and the SHELL variable.
112 * The default is false.
114 void SetMSYSShell(bool v) {this->MSYSShell = v;}
117 * If set to true, then NULL is set to nil for non Windows_NT.
118 * This uses make syntax used by nmake and borland.
119 * The default is false.
121 void SetDefineWindowsNULL(bool v) {this->DefineWindowsNULL = v;}
124 * If set to true, cd dir && command is used to
125 * run commands in a different directory.
127 void SetUnixCD(bool v) {this->UnixCD = v;}
130 * Set Support Verbose Variable. If true, then .SILENT will
131 * be not end with : i.e. .SILENT: or .SILENT
133 void SetSilentNoColon(bool v) {this->SilentNoColon = v;}
136 * Set the command to use for native make shell echo. The value
137 * should include all parts of the command up to the beginning of
138 * the message (including a whitespace separator).
140 void SetNativeEchoCommand(const char* cmd, bool isWindows)
141 { this->NativeEchoCommand = cmd; this->NativeEchoWindows = isWindows; }
144 * Set the string used to include one makefile into another default
145 * is include.
147 void SetIncludeDirective(const char* s) { this->IncludeDirective = s; }
148 const char *GetIncludeDirective() { return this->IncludeDirective.c_str(); }
151 * Set max makefile variable size, default is 0 which means unlimited.
153 void SetMakefileVariableSize(int s) { this->MakefileVariableSize = s; }
156 * If ignore lib prefix is true, then do not strip lib from the name
157 * of a library.
159 void SetIgnoreLibPrefix(bool s) { this->IgnoreLibPrefix = s; }
162 * Set whether passing a make target on a command line requires an
163 * extra level of escapes.
165 void SetMakeCommandEscapeTargetTwice(bool b)
166 { this->MakeCommandEscapeTargetTwice = b; }
169 * Set whether the Borland curly brace command line hack should be
170 * applied.
172 void SetBorlandMakeCurlyHack(bool b)
173 { this->BorlandMakeCurlyHack = b; }
175 // used in writing out Cmake files such as WriteDirectoryInformation
176 static void WriteCMakeArgument(std::ostream& os, const char* s);
178 /** creates the common disclainer text at the top of each makefile */
179 void WriteDisclaimer(std::ostream& os);
181 // write a comment line #====... in the stream
182 void WriteDivider(std::ostream& os);
184 /** used to create a recursive make call */
185 std::string GetRecursiveMakeCall(const char *makefile, const char* tgt);
187 // append flags to a string
188 virtual void AppendFlags(std::string& flags, const char* newFlags);
190 // append an echo command
191 enum EchoColor { EchoNormal, EchoDepend, EchoBuild, EchoLink,
192 EchoGenerate, EchoGlobal };
193 void AppendEcho(std::vector<std::string>& commands, const char* text,
194 EchoColor color = EchoNormal);
196 /** Get whether the makefile is to have color. */
197 bool GetColorMakefile() const { return this->ColorMakefile; }
199 virtual std::string GetTargetDirectory(cmTarget const& target) const;
201 // create a command that cds to the start dir then runs the commands
202 void CreateCDCommand(std::vector<std::string>& commands,
203 const char *targetDir,
204 cmLocalGenerator::RelativeRoot returnDir);
206 static std::string ConvertToQuotedOutputPath(const char* p);
208 std::string CreateMakeVariable(const char* sin, const char* s2in);
210 /** Called from command-line hook to bring dependencies up to date
211 for a target. */
212 virtual bool UpdateDependencies(const char* tgtInfo,
213 bool verbose, bool color);
215 /** Called from command-line hook to clear dependencies. */
216 virtual void ClearDependencies(cmMakefile* mf, bool verbose);
218 /** write some extra rules such as make test etc */
219 void WriteSpecialTargetsTop(std::ostream& makefileStream);
220 void WriteSpecialTargetsBottom(std::ostream& makefileStream);
222 std::string GetRelativeTargetDirectory(cmTarget const& target);
224 // File pairs for implicit dependency scanning. The key of the map
225 // is the depender and the value is the explicit dependee.
226 struct ImplicitDependFileMap: public std::map<cmStdString, cmStdString> {};
227 struct ImplicitDependLanguageMap:
228 public std::map<cmStdString, ImplicitDependFileMap> {};
229 struct ImplicitDependTargetMap:
230 public std::map<cmStdString, ImplicitDependLanguageMap> {};
231 ImplicitDependLanguageMap const& GetImplicitDepends(cmTarget const& tgt);
233 void AddImplicitDepends(cmTarget const& tgt, const char* lang,
234 const char* obj, const char* src);
236 void AppendGlobalTargetDepends(std::vector<std::string>& depends,
237 cmTarget& target);
239 // write the target rules for the local Makefile into the stream
240 void WriteLocalAllRules(std::ostream& ruleFileStream);
242 struct LocalObjectEntry
244 cmTarget* Target;
245 std::string Language;
246 LocalObjectEntry(): Target(0), Language() {}
247 LocalObjectEntry(cmTarget* t, const char* lang):
248 Target(t), Language(lang) {}
250 struct LocalObjectInfo: public std::vector<LocalObjectEntry>
252 bool HasSourceExtension;
254 std::map<cmStdString, LocalObjectInfo> const& GetLocalObjectFiles()
255 { return this->LocalObjectFiles;}
257 std::vector<cmStdString> const& GetLocalHelp() { return this->LocalHelp; }
259 // return info about progress actions
260 unsigned long GetNumberOfProgressActions();
261 unsigned long GetNumberOfProgressActionsForTarget(const char *);
263 /** Get whether to create rules to generate preprocessed and
264 assembly sources. This could be converted to a variable lookup
265 later. */
266 bool GetCreatePreprocessedSourceRules()
268 return !this->SkipPreprocessedSourceRules;
270 bool GetCreateAssemblySourceRules()
272 return !this->SkipAssemblySourceRules;
274 // Get the directories into which the .o files will go for this target
275 void GetTargetObjectFileDirectories(cmTarget* target,
276 std::vector<std::string>& dirs);
277 protected:
278 void WriteLocalMakefile();
281 // write the target rules for the local Makefile into the stream
282 void WriteLocalMakefileTargets(std::ostream& ruleFileStream,
283 std::set<cmStdString> &emitted);
285 // this method Writes the Directory information files
286 void WriteDirectoryInformationFile();
289 // write the depend info
290 void WriteDependLanguageInfo(std::ostream& cmakefileStream, cmTarget &tgt);
292 // write the local help rule
293 void WriteHelpRule(std::ostream& ruleFileStream);
295 // this converts a file name that is relative to the StartOuputDirectory
296 // into a full path
297 std::string ConvertToFullPath(const std::string& localPath);
300 void WriteConvenienceRule(std::ostream& ruleFileStream,
301 const char* realTarget,
302 const char* helpTarget);
304 void WriteTargetDependRule(std::ostream& ruleFileStream,
305 cmTarget& target);
306 void WriteTargetCleanRule(std::ostream& ruleFileStream,
307 cmTarget& target,
308 const std::vector<std::string>& files);
309 void WriteTargetRequiresRule(std::ostream& ruleFileStream,
310 cmTarget& target,
311 const std::vector<std::string>& objects);
312 void WriteObjectConvenienceRule(std::ostream& ruleFileStream,
313 const char* comment, const char* output,
314 LocalObjectInfo const& info);
316 std::string GetObjectFileName(cmTarget& target,
317 const cmSourceFile& source,
318 std::string* nameWithoutTargetDir = 0,
319 bool* hasSourceExtension = 0);
321 void AppendRuleDepend(std::vector<std::string>& depends,
322 const char* ruleFileName);
323 void AppendCustomDepends(std::vector<std::string>& depends,
324 const std::vector<cmCustomCommand>& ccs);
325 void AppendCustomDepend(std::vector<std::string>& depends,
326 const cmCustomCommand& cc);
327 void AppendCustomCommands(std::vector<std::string>& commands,
328 const std::vector<cmCustomCommand>& ccs,
329 cmTarget* target,
330 cmLocalGenerator::RelativeRoot relative =
331 cmLocalGenerator::HOME_OUTPUT);
332 void AppendCustomCommand(std::vector<std::string>& commands,
333 const cmCustomCommand& cc,
334 cmTarget* target,
335 bool echo_comment=false,
336 cmLocalGenerator::RelativeRoot relative =
337 cmLocalGenerator::HOME_OUTPUT,
338 std::ostream* content = 0);
339 void AppendCleanCommand(std::vector<std::string>& commands,
340 const std::vector<std::string>& files,
341 cmTarget& target, const char* filename =0);
343 std::map<cmStdString, std::vector<int> > ProgressFiles;
345 // Helper methods for dependeny updates.
346 bool ScanDependencies(const char* targetDir);
347 void CheckMultipleOutputs(bool verbose);
349 private:
350 std::string MakeLauncher(const cmCustomCommand& cc, cmTarget* target,
351 RelativeRoot relative);
353 friend class cmMakefileTargetGenerator;
354 friend class cmMakefileExecutableTargetGenerator;
355 friend class cmMakefileLibraryTargetGenerator;
356 friend class cmMakefileUtilityTargetGenerator;
357 friend class cmGlobalUnixMakefileGenerator3;
359 ImplicitDependTargetMap ImplicitDepends;
361 //==========================================================================
362 // Configuration settings.
363 int MakefileVariableSize;
364 std::string IncludeDirective;
365 std::string MakeSilentFlag;
366 std::string ConfigurationName;
367 std::string NativeEchoCommand;
368 bool NativeEchoWindows;
369 bool DefineWindowsNULL;
370 bool UnixCD;
371 bool PassMakeflags;
372 bool SilentNoColon;
373 bool MakeCommandEscapeTargetTwice;
374 bool BorlandMakeCurlyHack;
375 //==========================================================================
377 std::string HomeRelativeOutputPath;
379 /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
380 beginning of generation to avoid many duplicate lookups. */
381 bool ColorMakefile;
383 /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
384 CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
385 avoid many duplicate lookups. */
386 bool SkipPreprocessedSourceRules;
387 bool SkipAssemblySourceRules;
389 std::map<cmStdString, LocalObjectInfo> LocalObjectFiles;
390 std::vector<cmStdString> LocalHelp;
392 /* does the work for each target */
393 std::vector<cmMakefileTargetGenerator *> TargetGenerators;
394 std::map<cmStdString, cmStdString> MakeVariableMap;
395 std::map<cmStdString, cmStdString> ShortMakeVariableMap;
398 #endif