cmGlobalGhsMultiGenerator.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmGhsMultiGenerator_h
  4. #define cmGhsMultiGenerator_h
  5. #include "cmGlobalGenerator.h"
  6. #include "cmGhsMultiGpj.h"
  7. #include "cmGlobalGeneratorFactory.h"
  8. class cmGeneratedFileStream;
  9. class cmGlobalGhsMultiGenerator : public cmGlobalGenerator
  10. {
  11. public:
  12. // The default filename extension of GHS MULTI's build files.
  13. static const char* FILE_EXTENSION;
  14. cmGlobalGhsMultiGenerator(cmake* cm);
  15. ~cmGlobalGhsMultiGenerator();
  16. static cmGlobalGeneratorFactory* NewFactory()
  17. {
  18. return new cmGlobalGeneratorSimpleFactory<cmGlobalGhsMultiGenerator>();
  19. }
  20. ///! create the correct local generator
  21. cmLocalGenerator* CreateLocalGenerator(cmMakefile* mf) override;
  22. /// @return the name of this generator.
  23. static std::string GetActualName() { return "Green Hills MULTI"; }
  24. ///! Get the name for this generator
  25. std::string GetName() const override { return this->GetActualName(); }
  26. /// Overloaded methods. @see cmGlobalGenerator::GetDocumentation()
  27. static void GetDocumentation(cmDocumentationEntry& entry);
  28. /**
  29. * Utilized by the generator factory to determine if this generator
  30. * supports toolsets.
  31. */
  32. static bool SupportsToolset() { return true; }
  33. /**
  34. * Utilized by the generator factory to determine if this generator
  35. * supports platforms.
  36. */
  37. static bool SupportsPlatform() { return true; }
  38. // Toolset / Platform Support
  39. bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf) override;
  40. bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf) override;
  41. /**
  42. * Try to determine system information such as shared library
  43. * extension, pthreads, byte order etc.
  44. */
  45. void EnableLanguage(std::vector<std::string> const& languages, cmMakefile*,
  46. bool optional) override;
  47. /*
  48. * Determine what program to use for building the project.
  49. */
  50. bool FindMakeProgram(cmMakefile* mf) override;
  51. void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
  52. cmGeneratedFileStream* GetBuildFileStream()
  53. {
  54. return this->TargetFolderBuildStreams[""];
  55. }
  56. static void OpenBuildFileStream(std::string const& filepath,
  57. cmGeneratedFileStream** filestream);
  58. static void OpenBuildFileStream(cmGeneratedFileStream* filestream);
  59. void OpenBuildFileStream(std::ostream& fout);
  60. static void CloseBuildFileStream(cmGeneratedFileStream** filestream);
  61. /// Write the common disclaimer text at the top of each build file.
  62. static void WriteDisclaimer(std::ostream* os);
  63. std::vector<std::string> GetLibDirs() { return this->LibDirs; }
  64. static void AddFilesUpToPath(
  65. cmGeneratedFileStream* mainBuildFile,
  66. std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
  67. char const* homeOutputDirectory, std::string const& path,
  68. GhsMultiGpj::Types projType, std::string const& relPath = "");
  69. static void Open(std::string const& mapKeyName, std::string const& fileName,
  70. std::map<std::string, cmGeneratedFileStream*>* fileMap);
  71. static std::string trimQuotes(std::string const& str);
  72. // Target dependency sorting
  73. class TargetSet : public std::set<cmGeneratorTarget const*>
  74. {
  75. };
  76. class TargetCompare
  77. {
  78. std::string First;
  79. public:
  80. TargetCompare(std::string const& first)
  81. : First(first)
  82. {
  83. }
  84. bool operator()(cmGeneratorTarget const* l,
  85. cmGeneratorTarget const* r) const;
  86. };
  87. class OrderedTargetDependSet;
  88. protected:
  89. void Generate() override;
  90. void GenerateBuildCommand(std::vector<std::string>& makeCommand,
  91. const std::string& makeProgram,
  92. const std::string& projectName,
  93. const std::string& projectDir,
  94. const std::string& targetName,
  95. const std::string& config, bool fast, int jobs,
  96. bool verbose,
  97. std::vector<std::string> const& makeOptions =
  98. std::vector<std::string>()) override;
  99. private:
  100. void GetToolset(cmMakefile* mf, std::string& tsd, std::string& ts);
  101. /* top-level project */
  102. void OutputTopLevelProject(cmLocalGenerator* root,
  103. std::vector<cmLocalGenerator*>& generators);
  104. void WriteTopLevelProject(std::ostream& fout, cmLocalGenerator* root,
  105. std::vector<cmLocalGenerator*>& generators);
  106. void WriteMacros(std::ostream& fout);
  107. void WriteHighLevelDirectives(std::ostream& fout);
  108. void WriteSubProjects(std::ostream& fout, cmLocalGenerator* root,
  109. std::vector<cmLocalGenerator*>& generators);
  110. static void AddFilesUpToPathNewBuildFile(
  111. cmGeneratedFileStream* mainBuildFile,
  112. std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
  113. char const* homeOutputDirectory, std::string const& pathUpTo, bool isFirst,
  114. std::string const& relPath, GhsMultiGpj::Types projType);
  115. static void AddFilesUpToPathAppendNextFile(
  116. std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
  117. std::string const& pathUpTo,
  118. std::vector<std::string>::const_iterator splitPathI,
  119. std::vector<std::string>::const_iterator end, GhsMultiGpj::Types projType);
  120. static std::string GetFileNameFromPath(std::string const& path);
  121. bool IsTgtForBuild(const cmGeneratorTarget* tgt);
  122. std::vector<cmGeneratedFileStream*> TargetSubProjects;
  123. std::map<std::string, cmGeneratedFileStream*> TargetFolderBuildStreams;
  124. std::vector<std::string> LibDirs;
  125. static const char* DEFAULT_BUILD_PROGRAM;
  126. static const char* DEFAULT_TOOLSET_ROOT;
  127. };
  128. class cmGlobalGhsMultiGenerator::OrderedTargetDependSet
  129. : public std::multiset<cmTargetDepend,
  130. cmGlobalGhsMultiGenerator::TargetCompare>
  131. {
  132. typedef std::multiset<cmTargetDepend,
  133. cmGlobalGhsMultiGenerator::TargetCompare>
  134. derived;
  135. public:
  136. typedef cmGlobalGenerator::TargetDependSet TargetDependSet;
  137. OrderedTargetDependSet(TargetDependSet const&, std::string const& first);
  138. };
  139. #endif