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
21 #include "cmExportSetMap.h" // For cmExportSetMap
22 #include "cmGeneratorTarget.h"
23 #include "cmGeneratorExpression.h"
26 class cmGeneratorTarget;
27 class cmGeneratorExpressionEvaluationFile;
29 class cmLocalGenerator;
30 class cmExternalMakefileProjectGenerator;
32 class cmInstallTargetGenerator;
33 class cmInstallFilesGenerator;
35 /** \class cmGlobalGenerator
36 * \brief Responable for overseeing the generation process for the entire tree
38 * Subclasses of this class generate makefiles for various
41 class cmGlobalGenerator
44 ///! Free any memory allocated with the GlobalGenerator
46 virtual ~cmGlobalGenerator();
48 ///! Create a local generator appropriate to this Global Generator
49 virtual cmLocalGenerator *CreateLocalGenerator();
51 ///! Get the name for this generator
52 virtual const char *GetName() const { return "Generic"; };
54 /** Set the generator-specific toolset name. Returns true if toolset
55 is supported and false otherwise. */
56 virtual bool SetGeneratorToolset(std::string const& ts);
59 * Create LocalGenerators and process the CMakeLists files. This does not
60 * actually produce any makefiles, DSPs, etc.
62 virtual void Configure();
65 * Generate the all required files for building this project/tree. This
66 * basically creates a series of LocalGenerators for each directory and
67 * requests that they Generate.
69 virtual void Generate();
72 * Set/Get and Clear the enabled languages.
74 void SetLanguageEnabled(const char*, cmMakefile* mf);
75 bool GetLanguageEnabled(const char*) const;
76 void ClearEnabledLanguages();
77 void GetEnabledLanguages(std::vector<std::string>& lang);
79 * Try to determine system infomation such as shared library
80 * extension, pthreads, byte order etc.
82 virtual void EnableLanguage(std::vector<std::string>const& languages,
83 cmMakefile *, bool optional);
86 * Resolve the CMAKE_<lang>_COMPILER setting for the given language.
87 * Intended to be called from EnableLanguage.
89 void ResolveLanguageCompiler(const std::string &lang, cmMakefile *mf,
93 * Try to determine system infomation, get it from another generator
95 virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen,
99 * Try running cmake and building a file. This is used for dynamically
100 * loaded commands, not as part of the usual build process.
102 virtual int TryCompile(const char *srcdir, const char *bindir,
103 const char *projectName, const char *targetName,
104 bool fast, std::string *output, cmMakefile* mf);
108 * Build a file given the following information. This is a more direct call
109 * that is used by both CTest and TryCompile. If target name is NULL or
110 * empty then all is assumed. clean indicates if a "make clean" should be
113 int Build(const char *srcdir, const char *bindir,
114 const char *projectName, const char *targetName,
116 const char *makeProgram, const char *config,
117 bool clean, bool fast,
119 cmSystemTools::OutputOption outputflag=cmSystemTools::OUTPUT_NONE,
120 const char* extraOptions = 0,
121 std::vector<std::string> const& nativeOptions =
122 std::vector<std::string>());
124 virtual std::string GenerateBuildCommand(
125 const char* makeProgram,
126 const char *projectName, const char *projectDir,
127 const char* additionalOptions,
128 const char *targetName, const char* config,
129 bool ignoreErrors, bool fast);
132 ///! Set the CMake instance
133 void SetCMakeInstance(cmake *cm);
135 ///! Get the CMake instance
136 cmake *GetCMakeInstance() { return this->CMakeInstance; }
137 const cmake *GetCMakeInstance() const { return this->CMakeInstance; }
139 void SetConfiguredFilesPath(cmGlobalGenerator* gen);
140 const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
141 return this->LocalGenerators;}
143 cmLocalGenerator* GetCurrentLocalGenerator()
144 {return this->CurrentLocalGenerator;}
146 void SetCurrentLocalGenerator(cmLocalGenerator* lg)
147 {this->CurrentLocalGenerator = lg;}
149 void AddLocalGenerator(cmLocalGenerator *lg);
151 ///! Set an generator for an "external makefile based project"
152 void SetExternalMakefileProjectGenerator(
153 cmExternalMakefileProjectGenerator *extraGenerator);
155 const char* GetExtraGeneratorName() const;
157 void AddInstallComponent(const char* component);
159 const std::set<cmStdString>* GetInstallComponents() const
160 { return &this->InstallComponents; }
162 cmExportSetMap& GetExportSets() {return this->ExportSets;}
164 /** Add a file to the manifest of generated targets for a configuration. */
165 void AddToManifest(const char* config, std::string const& f);
167 void EnableInstallTarget();
169 int TryCompileTimeout;
171 bool GetForceUnixPaths() const { return this->ForceUnixPaths; }
172 bool GetToolSupportsColor() const { return this->ToolSupportsColor; }
174 ///! return the language for the given extension
175 const char* GetLanguageFromExtension(const char* ext);
176 ///! is an extension to be ignored
177 bool IgnoreFile(const char* ext);
178 ///! What is the preference for linkers and this language (None or Prefered)
179 int GetLinkerPreference(const char* lang);
180 ///! What is the object file extension for a given source file?
181 const char* GetLanguageOutputExtension(cmSourceFile const&);
183 ///! What is the configurations directory variable called?
184 virtual const char* GetCMakeCFGIntDir() const { return "."; }
186 /** Get whether the generator should use a script for link commands. */
187 bool GetUseLinkScript() const { return this->UseLinkScript; }
189 /** Get whether the generator should produce special marks on rules
190 producing symbolic (non-file) outputs. */
191 bool GetNeedSymbolicMark() const { return this->NeedSymbolicMark; }
194 * Determine what program to use for building the project.
196 void FindMakeProgram(cmMakefile*);
198 ///! Find a target by name by searching the local generators.
199 cmTarget* FindTarget(const char* project, const char* name,
200 bool excludeAliases = false);
202 void AddAlias(const char *name, cmTarget *tgt);
203 bool IsAlias(const char *name);
205 /** Determine if a name resolves to a framework on disk or a built target
206 that is a framework. */
207 bool NameResolvesToFramework(const std::string& libname);
209 /** If check to see if the target is linked to by any other
210 target in the project */
211 bool IsDependedOn(const char* project, cmTarget* target);
212 ///! Find a local generator by its startdirectory
213 cmLocalGenerator* FindLocalGenerator(const char* start_dir);
215 /** Append the subdirectory for the given configuration. If anything is
216 appended the given prefix and suffix will be appended around it, which
217 is useful for leading or trailing slashes. */
218 virtual void AppendDirectoryForConfig(const char* prefix,
223 /** Get the manifest of all targets that will be built for each
224 configuration. This is valid during generation only. */
225 cmTargetManifest const& GetTargetManifest() const
226 { return this->TargetManifest; }
228 /** Get the content of a directory. Directory listings are loaded
229 from disk at most once and cached. During the generation step
230 the content will include the target files to be built even if
231 they do not yet exist. */
232 std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
233 bool needDisk = true);
235 void AddTarget(cmTarget* t);
237 virtual const char* GetAllTargetName() const { return "ALL_BUILD"; }
238 virtual const char* GetInstallTargetName() const { return "INSTALL"; }
239 virtual const char* GetInstallLocalTargetName() const { return 0; }
240 virtual const char* GetInstallStripTargetName() const { return 0; }
241 virtual const char* GetPreinstallTargetName() const { return 0; }
242 virtual const char* GetTestTargetName() const { return "RUN_TESTS"; }
243 virtual const char* GetPackageTargetName() const { return "PACKAGE"; }
244 virtual const char* GetPackageSourceTargetName() const { return 0; }
245 virtual const char* GetEditCacheTargetName() const { return 0; }
246 virtual const char* GetRebuildCacheTargetName() const { return 0; }
247 virtual const char* GetCleanTargetName() const { return 0; }
249 // Class to track a set of dependencies.
250 typedef cmTargetDependSet TargetDependSet;
252 // what targets does the specified target depend on directly
253 // via a target_link_libraries or add_dependencies
254 TargetDependSet const& GetTargetDirectDepends(cmTarget & target);
256 /** Get per-target generator information. */
257 cmGeneratorTarget* GetGeneratorTarget(cmTarget*) const;
259 const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
260 const {return this->ProjectMap;}
262 // track files replaced during a Generate
263 void FileReplacedDuringGenerate(const std::string& filename);
264 void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
266 void AddRuleHash(const std::vector<std::string>& outputs,
267 std::string const& content);
269 /** Return whether the given binary directory is unused. */
270 bool BinaryDirectoryIsNew(const char* dir)
272 return this->BinaryDirectories.insert(dir).second;
274 /** Supported systems creates a GUID for the given name */
275 virtual void CreateGUID(const char*) {}
277 /** Return true if the generated build tree may contain multiple builds.
278 i.e. "Can I build Debug and Release in the same tree?" */
279 virtual bool IsMultiConfig() { return false; }
281 std::string GetSharedLibFlagsForLanguage(std::string const& lang);
283 /** Generate an <output>.rule file path for a given command output. */
284 virtual std::string GenerateRuleFile(std::string const& output) const;
286 static std::string EscapeJSON(const std::string& s);
288 void AddEvaluationFile(const std::string &inputFile,
289 cmsys::auto_ptr<cmCompiledGeneratorExpression> outputName,
290 cmMakefile *makefile,
291 cmsys::auto_ptr<cmCompiledGeneratorExpression> condition,
292 bool inputIsContent);
294 void ProcessEvaluationFiles();
297 typedef std::vector<cmLocalGenerator*> GeneratorVector;
298 // for a project collect all its targets by following depend
299 // information, and also collect all the targets
300 virtual void GetTargetSets(TargetDependSet& projectTargets,
301 TargetDependSet& originalTargets,
302 cmLocalGenerator* root, GeneratorVector const&);
303 virtual bool IsRootOnlyTarget(cmTarget* target);
304 void AddTargetDepends(cmTarget* target, TargetDependSet& projectTargets);
305 void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
306 void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
307 void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
309 virtual bool ComputeTargetDepends();
311 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
314 void CreateAutomocTargets();
317 // Fill the ProjectMap, this must be called after LocalGenerators
318 // has been populated.
319 void FillProjectMap();
320 void CheckLocalGenerators();
321 bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
322 bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
323 void FillLocalGeneratorToTargetMap();
324 void CreateDefaultGlobalTargets(cmTargets* targets);
325 cmTarget CreateGlobalTarget(const char* name, const char* message,
326 const cmCustomCommandLines* commandLines,
327 std::vector<std::string> depends, const char* workingDir);
329 bool NeedSymbolicMark;
332 bool ToolSupportsColor;
333 cmStdString FindMakeProgramFile;
334 cmStdString ConfiguredFilesPath;
335 cmake *CMakeInstance;
336 std::vector<cmLocalGenerator *> LocalGenerators;
337 cmLocalGenerator* CurrentLocalGenerator;
338 // map from project name to vector of local generators in that project
339 std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
340 std::map<cmLocalGenerator*, std::set<cmTarget *> > LocalGeneratorToTargetMap;
342 // Set of named installation components requested by the project.
343 std::set<cmStdString> InstallComponents;
344 bool InstallTargetEnabled;
345 // Sets of named target exports
346 cmExportSetMap ExportSets;
348 // Manifest of all targets that will be built for each configuration.
349 // This is computed just before local generators generate.
350 cmTargetManifest TargetManifest;
352 // All targets in the entire project.
353 std::map<cmStdString,cmTarget *> TotalTargets;
354 std::map<cmStdString,cmTarget *> AliasTargets;
355 std::map<cmStdString,cmTarget *> ImportedTargets;
356 std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles;
358 virtual const char* GetPredefinedTargetsFolder();
359 virtual bool UseFolderProperty();
360 void EnableMinGWLanguage(cmMakefile *mf);
363 cmMakefile* TryCompileOuterMakefile;
364 float FirstTimeProgress;
365 // If you add a new map here, make sure it is copied
366 // in EnableLanguagesFromGenerator
367 std::map<cmStdString, bool> IgnoreExtensions;
368 std::map<cmStdString, bool> LanguageEnabled;
369 std::set<cmStdString> LanguagesReady; // Ready for try_compile
370 std::map<cmStdString, cmStdString> OutputExtensions;
371 std::map<cmStdString, cmStdString> LanguageToOutputExtension;
372 std::map<cmStdString, cmStdString> ExtensionToLanguage;
373 std::map<cmStdString, int> LanguageToLinkerPreference;
374 std::map<cmStdString, cmStdString> LanguageToOriginalSharedLibFlags;
376 // Record hashes for rules and outputs.
377 struct RuleHash { char Data[32]; };
378 std::map<cmStdString, RuleHash> RuleHashes;
379 void CheckRuleHashes();
380 void CheckRuleHashes(std::string const& pfile, std::string const& home);
381 void WriteRuleHashes(std::string const& pfile);
384 void WriteSummary(cmTarget* target);
385 void FinalizeTargetCompileDefinitions();
387 cmExternalMakefileProjectGenerator* ExtraGenerator;
389 // track files replaced during a Generate
390 std::vector<std::string> FilesReplacedDuringGenerate;
392 // Store computed inter-target dependencies.
393 typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
394 TargetDependMap TargetDependencies;
396 // Per-target generator information.
397 cmGeneratorTargetsType GeneratorTargets;
398 void CreateGeneratorTargets();
399 void ClearGeneratorTargets();
400 virtual void ComputeTargetObjects(cmGeneratorTarget* gt) const;
402 // Cache directory content and target files to be built.
403 struct DirectoryContent: public std::set<cmStdString>
405 typedef std::set<cmStdString> derived;
407 DirectoryContent(): LoadedFromDisk(false) {}
408 DirectoryContent(DirectoryContent const& dc):
409 derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
411 std::map<cmStdString, DirectoryContent> DirectoryContentMap;
413 // Set of binary directories on disk.
414 std::set<cmStdString> BinaryDirectories;