BUG: fix some bad changes in progress calc
[cmake.git] / Source / cmGlobalGenerator.h
bloba0bea8dfb1800170865474f06934acb042bd592e
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalGenerator.h,v $
5 Language: C++
6 Date: $Date: 2008-02-14 21:42:29 $
7 Version: $Revision: 1.107 $
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 virtual 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);
109 virtual std::string GenerateBuildCommand
110 (const char* makeProgram,
111 const char *projectName, const char* additionalOptions,
112 const char *targetName,
113 const char* config, bool ignoreErrors, bool fast);
116 ///! Set the CMake instance
117 void SetCMakeInstance(cmake *cm);
119 ///! Get the CMake instance
120 cmake *GetCMakeInstance() { return this->CMakeInstance; };
122 void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
123 const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
124 return this->LocalGenerators;}
126 cmLocalGenerator* GetCurrentLocalGenerator()
127 {return this->CurrentLocalGenerator;}
129 void SetCurrentLocalGenerator(cmLocalGenerator* lg)
130 {this->CurrentLocalGenerator = lg;}
132 void AddLocalGenerator(cmLocalGenerator *lg);
134 ///! Set an generator for an "external makefile based project"
135 void SetExternalMakefileProjectGenerator(
136 cmExternalMakefileProjectGenerator *extraGenerator);
138 const char* GetExtraGeneratorName() const;
140 void AddInstallComponent(const char* component);
142 ///! Add one installed target to the sets of the exports
143 void AddTargetToExports(const char* exportSet, cmTarget* target,
144 cmInstallTargetGenerator* archive,
145 cmInstallTargetGenerator* runTime,
146 cmInstallTargetGenerator* library,
147 cmInstallTargetGenerator* framework,
148 cmInstallTargetGenerator* bundle,
149 cmInstallFilesGenerator* publicHeaders);
150 ///! Get the export target set with the given name
151 const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
153 /** Add a file to the manifest of generated targets for a configuration. */
154 void AddToManifest(const char* config, std::string const& f);
156 void EnableInstallTarget();
158 int TryCompileTimeout;
160 bool GetForceUnixPaths() {return this->ForceUnixPaths;}
161 bool GetToolSupportsColor() { return this->ToolSupportsColor; }
162 void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
164 ///! return the language for the given extension
165 const char* GetLanguageFromExtension(const char* ext);
166 ///! is an extension to be ignored
167 bool IgnoreFile(const char* ext);
168 ///! What is the preference for linkers and this language (None or Prefered)
169 int GetLinkerPreference(const char* lang);
170 ///! What is the object file extension for a given source file?
171 const char* GetLanguageOutputExtension(cmSourceFile const&);
173 ///! What is the configurations directory variable called?
174 virtual const char* GetCMakeCFGInitDirectory() { return "."; }
176 /** Get whether the generator should use a script for link commands. */
177 bool GetUseLinkScript() { return this->UseLinkScript; }
179 /** Get whether the generator should produce special marks on rules
180 producing symbolic (non-file) outputs. */
181 bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
184 * Determine what program to use for building the project.
186 void FindMakeProgram(cmMakefile*);
188 ///! Find a target by name by searching the local generators.
189 cmTarget* FindTarget(const char* project, const char* name);
191 /** Determine if a name resolves to a framework on disk or a built target
192 that is a framework. */
193 bool NameResolvesToFramework(const std::string& libname);
195 /** If check to see if the target is linked to by any other
196 target in the project */
197 bool IsDependedOn(const char* project, cmTarget* target);
198 ///! Find a local generator by its startdirectory
199 cmLocalGenerator* FindLocalGenerator(const char* start_dir);
201 /** Append the subdirectory for the given configuration. If anything is
202 appended the given prefix and suffix will be appended around it, which
203 is useful for leading or trailing slashes. */
204 virtual void AppendDirectoryForConfig(const char* prefix,
205 const char* config,
206 const char* suffix,
207 std::string& dir);
209 /** Get the manifest of all targets that will be built for each
210 configuration. This is valid during generation only. */
211 cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
213 /** Get the content of a directory on disk including the target
214 files to be generated. This may be called only during the
215 generation step. It is intended for use only by
216 cmComputeLinkInformation. */
217 std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
218 bool needDisk);
220 void AddTarget(cmTargets::value_type &v);
222 virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
223 virtual const char* GetInstallTargetName() { return "INSTALL"; }
224 virtual const char* GetInstallLocalTargetName() { return 0; }
225 virtual const char* GetInstallStripTargetName() { return 0; }
226 virtual const char* GetPreinstallTargetName() { return 0; }
227 virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
228 virtual const char* GetPackageTargetName() { return "PACKAGE"; }
229 virtual const char* GetPackageSourceTargetName(){ return 0; }
230 virtual const char* GetEditCacheTargetName() { return 0; }
231 virtual const char* GetRebuildCacheTargetName() { return 0; }
232 virtual const char* GetCleanTargetName() { return 0; }
234 // Class to track a set of dependencies.
235 class TargetDependSet: public std::set<cmTarget*> {};
237 // what targets does the specified target depend on directly
238 // via a target_link_libraries or add_dependencies
239 TargetDependSet & GetTargetDirectDepends(cmTarget & target);
241 const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
242 const {return this->ProjectMap;}
244 // track files replaced during a Generate
245 void FileReplacedDuringGenerate(const std::string& filename);
246 void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
248 protected:
249 // for a project collect all its targets by following depend
250 // information, and also collect all the targets
251 void GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
252 cmGlobalGenerator::TargetDependSet& originalTargets,
253 cmLocalGenerator* root,
254 std::vector<cmLocalGenerator*> const& generators);
255 void AddTargetDepends(cmTarget* target,
256 cmGlobalGenerator::TargetDependSet&
257 projectTargets);
258 void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
259 void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
261 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
263 // Fill the ProjectMap, this must be called after LocalGenerators
264 // has been populated.
265 void FillProjectMap();
266 void CheckLocalGenerators();
267 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
268 bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
269 void FillLocalGeneratorToTargetMap();
270 void CreateDefaultGlobalTargets(cmTargets* targets);
271 cmTarget CreateGlobalTarget(const char* name, const char* message,
272 const cmCustomCommandLines* commandLines,
273 std::vector<std::string> depends, bool depends_on_all = false);
275 bool NeedSymbolicMark;
276 bool UseLinkScript;
277 bool ForceUnixPaths;
278 bool ToolSupportsColor;
279 cmStdString FindMakeProgramFile;
280 cmStdString ConfiguredFilesPath;
281 cmake *CMakeInstance;
282 std::vector<cmLocalGenerator *> LocalGenerators;
283 cmLocalGenerator* CurrentLocalGenerator;
284 // map from project name to vector of local generators in that project
285 std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
286 std::map<cmLocalGenerator*, std::set<cmTarget *> >
287 LocalGeneratorToTargetMap;
289 // Set of named installation components requested by the project.
290 std::set<cmStdString> InstallComponents;
291 bool InstallTargetEnabled;
292 // Sets of named target exports
293 std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
295 // Manifest of all targets that will be built for each configuration.
296 // This is computed just before local generators generate.
297 cmTargetManifest TargetManifest;
299 private:
300 float FirstTimeProgress;
301 // If you add a new map here, make sure it is copied
302 // in EnableLanguagesFromGenerator
303 std::map<cmStdString, bool> IgnoreExtensions;
304 std::map<cmStdString, bool> LanguageEnabled;
305 std::map<cmStdString, cmStdString> OutputExtensions;
306 std::map<cmStdString, cmStdString> LanguageToOutputExtension;
307 std::map<cmStdString, cmStdString> ExtensionToLanguage;
308 std::map<cmStdString, int> LanguageToLinkerPreference;
310 // this is used to improve performance
311 std::map<cmStdString,cmTarget *> TotalTargets;
313 cmExternalMakefileProjectGenerator* ExtraGenerator;
315 // track files replaced during a Generate
316 std::vector<std::string> FilesReplacedDuringGenerate;
318 // Store computed inter-target dependencies.
319 typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
320 TargetDependMap TargetDependencies;
322 // Cache directory content and target files to be built.
323 struct DirectoryContent: public std::set<cmStdString>
325 typedef std::set<cmStdString> derived;
326 bool LoadedFromDisk;
327 DirectoryContent(): LoadedFromDisk(false) {}
328 DirectoryContent(DirectoryContent const& dc):
329 derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
331 std::map<cmStdString, DirectoryContent> DirectoryContentMap;
334 #endif