ENH: keep cleaning up Tcl/Tk modules
[cmake.git] / Source / cmLocalGenerator.h
blob9c39c740390b50894dbc9d24e555c3c68045624f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmLocalGenerator.h,v $
5 Language: C++
6 Date: $Date: 2008-01-23 18:03:03 $
7 Version: $Revision: 1.100 $
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 /** Escape the given string to be used as a command line argument in
214 the native build system shell. Optionally allow the build
215 system to replace make variable references. Optionally adjust
216 escapes for the special case of passing to the native echo
217 command. */
218 std::string EscapeForShell(const char* str, bool makeVars = false,
219 bool forEcho = false);
221 /** Backwards-compatibility version of EscapeForShell. */
222 std::string EscapeForShellOldStyle(const char* str);
224 /** Escape the given string as an argument in a CMake script. */
225 std::string EscapeForCMake(const char* str);
227 /** Return the directories into which object files will be put.
228 * There maybe more than one for fat binary systems like OSX.
230 virtual void
231 GetTargetObjectFileDirectories(cmTarget* target,
232 std::vector<std::string>&
233 dirs);
236 * Convert the given remote path to a relative path with respect to
237 * the given local path. The local path must be given in component
238 * form (see SystemTools::SplitPath) without a trailing slash. The
239 * remote path must use forward slashes and not already be escaped
240 * or quoted.
242 std::string ConvertToRelativePath(const std::vector<std::string>& local,
243 const char* remote);
246 * Get the relative path from the generator output directory to a
247 * per-target support directory.
249 virtual std::string GetTargetDirectory(cmTarget const& target) const;
251 ///! Determine the arguments for the linker call, used also by
252 /// cmInstallTargetGenerator
253 bool GetLinkerArgs(std::string& rpath, std::string& linkLibs,
254 cmTarget& tgt, bool relink, unsigned int minRpathSize);
256 bool IsChrpathAvailable(const cmTarget& target);
259 * Get the level of backwards compatibility requested by the project
260 * in this directory. This is the value of the CMake variable
261 * CMAKE_BACKWARDS_COMPATIBILITY whose format is
262 * "major.minor[.patch]". The returned integer is encoded as
264 * CMake_VERSION_ENCODE(major, minor, patch)
266 * and is monotonically increasing with the CMake version.
268 unsigned int GetBackwardsCompatibility();
271 * Test whether compatibility is set to a given version or lower.
273 bool NeedBackwardsCompatibility(unsigned int major,
274 unsigned int minor,
275 unsigned int patch = 0xFFu);
276 protected:
277 /** Construct a comment for a custom command. */
278 std::string ConstructComment(const cmCustomCommand& cc,
279 const char* default_comment = "");
281 /** Fill out these strings for the given target. Libraries to link,
282 * flags, and linkflags. */
283 void GetTargetFlags(std::string& linkLibs,
284 std::string& flags,
285 std::string& linkFlags,
286 cmTarget&target);
288 ///! put all the libraries for a target on into the given stream
289 virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
291 // Expand rule variables in CMake of the type found in language rules
292 void ExpandRuleVariables(std::string& string,
293 const RuleVariables& replaceValues);
294 // Expand rule variables in a single string
295 std::string ExpandRuleVariable(std::string const& variable,
296 const RuleVariables& replaceValues);
298 /** Convert a target to a utility target for unsupported
299 * languages of a generator */
300 void AddBuildTargetRule(const char* llang, cmTarget& target);
301 ///! add a custom command to build a .o file that is part of a target
302 void AddCustomCommandToCreateObject(const char* ofname,
303 const char* lang,
304 cmSourceFile& source,
305 cmTarget& target);
306 // Create Custom Targets and commands for unsupported languages
307 // The set passed in should contain the languages supported by the
308 // generator directly. Any targets containing files that are not
309 // of the types listed will be compiled as custom commands and added
310 // to a custom target.
311 void CreateCustomTargetsAndCommands(std::set<cmStdString> const&);
313 // Handle old-style install rules stored in the targets.
314 void GenerateTargetInstallRules(
315 std::ostream& os, const char* config,
316 std::vector<std::string> const& configurationTypes);
318 // Compute object file names.
319 std::string GetObjectFileNameWithoutTarget(const cmSourceFile& source,
320 std::string::size_type dir_len,
321 bool* hasSourceExtension = 0);
322 std::string& CreateSafeUniqueObjectFileName(const char* sin,
323 std::string::size_type dir_len);
325 void ConfigureRelativePaths();
326 std::string FindRelativePathTopSource();
327 std::string FindRelativePathTopBinary();
328 void SetupPathConversions();
330 std::string ConvertToLinkReference(std::string const& lib);
332 /** Check whether the native build system supports the given
333 definition. Issues a warning. */
334 virtual bool CheckDefinition(std::string const& define) const;
336 cmMakefile *Makefile;
337 cmGlobalGenerator *GlobalGenerator;
338 // members used for relative path function ConvertToMakefilePath
339 std::string RelativePathToSourceDir;
340 std::string RelativePathToBinaryDir;
341 std::vector<std::string> HomeDirectoryComponents;
342 std::vector<std::string> StartDirectoryComponents;
343 std::vector<std::string> HomeOutputDirectoryComponents;
344 std::vector<std::string> StartOutputDirectoryComponents;
345 cmLocalGenerator* Parent;
346 std::vector<cmLocalGenerator*> Children;
347 std::map<cmStdString, cmStdString> LanguageToIncludeFlags;
348 std::map<cmStdString, cmStdString> UniqueObjectNamesMap;
349 bool WindowsShell;
350 bool WindowsVSIDE;
351 bool WatcomWMake;
352 bool MinGWMake;
353 bool NMake;
354 bool ForceUnixPath;
355 bool MSYSShell;
356 bool UseRelativePaths;
357 bool IgnoreLibPrefix;
358 bool Configured;
359 bool EmitUniversalBinaryFlags;
360 // A type flag is not nice. It's used only in TraceDependencies().
361 bool IsMakefileGenerator;
362 // Hack for ExpandRuleVariable until object-oriented version is
363 // committed.
364 std::string TargetImplib;
366 // The top-most directories for relative path conversion. Both the
367 // source and destination location of a relative path conversion
368 // must be underneath one of these directories (both under source or
369 // both under binary) in order for the relative path to be evaluated
370 // safely by the build tools.
371 std::string RelativePathTopSource;
372 std::string RelativePathTopBinary;
373 bool RelativePathsConfigured;
374 bool PathConversionsSetup;
376 unsigned int BackwardsCompatibility;
377 bool BackwardsCompatibilityFinal;
380 #endif