cmFastbuildTargetGenerator.h 5.1 KB

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