cmGlobalGenerator.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. class cmake;
  17. class cmMakefile;
  18. class cmLocalGenerator;
  19. class cmTarget;
  20. /** \class cmGlobalGenerator
  21. * \brief Responable for overseeing the generation process for the entire tree
  22. *
  23. * Subclasses of this class generate makefiles for various
  24. * platforms.
  25. */
  26. class cmGlobalGenerator
  27. {
  28. public:
  29. ///! Free any memory allocated with the GlobalGenerator
  30. cmGlobalGenerator();
  31. virtual ~cmGlobalGenerator();
  32. ///! Create a local generator appropriate to this Global Generator
  33. virtual cmLocalGenerator *CreateLocalGenerator();
  34. ///! Get the name for this generator
  35. virtual const char *GetName() const { return "Generic"; };
  36. /** Get the documentation entry for this generator. */
  37. virtual void GetDocumentation(cmDocumentationEntry& entry) const;
  38. /**
  39. * Create LocalGenerators and process the CMakeLists files. This does not
  40. * actually produce any makefiles, DSPs, etc.
  41. */
  42. virtual void Configure();
  43. /**
  44. * Generate the all required files for building this project/tree. This
  45. * basically creates a series of LocalGenerators for each directory and
  46. * requests that they Generate.
  47. */
  48. virtual void Generate();
  49. /**
  50. * Generate the required files for building this directory. This
  51. * basically creates a single LocalGenerators and
  52. * requests that it Generate.
  53. */
  54. virtual void LocalGenerate();
  55. /**
  56. * Set/Get and Clear the enabled languages.
  57. */
  58. void SetLanguageEnabled(const char*, cmMakefile* mf);
  59. bool GetLanguageEnabled(const char*);
  60. void ClearEnabledLanguages();
  61. void GetEnabledLanguages(std::vector<std::string>& lang);
  62. /**
  63. * Try to determine system infomation such as shared library
  64. * extension, pthreads, byte order etc.
  65. */
  66. virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
  67. /**
  68. * Try to determine system infomation, get it from another generator
  69. */
  70. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  71. /**
  72. * Try running cmake and building a file. This is used for dynalically
  73. * loaded commands, not as part of the usual build process.
  74. */
  75. virtual int TryCompile(const char *srcdir, const char *bindir,
  76. const char *projectName, const char *targetName,
  77. std::string *output, cmMakefile* mf);
  78. /**
  79. * Build a file given the following information. This is a more direct call
  80. * that is used by both CTest and TryCompile. If target name is NULL or
  81. * empty then all is assumed. clean indicates if a "make clean" should be
  82. * done first.
  83. */
  84. virtual int Build(const char *srcdir, const char *bindir,
  85. const char *projectName, const char *targetName,
  86. std::string *output,
  87. const char *makeProgram, const char *config,
  88. bool clean);
  89. ///! Set the CMake instance
  90. void SetCMakeInstance(cmake *cm) {
  91. this->m_CMakeInstance = cm; };
  92. ///! Get the CMake instance
  93. cmake *GetCMakeInstance() {
  94. return this->m_CMakeInstance; };
  95. void SetConfiguredFilesPath(const char* s){m_ConfiguredFilesPath = s;}
  96. void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { g = m_LocalGenerators;}
  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. /**
  110. * Convert the given remote path to a relative path with respect to
  111. * the given local path. The local path must be given in component
  112. * form (see SystemTools::SplitPath) without a trailing slash. The
  113. * remote path must use forward slashes and not already be escaped
  114. * or quoted.
  115. */
  116. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  117. const char* remote);
  118. protected:
  119. // Fill the m_ProjectMap, this must be called after m_LocalGenerators has been populated.
  120. void FillProjectMap();
  121. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  122. void FindMakeProgram(cmMakefile*);
  123. void ConfigureRelativePaths();
  124. bool m_ForceUnixPaths;
  125. cmStdString m_FindMakeProgramFile;
  126. cmStdString m_ConfiguredFilesPath;
  127. cmake *m_CMakeInstance;
  128. std::vector<cmLocalGenerator *> m_LocalGenerators;
  129. // map from project name to vector of local generators in that project
  130. std::map<cmStdString, std::vector<cmLocalGenerator*> > m_ProjectMap;
  131. ///! used by Configure()
  132. void RecursiveConfigure(cmLocalGenerator *lg, float start, float end);
  133. ///! Find a target by name by searching the local generators.
  134. cmTarget* FindTarget(const char* name);
  135. private:
  136. // If you add a new map here, make sure it is copied
  137. // in EnableLanguagesFromGenerator
  138. std::map<cmStdString, bool> m_IgnoreExtensions;
  139. std::map<cmStdString, bool> m_LanguageEnabled;
  140. std::map<cmStdString, cmStdString> m_OutputExtensions;
  141. std::map<cmStdString, cmStdString> m_LanguageToOutputExtension;
  142. std::map<cmStdString, cmStdString> m_ExtensionToLanguage;
  143. std::map<cmStdString, cmStdString> m_LanguageToLinkerPreference;
  144. // The prefix required of a path to be converted to a relative path.
  145. // No sequence of ../.. will ever go past this path. This is the
  146. // longest common path between the top level source and build trees.
  147. std::string m_RelativePathTop;
  148. };
  149. #endif