cmGlobalGenerator.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. 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. virtual 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);
  90. virtual std::string GenerateBuildCommand
  91. (const char* makeProgram,
  92. const char *projectName, const char* additionalOptions,
  93. const char *targetName,
  94. const char* config, bool ignoreErrors, bool fast);
  95. ///! Set the CMake instance
  96. void SetCMakeInstance(cmake *cm);
  97. ///! Get the CMake instance
  98. cmake *GetCMakeInstance() { return this->CMakeInstance; };
  99. void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
  100. const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
  101. return this->LocalGenerators;}
  102. cmLocalGenerator* GetCurrentLocalGenerator()
  103. {return this->CurrentLocalGenerator;}
  104. void SetCurrentLocalGenerator(cmLocalGenerator* lg)
  105. {this->CurrentLocalGenerator = lg;}
  106. void AddLocalGenerator(cmLocalGenerator *lg);
  107. ///! Set an generator for an "external makefile based project"
  108. void SetExternalMakefileProjectGenerator(
  109. cmExternalMakefileProjectGenerator *extraGenerator);
  110. const char* GetExtraGeneratorName() const;
  111. void AddInstallComponent(const char* component);
  112. ///! Add one installed target to the sets of the exports
  113. void AddTargetToExports(const char* exportSet, cmTarget* target,
  114. cmInstallTargetGenerator* archive,
  115. cmInstallTargetGenerator* runTime,
  116. cmInstallTargetGenerator* library,
  117. cmInstallTargetGenerator* framework,
  118. cmInstallTargetGenerator* bundle,
  119. cmInstallFilesGenerator* publicHeaders);
  120. ///! Get the export target set with the given name
  121. const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
  122. /** Add a file to the manifest of generated targets for a configuration. */
  123. void AddToManifest(const char* config, std::string const& f);
  124. void EnableInstallTarget();
  125. int TryCompileTimeout;
  126. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  127. bool GetToolSupportsColor() { return this->ToolSupportsColor; }
  128. void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
  129. ///! return the language for the given extension
  130. const char* GetLanguageFromExtension(const char* ext);
  131. ///! is an extension to be ignored
  132. bool IgnoreFile(const char* ext);
  133. ///! What is the preference for linkers and this language (None or Prefered)
  134. int GetLinkerPreference(const char* lang);
  135. ///! What is the object file extension for a given source file?
  136. const char* GetLanguageOutputExtension(cmSourceFile const&);
  137. ///! What is the configurations directory variable called?
  138. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  139. /** Get whether the generator should use a script for link commands. */
  140. bool GetUseLinkScript() { return this->UseLinkScript; }
  141. /** Get whether the generator should produce special marks on rules
  142. producing symbolic (non-file) outputs. */
  143. bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
  144. /*
  145. * Determine what program to use for building the project.
  146. */
  147. void FindMakeProgram(cmMakefile*);
  148. ///! Find a target by name by searching the local generators.
  149. cmTarget* FindTarget(const char* project,
  150. const char* name,
  151. bool useImportedTargets);
  152. /** Determine if a name resolves to a framework on disk or a built target
  153. that is a framework. */
  154. bool NameResolvesToFramework(const std::string& libname);
  155. /** If check to see if the target is linked to by any other
  156. target in the project */
  157. bool IsDependedOn(const char* project, cmTarget* target);
  158. ///! Find a local generator by its startdirectory
  159. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  160. /** Append the subdirectory for the given configuration. If anything is
  161. appended the given prefix and suffix will be appended around it, which
  162. is useful for leading or trailing slashes. */
  163. virtual void AppendDirectoryForConfig(const char* prefix,
  164. const char* config,
  165. const char* suffix,
  166. std::string& dir);
  167. /** Get the manifest of all targets that will be built for each
  168. configuration. This is valid during generation only. */
  169. cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
  170. /** Get the content of a directory on disk including the target
  171. files to be generated. This may be called only during the
  172. generation step. It is intended for use only by
  173. cmComputeLinkInformation. */
  174. std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
  175. bool needDisk);
  176. void AddTarget(cmTargets::value_type &v);
  177. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  178. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  179. virtual const char* GetInstallLocalTargetName() { return 0; }
  180. virtual const char* GetInstallStripTargetName() { return 0; }
  181. virtual const char* GetPreinstallTargetName() { return 0; }
  182. virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
  183. virtual const char* GetPackageTargetName() { return "PACKAGE"; }
  184. virtual const char* GetPackageSourceTargetName(){ return 0; }
  185. virtual const char* GetEditCacheTargetName() { return 0; }
  186. virtual const char* GetRebuildCacheTargetName() { return 0; }
  187. virtual const char* GetCleanTargetName() { return 0; }
  188. // Class to track a set of dependencies.
  189. class TargetDependSet: public std::set<cmTarget const*> {};
  190. // what targets does the specified target depend on
  191. TargetDependSet const& GetTargetDepends(cmTarget const& target);
  192. const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
  193. const {return this->ProjectMap;}
  194. // track files replaced during a Generate
  195. void FileReplacedDuringGenerate(const std::string& filename);
  196. void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
  197. protected:
  198. void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
  199. void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
  200. // Fill the ProjectMap, this must be called after LocalGenerators
  201. // has been populated.
  202. void FillProjectMap();
  203. void CheckLocalGenerators();
  204. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  205. bool IsExcluded(cmLocalGenerator* root, cmTarget& target);
  206. void FillLocalGeneratorToTargetMap();
  207. void CreateDefaultGlobalTargets(cmTargets* targets);
  208. cmTarget CreateGlobalTarget(const char* name, const char* message,
  209. const cmCustomCommandLines* commandLines,
  210. std::vector<std::string> depends, bool depends_on_all = false);
  211. bool NeedSymbolicMark;
  212. bool UseLinkScript;
  213. bool ForceUnixPaths;
  214. bool ToolSupportsColor;
  215. cmStdString FindMakeProgramFile;
  216. cmStdString ConfiguredFilesPath;
  217. cmake *CMakeInstance;
  218. std::vector<cmLocalGenerator *> LocalGenerators;
  219. cmLocalGenerator* CurrentLocalGenerator;
  220. // map from project name to vector of local generators in that project
  221. std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
  222. std::map<cmLocalGenerator*, std::set<cmTarget const*> >
  223. LocalGeneratorToTargetMap;
  224. // Set of named installation components requested by the project.
  225. std::set<cmStdString> InstallComponents;
  226. bool InstallTargetEnabled;
  227. // Sets of named target exports
  228. std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
  229. // Manifest of all targets that will be built for each configuration.
  230. // This is computed just before local generators generate.
  231. cmTargetManifest TargetManifest;
  232. private:
  233. float FirstTimeProgress;
  234. // If you add a new map here, make sure it is copied
  235. // in EnableLanguagesFromGenerator
  236. std::map<cmStdString, bool> IgnoreExtensions;
  237. std::map<cmStdString, bool> LanguageEnabled;
  238. std::map<cmStdString, cmStdString> OutputExtensions;
  239. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  240. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  241. std::map<cmStdString, int> LanguageToLinkerPreference;
  242. // this is used to improve performance
  243. std::map<cmStdString,cmTarget *> TotalTargets;
  244. std::map<cmStdString,cmTarget *> ImportedTotalTargets;
  245. cmExternalMakefileProjectGenerator* ExtraGenerator;
  246. // track files replaced during a Generate
  247. std::vector<std::string> FilesReplacedDuringGenerate;
  248. // Track inter-target dependencies.
  249. bool ConsiderTargetDepends(cmTarget const* depender,
  250. TargetDependSet& depender_depends,
  251. const char* dependee_name);
  252. bool FindDependency(cmTarget const* goal, cmTarget const* current,
  253. std::vector<cmTarget const*>& steps);
  254. typedef std::map<cmTarget const*, TargetDependSet> TargetDependMap;
  255. TargetDependMap TargetDependencies;
  256. // Cache directory content and target files to be built.
  257. struct DirectoryContent: public std::set<cmStdString>
  258. {
  259. typedef std::set<cmStdString> derived;
  260. bool LoadedFromDisk;
  261. DirectoryContent(): LoadedFromDisk(false) {}
  262. DirectoryContent(DirectoryContent const& dc):
  263. derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
  264. };
  265. std::map<cmStdString, DirectoryContent> DirectoryContentMap;
  266. };
  267. #endif