cmGlobalGenerator.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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, cmMakefile *);
  62. /**
  63. * Try to determine system infomation, get it from another generator
  64. */
  65. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  66. /**
  67. * Try running cmake and building a file. This is used for dynalically
  68. * loaded commands, not as part of the usual build process.
  69. */
  70. virtual int TryCompile(const char *srcdir, const char *bindir,
  71. const char *projectName, const char *targetName,
  72. std::string *output, cmMakefile* mf);
  73. /**
  74. * Build a file given the following information. This is a more direct call
  75. * that is used by both CTest and TryCompile. If target name is NULL or
  76. * empty then all is assumed. clean indicates if a "make clean" should be
  77. * done first.
  78. */
  79. virtual int Build(const char *srcdir, const char *bindir,
  80. const char *projectName, const char *targetName,
  81. std::string *output,
  82. const char *makeProgram, const char *config,
  83. bool clean);
  84. virtual std::string GenerateBuildCommand(const char* makeProgram,
  85. const char *projectName, const char* additionalOptions, const char *targetName,
  86. const char* config, bool ignoreErrors);
  87. ///! Set the CMake instance
  88. void SetCMakeInstance(cmake *cm) {
  89. this->m_CMakeInstance = cm; };
  90. ///! Get the CMake instance
  91. cmake *GetCMakeInstance() {
  92. return this->m_CMakeInstance; };
  93. void SetConfiguredFilesPath(const char* s){m_ConfiguredFilesPath = s;}
  94. cmLocalGenerator* GetLocalGenerator(int p) { return m_LocalGenerators[p];}
  95. void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { g = m_LocalGenerators;}
  96. void AddLocalGenerator(cmLocalGenerator *lg);
  97. static int s_TryCompileTimeout;
  98. bool GetForceUnixPaths() {return m_ForceUnixPaths;}
  99. ///! return the language for the given extension
  100. const char* GetLanguageFromExtension(const char* ext);
  101. ///! is an extension to be ignored
  102. bool IgnoreFile(const char* ext);
  103. ///! What is the preference for linkers and this language (None or Prefered)
  104. const char* GetLinkerPreference(const char* lang);
  105. ///! What is the output extension for a given language.
  106. const char* GetLanguageOutputExtensionForLanguage(const char* lang);
  107. ///! What is the output extension for a given source file extension.
  108. const char* GetLanguageOutputExtensionFromExtension(const char* lang);
  109. ///! What is the configurations directory variable called?
  110. virtual const char* GetCMakeCFGInitDirectory() { return "."; }
  111. /**
  112. * Convert the given remote path to a relative path with respect to
  113. * the given local path. The local path must be given in component
  114. * form (see SystemTools::SplitPath) without a trailing slash. The
  115. * remote path must use forward slashes and not already be escaped
  116. * or quoted.
  117. */
  118. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  119. const char* remote);
  120. /*
  121. * Determine what program to use for building the project.
  122. */
  123. void FindMakeProgram(cmMakefile*);
  124. ///! Find a target by name by searching the local generators.
  125. cmTarget* FindTarget(const char* project, const char* name);
  126. ///! Find a local generator by its startdirectory
  127. cmLocalGenerator* FindLocalGenerator(const char* start_dir);
  128. /** Append the subdirectory for the given configuration. */
  129. virtual void AppendDirectoryForConfig(const char* config, std::string& dir);
  130. protected:
  131. // Fill the m_ProjectMap, this must be called after m_LocalGenerators has been populated.
  132. void FillProjectMap();
  133. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  134. void ConfigureRelativePaths();
  135. void SetupTests();
  136. void CreateDefaultGlobalTargets(cmTargets* targets);
  137. cmTarget CreateGlobalTarget(const char* name, const char* message,
  138. const cmCustomCommandLines* commandLines,
  139. std::vector<std::string> depends, bool depends_on_all = false);
  140. virtual const char* GetAllTargetName() { return "ALL_BUILD"; }
  141. virtual const char* GetInstallTargetName() { return "INSTALL"; }
  142. virtual const char* GetPreinstallTargetName() { return 0; }
  143. virtual const char* GetTestTargetName() { return "RUN_TESTS"; }
  144. virtual const char* GetPackageTargetName() { return "PACKAGE"; }
  145. virtual const char* GetEditCacheTargetName() { return 0; }
  146. virtual const char* GetRebuildCacheTargetName() { return 0; }
  147. bool m_ForceUnixPaths;
  148. cmStdString m_FindMakeProgramFile;
  149. cmStdString m_ConfiguredFilesPath;
  150. cmake *m_CMakeInstance;
  151. std::vector<cmLocalGenerator *> m_LocalGenerators;
  152. // map from project name to vector of local generators in that project
  153. std::map<cmStdString, std::vector<cmLocalGenerator*> > m_ProjectMap;
  154. private:
  155. // If you add a new map here, make sure it is copied
  156. // in EnableLanguagesFromGenerator
  157. std::map<cmStdString, bool> m_IgnoreExtensions;
  158. std::map<cmStdString, bool> m_LanguageEnabled;
  159. std::map<cmStdString, cmStdString> m_OutputExtensions;
  160. std::map<cmStdString, cmStdString> m_LanguageToOutputExtension;
  161. std::map<cmStdString, cmStdString> m_ExtensionToLanguage;
  162. std::map<cmStdString, cmStdString> m_LanguageToLinkerPreference;
  163. // The paths to the tops of the source and binary trees used for
  164. // relative path computation. A path must be either in the source
  165. // tree or the build tree to be converted to a relative path. The
  166. // ConfigureRelativePaths method may set these to be empty when
  167. // using relative paths is unsafe.
  168. std::string m_RelativePathTopSource;
  169. std::string m_RelativePathTopBinary;
  170. };
  171. #endif