1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.h,v $
6 Date: $Date: 2009-02-26 14:16:16 $
7 Version: $Revision: 1.112 $
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 cmLocalGenerator_h
18 #define cmLocalGenerator_h
20 #include "cmStandardIncludes.h"
23 class cmGlobalGenerator
;
25 class cmTargetManifest
;
27 class cmCustomCommand
;
29 /** \class cmLocalGenerator
30 * \brief Create required build files for a directory.
32 * Subclasses of this abstract class generate makefiles, DSP, etc for various
33 * platforms. This class should never be constructued directly. A
34 * GlobalGenerator will create it and invoke the appropriate commands on it.
36 class cmLocalGenerator
40 virtual ~cmLocalGenerator();
43 * Generate the makefile for this directory.
45 virtual void Generate() {}
48 * Process the CMakeLists files for this directory to fill in the
51 virtual void Configure();
54 * Calls TraceVSDependencies() on all targets of this generator.
56 virtual void TraceDependencies();
58 virtual void AddHelperCommands() {}
61 * Perform any final calculations prior to generation
63 virtual void ConfigureFinalPass();
66 * Generate the install rules files in this directory.
68 virtual void GenerateInstallRules();
71 * Generate the test files for tests.
73 virtual void GenerateTestFiles();
76 * Generate a manifest of target files that will be built.
78 virtual void GenerateTargetManifest();
80 ///! Get the makefile for this generator
81 cmMakefile
*GetMakefile() {
82 return this->Makefile
; };
84 ///! Get the makefile for this generator, const version
85 const cmMakefile
*GetMakefile() const {
86 return this->Makefile
; };
88 ///! Get the GlobalGenerator this is associated with
89 cmGlobalGenerator
*GetGlobalGenerator() {
90 return this->GlobalGenerator
; };
92 ///! Set the Global Generator, done on creation by the GlobalGenerator
93 void SetGlobalGenerator(cmGlobalGenerator
*gg
);
96 * Convert something to something else. This is a centralized coversion
97 * routine used by the generators to handle relative paths and the like.
98 * The flags determine what is actually done.
100 * relative: treat the argument as a directory and convert it to make it
101 * relative or full or unchanged. If relative (HOME, START etc) then that
102 * specifies what it should be relative to.
104 * output: make the result suitable for output to a...
106 * optional: should any relative path operation be controlled by the rel
109 enum RelativeRoot
{ NONE
, FULL
, HOME
, START
, HOME_OUTPUT
, START_OUTPUT
};
110 enum OutputFormat
{ UNCHANGED
, MAKEFILE
, SHELL
};
111 std::string
ConvertToOutputFormat(const char* source
, OutputFormat output
);
112 std::string
Convert(const char* remote
, RelativeRoot local
,
113 OutputFormat output
= UNCHANGED
,
114 bool optional
= false);
115 std::string
Convert(RelativeRoot remote
, const char* local
,
116 OutputFormat output
= UNCHANGED
,
117 bool optional
= false);
120 * Get path for the specified relative root.
122 const char* GetRelativeRootPath(RelativeRoot relroot
);
125 * Convert the given path to an output path that is optionally
126 * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
127 * remote path must use forward slashes and not already be escaped
130 std::string
ConvertToOptionallyRelativeOutputPath(const char* remote
);
132 ///! set/get the parent generator
133 cmLocalGenerator
* GetParent(){return this->Parent
;}
134 void SetParent(cmLocalGenerator
* g
) { this->Parent
= g
; g
->AddChild(this); }
136 ///! set/get the children
137 void AddChild(cmLocalGenerator
* g
) { this->Children
.push_back(g
); }
138 std::vector
<cmLocalGenerator
*>& GetChildren() { return this->Children
; };
141 void AddLanguageFlags(std::string
& flags
, const char* lang
,
143 void AddSharedFlags(std::string
& flags
, const char* lang
, bool shared
);
144 void AddConfigVariableFlags(std::string
& flags
, const char* var
,
146 virtual void AppendFlags(std::string
& flags
, const char* newFlags
);
147 ///! Get the include flags for the current makefile and language
148 const char* GetIncludeFlags(const char* lang
);
151 * Encode a list of preprocessor definitions for the compiler
154 void AppendDefines(std::string
& defines
, const char* defines_list
,
157 /** Translate a dependency as given in CMake code to the name to
158 appear in a generated build file. If the given name is that of
159 a CMake target it will be transformed to the real output
160 location of that target for the given configuration. If the
161 given name is the full path to a file it will be returned.
162 Otherwise the name is treated as a relative path with respect to
163 the source directory of this generator. This should only be
164 used for dependencies of custom commands. */
165 std::string
GetRealDependency(const char* name
, const char* config
);
167 /** Translate a command as given in CMake code to the location of the
168 executable if the command is the name of a CMake executable target.
169 If that's not the case, just return the original name. */
170 std::string
GetRealLocation(const char* inName
, const char* config
);
172 ///! for existing files convert to output path and short path if spaces
173 std::string
ConvertToOutputForExisting(const char* remote
,
174 RelativeRoot local
= START_OUTPUT
);
176 /** For existing path identified by RelativeRoot convert to output
177 path and short path if spaces. */
178 std::string
ConvertToOutputForExisting(RelativeRoot remote
,
179 const char* local
= 0);
181 /** Called from command-line hook to clear dependencies. */
182 virtual void ClearDependencies(cmMakefile
* /* mf */,
183 bool /* verbose */) {}
185 /** Called from command-line hook to update dependencies. */
186 virtual bool UpdateDependencies(const char* /* tgtInfo */,
191 /** Get the include flags for the current makefile and language. */
192 void GetIncludeDirectories(std::vector
<std::string
>& dirs
,
193 const char* lang
= "C");
195 /** Compute the language used to compile the given source file. */
196 const char* GetSourceFileLanguage(const cmSourceFile
& source
);
198 // Create a struct to hold the varibles passed into
199 // ExpandRuleVariables
204 memset(this, 0, sizeof(*this));
207 const char* TargetPDB
;
208 const char* TargetVersionMajor
;
209 const char* TargetVersionMinor
;
210 const char* Language
;
213 const char* LinkLibraries
;
215 const char* AssemblySource
;
216 const char* PreprocessedSource
;
219 const char* ObjectDir
;
221 const char* ObjectsQuoted
;
222 const char* TargetSOName
;
223 const char* TargetInstallNameDir
;
224 const char* LinkFlags
;
225 const char* LanguageCompileFlags
;
227 const char* RuleLauncher
;
230 /** Set whether to treat conversions to SHELL as a link script shell. */
231 void SetLinkScriptShell(bool b
) { this->LinkScriptShell
= b
; }
233 /** Escape the given string to be used as a command line argument in
234 the native build system shell. Optionally allow the build
235 system to replace make variable references. Optionally adjust
236 escapes for the special case of passing to the native echo
238 std::string
EscapeForShell(const char* str
, bool makeVars
= false,
239 bool forEcho
= false);
241 /** Backwards-compatibility version of EscapeForShell. */
242 std::string
EscapeForShellOldStyle(const char* str
);
244 /** Escape the given string as an argument in a CMake script. */
245 std::string
EscapeForCMake(const char* str
);
247 /** Return the directories into which object files will be put.
248 * There maybe more than one for fat binary systems like OSX.
251 GetTargetObjectFileDirectories(cmTarget
* target
,
252 std::vector
<std::string
>&
256 * Convert the given remote path to a relative path with respect to
257 * the given local path. The local path must be given in component
258 * form (see SystemTools::SplitPath) without a trailing slash. The
259 * remote path must use forward slashes and not already be escaped
262 std::string
ConvertToRelativePath(const std::vector
<std::string
>& local
,
266 * Get the relative path from the generator output directory to a
267 * per-target support directory.
269 virtual std::string
GetTargetDirectory(cmTarget
const& target
) const;
272 * Get the level of backwards compatibility requested by the project
273 * in this directory. This is the value of the CMake variable
274 * CMAKE_BACKWARDS_COMPATIBILITY whose format is
275 * "major.minor[.patch]". The returned integer is encoded as
277 * CMake_VERSION_ENCODE(major, minor, patch)
279 * and is monotonically increasing with the CMake version.
281 unsigned int GetBackwardsCompatibility();
284 * Test whether compatibility is set to a given version or lower.
286 bool NeedBackwardsCompatibility(unsigned int major
,
288 unsigned int patch
= 0xFFu
);
291 * Generate a Mac OS X application bundle Info.plist file.
293 void GenerateAppleInfoPList(cmTarget
* target
, const char* targetName
,
297 * Generate a Mac OS X framework Info.plist file.
299 void GenerateFrameworkInfoPList(cmTarget
* target
,
300 const char* targetName
,
303 /** Construct a comment for a custom command. */
304 std::string
ConstructComment(const cmCustomCommand
& cc
,
305 const char* default_comment
= "");
307 /** Fill out these strings for the given target. Libraries to link,
308 * flags, and linkflags. */
309 void GetTargetFlags(std::string
& linkLibs
,
311 std::string
& linkFlags
,
314 ///! put all the libraries for a target on into the given stream
315 virtual void OutputLinkLibraries(std::ostream
&, cmTarget
&, bool relink
);
317 // Expand rule variables in CMake of the type found in language rules
318 void ExpandRuleVariables(std::string
& string
,
319 const RuleVariables
& replaceValues
);
320 // Expand rule variables in a single string
321 std::string
ExpandRuleVariable(std::string
const& variable
,
322 const RuleVariables
& replaceValues
);
324 const char* GetRuleLauncher(cmTarget
* target
, const char* prop
);
325 void InsertRuleLauncher(std::string
& s
, cmTarget
* target
,
329 /** Convert a target to a utility target for unsupported
330 * languages of a generator */
331 void AddBuildTargetRule(const char* llang
, cmTarget
& target
);
332 ///! add a custom command to build a .o file that is part of a target
333 void AddCustomCommandToCreateObject(const char* ofname
,
335 cmSourceFile
& source
,
337 // Create Custom Targets and commands for unsupported languages
338 // The set passed in should contain the languages supported by the
339 // generator directly. Any targets containing files that are not
340 // of the types listed will be compiled as custom commands and added
341 // to a custom target.
342 void CreateCustomTargetsAndCommands(std::set
<cmStdString
> const&);
344 // Handle old-style install rules stored in the targets.
345 void GenerateTargetInstallRules(
346 std::ostream
& os
, const char* config
,
347 std::vector
<std::string
> const& configurationTypes
);
349 // Compute object file names.
350 std::string
GetObjectFileNameWithoutTarget(const cmSourceFile
& source
,
351 std::string
const& dir_max
,
352 bool* hasSourceExtension
= 0);
353 std::string
& CreateSafeUniqueObjectFileName(const char* sin
,
354 std::string
const& dir_max
);
356 void ConfigureRelativePaths();
357 std::string
FindRelativePathTopSource();
358 std::string
FindRelativePathTopBinary();
359 void SetupPathConversions();
361 std::string
ConvertToLinkReference(std::string
const& lib
);
363 /** Check whether the native build system supports the given
364 definition. Issues a warning. */
365 virtual bool CheckDefinition(std::string
const& define
) const;
367 cmMakefile
*Makefile
;
368 cmGlobalGenerator
*GlobalGenerator
;
369 // members used for relative path function ConvertToMakefilePath
370 std::string RelativePathToSourceDir
;
371 std::string RelativePathToBinaryDir
;
372 std::vector
<std::string
> HomeDirectoryComponents
;
373 std::vector
<std::string
> StartDirectoryComponents
;
374 std::vector
<std::string
> HomeOutputDirectoryComponents
;
375 std::vector
<std::string
> StartOutputDirectoryComponents
;
376 cmLocalGenerator
* Parent
;
377 std::vector
<cmLocalGenerator
*> Children
;
378 std::map
<cmStdString
, cmStdString
> LanguageToIncludeFlags
;
379 std::map
<cmStdString
, cmStdString
> UniqueObjectNamesMap
;
380 std::string::size_type ObjectPathMax
;
381 std::set
<cmStdString
> ObjectMaxPathViolations
;
389 bool LinkScriptShell
;
390 bool UseRelativePaths
;
391 bool IgnoreLibPrefix
;
393 bool EmitUniversalBinaryFlags
;
394 // A type flag is not nice. It's used only in TraceDependencies().
395 bool IsMakefileGenerator
;
396 // Hack for ExpandRuleVariable until object-oriented version is
398 std::string TargetImplib
;
400 // The top-most directories for relative path conversion. Both the
401 // source and destination location of a relative path conversion
402 // must be underneath one of these directories (both under source or
403 // both under binary) in order for the relative path to be evaluated
404 // safely by the build tools.
405 std::string RelativePathTopSource
;
406 std::string RelativePathTopBinary
;
407 bool RelativePathsConfigured
;
408 bool PathConversionsSetup
;
410 unsigned int BackwardsCompatibility
;
411 bool BackwardsCompatibilityFinal
;
413 std::string
ConvertToOutputForExistingCommon(const char* remote
,
414 std::string
const& result
);