1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.h,v $
6 Date: $Date: 2009-09-22 20:16:56 $
7 Version: $Revision: 1.117 $
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
,
263 const char* remote
, bool force
=false);
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
,
302 /** Construct a comment for a custom command. */
303 std::string
ConstructComment(const cmCustomCommand
& cc
,
304 const char* default_comment
= "");
305 // Compute object file names.
306 std::string
GetObjectFileNameWithoutTarget(const cmSourceFile
& source
,
307 std::string
const& dir_max
,
308 bool* hasSourceExtension
= 0);
311 /** Fill out these strings for the given target. Libraries to link,
312 * flags, and linkflags. */
313 void GetTargetFlags(std::string
& linkLibs
,
315 std::string
& linkFlags
,
318 ///! put all the libraries for a target on into the given stream
319 virtual void OutputLinkLibraries(std::ostream
&, cmTarget
&, bool relink
);
321 // Expand rule variables in CMake of the type found in language rules
322 void ExpandRuleVariables(std::string
& string
,
323 const RuleVariables
& replaceValues
);
324 // Expand rule variables in a single string
325 std::string
ExpandRuleVariable(std::string
const& variable
,
326 const RuleVariables
& replaceValues
);
328 const char* GetRuleLauncher(cmTarget
* target
, const char* prop
);
329 void InsertRuleLauncher(std::string
& s
, cmTarget
* target
,
333 /** Convert a target to a utility target for unsupported
334 * languages of a generator */
335 void AddBuildTargetRule(const char* llang
, cmTarget
& target
);
336 ///! add a custom command to build a .o file that is part of a target
337 void AddCustomCommandToCreateObject(const char* ofname
,
339 cmSourceFile
& source
,
341 // Create Custom Targets and commands for unsupported languages
342 // The set passed in should contain the languages supported by the
343 // generator directly. Any targets containing files that are not
344 // of the types listed will be compiled as custom commands and added
345 // to a custom target.
346 void CreateCustomTargetsAndCommands(std::set
<cmStdString
> const&);
348 // Handle old-style install rules stored in the targets.
349 void GenerateTargetInstallRules(
350 std::ostream
& os
, const char* config
,
351 std::vector
<std::string
> const& configurationTypes
);
353 std::string
& CreateSafeUniqueObjectFileName(const char* sin
,
354 std::string
const& dir_max
);
355 void ComputeObjectMaxPath();
357 void ConfigureRelativePaths();
358 std::string
FindRelativePathTopSource();
359 std::string
FindRelativePathTopBinary();
360 void SetupPathConversions();
362 std::string
ConvertToLinkReference(std::string
const& lib
);
364 /** Check whether the native build system supports the given
365 definition. Issues a warning. */
366 virtual bool CheckDefinition(std::string
const& define
) const;
368 /** Read the input CMakeLists.txt file. */
369 void ReadInputFile();
371 cmMakefile
*Makefile
;
372 cmGlobalGenerator
*GlobalGenerator
;
373 // members used for relative path function ConvertToMakefilePath
374 std::string RelativePathToSourceDir
;
375 std::string RelativePathToBinaryDir
;
376 std::vector
<std::string
> HomeDirectoryComponents
;
377 std::vector
<std::string
> StartDirectoryComponents
;
378 std::vector
<std::string
> HomeOutputDirectoryComponents
;
379 std::vector
<std::string
> StartOutputDirectoryComponents
;
380 cmLocalGenerator
* Parent
;
381 std::vector
<cmLocalGenerator
*> Children
;
382 std::map
<cmStdString
, cmStdString
> LanguageToIncludeFlags
;
383 std::map
<cmStdString
, cmStdString
> UniqueObjectNamesMap
;
384 std::string::size_type ObjectPathMax
;
385 std::set
<cmStdString
> ObjectMaxPathViolations
;
393 bool LinkScriptShell
;
394 bool UseRelativePaths
;
395 bool IgnoreLibPrefix
;
397 bool EmitUniversalBinaryFlags
;
398 // A type flag is not nice. It's used only in TraceDependencies().
399 bool IsMakefileGenerator
;
400 // Hack for ExpandRuleVariable until object-oriented version is
402 std::string TargetImplib
;
404 // The top-most directories for relative path conversion. Both the
405 // source and destination location of a relative path conversion
406 // must be underneath one of these directories (both under source or
407 // both under binary) in order for the relative path to be evaluated
408 // safely by the build tools.
409 std::string RelativePathTopSource
;
410 std::string RelativePathTopBinary
;
411 bool RelativePathsConfigured
;
412 bool PathConversionsSetup
;
414 unsigned int BackwardsCompatibility
;
415 bool BackwardsCompatibilityFinal
;
417 std::string
ConvertToOutputForExistingCommon(const char* remote
,
418 std::string
const& result
);