Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmGlobalGenerator.h
blobc673eb2d4591aa151be5d95b4bf10f6bf341d3d5
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalGenerator.h,v $
5 Language: C++
6 Date: $Date: 2009-03-09 16:19:27 $
7 Version: $Revision: 1.121 $
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 =========================================================================*/
18 #ifndef cmGlobalGenerator_h
19 #define cmGlobalGenerator_h
21 #include "cmStandardIncludes.h"
23 #include "cmTarget.h" // For cmTargets
25 class cmake;
26 class cmMakefile;
27 class cmLocalGenerator;
28 class cmExternalMakefileProjectGenerator;
29 class cmTarget;
30 class cmTargetExport;
31 class cmInstallTargetGenerator;
32 class cmInstallFilesGenerator;
34 /** \class cmGlobalGenerator
35 * \brief Responable for overseeing the generation process for the entire tree
37 * Subclasses of this class generate makefiles for various
38 * platforms.
40 class cmGlobalGenerator
42 public:
43 ///! Free any memory allocated with the GlobalGenerator
44 cmGlobalGenerator();
45 virtual ~cmGlobalGenerator();
47 ///! Create a local generator appropriate to this Global Generator
48 virtual cmLocalGenerator *CreateLocalGenerator();
50 ///! Get the name for this generator
51 virtual const char *GetName() const { return "Generic"; };
53 /** Get the documentation entry for this generator. */
54 virtual void GetDocumentation(cmDocumentationEntry& entry) const;
56 /**
57 * Create LocalGenerators and process the CMakeLists files. This does not
58 * actually produce any makefiles, DSPs, etc.
60 virtual void Configure();
62 /**
63 * Generate the all required files for building this project/tree. This
64 * basically creates a series of LocalGenerators for each directory and
65 * requests that they Generate.
67 virtual void Generate();
69 /**
70 * Set/Get and Clear the enabled languages.
72 void SetLanguageEnabled(const char*, cmMakefile* mf);
73 bool GetLanguageEnabled(const char*) const;
74 void ClearEnabledLanguages();
75 void GetEnabledLanguages(std::vector<std::string>& lang);
76 /**
77 * Try to determine system infomation such as shared library
78 * extension, pthreads, byte order etc.
80 virtual void EnableLanguage(std::vector<std::string>const& languages,
81 cmMakefile *, bool optional);
83 /**
84 * Try to determine system infomation, get it from another generator
86 virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
88 /**
89 * Try running cmake and building a file. This is used for dynalically
90 * loaded commands, not as part of the usual build process.
92 virtual int TryCompile(const char *srcdir, const char *bindir,
93 const char *projectName, const char *targetName,
94 std::string *output, cmMakefile* mf);
97 /**
98 * Build a file given the following information. This is a more direct call
99 * that is used by both CTest and TryCompile. If target name is NULL or
100 * empty then all is assumed. clean indicates if a "make clean" should be
101 * done first.
103 int Build(const char *srcdir, const char *bindir,
104 const char *projectName, const char *targetName,
105 std::string *output,
106 const char *makeProgram, const char *config,
107 bool clean, bool fast,
108 double timeout, bool verbose=false,
109 const char* extraOptions = 0,
110 std::vector<std::string> const& nativeOptions =
111 std::vector<std::string>());
113 virtual std::string GenerateBuildCommand(
114 const char* makeProgram,
115 const char *projectName, const char* additionalOptions,
116 const char *targetName,
117 const char* config, bool ignoreErrors, bool fast);
120 ///! Set the CMake instance
121 void SetCMakeInstance(cmake *cm);
123 ///! Get the CMake instance
124 cmake *GetCMakeInstance() { return this->CMakeInstance; };
126 void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
127 const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
128 return this->LocalGenerators;}
130 cmLocalGenerator* GetCurrentLocalGenerator()
131 {return this->CurrentLocalGenerator;}
133 void SetCurrentLocalGenerator(cmLocalGenerator* lg)
134 {this->CurrentLocalGenerator = lg;}
136 void AddLocalGenerator(cmLocalGenerator *lg);
138 ///! Set an generator for an "external makefile based project"
139 void SetExternalMakefileProjectGenerator(
140 cmExternalMakefileProjectGenerator *extraGenerator);
142 const char* GetExtraGeneratorName() const;
144 void AddInstallComponent(const char* component);
146 const std::set<cmStdString>* GetInstallComponents() const
147 { return &InstallComponents; }
149 ///! Add one installed target to the sets of the exports
150 void AddTargetToExports(const char* exportSet, cmTarget* target,
151 cmInstallTargetGenerator* archive,
152 cmInstallTargetGenerator* runTime,
153 cmInstallTargetGenerator* library,
154 cmInstallTargetGenerator* framework,
155 cmInstallTargetGenerator* bundle,
156 cmInstallFilesGenerator* publicHeaders);
157 ///! Get the export target set with the given name
158 const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
160 /** Add a file to the manifest of generated targets for a configuration. */
161 void AddToManifest(const char* config, std::string const& f);
163 void EnableInstallTarget();
165 int TryCompileTimeout;
167 bool GetForceUnixPaths() {return this->ForceUnixPaths;}
168 bool GetToolSupportsColor() { return this->ToolSupportsColor; }
169 void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
171 ///! return the language for the given extension
172 const char* GetLanguageFromExtension(const char* ext);
173 ///! is an extension to be ignored
174 bool IgnoreFile(const char* ext);
175 ///! What is the preference for linkers and this language (None or Prefered)
176 int GetLinkerPreference(const char* lang);
177 ///! What is the object file extension for a given source file?
178 const char* GetLanguageOutputExtension(cmSourceFile const&);
180 ///! What is the configurations directory variable called?
181 virtual const char* GetCMakeCFGInitDirectory() { return "."; }
183 /** Get whether the generator should use a script for link commands. */
184 bool GetUseLinkScript() { return this->UseLinkScript; }
186 /** Get whether the generator should produce special marks on rules
187 producing symbolic (non-file) outputs. */
188 bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
191 * Determine what program to use for building the project.
193 void FindMakeProgram(cmMakefile*);
195 ///! Find a target by name by searching the local generators.
196 cmTarget* FindTarget(const char* project, const char* name);
198 /** Determine if a name resolves to a framework on disk or a built target
199 that is a framework. */
200 bool NameResolvesToFramework(const std::string& libname);
202 /** If check to see if the target is linked to by any other
203 target in the project */
204 bool IsDependedOn(const char* project, cmTarget* target);
205 ///! Find a local generator by its startdirectory
206 cmLocalGenerator* FindLocalGenerator(const char* start_dir);
208 /** Append the subdirectory for the given configuration. If anything is
209 appended the given prefix and suffix will be appended around it, which
210 is useful for leading or trailing slashes. */
211 virtual void AppendDirectoryForConfig(const char* prefix,
212 const char* config,
213 const char* suffix,
214 std::string& dir);
216 /** Get the manifest of all targets that will be built for each
217 configuration. This is valid during generation only. */
218 cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
220 /** Get the content of a directory. Directory listings are loaded
221 from disk at most once and cached. During the generation step
222 the content will include the target files to be built even if
223 they do not yet exist. */
224 std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
225 bool needDisk = true);
227 void AddTarget(cmTargets::value_type &v);
229 virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
230 virtual const char* GetInstallTargetName() { return "INSTALL"; }
231 virtual const char* GetInstallLocalTargetName() { return 0; }
232 virtual const char* GetInstallStripTargetName() { return 0; }
233 virtual const char* GetPreinstallTargetName() { return 0; }
234 virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
235 virtual const char* GetPackageTargetName() { return "PACKAGE"; }
236 virtual const char* GetPackageSourceTargetName(){ return 0; }
237 virtual const char* GetEditCacheTargetName() { return 0; }
238 virtual const char* GetRebuildCacheTargetName() { return 0; }
239 virtual const char* GetCleanTargetName() { return 0; }
241 // Class to track a set of dependencies.
242 class TargetDependSet: public std::set<cmTarget*> {};
244 // what targets does the specified target depend on directly
245 // via a target_link_libraries or add_dependencies
246 TargetDependSet & GetTargetDirectDepends(cmTarget & target);
248 const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
249 const {return this->ProjectMap;}
251 // track files replaced during a Generate
252 void FileReplacedDuringGenerate(const std::string& filename);
253 void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
255 void AddRuleHash(const std::vector<std::string>& outputs,
256 std::string const& content);
258 /** Return whether the given binary directory is unused. */
259 bool BinaryDirectoryIsNew(const char* dir)
261 return this->BinaryDirectories.insert(dir).second;
264 protected:
265 // for a project collect all its targets by following depend
266 // information, and also collect all the targets
267 void GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
268 cmGlobalGenerator::TargetDependSet& originalTargets,
269 cmLocalGenerator* root,
270 std::vector<cmLocalGenerator*> const& generators);
271 void AddTargetDepends(cmTarget* target,
272 cmGlobalGenerator::TargetDependSet&
273 projectTargets);
274 void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
275 void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
276 void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
278 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
280 bool CheckTargets();
282 // Fill the ProjectMap, this must be called after LocalGenerators
283 // has been populated.
284 void FillProjectMap();
285 void CheckLocalGenerators();
286 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
287 bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
288 void FillLocalGeneratorToTargetMap();
289 void CreateDefaultGlobalTargets(cmTargets* targets);
290 cmTarget CreateGlobalTarget(const char* name, const char* message,
291 const cmCustomCommandLines* commandLines,
292 std::vector<std::string> depends, const char* workingDir,
293 bool depends_on_all = false);
295 bool NeedSymbolicMark;
296 bool UseLinkScript;
297 bool ForceUnixPaths;
298 bool ToolSupportsColor;
299 cmStdString FindMakeProgramFile;
300 cmStdString ConfiguredFilesPath;
301 cmake *CMakeInstance;
302 std::vector<cmLocalGenerator *> LocalGenerators;
303 cmLocalGenerator* CurrentLocalGenerator;
304 // map from project name to vector of local generators in that project
305 std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
306 std::map<cmLocalGenerator*, std::set<cmTarget *> >
307 LocalGeneratorToTargetMap;
309 // Set of named installation components requested by the project.
310 std::set<cmStdString> InstallComponents;
311 bool InstallTargetEnabled;
312 // Sets of named target exports
313 std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
314 void ClearExportSets();
316 // Manifest of all targets that will be built for each configuration.
317 // This is computed just before local generators generate.
318 cmTargetManifest TargetManifest;
320 private:
321 float FirstTimeProgress;
322 // If you add a new map here, make sure it is copied
323 // in EnableLanguagesFromGenerator
324 std::map<cmStdString, bool> IgnoreExtensions;
325 std::map<cmStdString, bool> LanguageEnabled;
326 std::map<cmStdString, cmStdString> OutputExtensions;
327 std::map<cmStdString, cmStdString> LanguageToOutputExtension;
328 std::map<cmStdString, cmStdString> ExtensionToLanguage;
329 std::map<cmStdString, int> LanguageToLinkerPreference;
331 // this is used to improve performance
332 std::map<cmStdString,cmTarget *> TotalTargets;
334 // Record hashes for rules and outputs.
335 struct RuleHash { char Data[32]; };
336 std::map<cmStdString, RuleHash> RuleHashes;
337 void CheckRuleHashes();
339 void WriteSummary();
340 void WriteSummary(cmTarget* target);
342 cmExternalMakefileProjectGenerator* ExtraGenerator;
344 // track files replaced during a Generate
345 std::vector<std::string> FilesReplacedDuringGenerate;
347 // Store computed inter-target dependencies.
348 typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
349 TargetDependMap TargetDependencies;
351 // Cache directory content and target files to be built.
352 struct DirectoryContent: public std::set<cmStdString>
354 typedef std::set<cmStdString> derived;
355 bool LoadedFromDisk;
356 DirectoryContent(): LoadedFromDisk(false) {}
357 DirectoryContent(DirectoryContent const& dc):
358 derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
360 std::map<cmStdString, DirectoryContent> DirectoryContentMap;
362 // Set of binary directories on disk.
363 std::set<cmStdString> BinaryDirectories;
366 #endif