Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmLocalGenerator.h
blob68acb3ca0dbcb92d9232d008550c7981293b5a6b
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.h,v $
5 Language: C++
6 Date: $Date: 2008/02/14 20:31:08 $
7 Version: $Revision: 1.103 $
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"
22 class cmMakefile;
23 class cmGlobalGenerator;
24 class cmTarget;
25 class cmTargetManifest;
26 class cmSourceFile;
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
38 public:
39 cmLocalGenerator();
40 virtual ~cmLocalGenerator();
42 /**
43 * Generate the makefile for this directory.
45 virtual void Generate() {}
47 /**
48 * Process the CMakeLists files for this directory to fill in the
49 * Makefile ivar
51 virtual void Configure();
53 /**
54 * Calls TraceVSDependencies() on all targets of this generator.
56 virtual void TraceDependencies();
58 virtual void AddHelperCommands() {}
60 /**
61 * Perform any final calculations prior to generation
63 virtual void ConfigureFinalPass();
65 /**
66 * Generate the install rules files in this directory.
68 virtual void GenerateInstallRules();
70 /**
71 * Generate the test files for tests.
73 virtual void GenerateTestFiles();
75 /**
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);
95 /**
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
107 * path setting
109 enum RelativeRoot { NONE, FULL, HOME, START, HOME_OUTPUT, START_OUTPUT };
110 enum OutputFormat { UNCHANGED, MAKEFILE, SHELL };
111 std::string Convert(const char* source,
112 RelativeRoot relative,
113 OutputFormat output = UNCHANGED,
114 bool optional = false);
117 * Convert the given path to an output path that is optionally
118 * relative based on the cache option CMAKE_USE_RELATIVE_PATHS. The
119 * remote path must use forward slashes and not already be escaped
120 * or quoted.
122 std::string ConvertToOptionallyRelativeOutputPath(const char* remote);
124 ///! set/get the parent generator
125 cmLocalGenerator* GetParent(){return this->Parent;}
126 void SetParent(cmLocalGenerator* g) { this->Parent = g; g->AddChild(this); }
128 ///! set/get the children
129 void AddChild(cmLocalGenerator* g) { this->Children.push_back(g); }
130 std::vector<cmLocalGenerator*>& GetChildren() { return this->Children; };
133 void AddLanguageFlags(std::string& flags, const char* lang,
134 const char* config);
135 void AddSharedFlags(std::string& flags, const char* lang, bool shared);
136 void AddConfigVariableFlags(std::string& flags, const char* var,
137 const char* config);
138 virtual void AppendFlags(std::string& flags, const char* newFlags);
139 ///! Get the include flags for the current makefile and language
140 const char* GetIncludeFlags(const char* lang);
143 * Encode a list of preprocessor definitions for the compiler
144 * command line.
146 void AppendDefines(std::string& defines, const char* defines_list,
147 const char* lang);
149 /** Translate a dependency as given in CMake code to the name to
150 appear in a generated build file. If the given name is that of
151 a CMake target it will be transformed to the real output
152 location of that target for the given configuration. If the
153 given name is the full path to a file it will be returned.
154 Otherwise the name is treated as a relative path with respect to
155 the source directory of this generator. This should only be
156 used for dependencies of custom commands. */
157 std::string GetRealDependency(const char* name, const char* config);
159 /** Translate a command as given in CMake code to the location of the
160 executable if the command is the name of a CMake executable target.
161 If that's not the case, just return the original name. */
162 std::string GetRealLocation(const char* inName, const char* config);
164 ///! for existing files convert to output path and short path if spaces
165 std::string ConvertToOutputForExisting(const char* p);
167 /** Called from command-line hook to clear dependencies. */
168 virtual void ClearDependencies(cmMakefile* /* mf */,
169 bool /* verbose */) {}
171 /** Called from command-line hook to update dependencies. */
172 virtual bool UpdateDependencies(const char* /* tgtInfo */,
173 bool /*verbose*/,
174 bool /*color*/)
175 { return true; }
177 /** Get the include flags for the current makefile and language. */
178 void GetIncludeDirectories(std::vector<std::string>& dirs,
179 bool filter_system_dirs = true);
181 /** Compute the language used to compile the given source file. */
182 const char* GetSourceFileLanguage(const cmSourceFile& source);
184 // Create a struct to hold the varibles passed into
185 // ExpandRuleVariables
186 struct RuleVariables
188 RuleVariables()
190 memset(this, 0, sizeof(*this));
192 const char* TargetPDB;
193 const char* TargetVersionMajor;
194 const char* TargetVersionMinor;
195 const char* Language;
196 const char* Objects;
197 const char* Target;
198 const char* LinkLibraries;
199 const char* Source;
200 const char* AssemblySource;
201 const char* PreprocessedSource;
202 const char* Object;
203 const char* ObjectDir;
204 const char* Flags;
205 const char* ObjectsQuoted;
206 const char* TargetSOName;
207 const char* TargetInstallNameDir;
208 const char* LinkFlags;
209 const char* LanguageCompileFlags;
210 const char* Defines;
213 /** Set whether to treat conversions to SHELL as a link script shell. */
214 void SetLinkScriptShell(bool b) { this->LinkScriptShell = b; }
216 /** Escape the given string to be used as a command line argument in
217 the native build system shell. Optionally allow the build
218 system to replace make variable references. Optionally adjust
219 escapes for the special case of passing to the native echo
220 command. */
221 std::string EscapeForShell(const char* str, bool makeVars = false,
222 bool forEcho = false);
224 /** Backwards-compatibility version of EscapeForShell. */
225 std::string EscapeForShellOldStyle(const char* str);
227 /** Escape the given string as an argument in a CMake script. */
228 std::string EscapeForCMake(const char* str);
230 /** Return the directories into which object files will be put.
231 * There maybe more than one for fat binary systems like OSX.
233 virtual void
234 GetTargetObjectFileDirectories(cmTarget* target,
235 std::vector<std::string>&
236 dirs);
239 * Convert the given remote path to a relative path with respect to
240 * the given local path. The local path must be given in component
241 * form (see SystemTools::SplitPath) without a trailing slash. The
242 * remote path must use forward slashes and not already be escaped
243 * or quoted.
245 std::string ConvertToRelativePath(const std::vector<std::string>& local,
246 const char* remote);
249 * Get the relative path from the generator output directory to a
250 * per-target support directory.
252 virtual std::string GetTargetDirectory(cmTarget const& target) const;
255 * Get the level of backwards compatibility requested by the project
256 * in this directory. This is the value of the CMake variable
257 * CMAKE_BACKWARDS_COMPATIBILITY whose format is
258 * "major.minor[.patch]". The returned integer is encoded as
260 * CMake_VERSION_ENCODE(major, minor, patch)
262 * and is monotonically increasing with the CMake version.
264 unsigned int GetBackwardsCompatibility();
267 * Test whether compatibility is set to a given version or lower.
269 bool NeedBackwardsCompatibility(unsigned int major,
270 unsigned int minor,
271 unsigned int patch = 0xFFu);
274 * Generate a Mac OS X application bundle Info.plist file.
276 void GenerateAppleInfoPList(cmTarget* target, const char* targetName,
277 const char* fname);
278 protected:
279 /** Construct a comment for a custom command. */
280 std::string ConstructComment(const cmCustomCommand& cc,
281 const char* default_comment = "");
283 /** Fill out these strings for the given target. Libraries to link,
284 * flags, and linkflags. */
285 void GetTargetFlags(std::string& linkLibs,
286 std::string& flags,
287 std::string& linkFlags,
288 cmTarget&target);
290 ///! put all the libraries for a target on into the given stream
291 virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
293 // Expand rule variables in CMake of the type found in language rules
294 void ExpandRuleVariables(std::string& string,
295 const RuleVariables& replaceValues);
296 // Expand rule variables in a single string
297 std::string ExpandRuleVariable(std::string const& variable,
298 const RuleVariables& replaceValues);
300 /** Convert a target to a utility target for unsupported
301 * languages of a generator */
302 void AddBuildTargetRule(const char* llang, cmTarget& target);
303 ///! add a custom command to build a .o file that is part of a target
304 void AddCustomCommandToCreateObject(const char* ofname,
305 const char* lang,
306 cmSourceFile& source,
307 cmTarget& target);
308 // Create Custom Targets and commands for unsupported languages
309 // The set passed in should contain the languages supported by the
310 // generator directly. Any targets containing files that are not
311 // of the types listed will be compiled as custom commands and added
312 // to a custom target.
313 void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
315 // Handle old-style install rules stored in the targets.
316 void GenerateTargetInstallRules(
317 std::ostream& os, const char* config,
318 std::vector<std::string> const& configurationTypes);
320 // Compute object file names.
321 std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
322 std::string::size_type dir_len,
323 bool* hasSourceExtension = 0);
324 std::string& CreateSafeUniqueObjectFileName(const char* sin,
325 std::string::size_type dir_len);
327 void ConfigureRelativePaths();
328 std::string FindRelativePathTopSource();
329 std::string FindRelativePathTopBinary();
330 void SetupPathConversions();
332 std::string ConvertToLinkReference(std::string const& lib);
334 /** Check whether the native build system supports the given
335 definition. Issues a warning. */
336 virtual bool CheckDefinition(std::string const& define) const;
338 cmMakefile *Makefile;
339 cmGlobalGenerator *GlobalGenerator;
340 // members used for relative path function ConvertToMakefilePath
341 std::string RelativePathToSourceDir;
342 std::string RelativePathToBinaryDir;
343 std::vector<std::string> HomeDirectoryComponents;
344 std::vector<std::string> StartDirectoryComponents;
345 std::vector<std::string> HomeOutputDirectoryComponents;
346 std::vector<std::string> StartOutputDirectoryComponents;
347 cmLocalGenerator* Parent;
348 std::vector<cmLocalGenerator*> Children;
349 std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
350 std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
351 bool WindowsShell;
352 bool WindowsVSIDE;
353 bool WatcomWMake;
354 bool MinGWMake;
355 bool NMake;
356 bool ForceUnixPath;
357 bool MSYSShell;
358 bool LinkScriptShell;
359 bool UseRelativePaths;
360 bool IgnoreLibPrefix;
361 bool Configured;
362 bool EmitUniversalBinaryFlags;
363 // A type flag is not nice. It's used only in TraceDependencies().
364 bool IsMakefileGenerator;
365 // Hack for ExpandRuleVariable until object-oriented version is
366 // committed.
367 std::string TargetImplib;
369 // The top-most directories for relative path conversion. Both the
370 // source and destination location of a relative path conversion
371 // must be underneath one of these directories (both under source or
372 // both under binary) in order for the relative path to be evaluated
373 // safely by the build tools.
374 std::string RelativePathTopSource;
375 std::string RelativePathTopBinary;
376 bool RelativePathsConfigured;
377 bool PathConversionsSetup;
379 unsigned int BackwardsCompatibility;
380 bool BackwardsCompatibilityFinal;
383 #endif