Rescan dependencies also if CMakeDirectoryInformation.cmake has changed.
[cmake.git] / Source / cmGlobalGenerator.h
blob776511adb49bafc667c48ffce4097e4c1ed7c44a
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalGenerator.h,v $
5 Language: C++
6 Date: $Date: 2009-08-04 18:37:46 $
7 Version: $Revision: 1.125 $
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 bool fast, 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(cmGlobalGenerator* gen);
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;
263 /** Supported systems creates a GUID for the given name */
264 virtual void CreateGUID(const char*) {}
266 protected:
267 // for a project collect all its targets by following depend
268 // information, and also collect all the targets
269 void GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
270 cmGlobalGenerator::TargetDependSet& originalTargets,
271 cmLocalGenerator* root,
272 std::vector<cmLocalGenerator*> const& generators);
273 void AddTargetDepends(cmTarget* target,
274 cmGlobalGenerator::TargetDependSet&
275 projectTargets);
276 void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
277 void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
278 void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
280 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
282 bool CheckTargets();
284 // Fill the ProjectMap, this must be called after LocalGenerators
285 // has been populated.
286 void FillProjectMap();
287 void CheckLocalGenerators();
288 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
289 bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
290 void FillLocalGeneratorToTargetMap();
291 void CreateDefaultGlobalTargets(cmTargets* targets);
292 cmTarget CreateGlobalTarget(const char* name, const char* message,
293 const cmCustomCommandLines* commandLines,
294 std::vector<std::string> depends, const char* workingDir,
295 bool depends_on_all = false);
297 bool NeedSymbolicMark;
298 bool UseLinkScript;
299 bool ForceUnixPaths;
300 bool ToolSupportsColor;
301 cmStdString FindMakeProgramFile;
302 cmStdString ConfiguredFilesPath;
303 cmake *CMakeInstance;
304 std::vector<cmLocalGenerator *> LocalGenerators;
305 cmLocalGenerator* CurrentLocalGenerator;
306 // map from project name to vector of local generators in that project
307 std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
308 std::map<cmLocalGenerator*, std::set<cmTarget *> >
309 LocalGeneratorToTargetMap;
311 // Set of named installation components requested by the project.
312 std::set<cmStdString> InstallComponents;
313 bool InstallTargetEnabled;
314 // Sets of named target exports
315 std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
316 void ClearExportSets();
318 // Manifest of all targets that will be built for each configuration.
319 // This is computed just before local generators generate.
320 cmTargetManifest TargetManifest;
322 // All targets in the entire project.
323 std::map<cmStdString,cmTarget *> TotalTargets;
325 private:
326 float FirstTimeProgress;
327 // If you add a new map here, make sure it is copied
328 // in EnableLanguagesFromGenerator
329 std::map<cmStdString, bool> IgnoreExtensions;
330 std::map<cmStdString, bool> LanguageEnabled;
331 std::map<cmStdString, cmStdString> OutputExtensions;
332 std::map<cmStdString, cmStdString> LanguageToOutputExtension;
333 std::map<cmStdString, cmStdString> ExtensionToLanguage;
334 std::map<cmStdString, int> LanguageToLinkerPreference;
336 // Record hashes for rules and outputs.
337 struct RuleHash { char Data[32]; };
338 std::map<cmStdString, RuleHash> RuleHashes;
339 void CheckRuleHashes();
341 void WriteSummary();
342 void WriteSummary(cmTarget* target);
344 cmExternalMakefileProjectGenerator* ExtraGenerator;
346 // track files replaced during a Generate
347 std::vector<std::string> FilesReplacedDuringGenerate;
349 // Store computed inter-target dependencies.
350 typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
351 TargetDependMap TargetDependencies;
353 // Cache directory content and target files to be built.
354 struct DirectoryContent: public std::set<cmStdString>
356 typedef std::set<cmStdString> derived;
357 bool LoadedFromDisk;
358 DirectoryContent(): LoadedFromDisk(false) {}
359 DirectoryContent(DirectoryContent const& dc):
360 derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
362 std::map<cmStdString, DirectoryContent> DirectoryContentMap;
364 // Set of binary directories on disk.
365 std::set<cmStdString> BinaryDirectories;
368 #endif