cmFastbuildTargetGenerator.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <memory>
  5. #include <set>
  6. #include <string>
  7. #include <unordered_map>
  8. #include <utility>
  9. #include <vector>
  10. #include "cmsys/FStream.hxx"
  11. #include "cmCommonTargetGenerator.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalFastbuildGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmOSXBundleGenerator.h"
  16. class cmCustomCommand;
  17. class cmCustomCommandGenerator;
  18. class cmLocalFastbuildGenerator;
  19. class cmMakefile;
  20. class cmSourceFile;
  21. enum class FastbuildBuildStep
  22. {
  23. PRE_BUILD,
  24. PRE_LINK,
  25. POST_BUILD,
  26. REST,
  27. };
  28. class cmFastbuildTargetGenerator : public cmCommonTargetGenerator
  29. {
  30. public:
  31. /// Create a cmFastbuildTargetGenerator according to the @a target's type and
  32. /// config.
  33. static cmFastbuildTargetGenerator* New(cmGeneratorTarget* target,
  34. std::string config);
  35. cmFastbuildTargetGenerator(cmGeneratorTarget* target, std::string config);
  36. virtual void Generate() {}
  37. std::string GetClangTidyReplacementsFilePath(
  38. std::string const& directory, cmSourceFile const& source,
  39. std::string const& Config) const override;
  40. void AddIncludeFlags(std::string& languageFlags, std::string const& language,
  41. std::string const&) override;
  42. cmGeneratorTarget::Names DetectOutput() const;
  43. void AddObjectDependencies(FastbuildTarget& fastbuildTarget,
  44. std::vector<std::string>& allObjectDepends) const;
  45. void AddLinkerNodeDependnecies(FastbuildTarget& fastbuildTarget);
  46. std::string ConvertToFastbuildPath(std::string const& path) const;
  47. cmGlobalFastbuildGenerator* GetGlobalGenerator() const;
  48. std::string GetName();
  49. cmMakefile* GetMakefile() const { return this->Makefile; }
  50. cmGeneratorTarget* GetGeneratorTarget() const
  51. {
  52. return this->GeneratorTarget;
  53. }
  54. void LogMessage(std::string const& m) const;
  55. private:
  56. std::string GetUtilityAliasFromBuildStep(FastbuildBuildStep step) const;
  57. protected:
  58. cmLocalFastbuildGenerator* GetLocalGenerator() const
  59. {
  60. return this->LocalGenerator;
  61. }
  62. std::string GetTargetName() const;
  63. std::string GetCdCommand(cmCustomCommandGenerator const& ccg) const;
  64. std::string GetScriptWorkingDir(cmCustomCommandGenerator const& ccg) const;
  65. std::string GetScriptFilename(std::string const& utilityTargetName) const;
  66. std::vector<std::string> GetDepends(
  67. cmCustomCommandGenerator const& ccg) const;
  68. void AddCommentPrinting(std::vector<std::string>& cmdLines,
  69. cmCustomCommandGenerator const& ccg) const;
  70. void WriteCmdsToFile(cmsys::ofstream& file,
  71. std::vector<std::string> const& cmds) const;
  72. void AddOutput(cmCustomCommandGenerator const& ccg, FastbuildExecNode& exec);
  73. void AddExecArguments(FastbuildExecNode& exec,
  74. std::string const& scriptFilename) const;
  75. void ReplaceProblematicMakeVars(std::string& command) const;
  76. FastbuildExecNodes GenerateCommands(FastbuildBuildStep buildStep);
  77. FastbuildExecNode GetAppleTextStubCommand() const;
  78. FastbuildExecNode GetDepsCheckExec(FastbuildExecNode const& depender);
  79. std::string MakeCustomLauncher(cmCustomCommandGenerator const& ccg);
  80. std::string GetCustomCommandTargetName(cmCustomCommand const& cc,
  81. FastbuildBuildStep step) const;
  82. std::vector<std::string> GetInputFiles(cmCustomCommandGenerator const& ccg,
  83. FastbuildBuildStep step) const;
  84. void WriteScriptProlog(cmsys::ofstream& file) const;
  85. void WriteScriptEpilog(cmsys::ofstream& file) const;
  86. void AdditionalCleanFiles();
  87. // write rules for Mac OS X Application Bundle content.
  88. struct MacOSXContentGeneratorType
  89. : cmOSXBundleGenerator::MacOSXContentGeneratorType
  90. {
  91. MacOSXContentGeneratorType(cmFastbuildTargetGenerator* g, std::string cfg)
  92. : Generator(g)
  93. , Config(std::move(cfg))
  94. {
  95. }
  96. void operator()(cmSourceFile const& source, char const* pkgloc,
  97. std::string const& config) override;
  98. private:
  99. cmFastbuildTargetGenerator* Generator;
  100. std::string const Config;
  101. };
  102. friend struct MacOSXContentGeneratorType;
  103. // "MacOSXContentGenerator" has to be per-config once multiconfig generator
  104. // is implemented.
  105. std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
  106. std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
  107. std::set<std::string> MacContentFolders;
  108. std::vector<FastbuildCopyNode> CopyNodes;
  109. cmLocalFastbuildGenerator* LocalGenerator;
  110. cmGlobalGenerator::TargetDependSet const TargetDirectDependencies;
  111. std::string const Config;
  112. // Sometimes CMake adds equivalent custom commands to different targets.
  113. // Not really supported by FBuild (can't have different exec nodes producing
  114. // same output). So, in such cases we need to "re-map" the exec to produce a
  115. // "dummy" output (and update all deps within the target).
  116. // TODO: potentially 1 map should be enough?
  117. std::unordered_map<std::string, std::string> OutputsToReplace;
  118. std::unordered_map<std::string, std::string> OutputToExecName;
  119. };