1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalUnixMakefileGenerator3.h,v $
6 Date: $Date: 2009-06-25 13:58:51 $
7 Version: $Revision: 1.89 $
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
;
25 class cmMakefileTargetGenerator
;
29 /** \class cmLocalUnixMakefileGenerator3
30 * \brief Write a LocalUnix makefiles.
32 * cmLocalUnixMakefileGenerator3 produces a LocalUnix makefile from its
35 class cmLocalUnixMakefileGenerator3
: public cmLocalGenerator
38 cmLocalUnixMakefileGenerator3();
39 virtual ~cmLocalUnixMakefileGenerator3();
42 * Process the CMakeLists files for this directory to fill in the
45 virtual void Configure();
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
,
61 const std::vector
<std::string
>& depends
,
62 const std::vector
<std::string
>& commands
,
64 bool in_help
= false);
66 // write the main variables used by the makefiles
67 void WriteMakeVariables(std::ostream
& makefileStream
);
70 * If true, then explicitly pass MAKEFLAGS on the make all target for makes
71 * that do not use environment variables.
74 void SetPassMakeflags(bool s
){this->PassMakeflags
= s
;}
75 bool GetPassMakeflags() { return this->PassMakeflags
; }
78 * Set the flag used to keep the make program silent.
80 void SetMakeSilentFlag(const char* s
) { this->MakeSilentFlag
= s
; }
81 std::string
&GetMakeSilentFlag() { return this->MakeSilentFlag
; }
84 * Set to true if the shell being used is the windows shell.
85 * This controls if statements in the makefile and the SHELL variable.
86 * The default is false.
88 void SetWindowsShell(bool v
) {this->WindowsShell
= v
;}
91 * Set to true if the make tool being used is Watcom WMake.
93 void SetWatcomWMake(bool v
) {this->WatcomWMake
= v
;}
96 * Set to true if the make tool being used is MinGW Make.
98 void SetMinGWMake(bool v
) {this->MinGWMake
= v
;}
101 * Set to true if the make tool being used is NMake.
103 void SetNMake(bool v
) {this->NMake
= v
;}
106 * Set to true if the shell being used is the MSYS shell.
107 * This controls if statements in the makefile and the SHELL variable.
108 * The default is false.
110 void SetMSYSShell(bool v
) {this->MSYSShell
= v
;}
113 * If set to true, then NULL is set to nil for non Windows_NT.
114 * This uses make syntax used by nmake and borland.
115 * The default is false.
117 void SetDefineWindowsNULL(bool v
) {this->DefineWindowsNULL
= v
;}
120 * If set to true, cd dir && command is used to
121 * run commands in a different directory.
123 void SetUnixCD(bool v
) {this->UnixCD
= v
;}
126 * Set Support Verbose Variable. If true, then .SILENT will
127 * be not end with : i.e. .SILENT: or .SILENT
129 void SetSilentNoColon(bool v
) {this->SilentNoColon
= v
;}
132 * Set the command to use for native make shell echo. The value
133 * should include all parts of the command up to the beginning of
134 * the message (including a whitespace separator).
136 void SetNativeEchoCommand(const char* cmd
, bool isWindows
)
137 { this->NativeEchoCommand
= cmd
; this->NativeEchoWindows
= isWindows
; }
140 * Set the string used to include one makefile into another default
143 void SetIncludeDirective(const char* s
) { this->IncludeDirective
= s
; }
144 const char *GetIncludeDirective() { return this->IncludeDirective
.c_str(); }
147 * Set max makefile variable size, default is 0 which means unlimited.
149 void SetMakefileVariableSize(int s
) { this->MakefileVariableSize
= s
; }
152 * If ignore lib prefix is true, then do not strip lib from the name
155 void SetIgnoreLibPrefix(bool s
) { this->IgnoreLibPrefix
= s
; }
158 * Set whether passing a make target on a command line requires an
159 * extra level of escapes.
161 void SetMakeCommandEscapeTargetTwice(bool b
)
162 { this->MakeCommandEscapeTargetTwice
= b
; }
165 * Set whether the Borland curly brace command line hack should be
168 void SetBorlandMakeCurlyHack(bool b
)
169 { this->BorlandMakeCurlyHack
= b
; }
171 // used in writing out Cmake files such as WriteDirectoryInformation
172 static void WriteCMakeArgument(std::ostream
& os
, const char* s
);
174 /** creates the common disclainer text at the top of each makefile */
175 void WriteDisclaimer(std::ostream
& os
);
177 // write a comment line #====... in the stream
178 void WriteDivider(std::ostream
& os
);
180 /** used to create a recursive make call */
181 std::string
GetRecursiveMakeCall(const char *makefile
, const char* tgt
);
183 // append flags to a string
184 virtual void AppendFlags(std::string
& flags
, const char* newFlags
);
186 // append an echo command
187 enum EchoColor
{ EchoNormal
, EchoDepend
, EchoBuild
, EchoLink
,
188 EchoGenerate
, EchoGlobal
};
189 void AppendEcho(std::vector
<std::string
>& commands
, const char* text
,
190 EchoColor color
= EchoNormal
);
192 /** Get whether the makefile is to have color. */
193 bool GetColorMakefile() const { return this->ColorMakefile
; }
195 virtual std::string
GetTargetDirectory(cmTarget
const& target
) const;
197 // create a command that cds to the start dir then runs the commands
198 void CreateCDCommand(std::vector
<std::string
>& commands
,
199 const char *targetDir
,
200 cmLocalGenerator::RelativeRoot returnDir
);
202 static std::string
ConvertToQuotedOutputPath(const char* p
);
204 std::string
CreateMakeVariable(const char* sin
, const char* s2in
);
206 /** Called from command-line hook to bring dependencies up to date
208 virtual bool UpdateDependencies(const char* tgtInfo
,
209 bool verbose
, bool color
);
211 /** Called from command-line hook to clear dependencies. */
212 virtual void ClearDependencies(cmMakefile
* mf
, bool verbose
);
214 /** write some extra rules such as make test etc */
215 void WriteSpecialTargetsTop(std::ostream
& makefileStream
);
216 void WriteSpecialTargetsBottom(std::ostream
& makefileStream
);
218 std::string
GetRelativeTargetDirectory(cmTarget
const& target
);
220 // File pairs for implicit dependency scanning. The key of the map
221 // is the depender and the value is the explicit dependee.
222 struct ImplicitDependFileMap
: public std::map
<cmStdString
, cmStdString
> {};
223 struct ImplicitDependLanguageMap
:
224 public std::map
<cmStdString
, ImplicitDependFileMap
> {};
225 struct ImplicitDependTargetMap
:
226 public std::map
<cmStdString
, ImplicitDependLanguageMap
> {};
227 ImplicitDependLanguageMap
const& GetImplicitDepends(cmTarget
const& tgt
);
229 void AddImplicitDepends(cmTarget
const& tgt
, const char* lang
,
230 const char* obj
, const char* src
);
232 void AppendGlobalTargetDepends(std::vector
<std::string
>& depends
,
235 // write the target rules for the local Makefile into the stream
236 void WriteLocalAllRules(std::ostream
& ruleFileStream
);
238 struct LocalObjectEntry
241 std::string Language
;
242 LocalObjectEntry(): Target(0), Language() {}
243 LocalObjectEntry(cmTarget
* t
, const char* lang
):
244 Target(t
), Language(lang
) {}
246 struct LocalObjectInfo
: public std::vector
<LocalObjectEntry
>
248 bool HasSourceExtension
;
250 std::map
<cmStdString
, LocalObjectInfo
> const& GetLocalObjectFiles()
251 { return this->LocalObjectFiles
;}
253 std::vector
<cmStdString
> const& GetLocalHelp() { return this->LocalHelp
; }
255 /** Get whether to create rules to generate preprocessed and
256 assembly sources. This could be converted to a variable lookup
258 bool GetCreatePreprocessedSourceRules()
260 return !this->SkipPreprocessedSourceRules
;
262 bool GetCreateAssemblySourceRules()
264 return !this->SkipAssemblySourceRules
;
266 // Get the directories into which the .o files will go for this target
267 void GetTargetObjectFileDirectories(cmTarget
* target
,
268 std::vector
<std::string
>& dirs
);
270 void WriteLocalMakefile();
273 // write the target rules for the local Makefile into the stream
274 void WriteLocalMakefileTargets(std::ostream
& ruleFileStream
,
275 std::set
<cmStdString
> &emitted
);
277 // this method Writes the Directory information files
278 void WriteDirectoryInformationFile();
281 // write the depend info
282 void WriteDependLanguageInfo(std::ostream
& cmakefileStream
, cmTarget
&tgt
);
284 // write the local help rule
285 void WriteHelpRule(std::ostream
& ruleFileStream
);
287 // this converts a file name that is relative to the StartOuputDirectory
289 std::string
ConvertToFullPath(const std::string
& localPath
);
292 void WriteConvenienceRule(std::ostream
& ruleFileStream
,
293 const char* realTarget
,
294 const char* helpTarget
);
296 void WriteTargetDependRule(std::ostream
& ruleFileStream
,
298 void WriteTargetCleanRule(std::ostream
& ruleFileStream
,
300 const std::vector
<std::string
>& files
);
301 void WriteTargetRequiresRule(std::ostream
& ruleFileStream
,
303 const std::vector
<std::string
>& objects
);
304 void WriteObjectConvenienceRule(std::ostream
& ruleFileStream
,
305 const char* comment
, const char* output
,
306 LocalObjectInfo
const& info
);
308 std::string
GetObjectFileName(cmTarget
& target
,
309 const cmSourceFile
& source
,
310 std::string
* nameWithoutTargetDir
= 0,
311 bool* hasSourceExtension
= 0);
313 void AppendRuleDepend(std::vector
<std::string
>& depends
,
314 const char* ruleFileName
);
315 void AppendCustomDepends(std::vector
<std::string
>& depends
,
316 const std::vector
<cmCustomCommand
>& ccs
);
317 void AppendCustomDepend(std::vector
<std::string
>& depends
,
318 const cmCustomCommand
& cc
);
319 void AppendCustomCommands(std::vector
<std::string
>& commands
,
320 const std::vector
<cmCustomCommand
>& ccs
,
322 cmLocalGenerator::RelativeRoot relative
=
323 cmLocalGenerator::HOME_OUTPUT
);
324 void AppendCustomCommand(std::vector
<std::string
>& commands
,
325 const cmCustomCommand
& cc
,
327 bool echo_comment
=false,
328 cmLocalGenerator::RelativeRoot relative
=
329 cmLocalGenerator::HOME_OUTPUT
,
330 std::ostream
* content
= 0);
331 void AppendCleanCommand(std::vector
<std::string
>& commands
,
332 const std::vector
<std::string
>& files
,
333 cmTarget
& target
, const char* filename
=0);
335 // Helper methods for dependeny updates.
336 bool ScanDependencies(const char* targetDir
);
337 void CheckMultipleOutputs(bool verbose
);
340 std::string
MakeLauncher(const cmCustomCommand
& cc
, cmTarget
* target
,
341 RelativeRoot relative
);
343 friend class cmMakefileTargetGenerator
;
344 friend class cmMakefileExecutableTargetGenerator
;
345 friend class cmMakefileLibraryTargetGenerator
;
346 friend class cmMakefileUtilityTargetGenerator
;
347 friend class cmGlobalUnixMakefileGenerator3
;
349 ImplicitDependTargetMap ImplicitDepends
;
351 //==========================================================================
352 // Configuration settings.
353 int MakefileVariableSize
;
354 std::string IncludeDirective
;
355 std::string MakeSilentFlag
;
356 std::string ConfigurationName
;
357 std::string NativeEchoCommand
;
358 bool NativeEchoWindows
;
359 bool DefineWindowsNULL
;
363 bool MakeCommandEscapeTargetTwice
;
364 bool BorlandMakeCurlyHack
;
365 //==========================================================================
367 std::string HomeRelativeOutputPath
;
369 /* Copy the setting of CMAKE_COLOR_MAKEFILE from the makefile at the
370 beginning of generation to avoid many duplicate lookups. */
373 /* Copy the setting of CMAKE_SKIP_PREPROCESSED_SOURCE_RULES and
374 CMAKE_SKIP_ASSEMBLY_SOURCE_RULES at the beginning of generation to
375 avoid many duplicate lookups. */
376 bool SkipPreprocessedSourceRules
;
377 bool SkipAssemblySourceRules
;
379 std::map
<cmStdString
, LocalObjectInfo
> LocalObjectFiles
;
380 std::vector
<cmStdString
> LocalHelp
;
382 /* does the work for each target */
383 std::map
<cmStdString
, cmStdString
> MakeVariableMap
;
384 std::map
<cmStdString
, cmStdString
> ShortMakeVariableMap
;