cmGlobalGenerator.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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);
  85. virtual std::string GenerateBuildCommand
  86. (const char* makeProgram,
  87. const char *projectName, const char* additionalOptions,
  88. const char *targetName,
  89. const char* config, bool ignoreErrors);
  90. ///! Set the CMake instance
  91. void SetCMakeInstance(cmake *cm) { this->CMakeInstance = cm; };
  92. ///! Get the CMake instance
  93. cmake *GetCMakeInstance() { return this->CMakeInstance; };
  94. void SetConfiguredFilesPath(const char* s){this->ConfiguredFilesPath = s;}
  95. cmLocalGenerator* GetLocalGenerator(int p) {
  96. return this->LocalGenerators[p];}
  97. void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) {
  98. g = this->LocalGenerators;}
  99. void AddLocalGenerator(cmLocalGenerator *lg);
  100. void AddInstallComponent(const char* component);
  101. static int s_TryCompileTimeout;
  102. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  103. bool GetToolSupportsColor() { return this->ToolSupportsColor; }
  104. ///! return the language for the given extension
  105. const char* GetLanguageFromExtension(const char* ext);
  106. ///! is an extension to be ignored
  107. bool IgnoreFile(const char* ext);
  108. ///! What is the preference for linkers and this language (None or Prefered)
  109. const char* GetLinkerPreference(const char* lang);
  110. ///! What is the output extension for a given language.
  111. const char* GetLanguageOutputExtensionForLanguage(const char* lang);
  112. ///! What is the output extension for a given source file extension.
  113. const char* GetLanguageOutputExtensionFromExtension(const char* lang);
  114. ///! What is the configurations directory variable called?
  115. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  116. /**
  117. * Convert the given remote path to a relative path with respect to
  118. * the given local path. The local path must be given in component
  119. * form (see SystemTools::SplitPath) without a trailing slash. The
  120. * remote path must use forward slashes and not already be escaped
  121. * or quoted.
  122. */
  123. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  124. const char* remote);
  125. /*
  126. * Determine what program to use for building the project.
  127. */
  128. void FindMakeProgram(cmMakefile*);
  129. ///! Find a target by name by searching the local generators.
  130. cmTarget* FindTarget(const char* project, const char* name);
  131. ///! Find a local generator by its startdirectory
  132. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  133. /** Append the subdirectory for the given configuration. If anything is
  134. appended the given prefix and suffix will be appended around it, which
  135. is useful for leading or trailing slashes. */
  136. virtual void AppendDirectoryForConfig(const char* prefix,
  137. const char* config,
  138. const char* suffix,
  139. std::string& dir);
  140. /** Get the manifest of all targets that will be built for each
  141. configuration. This is valid during generation only. */
  142. cmTargetManifest const& GetTargetManifest() { return this->TargetManifest; }
  143. void AddTarget(cmTargets::value_type &v) { this->TotalTargets[v.first] = &v.second;};
  144. /** Support for multiple custom command outputs. */
  145. virtual void CheckMultipleOutputs(cmMakefile* mf, bool verbose);
  146. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  147. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  148. virtual const char* GetPreinstallTargetName() { return 0; }
  149. virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
  150. virtual const char* GetPackageTargetName() { return "PACKAGE"; }
  151. virtual const char* GetPackageSourceTargetName(){ return 0; }
  152. virtual const char* GetEditCacheTargetName() { return 0; }
  153. virtual const char* GetRebuildCacheTargetName() { return 0; }
  154. protected:
  155. // Fill the ProjectMap, this must be called after LocalGenerators
  156. // has been populated.
  157. void FillProjectMap();
  158. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  159. void ConfigureRelativePaths();
  160. void SetupTests();
  161. void CreateDefaultGlobalTargets(cmTargets* targets);
  162. cmTarget CreateGlobalTarget(const char* name, const char* message,
  163. const cmCustomCommandLines* commandLines,
  164. std::vector<std::string> depends, bool depends_on_all = false);
  165. bool ForceUnixPaths;
  166. bool ToolSupportsColor;
  167. cmStdString FindMakeProgramFile;
  168. cmStdString ConfiguredFilesPath;
  169. cmake *CMakeInstance;
  170. std::vector<cmLocalGenerator *> LocalGenerators;
  171. // map from project name to vector of local generators in that project
  172. std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
  173. // Set of named installation components requested by the project.
  174. std::set<cmStdString> InstallComponents;
  175. // Manifest of all targets that will be built for each configuration.
  176. // This is computed just before local generators generate.
  177. cmTargetManifest TargetManifest;
  178. private:
  179. // If you add a new map here, make sure it is copied
  180. // in EnableLanguagesFromGenerator
  181. std::map<cmStdString, bool> IgnoreExtensions;
  182. std::map<cmStdString, bool> LanguageEnabled;
  183. std::map<cmStdString, cmStdString> OutputExtensions;
  184. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  185. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  186. std::map<cmStdString, cmStdString> LanguageToLinkerPreference;
  187. // The paths to the tops of the source and binary trees used for
  188. // relative path computation. A path must be either in the source
  189. // tree or the build tree to be converted to a relative path. The
  190. // ConfigureRelativePaths method may set these to be empty when
  191. // using relative paths is unsafe.
  192. std::string RelativePathTopSource;
  193. std::string RelativePathTopBinary;
  194. // this is used to improve performance
  195. std::map<cmStdString,cmTarget *> TotalTargets;
  196. };
  197. #endif