cmGlobalGenerator.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * Set/Get and Clear the enabled languages.
  51. */
  52. void SetLanguageEnabled(const char*, cmMakefile* mf);
  53. bool GetLanguageEnabled(const char*);
  54. void ClearEnabledLanguages();
  55. void GetEnabledLanguages(std::vector<std::string>& lang);
  56. /**
  57. * Try to determine system infomation such as shared library
  58. * extension, pthreads, byte order etc.
  59. */
  60. virtual void EnableLanguage(std::vector<std::string>const& languages, cmMakefile *);
  61. /**
  62. * Try to determine system infomation, get it from another generator
  63. */
  64. virtual void EnableLanguagesFromGenerator(cmGlobalGenerator *gen);
  65. /**
  66. * Try running cmake and building a file. This is used for dynalically
  67. * loaded commands, not as part of the usual build process.
  68. */
  69. virtual int TryCompile(const char *srcdir, const char *bindir,
  70. const char *projectName, const char *targetName,
  71. std::string *output, cmMakefile* mf);
  72. /**
  73. * Build a file given the following information. This is a more direct call
  74. * that is used by both CTest and TryCompile. If target name is NULL or
  75. * empty then all is assumed. clean indicates if a "make clean" should be
  76. * done first.
  77. */
  78. virtual int Build(const char *srcdir, const char *bindir,
  79. const char *projectName, const char *targetName,
  80. std::string *output,
  81. const char *makeProgram, const char *config,
  82. bool clean);
  83. ///! Set the CMake instance
  84. void SetCMakeInstance(cmake *cm) {
  85. this->m_CMakeInstance = cm; };
  86. ///! Get the CMake instance
  87. cmake *GetCMakeInstance() {
  88. return this->m_CMakeInstance; };
  89. void SetConfiguredFilesPath(const char* s){m_ConfiguredFilesPath = s;}
  90. void GetLocalGenerators(std::vector<cmLocalGenerator *>&g) { g = m_LocalGenerators;}
  91. void AddLocalGenerator(cmLocalGenerator *lg);
  92. static int s_TryCompileTimeout;
  93. bool GetForceUnixPaths() {return m_ForceUnixPaths;}
  94. ///! return the language for the given extension
  95. const char* GetLanguageFromExtension(const char* ext);
  96. ///! is an extension to be ignored
  97. bool IgnoreFile(const char* ext);
  98. ///! What is the preference for linkers and this language (None or Prefered)
  99. const char* GetLinkerPreference(const char* lang);
  100. ///! What is the output extension for a given language.
  101. const char* GetLanguageOutputExtensionForLanguage(const char* lang);
  102. ///! What is the output extension for a given source file extension.
  103. const char* GetLanguageOutputExtensionFromExtension(const char* lang);
  104. /**
  105. * Convert the given remote path to a relative path with respect to
  106. * the given local path. The local path must be given in component
  107. * form (see SystemTools::SplitPath) without a trailing slash. The
  108. * remote path must use forward slashes and not already be escaped
  109. * or quoted.
  110. */
  111. std::string ConvertToRelativePath(const std::vector<std::string>& local,
  112. const char* remote);
  113. protected:
  114. // Fill the m_ProjectMap, this must be called after m_LocalGenerators has been populated.
  115. void FillProjectMap();
  116. bool IsExcluded(cmLocalGenerator* root, cmLocalGenerator* gen);
  117. void FindMakeProgram(cmMakefile*);
  118. void ConfigureRelativePaths();
  119. void SetupTests();
  120. bool m_ForceUnixPaths;
  121. cmStdString m_FindMakeProgramFile;
  122. cmStdString m_ConfiguredFilesPath;
  123. cmake *m_CMakeInstance;
  124. std::vector<cmLocalGenerator *> m_LocalGenerators;
  125. // map from project name to vector of local generators in that project
  126. std::map<cmStdString, std::vector<cmLocalGenerator*> > m_ProjectMap;
  127. ///! Find a target by name by searching the local generators.
  128. cmTarget* FindTarget(const char* project, const char* name);
  129. private:
  130. // If you add a new map here, make sure it is copied
  131. // in EnableLanguagesFromGenerator
  132. std::map<cmStdString, bool> m_IgnoreExtensions;
  133. std::map<cmStdString, bool> m_LanguageEnabled;
  134. std::map<cmStdString, cmStdString> m_OutputExtensions;
  135. std::map<cmStdString, cmStdString> m_LanguageToOutputExtension;
  136. std::map<cmStdString, cmStdString> m_ExtensionToLanguage;
  137. std::map<cmStdString, cmStdString> m_LanguageToLinkerPreference;
  138. // The prefix required of a path to be converted to a relative path.
  139. // No sequence of ../.. will ever go past this path. This is the
  140. // longest common path between the top level source and build trees.
  141. std::string m_RelativePathTop;
  142. };
  143. #endif