cmGlobalGenerator.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmGlobalGenerator_h
  11. #define cmGlobalGenerator_h
  12. #include "cmStandardIncludes.h"
  13. #include "cmTarget.h" // For cmTargets
  14. class cmake;
  15. class cmMakefile;
  16. class cmLocalGenerator;
  17. class cmExternalMakefileProjectGenerator;
  18. class cmTarget;
  19. class cmTargetExport;
  20. class cmInstallTargetGenerator;
  21. class cmInstallFilesGenerator;
  22. /** \class cmGlobalGenerator
  23. * \brief Responable for overseeing the generation process for the entire tree
  24. *
  25. * Subclasses of this class generate makefiles for various
  26. * platforms.
  27. */
  28. class cmGlobalGenerator
  29. {
  30. public:
  31. ///! Free any memory allocated with the GlobalGenerator
  32. cmGlobalGenerator();
  33. virtual ~cmGlobalGenerator();
  34. ///! Create a local generator appropriate to this Global Generator
  35. virtual cmLocalGenerator *CreateLocalGenerator();
  36. ///! Get the name for this generator
  37. virtual const char *GetName() const { return "Generic"; };
  38. /** Get the documentation entry for this generator. */
  39. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  40. /**
  41. * Create LocalGenerators and process the CMakeLists files. This does not
  42. * actually produce any makefiles, DSPs, etc.
  43. */
  44. virtual void Configure();
  45. /**
  46. * Generate the all required files for building this project/tree. This
  47. * basically creates a series of LocalGenerators for each directory and
  48. * requests that they Generate.
  49. */
  50. virtual void Generate();
  51. /**
  52. * Set/Get and Clear the enabled languages.
  53. */
  54. void SetLanguageEnabled(const char*, cmMakefile* mf);
  55. bool GetLanguageEnabled(const char*) const;
  56. void ClearEnabledLanguages();
  57. void GetEnabledLanguages(std::vector<std::string>& lang);
  58. /**
  59. * Try to determine system infomation such as shared library
  60. * extension, pthreads, byte order etc.
  61. */
  62. virtual void EnableLanguage(std::vector<std::string>const& languages,
  63. cmMakefile *, bool optional);
  64. /**
  65. * Try to determine system infomation, get it from another generator
  66. */
  67. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  68. /**
  69. * Try running cmake and building a file. This is used for dynalically
  70. * loaded commands, not as part of the usual build process.
  71. */
  72. virtual int TryCompile(const char *srcdir, const char *bindir,
  73. const char *projectName, const char *targetName,
  74. bool fast, std::string *output, cmMakefile* mf);
  75. /**
  76. * Build a file given the following information. This is a more direct call
  77. * that is used by both CTest and TryCompile. If target name is NULL or
  78. * empty then all is assumed. clean indicates if a "make clean" should be
  79. * done first.
  80. */
  81. int Build(const char *srcdir, const char *bindir,
  82. const char *projectName, const char *targetName,
  83. std::string *output,
  84. const char *makeProgram, const char *config,
  85. bool clean, bool fast,
  86. double timeout, bool verbose=false,
  87. const char* extraOptions = 0,
  88. std::vector<std::string> const& nativeOptions =
  89. std::vector<std::string>());
  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(cmGlobalGenerator* gen);
  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. const std::set<cmStdString>* GetInstallComponents() const
  113. { return &InstallComponents; }
  114. ///! Add one installed target to the sets of the exports
  115. void AddTargetToExports(const char* exportSet, cmTarget* target,
  116. cmInstallTargetGenerator* archive,
  117. cmInstallTargetGenerator* runTime,
  118. cmInstallTargetGenerator* library,
  119. cmInstallTargetGenerator* framework,
  120. cmInstallTargetGenerator* bundle,
  121. cmInstallFilesGenerator* publicHeaders);
  122. ///! Get the export target set with the given name
  123. const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
  124. /** Add a file to the manifest of generated targets for a configuration. */
  125. void AddToManifest(const char* config, std::string const& f);
  126. void EnableInstallTarget();
  127. int TryCompileTimeout;
  128. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  129. bool GetToolSupportsColor() { return this->ToolSupportsColor; }
  130. void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
  131. ///! return the language for the given extension
  132. const char* GetLanguageFromExtension(const char* ext);
  133. ///! is an extension to be ignored
  134. bool IgnoreFile(const char* ext);
  135. ///! What is the preference for linkers and this language (None or Prefered)
  136. int GetLinkerPreference(const char* lang);
  137. ///! What is the object file extension for a given source file?
  138. const char* GetLanguageOutputExtension(cmSourceFile const&);
  139. ///! What is the configurations directory variable called?
  140. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  141. /** Get whether the generator should use a script for link commands. */
  142. bool GetUseLinkScript() { return this->UseLinkScript; }
  143. /** Get whether the generator should produce special marks on rules
  144. producing symbolic (non-file) outputs. */
  145. bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
  146. /*
  147. * Determine what program to use for building the project.
  148. */
  149. void FindMakeProgram(cmMakefile*);
  150. ///! Find a target by name by searching the local generators.
  151. cmTarget* FindTarget(const char* project, const char* name);
  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. Directory listings are loaded
  171. from disk at most once and cached. During the generation step
  172. the content will include the target files to be built even if
  173. they do not yet exist. */
  174. std::set<cmStdString> const& GetDirectoryContent(std::string const& dir,
  175. bool needDisk = true);
  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*> {};
  190. // what targets does the specified target depend on directly
  191. // via a target_link_libraries or add_dependencies
  192. TargetDependSet const& GetTargetDirectDepends(cmTarget & target);
  193. const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap()
  194. const {return this->ProjectMap;}
  195. // track files replaced during a Generate
  196. void FileReplacedDuringGenerate(const std::string& filename);
  197. void GetFilesReplacedDuringGenerate(std::vector<std::string>& filenames);
  198. void AddRuleHash(const std::vector<std::string>& outputs,
  199. std::string const& content);
  200. /** Return whether the given binary directory is unused. */
  201. bool BinaryDirectoryIsNew(const char* dir)
  202. {
  203. return this->BinaryDirectories.insert(dir).second;
  204. }
  205. /** Supported systems creates a GUID for the given name */
  206. virtual void CreateGUID(const char*) {}
  207. /** Return true if the generated build tree may contain multiple builds.
  208. i.e. "Can I build Debug and Release in the same tree?" */
  209. virtual bool IsMultiConfig() { return false; }
  210. protected:
  211. typedef std::vector<cmLocalGenerator*> GeneratorVector;
  212. // for a project collect all its targets by following depend
  213. // information, and also collect all the targets
  214. virtual void GetTargetSets(TargetDependSet& projectTargets,
  215. TargetDependSet& originalTargets,
  216. cmLocalGenerator* root, GeneratorVector const&);
  217. virtual bool IsRootOnlyTarget(cmTarget* target);
  218. void AddTargetDepends(cmTarget* target, TargetDependSet& projectTargets);
  219. void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
  220. void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
  221. void FillExtensionToLanguageMap(const char* l, cmMakefile* mf);
  222. virtual bool ComputeTargetDepends();
  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. virtual const char* GetPredefinedTargetsFolder();
  262. virtual bool UseFolderProperty();
  263. private:
  264. float FirstTimeProgress;
  265. // If you add a new map here, make sure it is copied
  266. // in EnableLanguagesFromGenerator
  267. std::map<cmStdString, bool> IgnoreExtensions;
  268. std::map<cmStdString, bool> LanguageEnabled;
  269. std::map<cmStdString, cmStdString> OutputExtensions;
  270. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  271. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  272. std::map<cmStdString, int> LanguageToLinkerPreference;
  273. // Record hashes for rules and outputs.
  274. struct RuleHash { char Data[32]; };
  275. std::map<cmStdString, RuleHash> RuleHashes;
  276. void CheckRuleHashes();
  277. void CheckRuleHashes(std::string const& pfile, std::string const& home);
  278. void WriteRuleHashes(std::string const& pfile);
  279. void WriteSummary();
  280. void WriteSummary(cmTarget* target);
  281. cmExternalMakefileProjectGenerator* ExtraGenerator;
  282. // track files replaced during a Generate
  283. std::vector<std::string> FilesReplacedDuringGenerate;
  284. // Store computed inter-target dependencies.
  285. typedef std::map<cmTarget *, TargetDependSet> TargetDependMap;
  286. TargetDependMap TargetDependencies;
  287. // Cache directory content and target files to be built.
  288. struct DirectoryContent: public std::set<cmStdString>
  289. {
  290. typedef std::set<cmStdString> derived;
  291. bool LoadedFromDisk;
  292. DirectoryContent(): LoadedFromDisk(false) {}
  293. DirectoryContent(DirectoryContent const& dc):
  294. derived(dc), LoadedFromDisk(dc.LoadedFromDisk) {}
  295. };
  296. std::map<cmStdString, DirectoryContent> DirectoryContentMap;
  297. // Set of binary directories on disk.
  298. std::set<cmStdString> BinaryDirectories;
  299. };
  300. #endif