1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
13 #ifndef cmGlobalGenerator_h
14 #define cmGlobalGenerator_h
16 #include "cmStandardIncludes.h"
18 #include "cmTarget.h" // For cmTargets
19 #include "cmTargetDepend.h" // For cmTargetDependSet
20 #include "cmSystemTools.h" // for cmSystemTools::OutputOption
22 class cmGeneratorTarget;
24 class cmLocalGenerator;
25 class cmExternalMakefileProjectGenerator;
28 class cmInstallTargetGenerator;
29 class cmInstallFilesGenerator;
31 /** \class cmGlobalGenerator
32 * \brief Responable for overseeing the generation process for the entire tree
34 * Subclasses of this class generate makefiles for various
37 class cmGlobalGenerator
40 ///! Free any memory allocated with the GlobalGenerator
42 virtual ~cmGlobalGenerator();
44 ///! Create a local generator appropriate to this Global Generator
45 virtual cmLocalGenerator *CreateLocalGenerator();
47 ///! Get the name for this generator
48 virtual const char *GetName() const { return "Generic"; };
50 /** Get the documentation entry for this generator. */
51 virtual void GetDocumentation(cmDocumentationEntry& entry) const;
54 * Create LocalGenerators and process the CMakeLists files. This does not
55 * actually produce any makefiles, DSPs, etc.
57 virtual void Configure();
60 * Generate the all required files for building this project/tree. This
61 * basically creates a series of LocalGenerators for each directory and
62 * requests that they Generate.
64 virtual void Generate();
67 * Set/Get and Clear the enabled languages.
69 void SetLanguageEnabled(const char*, cmMakefile* mf);
70 bool GetLanguageEnabled(const char*) const;
71 void ClearEnabledLanguages();
72 void GetEnabledLanguages(std::vector<std::string>& lang);
74 * Try to determine system infomation such as shared library
75 * extension, pthreads, byte order etc.
77 virtual void EnableLanguage(std::vector<std::string>const& languages,
78 cmMakefile *, bool optional);
81 * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
82 * Intended to be called from EnableLanguage.
84 void ResolveLanguageCompiler(const std::string &lang, cmMakefile *mf,
88 * Try to determine system infomation, get it from another generator
90 virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
94 * Try running cmake and building a file. This is used for dynamically
95 * loaded commands, not as part of the usual build process.
97 virtual int TryCompile(const char *srcdir, const char *bindir,
98 const char *projectName, const char *targetName,
99 bool fast, std::string *output, cmMakefile* mf);
103 * Build a file given the following information. This is a more direct call
104 * that is used by both CTest and TryCompile. If target name is NULL or
105 * empty then all is assumed. clean indicates if a "make clean" should be
108 int Build(const char *srcdir, const char *bindir,
109 const char *projectName, const char *targetName,
111 const char *makeProgram, const char *config,
112 bool clean, bool fast,
114 cmSystemTools::OutputOption outputflag=cmSystemTools::OUTPUT_NONE,
115 const char* extraOptions = 0,
116 std::vector<std::string> const& nativeOptions =
117 std::vector<std::string>());
119 virtual std::string GenerateBuildCommand(
120 const char* makeProgram,
121 const char *projectName, const char* additionalOptions,
122 const char *targetName,
123 const char* config, bool ignoreErrors, bool fast);
126 ///! Set the CMake instance
127 void SetCMakeInstance(cmake *cm);
129 ///! Get the CMake instance
130 cmake *GetCMakeInstance() { return this->CMakeInstance; };
131 const cmake *GetCMakeInstance() const { return this->CMakeInstance; };
133 void SetConfiguredFilesPath(cmGlobalGenerator* gen);
134 const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
135 return this->LocalGenerators;}
137 cmLocalGenerator* GetCurrentLocalGenerator()
138 {return this->CurrentLocalGenerator;}
140 void SetCurrentLocalGenerator(cmLocalGenerator* lg)
141 {this->CurrentLocalGenerator = lg;}
143 void AddLocalGenerator(cmLocalGenerator *lg);
145 ///! Set an generator for an "external makefile based project"
146 void SetExternalMakefileProjectGenerator(
147 cmExternalMakefileProjectGenerator *extraGenerator);
149 const char* GetExtraGeneratorName() const;
151 void AddInstallComponent(const char* component);
153 const std::set<cmStdString>* GetInstallComponents() const
154 { return &InstallComponents; }
156 ///! Add one installed target to the sets of the exports
157 void AddTargetToExports(const char* exportSet, cmTarget* target,
158 cmInstallTargetGenerator* archive,
159 cmInstallTargetGenerator* runTime,
160 cmInstallTargetGenerator* library,
161 cmInstallTargetGenerator* framework,
162 cmInstallTargetGenerator* bundle,
163 cmInstallFilesGenerator* publicHeaders);
164 ///! Get the export target set with the given name
165 const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
167 /** Add a file to the manifest of generated targets for a configuration. */
168 void AddToManifest(const char* config, std::string const& f);
170 void EnableInstallTarget();
172 int TryCompileTimeout;
174 bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
175 bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
177 ///! return the language for the given extension
178 const char* GetLanguageFromExtension(const char* ext);
179 ///! is an extension to be ignored
180 bool IgnoreFile(const char* ext);
181 ///! What is the preference for linkers and this language (None or Prefered)
182 int GetLinkerPreference(const char* lang);
183 ///! What is the object file extension for a given source file?
184 const char* GetLanguageOutputExtension(cmSourceFile const&);
186 ///! What is the configurations directory variable called?
187 virtual const char* GetCMakeCFGIntDir() const { return "."; }
189 /** Get whether the generator should use a script for link commands. */
190 bool GetUseLinkScript() const { return this->UseLinkScript; }
192 /** Get whether the generator should produce special marks on rules
193 producing symbolic (non-file) outputs. */
194 bool GetNeedSymbolicMark() const { return this->NeedSymbolicMark; }
197 * Determine what program to use for building the project.
199 void FindMakeProgram(cmMakefile*);
201 ///! Find a target by name by searching the local generators.
202 cmTarget* FindTarget(const char* project, const char* name);
204 /** Determine if a name resolves to a framework on disk or a built target
205 that is a framework. */
206 bool NameResolvesToFramework(const std::string& libname);
208 /** If check to see if the target is linked to by any other
209 target in the project */
210 bool IsDependedOn(const char* project, cmTarget* target);
211 ///! Find a local generator by its startdirectory
212 cmLocalGenerator* FindLocalGenerator(const char* start_dir);
214 /** Append the subdirectory for the given configuration. If anything is
215 appended the given prefix and suffix will be appended around it, which
216 is useful for leading or trailing slashes. */
217 virtual void AppendDirectoryForConfig(const char* prefix,
222 /** Get the manifest of all targets that will be built for each
223 configuration. This is valid during generation only. */
224 cmTargetManifest const& GetTargetManifest() const
225 { return this->TargetManifest; }
227 /** Get the content of a directory. Directory listings are loaded
228 from disk at most once and cached. During the generation step
229 the content will include the target files to be built even if
230 they do not yet exist. */
231 std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
232 bool needDisk = true);
234 void AddTarget(cmTarget* t);
236 virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
237 virtual const char* GetInstallTargetName() const { return "INSTALL"; }
238 virtual const char* GetInstallLocalTargetName() const { return 0; }
239 virtual const char* GetInstallStripTargetName() const { return 0; }
240 virtual const char* GetPreinstallTargetName() const { return 0; }
241 virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
242 virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
243 virtual const char* GetPackageSourceTargetName() const { return 0; }
244 virtual const char* GetEditCacheTargetName() const { return 0; }
245 virtual const char* GetRebuildCacheTargetName() const { return 0; }
246 virtual const char* GetCleanTargetName() const { return 0; }
248 // Class to track a set of dependencies.
249 typedef cmTargetDependSet TargetDependSet;
251 // what targets does the specified target depend on directly
252 // via a target_link_libraries or add_dependencies
253 TargetDependSet const& GetTargetDirectDepends(cmTarget & target);
255 /** Get per-target generator information. */
256 cmGeneratorTarget* GetGeneratorTarget(cmTarget*) const;
258 const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
259 const {return this->ProjectMap;}
261 // track files replaced during a Generate
262 void FileReplacedDuringGenerate(const std::string& filename);
263 void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
265 void AddRuleHash(const std::vector<std::string>& outputs,
266 std::string const& content);
268 /** Return whether the given binary directory is unused. */
269 bool BinaryDirectoryIsNew(const char* dir)
271 return this->BinaryDirectories.insert(dir).second;
273 /** Supported systems creates a GUID for the given name */
274 virtual void CreateGUID(const char*) {}
276 /** Return true if the generated build tree may contain multiple builds.
277 i.e. "Can I build Debug and Release in the same tree?" */
278 virtual bool IsMultiConfig() { return false; }
280 std::string GetSharedLibFlagsForLanguage(std::string const& lang);
282 /** Generate an <output>.rule file path for a given command output. */
283 virtual std::string GenerateRuleFile(std::string const& output) const;
285 static std::string EscapeJSON(const std::string& s);
288 typedef std::vector<cmLocalGenerator*> GeneratorVector;
289 // for a project collect all its targets by following depend
290 // information, and also collect all the targets
291 virtual void GetTargetSets(TargetDependSet& projectTargets,
292 TargetDependSet& originalTargets,
293 cmLocalGenerator* root, GeneratorVector const&);
294 virtual bool IsRootOnlyTarget(cmTarget* target);
295 void AddTargetDepends(cmTarget* target, TargetDependSet& projectTargets);
296 void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
297 void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
298 void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
300 virtual bool ComputeTargetDepends();
302 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
305 void CreateAutomocTargets();
308 // Fill the ProjectMap, this must be called after LocalGenerators
309 // has been populated.
310 void FillProjectMap();
311 void CheckLocalGenerators();
312 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
313 bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
314 void FillLocalGeneratorToTargetMap();
315 void CreateDefaultGlobalTargets(cmTargets* targets);
316 cmTarget CreateGlobalTarget(const char* name, const char* message,
317 const cmCustomCommandLines* commandLines,
318 std::vector<std::string> depends, const char* workingDir);
320 bool NeedSymbolicMark;
323 bool ToolSupportsColor;
324 cmStdString FindMakeProgramFile;
325 cmStdString ConfiguredFilesPath;
326 cmake *CMakeInstance;
327 std::vector<cmLocalGenerator *> LocalGenerators;
328 cmLocalGenerator* CurrentLocalGenerator;
329 // map from project name to vector of local generators in that project
330 std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
331 std::map<cmLocalGenerator*, std::set<cmTarget *> >
332 LocalGeneratorToTargetMap;
334 // Set of named installation components requested by the project.
335 std::set<cmStdString> InstallComponents;
336 bool InstallTargetEnabled;
337 // Sets of named target exports
338 std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
339 void ClearExportSets();
341 // Manifest of all targets that will be built for each configuration.
342 // This is computed just before local generators generate.
343 cmTargetManifest TargetManifest;
345 // All targets in the entire project.
346 std::map<cmStdString,cmTarget *> TotalTargets;
347 std::map<cmStdString,cmTarget *> ImportedTargets;
349 virtual const char* GetPredefinedTargetsFolder();
350 virtual bool UseFolderProperty();
353 cmMakefile* TryCompileOuterMakefile;
354 float FirstTimeProgress;
355 // If you add a new map here, make sure it is copied
356 // in EnableLanguagesFromGenerator
357 std::map<cmStdString, bool> IgnoreExtensions;
358 std::map<cmStdString, bool> LanguageEnabled;
359 std::set<cmStdString> LanguagesReady; // Ready for try_compile
360 std::map<cmStdString, cmStdString> OutputExtensions;
361 std::map<cmStdString, cmStdString> LanguageToOutputExtension;
362 std::map<cmStdString, cmStdString> ExtensionToLanguage;
363 std::map<cmStdString, int> LanguageToLinkerPreference;
364 std::map<cmStdString, cmStdString> LanguageToOriginalSharedLibFlags;
366 // Record hashes for rules and outputs.
367 struct RuleHash { char Data[32]; };
368 std::map<cmStdString, RuleHash> RuleHashes;
369 void CheckRuleHashes();
370 void CheckRuleHashes(std::string const& pfile, std::string const& home);
371 void WriteRuleHashes(std::string const& pfile);
374 void WriteSummary(cmTarget* target);
376 cmExternalMakefileProjectGenerator* ExtraGenerator;
378 // track files replaced during a Generate
379 std::vector<std::string> FilesReplacedDuringGenerate;
381 // Store computed inter-target dependencies.
382 typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
383 TargetDependMap TargetDependencies;
385 // Per-target generator information.
386 typedef std::map<cmTarget*, cmGeneratorTarget*> GeneratorTargetsType;
387 GeneratorTargetsType GeneratorTargets;
388 void CreateGeneratorTargets();
389 void ClearGeneratorTargets();
390 virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
392 // Cache directory content and target files to be built.
393 struct DirectoryContent: public std::set<cmStdString>
395 typedef std::set<cmStdString> derived;
397 DirectoryContent(): LoadedFromDisk(false) {}
398 DirectoryContent(DirectoryContent const& dc):
399 derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
401 std::map<cmStdString, DirectoryContent> DirectoryContentMap;
403 // Set of binary directories on disk.
404 std::set<cmStdString> BinaryDirectories;