cmGlobalGenerator.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. static int s_TryCompileTimeout;
  101. bool GetForceUnixPaths() {return this->ForceUnixPaths;}
  102. ///! return the language for the given extension
  103. const char* GetLanguageFromExtension(const char* ext);
  104. ///! is an extension to be ignored
  105. bool IgnoreFile(const char* ext);
  106. ///! What is the preference for linkers and this language (None or Prefered)
  107. const char* GetLinkerPreference(const char* lang);
  108. ///! What is the output extension for a given language.
  109. const char* GetLanguageOutputExtensionForLanguage(const char* lang);
  110. ///! What is the output extension for a given source file extension.
  111. const char* GetLanguageOutputExtensionFromExtension(const char* lang);
  112. ///! What is the configurations directory variable called?
  113. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  114. /**
  115. * Convert the given remote path to a relative path with respect to
  116. * the given local path. The local path must be given in component
  117. * form (see SystemTools::SplitPath) without a trailing slash. The
  118. * remote path must use forward slashes and not already be escaped
  119. * or quoted.
  120. */
  121. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  122. const char* remote);
  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. ///! Find a local generator by its startdirectory
  130. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  131. /** Append the subdirectory for the given configuration. If anything is
  132. appended the given prefix and suffix will be appended around it, which
  133. is useful for leading or trailing slashes. */
  134. virtual void AppendDirectoryForConfig(const char* prefix,
  135. const char* config,
  136. const char* suffix,
  137. std::string& dir);
  138. protected:
  139. // Fill the m_ProjectMap, this must be called after m_LocalGenerators
  140. // has been populated.
  141. void FillProjectMap();
  142. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  143. void ConfigureRelativePaths();
  144. void SetupTests();
  145. void CreateDefaultGlobalTargets(cmTargets* targets);
  146. cmTarget CreateGlobalTarget(const char* name, const char* message,
  147. const cmCustomCommandLines* commandLines,
  148. std::vector<std::string> depends, bool depends_on_all = false);
  149. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  150. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  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* GetEditCacheTargetName() { return 0; }
  155. virtual const char* GetRebuildCacheTargetName() { return 0; }
  156. bool ForceUnixPaths;
  157. cmStdString FindMakeProgramFile;
  158. cmStdString ConfiguredFilesPath;
  159. cmake *CMakeInstance;
  160. std::vector<cmLocalGenerator *> LocalGenerators;
  161. // map from project name to vector of local generators in that project
  162. std::map<cmStdString, std::vector<cmLocalGenerator*> > ProjectMap;
  163. private:
  164. // If you add a new map here, make sure it is copied
  165. // in EnableLanguagesFromGenerator
  166. std::map<cmStdString, bool> IgnoreExtensions;
  167. std::map<cmStdString, bool> LanguageEnabled;
  168. std::map<cmStdString, cmStdString> OutputExtensions;
  169. std::map<cmStdString, cmStdString> LanguageToOutputExtension;
  170. std::map<cmStdString, cmStdString> ExtensionToLanguage;
  171. std::map<cmStdString, cmStdString> LanguageToLinkerPreference;
  172. // The paths to the tops of the source and binary trees used for
  173. // relative path computation. A path must be either in the source
  174. // tree or the build tree to be converted to a relative path. The
  175. // ConfigureRelativePaths method may set these to be empty when
  176. // using relative paths is unsafe.
  177. std::string RelativePathTopSource;
  178. std::string RelativePathTopBinary;
  179. };
  180. #endif