cmGlobalGenerator.h 9.2 KB

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