1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGlobalGenerator.h,v $
6 Date: $Date: 2008-10-01 13:50:11 $
7 Version: $Revision: 1.115 $
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
27 class cmLocalGenerator
;
28 class cmExternalMakefileProjectGenerator
;
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
40 class cmGlobalGenerator
43 ///! Free any memory allocated with the GlobalGenerator
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;
57 * Create LocalGenerators and process the CMakeLists files. This does not
58 * actually produce any makefiles, DSPs, etc.
60 virtual void Configure();
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();
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
);
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
);
84 * Try to determine system infomation, get it from another generator
86 virtual void EnableLanguagesFromGenerator(cmGlobalGenerator
*gen
);
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
);
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
103 virtual int Build(const char *srcdir
, const char *bindir
,
104 const char *projectName
, const char *targetName
,
106 const char *makeProgram
, const char *config
,
107 bool clean
, bool fast
,
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 const std::set
<cmStdString
>* GetInstallComponents() const
143 { return &InstallComponents
; }
145 ///! Add one installed target to the sets of the exports
146 void AddTargetToExports(const char* exportSet
, cmTarget
* target
,
147 cmInstallTargetGenerator
* archive
,
148 cmInstallTargetGenerator
* runTime
,
149 cmInstallTargetGenerator
* library
,
150 cmInstallTargetGenerator
* framework
,
151 cmInstallTargetGenerator
* bundle
,
152 cmInstallFilesGenerator
* publicHeaders
);
153 ///! Get the export target set with the given name
154 const std::vector
<cmTargetExport
*>* GetExportSet(const char* name
) const;
156 /** Add a file to the manifest of generated targets for a configuration. */
157 void AddToManifest(const char* config
, std::string
const& f
);
159 void EnableInstallTarget();
161 int TryCompileTimeout
;
163 bool GetForceUnixPaths() {return this->ForceUnixPaths
;}
164 bool GetToolSupportsColor() { return this->ToolSupportsColor
; }
165 void SetToolSupportsColor(bool enable
) { this->ToolSupportsColor
= enable
; }
167 ///! return the language for the given extension
168 const char* GetLanguageFromExtension(const char* ext
);
169 ///! is an extension to be ignored
170 bool IgnoreFile(const char* ext
);
171 ///! What is the preference for linkers and this language (None or Prefered)
172 int GetLinkerPreference(const char* lang
);
173 ///! What is the object file extension for a given source file?
174 const char* GetLanguageOutputExtension(cmSourceFile
const&);
176 ///! What is the configurations directory variable called?
177 virtual const char* GetCMakeCFGInitDirectory() { return "."; }
179 /** Get whether the generator should use a script for link commands. */
180 bool GetUseLinkScript() { return this->UseLinkScript
; }
182 /** Get whether the generator should produce special marks on rules
183 producing symbolic (non-file) outputs. */
184 bool GetNeedSymbolicMark() { return this->NeedSymbolicMark
; }
187 * Determine what program to use for building the project.
189 void FindMakeProgram(cmMakefile
*);
191 ///! Find a target by name by searching the local generators.
192 cmTarget
* FindTarget(const char* project
, const char* name
);
194 /** Determine if a name resolves to a framework on disk or a built target
195 that is a framework. */
196 bool NameResolvesToFramework(const std::string
& libname
);
198 /** If check to see if the target is linked to by any other
199 target in the project */
200 bool IsDependedOn(const char* project
, cmTarget
* target
);
201 ///! Find a local generator by its startdirectory
202 cmLocalGenerator
* FindLocalGenerator(const char* start_dir
);
204 /** Append the subdirectory for the given configuration. If anything is
205 appended the given prefix and suffix will be appended around it, which
206 is useful for leading or trailing slashes. */
207 virtual void AppendDirectoryForConfig(const char* prefix
,
212 /** Get the manifest of all targets that will be built for each
213 configuration. This is valid during generation only. */
214 cmTargetManifest
const& GetTargetManifest() { return this->TargetManifest
; }
216 /** Get the content of a directory. Directory listings are loaded
217 from disk at most once and cached. During the generation step
218 the content will include the target files to be built even if
219 they do not yet exist. */
220 std::set
<cmStdString
> const& GetDirectoryContent(std::string
const& dir
,
221 bool needDisk
= true);
223 void AddTarget(cmTargets::value_type
&v
);
225 virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
226 virtual const char* GetInstallTargetName() { return "INSTALL"; }
227 virtual const char* GetInstallLocalTargetName() { return 0; }
228 virtual const char* GetInstallStripTargetName() { return 0; }
229 virtual const char* GetPreinstallTargetName() { return 0; }
230 virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
231 virtual const char* GetPackageTargetName() { return "PACKAGE"; }
232 virtual const char* GetPackageSourceTargetName(){ return 0; }
233 virtual const char* GetEditCacheTargetName() { return 0; }
234 virtual const char* GetRebuildCacheTargetName() { return 0; }
235 virtual const char* GetCleanTargetName() { return 0; }
237 // Class to track a set of dependencies.
238 class TargetDependSet
: public std::set
<cmTarget
*> {};
240 // what targets does the specified target depend on directly
241 // via a target_link_libraries or add_dependencies
242 TargetDependSet
& GetTargetDirectDepends(cmTarget
& target
);
244 const std::map
<cmStdString
, std::vector
<cmLocalGenerator
*> >& GetProjectMap()
245 const {return this->ProjectMap
;}
247 // track files replaced during a Generate
248 void FileReplacedDuringGenerate(const std::string
& filename
);
249 void GetFilesReplacedDuringGenerate(std::vector
<std::string
>& filenames
);
251 void AddRuleHash(const std::vector
<std::string
>& outputs
,
252 std::vector
<std::string
>::const_iterator first
,
253 std::vector
<std::string
>::const_iterator last
);
256 // for a project collect all its targets by following depend
257 // information, and also collect all the targets
258 void GetTargetSets(cmGlobalGenerator::TargetDependSet
& projectTargets
,
259 cmGlobalGenerator::TargetDependSet
& originalTargets
,
260 cmLocalGenerator
* root
,
261 std::vector
<cmLocalGenerator
*> const& generators
);
262 void AddTargetDepends(cmTarget
* target
,
263 cmGlobalGenerator::TargetDependSet
&
265 void SetLanguageEnabledFlag(const char* l
, cmMakefile
* mf
);
266 void SetLanguageEnabledMaps(const char* l
, cmMakefile
* mf
);
267 void FillExtensionToLanguageMap(const char* l
, cmMakefile
* mf
);
269 virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
273 // Fill the ProjectMap, this must be called after LocalGenerators
274 // has been populated.
275 void FillProjectMap();
276 void CheckLocalGenerators();
277 bool IsExcluded(cmLocalGenerator
* root
, cmLocalGenerator
* gen
);
278 bool IsExcluded(cmLocalGenerator
* root
, cmTarget
& target
);
279 void FillLocalGeneratorToTargetMap();
280 void CreateDefaultGlobalTargets(cmTargets
* targets
);
281 cmTarget
CreateGlobalTarget(const char* name
, const char* message
,
282 const cmCustomCommandLines
* commandLines
,
283 std::vector
<std::string
> depends
, const char* workingDir
,
284 bool depends_on_all
= false);
286 bool NeedSymbolicMark
;
289 bool ToolSupportsColor
;
290 cmStdString FindMakeProgramFile
;
291 cmStdString ConfiguredFilesPath
;
292 cmake
*CMakeInstance
;
293 std::vector
<cmLocalGenerator
*> LocalGenerators
;
294 cmLocalGenerator
* CurrentLocalGenerator
;
295 // map from project name to vector of local generators in that project
296 std::map
<cmStdString
, std::vector
<cmLocalGenerator
*> > ProjectMap
;
297 std::map
<cmLocalGenerator
*, std::set
<cmTarget
*> >
298 LocalGeneratorToTargetMap
;
300 // Set of named installation components requested by the project.
301 std::set
<cmStdString
> InstallComponents
;
302 bool InstallTargetEnabled
;
303 // Sets of named target exports
304 std::map
<cmStdString
, std::vector
<cmTargetExport
*> > ExportSets
;
305 void ClearExportSets();
307 // Manifest of all targets that will be built for each configuration.
308 // This is computed just before local generators generate.
309 cmTargetManifest TargetManifest
;
312 float FirstTimeProgress
;
313 // If you add a new map here, make sure it is copied
314 // in EnableLanguagesFromGenerator
315 std::map
<cmStdString
, bool> IgnoreExtensions
;
316 std::map
<cmStdString
, bool> LanguageEnabled
;
317 std::map
<cmStdString
, cmStdString
> OutputExtensions
;
318 std::map
<cmStdString
, cmStdString
> LanguageToOutputExtension
;
319 std::map
<cmStdString
, cmStdString
> ExtensionToLanguage
;
320 std::map
<cmStdString
, int> LanguageToLinkerPreference
;
322 // this is used to improve performance
323 std::map
<cmStdString
,cmTarget
*> TotalTargets
;
325 // Record hashes for rules and outputs.
326 struct RuleHash
{ char Data
[32]; };
327 std::map
<cmStdString
, RuleHash
> RuleHashes
;
328 void CheckRuleHashes();
330 cmExternalMakefileProjectGenerator
* ExtraGenerator
;
332 // track files replaced during a Generate
333 std::vector
<std::string
> FilesReplacedDuringGenerate
;
335 // Store computed inter-target dependencies.
336 typedef std::map
<cmTarget
*, TargetDependSet
> TargetDependMap
;
337 TargetDependMap TargetDependencies
;
339 // Cache directory content and target files to be built.
340 struct DirectoryContent
: public std::set
<cmStdString
>
342 typedef std::set
<cmStdString
> derived
;
344 DirectoryContent(): LoadedFromDisk(false) {}
345 DirectoryContent(DirectoryContent
const& dc
):
346 derived(dc
), LoadedFromDisk(dc
.LoadedFromDisk
) {}
348 std::map
<cmStdString
, DirectoryContent
> DirectoryContentMap
;