cmGlobalGenerator.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 cmGlobalGenerator
  25. * \brief Responable for overseeing the generation process for the entire tree
  26. *
  27. * Subclasses of this class generate makefiles for various
  28. * platforms.
  29. */
  30. class cmGlobalGenerator
  31. {
  32. public:
  33. ///! Free any memory allocated with the GlobalGenerator
  34. cmGlobalGenerator();
  35. virtual ~cmGlobalGenerator();
  36. ///! Create a local generator appropriate to this Global Generator
  37. virtual cmLocalGenerator *CreateLocalGenerator();
  38. ///! Get the name for this generator
  39. virtual const char *GetName() const { return "Generic"; };
  40. /** Get the documentation entry for this generator. */
  41. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  42. /**
  43. * Create LocalGenerators and process the CMakeLists files. This does not
  44. * actually produce any makefiles, DSPs, etc.
  45. */
  46. virtual void Configure();
  47. /**
  48. * Generate the all required files for building this project/tree. This
  49. * basically creates a series of LocalGenerators for each directory and
  50. * requests that they Generate.
  51. */
  52. virtual void Generate();
  53. /**
  54. * Set/Get and Clear the enabled languages.
  55. */
  56. void SetLanguageEnabled(const char*, cmMakefile* mf);
  57. bool GetLanguageEnabled(const char*);
  58. void ClearEnabledLanguages();
  59. void GetEnabledLanguages(std::vector<std::string>& lang);
  60. /**
  61. * Try to determine system infomation such as shared library
  62. * extension, pthreads, byte order etc.
  63. */
  64. virtual void EnableLanguage(std::vector<std::string>const& languages,
  65. cmMakefile *, bool optional);
  66. /**
  67. * Try to determine system infomation, get it from another generator
  68. */
  69. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  70. /**
  71. * Try running cmake and building a file. This is used for dynalically
  72. * loaded commands, not as part of the usual build process.
  73. */
  74. virtual int TryCompile(const char *srcdir, const char *bindir,
  75. const char *projectName, const char *targetName,
  76. std::string *output, cmMakefile* mf);
  77. /**
  78. * Build a file given the following information. This is a more direct call
  79. * that is used by both CTest and TryCompile. If target name is NULL or
  80. * empty then all is assumed. clean indicates if a "make clean" should be
  81. * done first.
  82. */
  83. virtual int Build(const char *srcdir, const char *bindir,
  84. const char *projectName, const char *targetName,
  85. std::string *output,
  86. const char *makeProgram, const char *config,
  87. bool clean, bool fast,
  88. double timeout);
  89. virtual std::string GenerateBuildCommand
  90. (const char* makeProgram,
  91. const char *projectName, const char* additionalOptions,
  92. const char *targetName,
  93. const char* config, bool ignoreErrors, bool fast);
  94. ///! Set the CMake instance
  95. void SetCMakeInstance(cmake *cm);
  96. ///! Get the CMake instance
  97. cmake *GetCMakeInstance() { return this->CMakeInstance; };
  98. void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
  99. const std::vector<cmLocalGenerator *>& GetLocalGenerators() const {
  100. return this->LocalGenerators;}
  101. void AddLocalGenerator(cmLocalGenerator *lg);
  102. ///! Set an generator for an "external makefile based project"
  103. void SetExternalMakefileProjectGenerator(
  104. cmExternalMakefileProjectGenerator *extraGenerator);
  105. const char* GetExtraGeneratorName() const;
  106. void AddInstallComponent(const char* component);
  107. ///! Add one installed target to the sets of the exports
  108. void AddTargetToExports(const char* exportSet, cmTarget* target,
  109. cmInstallTargetGenerator* archive,
  110. cmInstallTargetGenerator* runTime,
  111. cmInstallTargetGenerator* library);
  112. ///! Get the export target set with the given name
  113. const std::vector<cmTargetExport*>* GetExportSet(const char* name) const;
  114. void EnableInstallTarget();
  115. int TryCompileTimeout;
  116. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  117. bool GetToolSupportsColor() { return this->ToolSupportsColor; }
  118. void SetToolSupportsColor(bool enable) { this->ToolSupportsColor = enable; }
  119. ///! return the language for the given extension
  120. const char* GetLanguageFromExtension(const char* ext);
  121. ///! is an extension to be ignored
  122. bool IgnoreFile(const char* ext);
  123. ///! What is the preference for linkers and this language (None or Prefered)
  124. const char* GetLinkerPreference(const char* lang);
  125. ///! What is the object file extension for a given source file?
  126. const char* GetLanguageOutputExtension(cmSourceFile const&);
  127. ///! What is the configurations directory variable called?
  128. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  129. /** Get whether the generator should use a script for link commands. */
  130. bool GetUseLinkScript() { return this->UseLinkScript; }
  131. /** Get whether the generator should produce special marks on rules
  132. producing symbolic (non-file) outputs. */
  133. bool GetNeedSymbolicMark() { return this->NeedSymbolicMark; }
  134. /*
  135. * Determine what program to use for building the project.
  136. */
  137. void FindMakeProgram(cmMakefile*);
  138. ///! Find a target by name by searching the local generators.
  139. cmTarget* FindTarget(const char* project, const char* name, bool useImportedTargets);
  140. /** If check to see if the target is linked to by any other
  141. target in the project */
  142. bool IsDependedOn(const char* project, cmTarget* target);
  143. ///! Find a local generator by its startdirectory
  144. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  145. /** Append the subdirectory for the given configuration. If anything is
  146. appended the given prefix and suffix will be appended around it, which
  147. is useful for leading or trailing slashes. */
  148. virtual void AppendDirectoryForConfig(const char* prefix,
  149. const char* config,
  150. const char* suffix,
  151. std::string& dir);
  152. /** Get the manifest of all targets that will be built for each
  153. configuration. This is valid during generation only. */
  154. cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
  155. void AddTarget(cmTargets::value_type &v);
  156. /** Support for multiple custom command outputs. */
  157. virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
  158. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  159. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  160. virtual const char* GetInstallLocalTargetName() { return 0; }
  161. virtual const char* GetInstallStripTargetName() { return 0; }
  162. virtual const char* GetPreinstallTargetName() { return 0; }
  163. virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
  164. virtual const char* GetPackageTargetName() { return "PACKAGE"; }
  165. virtual const char* GetPackageSourceTargetName(){ return 0; }
  166. virtual const char* GetEditCacheTargetName() { return 0; }
  167. virtual const char* GetRebuildCacheTargetName() { return 0; }
  168. // what targets does the specified target depend on
  169. std::vector<cmTarget *>& GetTargetDepends(cmTarget& target);
  170. const std::map<cmStdString, std::vector<cmLocalGenerator*> >& GetProjectMap() const {return this->ProjectMap;}
  171. protected:
  172. void SetLanguageEnabledFlag(const char* l, cmMakefile* mf);
  173. void SetLanguageEnabledMaps(const char* l, cmMakefile* mf);
  174. // Fill the ProjectMap, this must be called after LocalGenerators
  175. // has been populated.
  176. void FillProjectMap();
  177. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  178. void FillProjectToTargetMap();
  179. void CreateDefaultGlobalTargets(cmTargets* targets);
  180. cmTarget CreateGlobalTarget(const char* name, const char* message,
  181. const cmCustomCommandLines* commandLines,
  182. std::vector<std::string> depends, bool depends_on_all = false);
  183. bool NeedSymbolicMark;
  184. bool UseLinkScript;
  185. bool ForceUnixPaths;
  186. bool ToolSupportsColor;
  187. cmStdString FindMakeProgramFile;
  188. cmStdString ConfiguredFilesPath;
  189. cmake *CMakeInstance;
  190. std::vector<cmLocalGenerator *> LocalGenerators;
  191. // map from project name to vector of local generators in that project
  192. std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
  193. std::map<cmStdString, std::set<cmTarget*> > ProjectToTargetMap;
  194. // Set of named installation components requested by the project.
  195. std::set<cmStdString> InstallComponents;
  196. bool InstallTargetEnabled;
  197. // Sets of named target exports
  198. std::map<cmStdString, std::vector<cmTargetExport*> > ExportSets;
  199. // Manifest of all targets that will be built for each configuration.
  200. // This is computed just before local generators generate.
  201. cmTargetManifest TargetManifest;
  202. private:
  203. // If you add a new map here, make sure it is copied
  204. // in EnableLanguagesFromGenerator
  205. std::map<cmStdString, bool> IgnoreExtensions;
  206. std::map<cmStdString, bool> LanguageEnabled;
  207. std::map<cmStdString, cmStdString> OutputExtensions;
  208. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  209. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  210. std::map<cmStdString, cmStdString> LanguageToLinkerPreference;
  211. // this is used to improve performance
  212. std::map<cmStdString,cmTarget *> TotalTargets;
  213. std::map<cmStdString,cmTarget *> ImportedTotalTargets;
  214. std::map<cmStdString, std::vector<cmTarget *> > TargetDependencies;
  215. cmExternalMakefileProjectGenerator* ExtraGenerator;
  216. };
  217. #endif