cmFastbuildNormalTargetGenerator.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <map>
  5. #include <memory>
  6. #include <set>
  7. #include <string>
  8. #include <unordered_map>
  9. #include <utility>
  10. #include <vector>
  11. #include "cmComputeLinkInformation.h"
  12. #include "cmFastbuildTargetGenerator.h"
  13. #include "cmGeneratorTarget.h"
  14. #include "cmGlobalFastbuildGenerator.h"
  15. #include "cmRulePlaceholderExpander.h"
  16. class cmSourceFile;
  17. class cmFastbuildNormalTargetGenerator : public cmFastbuildTargetGenerator
  18. {
  19. std::unique_ptr<cmRulePlaceholderExpander> const RulePlaceholderExpander;
  20. std::string const ObjectOutDir;
  21. std::set<std::string> const Languages;
  22. std::unordered_map<std::string, std::string> const CompileObjectCmakeRules;
  23. std::string const CudaCompileMode;
  24. // Now we're adding our link deps to command line and using .Libraries2 for
  25. // tracking deps.
  26. bool UsingCommandLine = false;
  27. std::unordered_map<std::string, std::string> TargetIncludesByLanguage;
  28. std::map<std::pair<std::string, std::string>, std::string>
  29. CompileFlagsByLangAndArch;
  30. public:
  31. cmFastbuildNormalTargetGenerator(cmGeneratorTarget* gt, std::string config);
  32. void Generate() override;
  33. private:
  34. void GenerateLink(FastbuildTarget& target,
  35. std::vector<std::string> const& objectDepends);
  36. bool DetectBaseLinkerCommand(std::string& command, std::string const& arch,
  37. cmGeneratorTarget::Names const& targetNames);
  38. // Get languages used by the target.
  39. std::set<std::string> GetLanguages();
  40. // Returns mapping from language to command how to compile object file for
  41. // the it.
  42. // Example return value: {"CXX" : "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES>
  43. // <FLAGS> -o <OBJECT> -c <SOURCE>" }
  44. std::unordered_map<std::string, std::string> GetCompileObjectCommand() const;
  45. std::string GetCudaCompileMode() const;
  46. std::string GetLinkCommand() const;
  47. void AddCompilerLaunchersForLanguages();
  48. void AddLinkerLauncher();
  49. void AddCMakeLauncher();
  50. void ComputePaths(FastbuildTarget& fastbuildTarget) const;
  51. std::string ComputeCodeCheckOptions(cmSourceFile const& srcFile);
  52. cmRulePlaceholderExpander::RuleVariables ComputeRuleVariables() const;
  53. std::vector<std::string> GetSourceProperty(cmSourceFile const& srcFile,
  54. std::string const& prop) const;
  55. std::string GetCompileOptions(cmSourceFile const& srcFile,
  56. std::string const& arch);
  57. std::vector<std::string> GetArches() const;
  58. void GetCudaDeviceLinkLinkerAndArgs(std::string& linker,
  59. std::string& args) const;
  60. void GenerateCudaDeviceLink(FastbuildTarget& target) const;
  61. void GenerateObjects(FastbuildTarget& target);
  62. FastbuildUnityNode GetOneUnity(std::set<std::string> const& isolatedFiles,
  63. std::vector<std::string>& files,
  64. int unitySize) const;
  65. int GetUnityBatchSize() const;
  66. std::vector<FastbuildUnityNode> GenerateUnity(
  67. std::vector<FastbuildObjectListNode>& objects,
  68. std::set<std::string> const& isolatedSources,
  69. std::map<std::string, std::vector<std::string>> const& sourcesWithGroups);
  70. FastbuildUnityNode GenerateGroupedUnityNode(
  71. std::vector<std::string>& inputFiles,
  72. std::map<std::string, std::vector<std::string>> const& sourcesWithGroups,
  73. int& groupId);
  74. // Computes .CompilerOptions for the ObjectList node.
  75. void ComputeCompilerAndOptions(std::string const& compilerOptions,
  76. std::string const& staticCheckOptions,
  77. std::string const& language,
  78. FastbuildObjectListNode& outObjectList);
  79. std::string GetImportedLoc(cmComputeLinkInformation::Item const& item) const;
  80. std::string ResolveIfAlias(std::string const& targetName) const;
  81. void AppendExtraResources(std::set<std::string>& deps) const;
  82. void AppendExternalObject(FastbuildLinkerNode& linkerNode,
  83. std::set<std::string>& linkedObjects) const;
  84. void AppendExeToLink(FastbuildLinkerNode& linkerNode,
  85. cmComputeLinkInformation::Item const& item) const;
  86. void AppendTargetDep(FastbuildLinkerNode& linkerNode,
  87. std::set<std::string>& linkedObjects,
  88. cmComputeLinkInformation::Item const& item) const;
  89. void AppendPrebuildDeps(FastbuildLinkerNode& linkerNode,
  90. cmComputeLinkInformation::Item const& item) const;
  91. void AppendTransitivelyLinkedObjects(
  92. cmGeneratorTarget const& target,
  93. std::set<std::string>& linkedObjects) const;
  94. void AppendCommandLineDep(FastbuildLinkerNode& linkerNode,
  95. cmComputeLinkInformation::Item const& item) const;
  96. void AppendToLibraries2IfApplicable(FastbuildLinkerNode& linkerNode,
  97. std::string dep) const;
  98. void AppendLINK_DEPENDS(FastbuildLinkerNode& linkerNode) const;
  99. void AppendLinkDep(FastbuildLinkerNode& linkerNode, std::string dep) const;
  100. void AppendDirectObjectLibs(FastbuildLinkerNode& linkerNode,
  101. std::set<std::string>& linkedObjects);
  102. void AppendLinkDeps(std::set<FastbuildTargetDep>& preBuildDeps,
  103. FastbuildLinkerNode& linkerNode,
  104. FastbuildLinkerNode& cudaDeviceLinkLinkerNode);
  105. void AddLipoCommand(FastbuildTarget& target);
  106. void GenerateModuleDefinitionInfo(FastbuildTarget& target) const;
  107. std::vector<FastbuildExecNode> GetSymlinkExecs() const;
  108. void ProcessManifests(FastbuildLinkerNode& linkerNode) const;
  109. void AddStampExeIfApplicable(FastbuildTarget& fastbuildTarget) const;
  110. void ProcessPostBuildForStaticLib(FastbuildTarget& fastbuildTarget) const;
  111. void CollapseAllExecsIntoOneScriptfile(
  112. std::string const& scriptFileName,
  113. std::vector<FastbuildExecNode> const& execs) const;
  114. void AddPrebuildDeps(FastbuildTarget& target) const;
  115. std::string DetectCompilerFlags(cmSourceFile const& srcFile,
  116. std::string const& arch);
  117. void SplitLinkerFromArgs(std::string const& command,
  118. std::string& outLinkerExecutable,
  119. std::string& outLinkerArgs) const;
  120. void GetLinkerExecutableAndArgs(std::string const& command,
  121. std::string& outLinkerExecutable,
  122. std::string& outLinkerArgs);
  123. void ApplyLinkRuleLauncher(std::string& command);
  124. void ApplyLWYUToLinkerCommand(FastbuildLinkerNode& linkerNode);
  125. std::string ComputeDefines(cmSourceFile const& srcFile);
  126. void ComputePCH(cmSourceFile const& srcFile, FastbuildObjectListNode& node,
  127. std::set<std::string>& createdPCH);
  128. std::vector<std::string> GetManifestsAsFastbuildPath() const;
  129. void EnsureDirectoryExists(std::string const& path) const;
  130. void EnsureParentDirectoryExists(std::string const& path) const;
  131. };