1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.h,v $
6 Date: $Date: 2008-10-09 19:30:07 $
7 Version: $Revision: 1.106 $
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 bool filter_system_dirs
= true);
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));
206 const char* TargetPDB
;
207 const char* TargetVersionMajor
;
208 const char* TargetVersionMinor
;
209 const char* Language
;
212 const char* LinkLibraries
;
214 const char* AssemblySource
;
215 const char* PreprocessedSource
;
217 const char* ObjectDir
;
219 const char* ObjectsQuoted
;
220 const char* TargetSOName
;
221 const char* TargetInstallNameDir
;
222 const char* LinkFlags
;
223 const char* LanguageCompileFlags
;
227 /** Set whether to treat conversions to SHELL as a link script shell. */
228 void SetLinkScriptShell(bool b
) { this->LinkScriptShell
= b
; }
230 /** Escape the given string to be used as a command line argument in
231 the native build system shell. Optionally allow the build
232 system to replace make variable references. Optionally adjust
233 escapes for the special case of passing to the native echo
235 std::string
EscapeForShell(const char* str
, bool makeVars
= false,
236 bool forEcho
= false);
238 /** Backwards-compatibility version of EscapeForShell. */
239 std::string
EscapeForShellOldStyle(const char* str
);
241 /** Escape the given string as an argument in a CMake script. */
242 std::string
EscapeForCMake(const char* str
);
244 /** Return the directories into which object files will be put.
245 * There maybe more than one for fat binary systems like OSX.
248 GetTargetObjectFileDirectories(cmTarget
* target
,
249 std::vector
<std::string
>&
253 * Convert the given remote path to a relative path with respect to
254 * the given local path. The local path must be given in component
255 * form (see SystemTools::SplitPath) without a trailing slash. The
256 * remote path must use forward slashes and not already be escaped
259 std::string
ConvertToRelativePath(const std::vector
<std::string
>& local
,
263 * Get the relative path from the generator output directory to a
264 * per-target support directory.
266 virtual std::string
GetTargetDirectory(cmTarget
const& target
) const;
269 * Get the level of backwards compatibility requested by the project
270 * in this directory. This is the value of the CMake variable
271 * CMAKE_BACKWARDS_COMPATIBILITY whose format is
272 * "major.minor[.patch]". The returned integer is encoded as
274 * CMake_VERSION_ENCODE(major, minor, patch)
276 * and is monotonically increasing with the CMake version.
278 unsigned int GetBackwardsCompatibility();
281 * Test whether compatibility is set to a given version or lower.
283 bool NeedBackwardsCompatibility(unsigned int major
,
285 unsigned int patch
= 0xFFu
);
288 * Generate a Mac OS X application bundle Info.plist file.
290 void GenerateAppleInfoPList(cmTarget
* target
, const char* targetName
,
294 * Generate a Mac OS X framework Info.plist file.
296 void GenerateFrameworkInfoPList(cmTarget
* target
,
297 const char* targetName
,
300 /** Construct a comment for a custom command. */
301 std::string
ConstructComment(const cmCustomCommand
& cc
,
302 const char* default_comment
= "");
304 /** Fill out these strings for the given target. Libraries to link,
305 * flags, and linkflags. */
306 void GetTargetFlags(std::string
& linkLibs
,
308 std::string
& linkFlags
,
311 ///! put all the libraries for a target on into the given stream
312 virtual void OutputLinkLibraries(std::ostream
&, cmTarget
&, bool relink
);
314 // Expand rule variables in CMake of the type found in language rules
315 void ExpandRuleVariables(std::string
& string
,
316 const RuleVariables
& replaceValues
);
317 // Expand rule variables in a single string
318 std::string
ExpandRuleVariable(std::string
const& variable
,
319 const RuleVariables
& replaceValues
);
321 /** Convert a target to a utility target for unsupported
322 * languages of a generator */
323 void AddBuildTargetRule(const char* llang
, cmTarget
& target
);
324 ///! add a custom command to build a .o file that is part of a target
325 void AddCustomCommandToCreateObject(const char* ofname
,
327 cmSourceFile
& source
,
329 // Create Custom Targets and commands for unsupported languages
330 // The set passed in should contain the languages supported by the
331 // generator directly. Any targets containing files that are not
332 // of the types listed will be compiled as custom commands and added
333 // to a custom target.
334 void CreateCustomTargetsAndCommands(std::set
<cmStdString
> const&);
336 // Handle old-style install rules stored in the targets.
337 void GenerateTargetInstallRules(
338 std::ostream
& os
, const char* config
,
339 std::vector
<std::string
> const& configurationTypes
);
341 // Compute object file names.
342 std::string
GetObjectFileNameWithoutTarget(const cmSourceFile
& source
,
343 std::string::size_type dir_len
,
344 bool* hasSourceExtension
= 0);
345 std::string
& CreateSafeUniqueObjectFileName(const char* sin
,
346 std::string::size_type dir_len
);
348 void ConfigureRelativePaths();
349 std::string
FindRelativePathTopSource();
350 std::string
FindRelativePathTopBinary();
351 void SetupPathConversions();
353 std::string
ConvertToLinkReference(std::string
const& lib
);
355 /** Check whether the native build system supports the given
356 definition. Issues a warning. */
357 virtual bool CheckDefinition(std::string
const& define
) const;
359 cmMakefile
*Makefile
;
360 cmGlobalGenerator
*GlobalGenerator
;
361 // members used for relative path function ConvertToMakefilePath
362 std::string RelativePathToSourceDir
;
363 std::string RelativePathToBinaryDir
;
364 std::vector
<std::string
> HomeDirectoryComponents
;
365 std::vector
<std::string
> StartDirectoryComponents
;
366 std::vector
<std::string
> HomeOutputDirectoryComponents
;
367 std::vector
<std::string
> StartOutputDirectoryComponents
;
368 cmLocalGenerator
* Parent
;
369 std::vector
<cmLocalGenerator
*> Children
;
370 std::map
<cmStdString
, cmStdString
> LanguageToIncludeFlags
;
371 std::map
<cmStdString
, cmStdString
> UniqueObjectNamesMap
;
372 std::string::size_type ObjectPathMax
;
380 bool LinkScriptShell
;
381 bool UseRelativePaths
;
382 bool IgnoreLibPrefix
;
384 bool EmitUniversalBinaryFlags
;
385 // A type flag is not nice. It's used only in TraceDependencies().
386 bool IsMakefileGenerator
;
387 // Hack for ExpandRuleVariable until object-oriented version is
389 std::string TargetImplib
;
391 // The top-most directories for relative path conversion. Both the
392 // source and destination location of a relative path conversion
393 // must be underneath one of these directories (both under source or
394 // both under binary) in order for the relative path to be evaluated
395 // safely by the build tools.
396 std::string RelativePathTopSource
;
397 std::string RelativePathTopBinary
;
398 bool RelativePathsConfigured
;
399 bool PathConversionsSetup
;
401 unsigned int BackwardsCompatibility
;
402 bool BackwardsCompatibilityFinal
;
404 std::string
ConvertToOutputForExistingCommon(const char* remote
,
405 std::string
const& result
);