cmGlobalGenerator.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef cmGlobalGenerator_h
  14. #define cmGlobalGenerator_h
  15. #include "cmStandardIncludes.h"
  16. #include "cmTarget.h" // For cmTargets
  17. class cmake;
  18. class cmMakefile;
  19. class cmLocalGenerator;
  20. class cmExternalMakefileProjectGenerator;
  21. class cmTarget;
  22. class cmTargetExport;
  23. class cmInstallTargetGenerator;
  24. class cmInstallFilesGenerator;
  25. /** \class cmGlobalGenerator
  26. * \brief Responable for overseeing the generation process for the entire tree
  27. *
  28. * Subclasses of this class generate makefiles for various
  29. * platforms.
  30. */
  31. class cmGlobalGenerator
  32. {
  33. public:
  34. ///! Free any memory allocated with the GlobalGenerator
  35. cmGlobalGenerator();
  36. virtual ~cmGlobalGenerator();
  37. ///! Create a local generator appropriate to this Global Generator
  38. virtual cmLocalGenerator *CreateLocalGenerator();
  39. ///! Get the name for this generator
  40. virtual const char *GetName() const { return "Generic"; };
  41. /** Get the documentation entry for this generator. */
  42. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  43. /**
  44. * Create LocalGenerators and process the CMakeLists files. This does not
  45. * actually produce any makefiles, DSPs, etc.
  46. */
  47. virtual void Configure();
  48. /**
  49. * Generate the all required files for building this project/tree. This
  50. * basically creates a series of LocalGenerators for each directory and
  51. * requests that they Generate.
  52. */
  53. virtual void Generate();
  54. /**
  55. * Set/Get and Clear the enabled languages.
  56. */
  57. void SetLanguageEnabled(const char*, cmMakefile* mf);
  58. bool GetLanguageEnabled(const char*) const;
  59. void ClearEnabledLanguages();
  60. void GetEnabledLanguages(std::vector<std::string>& lang);
  61. /**
  62. * Try to determine system infomation such as shared library
  63. * extension, pthreads, byte order etc.
  64. */
  65. virtual void EnableLanguage(std::vector<std::string>const& languages,
  66. cmMakefile *, bool optional);
  67. /**
  68. * Try to determine system infomation, get it from another generator
  69. */
  70. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  71. /**
  72. * Try running cmake and building a file. This is used for dynalically
  73. * loaded commands, not as part of the usual build process.
  74. */
  75. virtual int TryCompile(const char *srcdir, const char *bindir,
  76. const char *projectName, const char *targetName,
  77. bool fast, std::string *output, cmMakefile* mf);
  78. /**
  79. * Build a file given the following information. This is a more direct call
  80. * that is used by both CTest and TryCompile. If target name is NULL or
  81. * empty then all is assumed. clean indicates if a "make clean" should be
  82. * done first.
  83. */
  84. int Build(const char *srcdir, const char *bindir,
  85. const char *projectName, const char *targetName,
  86. std::string *output,
  87. const char *makeProgram, const char *config,
  88. bool clean, bool fast,
  89. double timeout, bool verbose=false,
  90. const char* extraOptions = 0,
  91. std::vector<std::string> const& nativeOptions =
  92. std::vector<std::string>());
  93. virtual std::string GenerateBuildCommand(
  94. const char* makeProgram,
  95. const char *projectName, const char* additionalOptions,
  96. const char *targetName,
  97. const char* config, bool ignoreErrors, bool fast);
  98. ///! Set the CMake instance
  99. void SetCMakeInstance(cmake *cm);
  100. ///! Get the CMake instance
  101. cmake *GetCMakeInstance() { return this->CMakeInstance; };
  102. void SetConfiguredFilesPath(cmGlobalGenerator* gen);
  103. const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
  104. return this->LocalGenerators;}
  105. cmLocalGenerator* GetCurrentLocalGenerator()
  106. {return this->CurrentLocalGenerator;}
  107. void SetCurrentLocalGenerator(cmLocalGenerator* lg)
  108. {this->CurrentLocalGenerator = lg;}
  109. void AddLocalGenerator(cmLocalGenerator *lg);
  110. ///! Set an generator for an "external makefile based project"
  111. void SetExternalMakefileProjectGenerator(
  112. cmExternalMakefileProjectGenerator *extraGenerator);
  113. const char* GetExtraGeneratorName() const;
  114. void AddInstallComponent(const char* component);
  115. const std::set<cmStdString>* GetInstallComponents() const
  116. { return &InstallComponents; }
  117. ///! Add one installed target to the sets of the exports
  118. void AddTargetToExports(const char* exportSet, cmTarget* target,
  119. cmInstallTargetGenerator* archive,
  120. cmInstallTargetGenerator* runTime,
  121. cmInstallTargetGenerator* library,
  122. cmInstallTargetGenerator* framework,
  123. cmInstallTargetGenerator* bundle,
  124. cmInstallFilesGenerator* publicHeaders);
  125. ///! Get the export target set with the given name
  126. const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
  127. /** Add a file to the manifest of generated targets for a configuration. */
  128. void AddToManifest(const char* config, std::string const& f);
  129. void EnableInstallTarget();
  130. int TryCompileTimeout;
  131. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  132. bool GetToolSupportsColor() { return this->ToolSupportsColor; }
  133. void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
  134. ///! return the language for the given extension
  135. const char* GetLanguageFromExtension(const char* ext);
  136. ///! is an extension to be ignored
  137. bool IgnoreFile(const char* ext);
  138. ///! What is the preference for linkers and this language (None or Prefered)
  139. int GetLinkerPreference(const char* lang);
  140. ///! What is the object file extension for a given source file?
  141. const char* GetLanguageOutputExtension(cmSourceFile const&);
  142. ///! What is the configurations directory variable called?
  143. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  144. /** Get whether the generator should use a script for link commands. */
  145. bool GetUseLinkScript() { return this->UseLinkScript; }
  146. /** Get whether the generator should produce special marks on rules
  147. producing symbolic (non-file) outputs. */
  148. bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
  149. /*
  150. * Determine what program to use for building the project.
  151. */
  152. void FindMakeProgram(cmMakefile*);
  153. ///! Find a target by name by searching the local generators.
  154. cmTarget* FindTarget(const char* project, const char* name);
  155. /** Determine if a name resolves to a framework on disk or a built target
  156. that is a framework. */
  157. bool NameResolvesToFramework(const std::string& libname);
  158. /** If check to see if the target is linked to by any other
  159. target in the project */
  160. bool IsDependedOn(const char* project, cmTarget* target);
  161. ///! Find a local generator by its startdirectory
  162. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  163. /** Append the subdirectory for the given configuration. If anything is
  164. appended the given prefix and suffix will be appended around it, which
  165. is useful for leading or trailing slashes. */
  166. virtual void AppendDirectoryForConfig(const char* prefix,
  167. const char* config,
  168. const char* suffix,
  169. std::string& dir);
  170. /** Get the manifest of all targets that will be built for each
  171. configuration. This is valid during generation only. */
  172. cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
  173. /** Get the content of a directory. Directory listings are loaded
  174. from disk at most once and cached. During the generation step
  175. the content will include the target files to be built even if
  176. they do not yet exist. */
  177. std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
  178. bool needDisk = true);
  179. void AddTarget(cmTargets::value_type &v);
  180. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  181. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  182. virtual const char* GetInstallLocalTargetName() { return 0; }
  183. virtual const char* GetInstallStripTargetName() { return 0; }
  184. virtual const char* GetPreinstallTargetName() { return 0; }
  185. virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
  186. virtual const char* GetPackageTargetName() { return "PACKAGE"; }
  187. virtual const char* GetPackageSourceTargetName(){ return 0; }
  188. virtual const char* GetEditCacheTargetName() { return 0; }
  189. virtual const char* GetRebuildCacheTargetName() { return 0; }
  190. virtual const char* GetCleanTargetName() { return 0; }
  191. // Class to track a set of dependencies.
  192. class TargetDependSet: public std::set<cmTarget*> {};
  193. // what targets does the specified target depend on directly
  194. // via a target_link_libraries or add_dependencies
  195. TargetDependSet & GetTargetDirectDepends(cmTarget & target);
  196. const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
  197. const {return this->ProjectMap;}
  198. // track files replaced during a Generate
  199. void FileReplacedDuringGenerate(const std::string& filename);
  200. void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
  201. void AddRuleHash(const std::vector<std::string>& outputs,
  202. std::string const& content);
  203. /** Return whether the given binary directory is unused. */
  204. bool BinaryDirectoryIsNew(const char* dir)
  205. {
  206. return this->BinaryDirectories.insert(dir).second;
  207. }
  208. /** Supported systems creates a GUID for the given name */
  209. virtual void CreateGUID(const char*) {}
  210. protected:
  211. // for a project collect all its targets by following depend
  212. // information, and also collect all the targets
  213. void GetTargetSets(cmGlobalGenerator::TargetDependSet& projectTargets,
  214. cmGlobalGenerator::TargetDependSet& originalTargets,
  215. cmLocalGenerator* root,
  216. std::vector<cmLocalGenerator*> const& generators);
  217. void AddTargetDepends(cmTarget* target,
  218. cmGlobalGenerator::TargetDependSet&
  219. projectTargets);
  220. void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
  221. void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
  222. void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
  223. virtual bool CheckALLOW_DUPLICATE_CUSTOM_TARGETS();
  224. bool CheckTargets();
  225. // Fill the ProjectMap, this must be called after LocalGenerators
  226. // has been populated.
  227. void FillProjectMap();
  228. void CheckLocalGenerators();
  229. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  230. bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
  231. void FillLocalGeneratorToTargetMap();
  232. void CreateDefaultGlobalTargets(cmTargets* targets);
  233. cmTarget CreateGlobalTarget(const char* name, const char* message,
  234. const cmCustomCommandLines* commandLines,
  235. std::vector<std::string> depends, const char* workingDir,
  236. bool depends_on_all = false);
  237. bool NeedSymbolicMark;
  238. bool UseLinkScript;
  239. bool ForceUnixPaths;
  240. bool ToolSupportsColor;
  241. cmStdString FindMakeProgramFile;
  242. cmStdString ConfiguredFilesPath;
  243. cmake *CMakeInstance;
  244. std::vector<cmLocalGenerator *> LocalGenerators;
  245. cmLocalGenerator* CurrentLocalGenerator;
  246. // map from project name to vector of local generators in that project
  247. std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
  248. std::map<cmLocalGenerator*, std::set<cmTarget *> >
  249. LocalGeneratorToTargetMap;
  250. // Set of named installation components requested by the project.
  251. std::set<cmStdString> InstallComponents;
  252. bool InstallTargetEnabled;
  253. // Sets of named target exports
  254. std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
  255. void ClearExportSets();
  256. // Manifest of all targets that will be built for each configuration.
  257. // This is computed just before local generators generate.
  258. cmTargetManifest TargetManifest;
  259. // All targets in the entire project.
  260. std::map<cmStdString,cmTarget *> TotalTargets;
  261. private:
  262. float FirstTimeProgress;
  263. // If you add a new map here, make sure it is copied
  264. // in EnableLanguagesFromGenerator
  265. std::map<cmStdString, bool> IgnoreExtensions;
  266. std::map<cmStdString, bool> LanguageEnabled;
  267. std::map<cmStdString, cmStdString> OutputExtensions;
  268. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  269. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  270. std::map<cmStdString, int> LanguageToLinkerPreference;
  271. // Record hashes for rules and outputs.
  272. struct RuleHash { char Data[32]; };
  273. std::map<cmStdString, RuleHash> RuleHashes;
  274. void CheckRuleHashes();
  275. void WriteSummary();
  276. void WriteSummary(cmTarget* target);
  277. cmExternalMakefileProjectGenerator* ExtraGenerator;
  278. // track files replaced during a Generate
  279. std::vector<std::string> FilesReplacedDuringGenerate;
  280. // Store computed inter-target dependencies.
  281. typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
  282. TargetDependMap TargetDependencies;
  283. // Cache directory content and target files to be built.
  284. struct DirectoryContent: public std::set<cmStdString>
  285. {
  286. typedef std::set<cmStdString> derived;
  287. bool LoadedFromDisk;
  288. DirectoryContent(): LoadedFromDisk(false) {}
  289. DirectoryContent(DirectoryContent const& dc):
  290. derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
  291. };
  292. std::map<cmStdString, DirectoryContent> DirectoryContentMap;
  293. // Set of binary directories on disk.
  294. std::set<cmStdString> BinaryDirectories;
  295. };
  296. #endif