cmFastbuildNormalTargetGenerator.cxx 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmFastbuildNormalTargetGenerator.h"
  4. #include <algorithm>
  5. #include <cstddef>
  6. #include <iterator>
  7. #include <map>
  8. #include <sstream>
  9. #include <string>
  10. #include <unordered_map>
  11. #include <unordered_set>
  12. #include <utility>
  13. #include <cm/memory>
  14. #include <cm/optional>
  15. #include "cmsys/FStream.hxx"
  16. #include "cmAlgorithms.h"
  17. #include "cmCommonTargetGenerator.h"
  18. #include "cmCryptoHash.h"
  19. #include "cmFastbuildTargetGenerator.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorTarget.h"
  23. #include "cmGlobalCommonGenerator.h"
  24. #include "cmGlobalFastbuildGenerator.h"
  25. #include "cmLinkLineComputer.h"
  26. #include "cmList.h"
  27. #include "cmListFileCache.h"
  28. #include "cmLocalCommonGenerator.h"
  29. #include "cmLocalFastbuildGenerator.h"
  30. #include "cmLocalGenerator.h"
  31. #include "cmMakefile.h"
  32. #include "cmOSXBundleGenerator.h"
  33. #include "cmObjectLocation.h"
  34. #include "cmOutputConverter.h"
  35. #include "cmSourceFile.h"
  36. #include "cmState.h"
  37. #include "cmStateDirectory.h"
  38. #include "cmStateSnapshot.h"
  39. #include "cmStateTypes.h"
  40. #include "cmStringAlgorithms.h"
  41. #include "cmSystemTools.h"
  42. #include "cmTarget.h"
  43. #include "cmTargetDepend.h"
  44. #include "cmValue.h"
  45. #include "cmake.h"
  46. namespace {
  47. std::string const COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
  48. std::string const COMPILE_OPTIONS("COMPILE_OPTIONS");
  49. std::string const COMPILE_FLAGS("COMPILE_FLAGS");
  50. std::string const CMAKE_LANGUAGE("CMAKE");
  51. std::string const INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
  52. } // anonymous namespace
  53. cmFastbuildNormalTargetGenerator::cmFastbuildNormalTargetGenerator(
  54. cmGeneratorTarget* gt, std::string configParam)
  55. : cmFastbuildTargetGenerator(gt, std::move(configParam))
  56. , RulePlaceholderExpander(
  57. this->LocalCommonGenerator->CreateRulePlaceholderExpander())
  58. , ObjectOutDir(this->GetGlobalGenerator()->ConvertToFastbuildPath(
  59. this->GeneratorTarget->GetObjectDirectory(Config)))
  60. , Languages(GetLanguages())
  61. , CompileObjectCmakeRules(GetCompileObjectCommand())
  62. {
  63. LogMessage(cmStrCat("objectOutDir: ", ObjectOutDir));
  64. this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(gt);
  65. this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
  66. // Quotes to account for potential spaces.
  67. RulePlaceholderExpander->SetTargetImpLib(
  68. "\"" FASTBUILD_DOLLAR_TAG "TargetOutputImplib" FASTBUILD_DOLLAR_TAG "\"");
  69. for (auto const& lang : Languages) {
  70. TargetIncludesByLanguage[lang] = this->GetIncludes(lang, Config);
  71. LogMessage("targetIncludes for lang " + lang + " = " +
  72. TargetIncludesByLanguage[lang]);
  73. for (auto const& arch : this->GetArches()) {
  74. auto& flags = CompileFlagsByLangAndArch[std::make_pair(lang, arch)];
  75. this->LocalCommonGenerator->GetTargetCompileFlags(
  76. this->GeneratorTarget, Config, lang, flags, arch);
  77. LogMessage(
  78. cmStrCat("Lang: ", lang, ", arch: ", arch, ", flags: ", flags));
  79. }
  80. }
  81. }
  82. std::string cmFastbuildNormalTargetGenerator::DetectCompilerFlags(
  83. cmSourceFile const& srcFile, std::string const& arch)
  84. {
  85. std::string const language = srcFile.GetLanguage();
  86. cmGeneratorExpressionInterpreter genexInterpreter(
  87. this->GetLocalGenerator(), Config, this->GeneratorTarget, language);
  88. std::vector<std::string> sourceIncludesVec;
  89. if (cmValue cincludes = srcFile.GetProperty(INCLUDE_DIRECTORIES)) {
  90. this->LocalGenerator->AppendIncludeDirectories(
  91. sourceIncludesVec,
  92. genexInterpreter.Evaluate(*cincludes, INCLUDE_DIRECTORIES), srcFile);
  93. }
  94. std::string sourceIncludesStr = this->LocalGenerator->GetIncludeFlags(
  95. sourceIncludesVec, this->GeneratorTarget, language, Config, false);
  96. LogMessage(cmStrCat("sourceIncludes = ", sourceIncludesStr));
  97. std::string compileFlags =
  98. CompileFlagsByLangAndArch[std::make_pair(language, arch)];
  99. this->GeneratorTarget->AddExplicitLanguageFlags(compileFlags, srcFile);
  100. if (cmValue const cflags = srcFile.GetProperty(COMPILE_FLAGS)) {
  101. this->LocalGenerator->AppendFlags(
  102. compileFlags, genexInterpreter.Evaluate(*cflags, COMPILE_FLAGS));
  103. }
  104. if (cmValue const coptions = srcFile.GetProperty(COMPILE_OPTIONS)) {
  105. this->LocalGenerator->AppendCompileOptions(
  106. compileFlags, genexInterpreter.Evaluate(*coptions, COMPILE_OPTIONS));
  107. }
  108. // Source includes take precedence over target includes.
  109. this->LocalGenerator->AppendFlags(compileFlags, sourceIncludesStr);
  110. this->LocalGenerator->AppendFlags(compileFlags,
  111. TargetIncludesByLanguage[language]);
  112. if (language == "Fortran") {
  113. this->AppendFortranFormatFlags(compileFlags, srcFile);
  114. this->AppendFortranPreprocessFlags(compileFlags, srcFile);
  115. }
  116. LogMessage(cmStrCat("compileFlags = ", compileFlags));
  117. return compileFlags;
  118. }
  119. void cmFastbuildNormalTargetGenerator::GetLinkerExecutableAndArgs(
  120. std::string const& command, std::string& outLinkerExecutable,
  121. std::string& outLinkerArgs)
  122. {
  123. if (command.empty()) {
  124. return;
  125. }
  126. LogMessage("Link Command: " + command);
  127. auto const& compilers = this->GetGlobalGenerator()->Compilers;
  128. auto const linkerLauncherVarName = FASTBUILD_LINKER_LAUNCHER_PREFIX +
  129. this->GeneratorTarget->GetLinkerLanguage(Config);
  130. auto const iter = compilers.find(linkerLauncherVarName);
  131. // Tested in "RunCMake.LinkerLauncher" test.
  132. if (iter != compilers.end()) {
  133. LogMessage("Linker launcher: " + iter->first);
  134. outLinkerExecutable = iter->second.Executable;
  135. outLinkerArgs = cmStrCat(iter->second.Args, " ", command);
  136. } else {
  137. #ifdef _WIN32
  138. std::vector<std::string> args;
  139. std::string tmp;
  140. cmSystemTools::SplitProgramFromArgs(command, tmp, outLinkerArgs);
  141. // cmLocalGenerator::GetStaticLibraryFlags seems to add empty quotes when
  142. // appending "STATIC_LIBRARY_FLAGS_DEBUG"...
  143. cmSystemTools::ReplaceString(outLinkerArgs, "\"\"", "");
  144. cmSystemTools::ParseWindowsCommandLine(command.c_str(), args);
  145. outLinkerExecutable = std::move(args[0]);
  146. #else
  147. cmSystemTools::SplitProgramFromArgs(command, outLinkerExecutable,
  148. outLinkerArgs);
  149. #endif
  150. }
  151. LogMessage("Linker Exe: " + outLinkerExecutable);
  152. LogMessage("Linker args: " + outLinkerArgs);
  153. }
  154. bool cmFastbuildNormalTargetGenerator::DetectBaseLinkerCommand(
  155. std::string& command, std::string const& arch,
  156. cmGeneratorTarget::Names const& targetNames)
  157. {
  158. std::string const linkLanguage =
  159. this->GeneratorTarget->GetLinkerLanguage(Config);
  160. if (linkLanguage.empty()) {
  161. cmSystemTools::Error("CMake can not determine linker language for "
  162. "target: " +
  163. this->GeneratorTarget->GetName());
  164. return false;
  165. }
  166. LogMessage("linkLanguage: " + linkLanguage);
  167. std::string linkLibs;
  168. std::string targetFlags;
  169. std::string linkFlags;
  170. std::string frameworkPath;
  171. // Tested in "RunCMake.StandardLinkDirectories" test.
  172. std::string linkPath;
  173. std::unique_ptr<cmLinkLineComputer> const linkLineComputer =
  174. this->GetGlobalGenerator()->CreateLinkLineComputer(
  175. this->LocalGenerator,
  176. this->GetLocalGenerator()->GetStateSnapshot().GetDirectory());
  177. this->LocalCommonGenerator->GetTargetFlags(
  178. linkLineComputer.get(), Config, linkLibs, targetFlags, linkFlags,
  179. frameworkPath, linkPath, this->GeneratorTarget);
  180. // cmLocalGenerator::GetStaticLibraryFlags seems to add empty quotes when
  181. // appending "STATIC_LIBRARY_FLAGS_DEBUG"...
  182. cmSystemTools::ReplaceString(linkFlags, "\"\"", "");
  183. LogMessage("linkLibs: " + linkLibs);
  184. LogMessage("targetFlags: " + targetFlags);
  185. LogMessage("linkFlags: " + linkFlags);
  186. LogMessage("frameworkPath: " + frameworkPath);
  187. LogMessage("linkPath: " + linkPath);
  188. LogMessage("MANIFESTS: " + this->GetManifests(Config));
  189. cmComputeLinkInformation* linkInfo =
  190. this->GeneratorTarget->GetLinkInformation(Config);
  191. if (!linkInfo) {
  192. return false;
  193. }
  194. // Tested in "RunCMake.RuntimePath" test.
  195. std::string const rpath = linkLineComputer->ComputeRPath(*linkInfo);
  196. LogMessage("RPath: " + rpath);
  197. if (!linkFlags.empty()) {
  198. linkFlags += " ";
  199. }
  200. linkFlags += cmJoin({ rpath, frameworkPath, linkPath }, " ");
  201. cmStateEnums::TargetType const targetType = this->GeneratorTarget->GetType();
  202. // Add OS X version flags, if any.
  203. if (targetType == cmStateEnums::SHARED_LIBRARY ||
  204. targetType == cmStateEnums::MODULE_LIBRARY) {
  205. this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true);
  206. this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false);
  207. }
  208. // Add Arch flags to link flags for binaries
  209. if (targetType == cmStateEnums::SHARED_LIBRARY ||
  210. targetType == cmStateEnums::MODULE_LIBRARY ||
  211. targetType == cmStateEnums::EXECUTABLE) {
  212. this->LocalCommonGenerator->AddArchitectureFlags(
  213. linkFlags, this->GeneratorTarget, linkLanguage, Config, arch);
  214. this->UseLWYU = this->GetLocalGenerator()->AppendLWYUFlags(
  215. linkFlags, this->GetGeneratorTarget(), linkLanguage);
  216. }
  217. cmRulePlaceholderExpander::RuleVariables vars;
  218. vars.CMTargetName = this->GeneratorTarget->GetName().c_str();
  219. vars.CMTargetType = cmState::GetTargetTypeName(targetType).c_str();
  220. vars.Language = linkLanguage.c_str();
  221. std::string const manifests =
  222. cmJoin(this->GetManifestsAsFastbuildPath(), " ");
  223. vars.Manifests = manifests.c_str();
  224. std::string const stdLibString = this->Makefile->GetSafeDefinition(
  225. cmStrCat("CMAKE_", linkLanguage, "_STANDARD_LIBRARIES"));
  226. LogMessage(cmStrCat("Target type: ", this->GeneratorTarget->GetType()));
  227. if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE ||
  228. this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  229. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  230. vars.Objects = FASTBUILD_1_0_INPUT_PLACEHOLDER;
  231. vars.LinkLibraries = stdLibString.c_str();
  232. } else {
  233. vars.Objects = FASTBUILD_1_INPUT_PLACEHOLDER;
  234. }
  235. vars.ObjectDir = FASTBUILD_DOLLAR_TAG "TargetOutDir" FASTBUILD_DOLLAR_TAG;
  236. vars.Target = FASTBUILD_2_INPUT_PLACEHOLDER;
  237. std::string install_dir;
  238. std::string target_so_name;
  239. if (this->GeneratorTarget->HasSOName(Config)) {
  240. vars.SONameFlag = this->Makefile->GetSONameFlag(
  241. this->GeneratorTarget->GetLinkerLanguage(Config));
  242. target_so_name =
  243. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(targetNames.SharedObject);
  244. vars.TargetSOName = target_so_name.c_str();
  245. // Tested in "RunCMake.RuntimePath / RunCMake.INSTALL_NAME_DIR"
  246. // tests.
  247. install_dir = this->LocalGenerator->ConvertToOutputFormat(
  248. this->GeneratorTarget->GetInstallNameDirForBuildTree(Config),
  249. cmOutputConverter::SHELL);
  250. vars.TargetInstallNameDir = install_dir.c_str();
  251. } else {
  252. vars.TargetSOName = "";
  253. }
  254. vars.TargetPDB = FASTBUILD_DOLLAR_TAG "LinkerPDB" FASTBUILD_DOLLAR_TAG;
  255. // Setup the target version.
  256. std::string targetVersionMajor;
  257. std::string targetVersionMinor;
  258. {
  259. std::ostringstream majorStream;
  260. std::ostringstream minorStream;
  261. int major;
  262. int minor;
  263. this->GeneratorTarget->GetTargetVersion(major, minor);
  264. majorStream << major;
  265. minorStream << minor;
  266. targetVersionMajor = majorStream.str();
  267. targetVersionMinor = minorStream.str();
  268. }
  269. vars.TargetVersionMajor = targetVersionMajor.c_str();
  270. vars.TargetVersionMinor = targetVersionMinor.c_str();
  271. vars.Defines =
  272. FASTBUILD_DOLLAR_TAG "CompileDefineFlags" FASTBUILD_DOLLAR_TAG;
  273. vars.Flags = targetFlags.c_str();
  274. vars.LinkFlags = linkFlags.c_str();
  275. vars.LanguageCompileFlags = "";
  276. std::string const linker = this->GeneratorTarget->GetLinkerTool(Config);
  277. vars.Linker = linker.c_str();
  278. std::string const targetSupportPath = this->ConvertToFastbuildPath(
  279. this->GetGeneratorTarget()->GetCMFSupportDirectory());
  280. vars.TargetSupportDir = targetSupportPath.c_str();
  281. LogMessage("linkFlags: " + linkFlags);
  282. LogMessage("linker: " + linker);
  283. std::string linkRule = GetLinkCommand();
  284. ApplyLinkRuleLauncher(linkRule);
  285. RulePlaceholderExpander->ExpandRuleVariables(
  286. dynamic_cast<cmLocalFastbuildGenerator*>(this->LocalCommonGenerator),
  287. linkRule, vars);
  288. command = std::move(linkRule);
  289. LogMessage(cmStrCat("Expanded link command: ", command));
  290. return true;
  291. }
  292. void cmFastbuildNormalTargetGenerator::ApplyLinkRuleLauncher(
  293. std::string& command)
  294. {
  295. std::string const val = this->GetLocalGenerator()->GetRuleLauncher(
  296. this->GetGeneratorTarget(), "RULE_LAUNCH_LINK", Config);
  297. if (cmNonempty(val)) {
  298. LogMessage("RULE_LAUNCH_LINK: " + val);
  299. command = cmStrCat(val, " ", command);
  300. }
  301. }
  302. void cmFastbuildNormalTargetGenerator::ApplyLWYUToLinkerCommand(
  303. FastbuildLinkerNode& linkerNode)
  304. {
  305. cmValue const lwyuCheck =
  306. this->Makefile->GetDefinition("CMAKE_LINK_WHAT_YOU_USE_CHECK");
  307. if (this->UseLWYU && lwyuCheck) {
  308. LogMessage("UseLWYU=true");
  309. std::string args = " -E __run_co_compile --lwyu=";
  310. args += this->GetLocalGenerator()->EscapeForShell(*lwyuCheck);
  311. args += cmStrCat(
  312. " --source=",
  313. this->ConvertToFastbuildPath(this->GetGeneratorTarget()->GetFullPath(
  314. Config, cmStateEnums::RuntimeBinaryArtifact,
  315. /*realname=*/true)));
  316. LogMessage("LWUY args: " + args);
  317. linkerNode.LinkerStampExe = cmSystemTools::GetCMakeCommand();
  318. linkerNode.LinkerStampExeArgs = std::move(args);
  319. }
  320. }
  321. std::string cmFastbuildNormalTargetGenerator::ComputeDefines(
  322. cmSourceFile const& srcFile)
  323. {
  324. std::string const language = srcFile.GetLanguage();
  325. std::set<std::string> defines;
  326. cmGeneratorExpressionInterpreter genexInterpreter(
  327. this->GetLocalGenerator(), Config, this->GeneratorTarget, language);
  328. if (auto compile_defs = srcFile.GetProperty(COMPILE_DEFINITIONS)) {
  329. this->GetLocalGenerator()->AppendDefines(
  330. defines, genexInterpreter.Evaluate(*compile_defs, COMPILE_DEFINITIONS));
  331. }
  332. std::string defPropName = "COMPILE_DEFINITIONS_";
  333. defPropName += cmSystemTools::UpperCase(Config);
  334. if (auto config_compile_defs = srcFile.GetProperty(defPropName)) {
  335. this->GetLocalGenerator()->AppendDefines(
  336. defines,
  337. genexInterpreter.Evaluate(*config_compile_defs, COMPILE_DEFINITIONS));
  338. }
  339. std::string definesString = this->GetDefines(language, Config);
  340. LogMessage(cmStrCat("TARGET DEFINES = ", definesString));
  341. this->GetLocalGenerator()->JoinDefines(defines, definesString, language);
  342. LogMessage(cmStrCat("DEFINES = ", definesString));
  343. return definesString;
  344. }
  345. void cmFastbuildNormalTargetGenerator::ComputePCH(
  346. cmSourceFile const& srcFile, FastbuildObjectListNode& node,
  347. std::set<std::string>& createdPCH)
  348. {
  349. if (srcFile.GetProperty("SKIP_PRECOMPILE_HEADERS")) {
  350. return;
  351. }
  352. // We have already computed PCH for this node.
  353. if (!node.PCHOptions.empty() || !node.PCHInputFile.empty() ||
  354. !node.PCHOutputFile.empty()) {
  355. return;
  356. }
  357. std::string const language = srcFile.GetLanguage();
  358. cmGeneratorExpressionInterpreter genexInterpreter(
  359. this->GetLocalGenerator(), Config, this->GeneratorTarget, language);
  360. //.cxx
  361. std::string const pchSource =
  362. this->GeneratorTarget->GetPchSource(Config, language);
  363. //.hxx
  364. std::string const pchHeader =
  365. this->GeneratorTarget->GetPchHeader(Config, language);
  366. //.pch
  367. std::string const pchFile =
  368. this->GeneratorTarget->GetPchFile(Config, language);
  369. if (pchHeader.empty() || pchFile.empty()) {
  370. return;
  371. }
  372. // In "RunCMake.GenEx-TARGET_PROPERTY" test we call set
  373. // CMAKE_PCH_EXTENSION="", so pchHeader becomes same as pchFile...
  374. if (pchHeader == pchFile) {
  375. LogMessage("pchHeader == pchFile > skipping");
  376. LogMessage("pchHeader: " + pchHeader);
  377. LogMessage("pchFile: " + pchFile);
  378. return;
  379. }
  380. node.PCHOutputFile =
  381. this->GetGlobalGenerator()->ConvertToFastbuildPath(pchFile);
  382. // Tell the ObjectList how to use PCH.
  383. std::string const pchUseOption =
  384. this->GeneratorTarget->GetPchUseCompileOptions(Config, language);
  385. LogMessage(cmStrCat("pchUseOption: ", pchUseOption));
  386. std::string origCompileOptions = node.CompilerOptions;
  387. for (auto const& opt :
  388. cmList{ genexInterpreter.Evaluate(pchUseOption, COMPILE_OPTIONS) }) {
  389. node.CompilerOptions += " ";
  390. node.CompilerOptions += opt;
  391. }
  392. if (!createdPCH.emplace(node.PCHOutputFile).second) {
  393. LogMessage(node.PCHOutputFile + " is already created by this target");
  394. return;
  395. }
  396. // Short circuit if the PCH has already been created by another target.
  397. if (!this->GeneratorTarget->GetSafeProperty("PRECOMPILE_HEADERS_REUSE_FROM")
  398. .empty()) {
  399. LogMessage(cmStrCat("PCH: ", node.PCHOutputFile,
  400. " already created by another target"));
  401. return;
  402. }
  403. node.PCHInputFile =
  404. this->GetGlobalGenerator()->ConvertToFastbuildPath(pchSource);
  405. std::string const pchCreateOptions =
  406. this->GeneratorTarget->GetPchCreateCompileOptions(Config, language);
  407. LogMessage(cmStrCat("pchCreateOptions: ", pchCreateOptions));
  408. char const* sep = "";
  409. for (auto const& opt : cmList{
  410. genexInterpreter.Evaluate(pchCreateOptions, COMPILE_OPTIONS) }) {
  411. node.PCHOptions += sep;
  412. node.PCHOptions += opt;
  413. sep = " ";
  414. }
  415. // Reuse compiler options for PCH options.
  416. node.PCHOptions += origCompileOptions;
  417. if (this->Makefile->GetSafeDefinition("CMAKE_" + language +
  418. "_COMPILER_ID") == "MSVC") {
  419. cmSystemTools::ReplaceString(node.PCHOptions,
  420. FASTBUILD_2_INPUT_PLACEHOLDER,
  421. FASTBUILD_3_INPUT_PLACEHOLDER);
  422. }
  423. LogMessage("PCH Source: " + pchSource);
  424. LogMessage("node.PCHInputFile: " + node.PCHInputFile);
  425. LogMessage("node.PCHOutputFile: " + node.PCHOutputFile);
  426. LogMessage("node.PCHOptions: " + node.PCHOptions);
  427. LogMessage("node.CompilerOptions: " + node.CompilerOptions);
  428. }
  429. void cmFastbuildNormalTargetGenerator::EnsureDirectoryExists(
  430. std::string const& path) const
  431. {
  432. if (cmSystemTools::FileIsFullPath(path.c_str())) {
  433. cmSystemTools::MakeDirectory(path.c_str());
  434. } else {
  435. auto* gg = this->GetGlobalGenerator();
  436. std::string fullPath = gg->GetCMakeInstance()->GetHomeOutputDirectory();
  437. // Also ensures there is a trailing slash.
  438. fullPath += path;
  439. cmSystemTools::MakeDirectory(fullPath);
  440. }
  441. }
  442. std::vector<std::string>
  443. cmFastbuildNormalTargetGenerator::GetManifestsAsFastbuildPath() const
  444. {
  445. std::vector<cmSourceFile const*> manifest_srcs;
  446. this->GeneratorTarget->GetManifests(manifest_srcs, Config);
  447. std::vector<std::string> manifests;
  448. manifests.reserve(manifest_srcs.size());
  449. for (auto& manifest_src : manifest_srcs) {
  450. std::string str = this->ConvertToFastbuildPath(
  451. cmSystemTools::ConvertToOutputPath(manifest_src->GetFullPath()));
  452. LogMessage("Manifest: " + str);
  453. manifests.emplace_back(std::move(str));
  454. }
  455. return manifests;
  456. }
  457. void cmFastbuildNormalTargetGenerator::GenerateModuleDefinitionInfo(
  458. FastbuildTarget& target) const
  459. {
  460. cmGeneratorTarget::ModuleDefinitionInfo const* mdi =
  461. GeneratorTarget->GetModuleDefinitionInfo(Config);
  462. if (mdi && mdi->DefFileGenerated) {
  463. FastbuildExecNode execNode;
  464. execNode.Name = target.Name + "-def-files";
  465. execNode.ExecExecutable = cmSystemTools::GetCMakeCommand();
  466. execNode.ExecArguments =
  467. cmStrCat("-E __create_def ", FASTBUILD_2_INPUT_PLACEHOLDER, " ",
  468. FASTBUILD_1_INPUT_PLACEHOLDER);
  469. std::string const obj_list_file = mdi->DefFile + ".objs";
  470. auto const nm_executable = GetMakefile()->GetDefinition("CMAKE_NM");
  471. if (!nm_executable.IsEmpty()) {
  472. execNode.ExecArguments += " --nm=";
  473. execNode.ExecArguments += ConvertToFastbuildPath(*nm_executable);
  474. }
  475. execNode.ExecOutput = ConvertToFastbuildPath(mdi->DefFile);
  476. execNode.ExecInput.push_back(ConvertToFastbuildPath(obj_list_file));
  477. // RunCMake.AutoExportDll
  478. for (auto const& objList : target.ObjectListNodes) {
  479. execNode.PreBuildDependencies.emplace(objList.Name);
  480. }
  481. // Tested in "RunCMake.AutoExportDll" / "ModuleDefinition" tests.
  482. for (auto& linkerNode : target.LinkerNode) {
  483. linkerNode.Libraries2.emplace_back(execNode.Name);
  484. }
  485. target.PreLinkExecNodes.Nodes.emplace_back(std::move(execNode));
  486. // create a list of obj files for the -E __create_def to read
  487. cmGeneratedFileStream fout(obj_list_file);
  488. // Since we generate this file once during configuration, we should not
  489. // remove it when "clean" is built.
  490. // Tested in "RunCMake.AutoExportDll" / "ModuleDefinition" tests.
  491. this->GetGlobalGenerator()->AllFilesToKeep.insert(obj_list_file);
  492. if (mdi->WindowsExportAllSymbols) {
  493. std::vector<cmSourceFile const*> objectSources;
  494. GeneratorTarget->GetObjectSources(objectSources, Config);
  495. std::map<cmSourceFile const*, cmObjectLocations> mapping;
  496. for (cmSourceFile const* it : objectSources) {
  497. mapping[it];
  498. }
  499. GeneratorTarget->LocalGenerator->ComputeObjectFilenames(mapping,
  500. GeneratorTarget);
  501. std::vector<std::string> objs;
  502. for (cmSourceFile const* it : objectSources) {
  503. auto const& v = mapping[it];
  504. LogMessage("Obj source : " + v.LongLoc.GetPath());
  505. std::string objFile = this->ConvertToFastbuildPath(
  506. GeneratorTarget->GetObjectDirectory(Config) + v.LongLoc.GetPath());
  507. objFile = cmSystemTools::ConvertToOutputPath(objFile);
  508. LogMessage("objFile path: " + objFile);
  509. objs.push_back(objFile);
  510. }
  511. std::vector<cmSourceFile const*> externalObjectSources;
  512. GeneratorTarget->GetExternalObjects(externalObjectSources, Config);
  513. for (cmSourceFile const* it : externalObjectSources) {
  514. objs.push_back(cmSystemTools::ConvertToOutputPath(
  515. this->ConvertToFastbuildPath(it->GetFullPath())));
  516. }
  517. for (std::string const& objFile : objs) {
  518. if (cmHasLiteralSuffix(objFile, ".obj")) {
  519. fout << objFile << "\n";
  520. }
  521. }
  522. }
  523. for (cmSourceFile const* src : mdi->Sources) {
  524. fout << src->GetFullPath() << "\n";
  525. }
  526. }
  527. }
  528. void cmFastbuildNormalTargetGenerator::AddPrebuildDeps(
  529. FastbuildTarget& target) const
  530. {
  531. // All ObjectLists should wait for PRE_BUILD.
  532. for (FastbuildObjectListNode& node : target.ObjectListNodes) {
  533. if (!target.PreBuildExecNodes.Name.empty()) {
  534. node.PreBuildDependencies.emplace(target.PreBuildExecNodes.Name);
  535. }
  536. if (!target.ExecNodes.Name.empty()) {
  537. node.PreBuildDependencies.emplace(target.ExecNodes.Name);
  538. }
  539. }
  540. for (auto& linkerNode : target.LinkerNode) {
  541. // Wait for 'PRE_BUILD' custom commands.
  542. if (!target.PreBuildExecNodes.Name.empty()) {
  543. linkerNode.PreBuildDependencies.emplace(target.PreBuildExecNodes.Name);
  544. }
  545. // Wait for regular custom commands.
  546. if (!target.ExecNodes.Name.empty()) {
  547. linkerNode.PreBuildDependencies.emplace(target.ExecNodes.Name);
  548. }
  549. // All targets that we depend on must be prebuilt.
  550. if (!target.DependenciesAlias.PreBuildDependencies.empty()) {
  551. linkerNode.PreBuildDependencies.emplace(target.DependenciesAlias.Name);
  552. }
  553. }
  554. }
  555. std::set<std::string> cmFastbuildNormalTargetGenerator::GetLanguages()
  556. {
  557. std::set<std::string> result;
  558. this->GetGeneratorTarget()->GetLanguages(result, Config);
  559. for (std::string const& lang : result) {
  560. this->GetGlobalGenerator()->AddCompiler(lang, this->GetMakefile());
  561. }
  562. LogMessage("Languages: " + cmJoin(result, ", "));
  563. return result;
  564. }
  565. std::unordered_map<std::string, std::string>
  566. cmFastbuildNormalTargetGenerator::GetCompileObjectCommand() const
  567. {
  568. std::unordered_map<std::string, std::string> result;
  569. result.reserve(Languages.size());
  570. for (std::string const& lang : Languages) {
  571. std::vector<std::string> commands;
  572. std::string cmakeVar;
  573. if (lang == "CUDA") {
  574. if (this->GeneratorTarget->GetPropertyAsBool(
  575. "CUDA_SEPARABLE_COMPILATION")) {
  576. cmakeVar = "CMAKE_CUDA_COMPILE_SEPARABLE_COMPILATION";
  577. } else if (this->GeneratorTarget->GetPropertyAsBool(
  578. "CUDA_PTX_COMPILATION")) {
  579. cmakeVar = "CMAKE_CUDA_COMPILE_PTX_COMPILATION";
  580. } else {
  581. cmakeVar = "CMAKE_CUDA_COMPILE_WHOLE_COMPILATION";
  582. }
  583. } else {
  584. cmakeVar = "CMAKE_";
  585. cmakeVar += lang;
  586. cmakeVar += "_COMPILE_OBJECT";
  587. }
  588. std::string cmakeValue =
  589. LocalCommonGenerator->GetMakefile()->GetSafeDefinition(cmakeVar);
  590. LogMessage(cmakeVar.append(" = ").append(cmakeValue));
  591. result[lang] = std::move(cmakeValue);
  592. }
  593. return result;
  594. }
  595. std::string cmFastbuildNormalTargetGenerator::GetLinkCommand() const
  596. {
  597. std::string const& linkLanguage = GeneratorTarget->GetLinkerLanguage(Config);
  598. std::string linkCmdVar =
  599. GeneratorTarget->GetCreateRuleVariable(linkLanguage, Config);
  600. std::string res = this->Makefile->GetSafeDefinition(linkCmdVar);
  601. if (res.empty() &&
  602. this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  603. linkCmdVar = linkCmdVar =
  604. cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_CREATE");
  605. res = this->Makefile->GetSafeDefinition(linkCmdVar);
  606. }
  607. LogMessage("Link rule: " + cmStrCat(linkCmdVar, " = ", res));
  608. return res;
  609. }
  610. void cmFastbuildNormalTargetGenerator::AddCompilerLaunchersForLanguages()
  611. {
  612. // General rule for all languages.
  613. std::string const launchCompile = this->GetLocalGenerator()->GetRuleLauncher(
  614. this->GetGeneratorTarget(), "RULE_LAUNCH_COMPILE", Config);
  615. // See if we need to use a compiler launcher like ccache or distcc
  616. for (std::string const& language : Languages) {
  617. std::string const compilerLauncher =
  618. cmCommonTargetGenerator::GetCompilerLauncher(language, Config);
  619. LogMessage("compilerLauncher: " + compilerLauncher);
  620. std::vector<std::string> expanded;
  621. cmExpandList(compilerLauncher, expanded);
  622. if (!expanded.empty()) {
  623. std::string const exe = expanded[0];
  624. expanded.erase(expanded.begin());
  625. this->GetGlobalGenerator()->AddLauncher(FASTBUILD_LAUNCHER_PREFIX, exe,
  626. language, cmJoin(expanded, " "));
  627. } else if (!launchCompile.empty()) {
  628. std::string exe;
  629. std::string args;
  630. cmSystemTools::SplitProgramFromArgs(launchCompile, exe, args);
  631. this->GetGlobalGenerator()->AddLauncher(FASTBUILD_LAUNCHER_PREFIX, exe,
  632. language, args);
  633. }
  634. }
  635. }
  636. void cmFastbuildNormalTargetGenerator::AddLinkerLauncher()
  637. {
  638. std::string const linkerLauncher =
  639. cmCommonTargetGenerator::GetLinkerLauncher(Config);
  640. std::vector<std::string> args;
  641. #ifdef _WIN32
  642. cmSystemTools::ParseWindowsCommandLine(linkerLauncher.c_str(), args);
  643. #else
  644. cmSystemTools::ParseUnixCommandLine(linkerLauncher.c_str(), args);
  645. #endif
  646. if (!args.empty()) {
  647. std::string const exe = std::move(args[0]);
  648. args.erase(args.begin());
  649. this->GetGlobalGenerator()->AddLauncher(
  650. FASTBUILD_LINKER_LAUNCHER_PREFIX, exe,
  651. this->GeneratorTarget->GetLinkerLanguage(Config), cmJoin(args, " "));
  652. }
  653. }
  654. void cmFastbuildNormalTargetGenerator::AddCMakeLauncher()
  655. {
  656. // Add CMake launcher (might be used for static analysis).
  657. this->GetGlobalGenerator()->AddLauncher(FASTBUILD_LAUNCHER_PREFIX,
  658. cmSystemTools::GetCMakeCommand(),
  659. CMAKE_LANGUAGE, "");
  660. }
  661. void cmFastbuildNormalTargetGenerator::ComputePaths(
  662. FastbuildTarget& target) const
  663. {
  664. std::string const objPath = GetGeneratorTarget()->GetSupportDirectory();
  665. EnsureDirectoryExists(objPath);
  666. target.Variables["TargetOutDir"] =
  667. cmSystemTools::ConvertToOutputPath(this->ConvertToFastbuildPath(objPath));
  668. if (GeneratorTarget->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  669. std::string const pdbDir = GeneratorTarget->GetPDBDirectory(Config);
  670. LogMessage("GetPDBDirectory: " + pdbDir);
  671. EnsureDirectoryExists(pdbDir);
  672. std::string const linkerPDB =
  673. cmStrCat(pdbDir, '/', this->GeneratorTarget->GetPDBName(Config));
  674. if (!linkerPDB.empty()) {
  675. target.Variables["LinkerPDB"] = cmSystemTools::ConvertToOutputPath(
  676. this->ConvertToFastbuildPath(linkerPDB));
  677. }
  678. }
  679. if (GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) {
  680. std::string const pdbDir = GeneratorTarget->GetCompilePDBDirectory(Config);
  681. LogMessage("GetCompilePDBDirectory: " + pdbDir);
  682. EnsureDirectoryExists(pdbDir);
  683. std::string pdbName = this->GeneratorTarget->GetCompilePDBName(Config);
  684. LogMessage("GetCompilePDBName: " + pdbDir);
  685. // If we don't have Compiler's PDB, we must add a trailing slash to satisfy
  686. // MSVC.
  687. bool needTrailingSlash = false;
  688. if (pdbName.empty()) {
  689. needTrailingSlash = true;
  690. }
  691. std::string const compilerPDB = cmStrCat(pdbDir, '\\', pdbName);
  692. if (!compilerPDB.empty()) {
  693. target.Variables["CompilerPDB"] = cmSystemTools::ConvertToOutputPath(
  694. this->ConvertToFastbuildPath(compilerPDB) +
  695. (needTrailingSlash ? "\\ " : ""));
  696. }
  697. }
  698. std::string impLibFile = ConvertToFastbuildPath(
  699. GeneratorTarget->GetFullPath(Config, cmStateEnums::ImportLibraryArtifact));
  700. cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(impLibFile));
  701. if (!impLibFile.empty()) {
  702. cmSystemTools::ConvertToOutputSlashes(impLibFile);
  703. target.Variables["TargetOutputImplib"] = std::move(impLibFile);
  704. }
  705. }
  706. void cmFastbuildNormalTargetGenerator::Generate()
  707. {
  708. this->GeneratorTarget->CheckCxxModuleStatus(Config);
  709. FastbuildTarget fastbuildTarget;
  710. fastbuildTarget.Name = GetTargetName();
  711. fastbuildTarget.BaseName = this->GeneratorTarget->GetName();
  712. LogMessage("<-------------->");
  713. LogMessage("Generate target: " + fastbuildTarget.Name);
  714. LogMessage("Config: " + Config);
  715. LogMessage("Deps: ");
  716. for (cmTargetDepend const& dep : TargetDirectDependencies) {
  717. auto const tname = dep->GetName();
  718. LogMessage(tname);
  719. FastbuildTargetDep targetDep{ tname };
  720. if (dep->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  721. targetDep.Type = FastbuildTargetDepType::ORDER_ONLY;
  722. } else {
  723. targetDep.Type = FastbuildTargetDepType::ALL;
  724. }
  725. fastbuildTarget.PreBuildDependencies.emplace(std::move(targetDep));
  726. }
  727. ComputePaths(fastbuildTarget);
  728. AddCompilerLaunchersForLanguages();
  729. AddLinkerLauncher();
  730. AddCMakeLauncher();
  731. for (auto& cc : GenerateCommands(FastbuildBuildStep::PRE_BUILD).Nodes) {
  732. fastbuildTarget.PreBuildExecNodes.PreBuildDependencies.emplace(cc.Name);
  733. fastbuildTarget.PreBuildDependencies.emplace(cc.Name);
  734. this->GetGlobalGenerator()->AddTarget(std::move(cc));
  735. }
  736. for (auto& cc : GenerateCommands(FastbuildBuildStep::PRE_LINK).Nodes) {
  737. cc.PreBuildDependencies.emplace(fastbuildTarget.Name +
  738. FASTBUILD_DEPS_ARTIFACTS_ALIAS_POSTFIX);
  739. fastbuildTarget.PreLinkExecNodes.Nodes.emplace_back(std::move(cc));
  740. }
  741. for (auto& cc : GenerateCommands(FastbuildBuildStep::REST).Nodes) {
  742. fastbuildTarget.ExecNodes.PreBuildDependencies.emplace(cc.Name);
  743. this->GetGlobalGenerator()->AddTarget(std::move(cc));
  744. }
  745. for (auto& cc : GenerateCommands(FastbuildBuildStep::POST_BUILD).Nodes) {
  746. fastbuildTarget.PostBuildExecNodes.Alias.PreBuildDependencies.emplace(
  747. cc.Name);
  748. fastbuildTarget.PostBuildExecNodes.Nodes.emplace_back(std::move(cc));
  749. }
  750. fastbuildTarget.ObjectListNodes = GenerateObjects();
  751. std::vector<std::string> objectDepends;
  752. AddObjectDependencies(fastbuildTarget, objectDepends);
  753. GenerateLink(fastbuildTarget, objectDepends);
  754. if (fastbuildTarget.LinkerNode.size() > 1) {
  755. if (!this->GeneratorTarget->IsApple()) {
  756. cmSystemTools::Error(
  757. "Can't handle more than 1 arch on non-Apple target");
  758. return;
  759. }
  760. AddLipoCommand(fastbuildTarget);
  761. }
  762. fastbuildTarget.CopyNodes = std::move(this->CopyNodes);
  763. // Generate symlink commands if real output name differs from "expected".
  764. for (auto& symlink : GetSymlinkExecs()) {
  765. fastbuildTarget.PostBuildExecNodes.Alias.PreBuildDependencies.emplace(
  766. symlink.Name);
  767. fastbuildTarget.PostBuildExecNodes.Nodes.emplace_back(std::move(symlink));
  768. }
  769. {
  770. auto appleTextStubCommand = GetAppleTextStubCommand();
  771. if (!appleTextStubCommand.Name.empty()) {
  772. fastbuildTarget.PostBuildExecNodes.Alias.PreBuildDependencies.emplace(
  773. appleTextStubCommand.Name);
  774. fastbuildTarget.PostBuildExecNodes.Nodes.emplace_back(
  775. std::move(appleTextStubCommand));
  776. }
  777. }
  778. AddPrebuildDeps(fastbuildTarget);
  779. fastbuildTarget.IsGlobal =
  780. GeneratorTarget->GetType() == cmStateEnums::GLOBAL_TARGET;
  781. fastbuildTarget.ExcludeFromAll =
  782. this->GetGlobalGenerator()->IsExcluded(GeneratorTarget);
  783. if (GeneratorTarget->GetPropertyAsBool("DONT_DISTRIBUTE")) {
  784. fastbuildTarget.AllowDistribution = false;
  785. }
  786. GenerateModuleDefinitionInfo(fastbuildTarget);
  787. // Needs to be called after we've added all PRE-LINK steps (like creation of
  788. // .def files on Windows).
  789. AddLinkerNodeDependnecies(fastbuildTarget);
  790. // Must be called after "GenerateObjects", since it also adds Prebuild deps
  791. // to it.
  792. // Also after "GenerateModuleDefinitionInfo", since uses PreLinkExecNodes.
  793. fastbuildTarget.GenerateAliases();
  794. if (!fastbuildTarget.ExecNodes.PreBuildDependencies.empty()) {
  795. fastbuildTarget.DependenciesAlias.PreBuildDependencies.emplace(
  796. fastbuildTarget.ExecNodes.Name);
  797. }
  798. fastbuildTarget.Hidden = false;
  799. fastbuildTarget.BasePath = this->GetMakefile()->GetCurrentSourceDirectory();
  800. this->GetGlobalGenerator()->AddIDEProject(fastbuildTarget, Config);
  801. AddStampExeIfApplicable(fastbuildTarget);
  802. AdditionalCleanFiles();
  803. this->GetGlobalGenerator()->AddTarget(std::move(fastbuildTarget));
  804. }
  805. void cmFastbuildNormalTargetGenerator::ProcessManifests(
  806. FastbuildLinkerNode& linkerNode) const
  807. {
  808. if (this->GetGlobalGenerator()->GetCMakeInstance()->GetIsInTryCompile()) {
  809. return;
  810. }
  811. auto manifests = this->GetManifestsAsFastbuildPath();
  812. if (manifests.empty()) {
  813. return;
  814. }
  815. // Manifests should always be in .Libraries2, so we re-link when needed.
  816. // Tested in RunCMake.BuildDepends
  817. for (auto const& manifest : manifests) {
  818. linkerNode.Libraries2.emplace_back(manifest);
  819. }
  820. if (this->Makefile->GetSafeDefinition("CMAKE_C_COMPILER_ID") != "MSVC") {
  821. return;
  822. }
  823. for (auto const& manifest : manifests) {
  824. linkerNode.LinkerOptions =
  825. cmStrCat("/MANIFESTINPUT:", manifest, ' ', linkerNode.LinkerOptions);
  826. }
  827. // /MANIFESTINPUT only works with /MANIFEST:EMBED
  828. linkerNode.LinkerOptions =
  829. cmStrCat("/MANIFEST:EMBED ", linkerNode.LinkerOptions);
  830. }
  831. void cmFastbuildNormalTargetGenerator::AddStampExeIfApplicable(
  832. FastbuildTarget& fastbuildTarget) const
  833. {
  834. LogMessage("AddStampExeIfApplicable(...)");
  835. if (fastbuildTarget.LinkerNode.empty() ||
  836. (fastbuildTarget.LinkerNode[0].Type != FastbuildLinkerNode::EXECUTABLE &&
  837. fastbuildTarget.LinkerNode[0].Type !=
  838. FastbuildLinkerNode::SHARED_LIBRARY)) {
  839. return;
  840. }
  841. // File which executes all POST_BUILD steps.
  842. // We use it in .LinkerStampExeArgs in order to run POST_BUILD steps after
  843. // the compilation.
  844. if (!fastbuildTarget.PostBuildExecNodes.Nodes.empty()) {
  845. std::string const AllPostBuildExecsScriptFile =
  846. cmStrCat(this->Makefile->GetHomeOutputDirectory(), "/CMakeFiles/",
  847. fastbuildTarget.Name,
  848. "-all-postbuild-commands" FASTBUILD_SCRIPT_FILE_EXTENSION);
  849. CollapseAllExecsIntoOneScriptfile(
  850. AllPostBuildExecsScriptFile, fastbuildTarget.PostBuildExecNodes.Nodes);
  851. auto& linkerNode = fastbuildTarget.LinkerNode.back();
  852. // On macOS, a target may have multiple linker nodes (e.g., for different
  853. // architectures). In that case, add the POST_BUILD step to only one node
  854. // to avoid running lipo multiple times.
  855. linkerNode.LinkerStampExe =
  856. cmGlobalFastbuildGenerator::GetExternalShellExecutable();
  857. linkerNode.LinkerStampExeArgs = FASTBUILD_SCRIPT_FILE_ARG;
  858. linkerNode.LinkerStampExeArgs +=
  859. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(
  860. AllPostBuildExecsScriptFile);
  861. } else {
  862. LogMessage("No POST_BUILD steps for target: " + fastbuildTarget.Name);
  863. }
  864. }
  865. void cmFastbuildNormalTargetGenerator::CollapseAllExecsIntoOneScriptfile(
  866. std::string const& scriptFileName,
  867. std::vector<FastbuildExecNode> const& execs) const
  868. {
  869. cmsys::ofstream scriptFile(scriptFileName.c_str());
  870. if (!scriptFile.is_open()) {
  871. cmSystemTools::Error("Failed to open: " + scriptFileName);
  872. return;
  873. }
  874. LogMessage("Writing collapsed Execs to " + scriptFileName);
  875. auto const shell = cmGlobalFastbuildGenerator::GetExternalShellExecutable();
  876. for (auto const& exec : execs) {
  877. if (exec.ScriptFile.empty()) {
  878. scriptFile << cmSystemTools::ConvertToOutputPath(exec.ExecExecutable)
  879. << " " << exec.ExecArguments << '\n';
  880. } else {
  881. #if defined(_WIN32)
  882. scriptFile << "call "
  883. << cmSystemTools::ConvertToWindowsOutputPath(exec.ScriptFile)
  884. << '\n';
  885. #else
  886. scriptFile << cmSystemTools::ConvertToOutputPath(shell) << " "
  887. << cmSystemTools::ConvertToOutputPath(exec.ScriptFile)
  888. << '\n';
  889. #endif
  890. }
  891. }
  892. }
  893. std::string cmFastbuildNormalTargetGenerator::ComputeCodeCheckOptions(
  894. cmSourceFile const& srcFile)
  895. {
  896. cmValue const skipCodeCheck = srcFile.GetProperty("SKIP_LINTING");
  897. std::string staticCheckRule;
  898. if (!skipCodeCheck.IsOn()) {
  899. std::string compilerLauncher;
  900. staticCheckRule = this->GenerateCodeCheckRules(srcFile, compilerLauncher,
  901. "", Config, nullptr);
  902. LogMessage(cmStrCat("CodeCheck: ", staticCheckRule));
  903. }
  904. return staticCheckRule;
  905. }
  906. void cmFastbuildNormalTargetGenerator::ComputeCompilerAndOptions(
  907. std::string const& compilerOptions, std::string const& staticCheckOptions,
  908. std::string const& language, FastbuildObjectListNode& outObjectList)
  909. {
  910. auto& compilers = this->GetGlobalGenerator()->Compilers;
  911. auto const compilerIter =
  912. compilers.find(FASTBUILD_COMPILER_PREFIX + language);
  913. auto const launcherIter =
  914. compilers.find(FASTBUILD_LAUNCHER_PREFIX + language);
  915. if (!staticCheckOptions.empty()) {
  916. // If we want to run static checks - use CMake as a launcher.
  917. // Tested in "RunCMake.ClangTidy", "RunCMake.IncludeWhatYouUse",
  918. // "RunCMake.Cpplint", "RunCMake.Cppcheck", "RunCMake.MultiLint" tests.
  919. outObjectList.Compiler = "." FASTBUILD_LAUNCHER_PREFIX + CMAKE_LANGUAGE;
  920. outObjectList.CompilerOptions = staticCheckOptions;
  921. // Add compile command which will be passed to the static analyzer via
  922. // dash-dash.
  923. if (compilerIter != compilers.end()) {
  924. // Wrap in quotes to account for potential spaces in the path.
  925. outObjectList.CompilerOptions +=
  926. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(
  927. compilerIter->second.Executable);
  928. outObjectList.CompilerOptions += compilerOptions;
  929. }
  930. } else if (launcherIter != compilers.end()) {
  931. // Tested in "RunCMake.CompilerLauncher" test.
  932. outObjectList.Compiler = "." + launcherIter->first;
  933. outObjectList.CompilerOptions = launcherIter->second.Args;
  934. auto vars = cmFastbuildNormalTargetGenerator::ComputeRuleVariables();
  935. vars.Language = language.c_str();
  936. std::string const targetSupportPath = this->ConvertToFastbuildPath(
  937. this->GetGeneratorTarget()->GetCMFSupportDirectory());
  938. vars.TargetSupportDir = targetSupportPath.c_str();
  939. RulePlaceholderExpander->ExpandRuleVariables(
  940. LocalCommonGenerator, outObjectList.CompilerOptions, vars);
  941. // Add compiler executable explicitly to the compile options.
  942. if (compilerIter != compilers.end()) {
  943. outObjectList.CompilerOptions += " ";
  944. // Wrap in quotes to account for potential spaces in the path.
  945. outObjectList.CompilerOptions +=
  946. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(
  947. compilerIter->second.Executable);
  948. outObjectList.CompilerOptions += compilerOptions;
  949. }
  950. } else if (compilerIter != compilers.end()) {
  951. outObjectList.Compiler = "." + compilerIter->first;
  952. outObjectList.CompilerOptions = compilerOptions;
  953. }
  954. LogMessage(cmStrCat(".Compiler = ", outObjectList.Compiler));
  955. LogMessage(cmStrCat(".CompilerOptions = ", outObjectList.CompilerOptions));
  956. }
  957. cmRulePlaceholderExpander::RuleVariables
  958. cmFastbuildNormalTargetGenerator::ComputeRuleVariables() const
  959. {
  960. cmRulePlaceholderExpander::RuleVariables compileObjectVars;
  961. compileObjectVars.CMTargetName = GeneratorTarget->GetName().c_str();
  962. compileObjectVars.CMTargetType =
  963. cmState::GetTargetTypeName(GeneratorTarget->GetType()).c_str();
  964. compileObjectVars.CMTargetLabels =
  965. this->GetGeneratorTarget()->GetTargetLabelsString().c_str();
  966. compileObjectVars.Source = FASTBUILD_1_INPUT_PLACEHOLDER;
  967. compileObjectVars.Object = FASTBUILD_2_INPUT_PLACEHOLDER;
  968. compileObjectVars.ObjectDir =
  969. FASTBUILD_DOLLAR_TAG "TargetOutputDir" FASTBUILD_DOLLAR_TAG;
  970. compileObjectVars.ObjectFileDir = "";
  971. compileObjectVars.Flags = "";
  972. compileObjectVars.Includes = "";
  973. compileObjectVars.Defines = "";
  974. compileObjectVars.Includes = "";
  975. compileObjectVars.TargetCompilePDB =
  976. FASTBUILD_DOLLAR_TAG "CompilerPDB" FASTBUILD_DOLLAR_TAG;
  977. compileObjectVars.Config = Config.c_str();
  978. return compileObjectVars;
  979. }
  980. std::vector<std::string> cmFastbuildNormalTargetGenerator::GetSourceProperty(
  981. cmSourceFile const& srcFile, std::string const& prop) const
  982. {
  983. std::vector<std::string> res;
  984. if (cmValue val = srcFile.GetProperty(prop)) {
  985. cmExpandList(*val, res);
  986. return GetGlobalGenerator()->ConvertToFastbuildPath(res);
  987. }
  988. return res;
  989. }
  990. void cmFastbuildNormalTargetGenerator::AppendExtraResources(
  991. std::set<std::string>& deps) const
  992. {
  993. // Generate Fastbuild's "Copy" commands to copy resources.
  994. auto const generateCopyCommands =
  995. [this](std::vector<cmSourceFile const*>& frameworkDeps) {
  996. this->OSXBundleGenerator->GenerateMacOSXContentStatements(
  997. frameworkDeps, this->MacOSXContentGenerator.get(), Config);
  998. };
  999. std::vector<cmSourceFile const*> headerSources;
  1000. this->GeneratorTarget->GetHeaderSources(headerSources, Config);
  1001. generateCopyCommands(headerSources);
  1002. std::vector<cmSourceFile const*> extraSources;
  1003. this->GeneratorTarget->GetExtraSources(extraSources, Config);
  1004. generateCopyCommands(extraSources);
  1005. std::vector<cmSourceFile const*> externalObjects;
  1006. this->GeneratorTarget->GetExternalObjects(externalObjects, Config);
  1007. generateCopyCommands(externalObjects);
  1008. for (FastbuildCopyNode const& node : this->CopyNodes) {
  1009. LogMessage("Adding resource: " + node.Name);
  1010. deps.emplace(node.Name);
  1011. }
  1012. }
  1013. std::string cmFastbuildNormalTargetGenerator::GetCompileOptions(
  1014. cmSourceFile const& srcFile, std::string const& arch)
  1015. {
  1016. std::string const language = srcFile.GetLanguage();
  1017. cmRulePlaceholderExpander::RuleVariables compileObjectVars =
  1018. ComputeRuleVariables();
  1019. std::string const compilerFlags = DetectCompilerFlags(srcFile, arch);
  1020. std::string const compilerDefines = ComputeDefines(srcFile);
  1021. compileObjectVars.Flags = compilerFlags.c_str();
  1022. compileObjectVars.Defines = compilerDefines.c_str();
  1023. compileObjectVars.Language = language.c_str();
  1024. std::string rule = CompileObjectCmakeRules.at(language);
  1025. RulePlaceholderExpander->ExpandRuleVariables(LocalCommonGenerator, rule,
  1026. compileObjectVars);
  1027. std::string compilerExecutable;
  1028. // Remove the compiler from .CompilerOptions, since it would be set as
  1029. // .Compiler in Fastbuild.
  1030. // See https://www.fastbuild.org/docs/functions/objectlist.html for a
  1031. // reference.
  1032. std::string options;
  1033. if (!cmSystemTools::SplitProgramFromArgs(rule, compilerExecutable,
  1034. options)) {
  1035. cmSystemTools::Error(cmStrCat("Failed to split compiler options: ", rule));
  1036. }
  1037. LogMessage("Expanded compile options = " + options);
  1038. LogMessage("Compiler executable = " + compilerExecutable);
  1039. return options;
  1040. }
  1041. std::vector<std::string> cmFastbuildNormalTargetGenerator::GetArches() const
  1042. {
  1043. auto arches = this->GetGeneratorTarget()->GetAppleArchs(Config, {});
  1044. // Don't add any arch-specific logic if arch is only one.
  1045. if (arches.empty() || arches.size() == 1) {
  1046. arches.clear();
  1047. arches.emplace_back();
  1048. }
  1049. return arches;
  1050. }
  1051. std::vector<FastbuildObjectListNode>
  1052. cmFastbuildNormalTargetGenerator::GenerateObjects()
  1053. {
  1054. this->GetGlobalGenerator()->AllFoldersToClean.insert(ObjectOutDir);
  1055. std::map<std::string, FastbuildObjectListNode> nodesPermutations;
  1056. cmCryptoHash hash(cmCryptoHash::AlgoSHA256);
  1057. std::vector<cmSourceFile const*> objectSources;
  1058. GeneratorTarget->GetObjectSources(objectSources, Config);
  1059. std::set<std::string> createdPCH;
  1060. for (cmSourceFile const* source : objectSources) {
  1061. cmSourceFile const& srcFile = *source;
  1062. // Do not generate separate node for PCH source file.
  1063. if (this->GeneratorTarget->GetPchSource(Config, srcFile.GetLanguage()) ==
  1064. srcFile.GetFullPath()) {
  1065. continue;
  1066. }
  1067. std::string const language = srcFile.GetLanguage();
  1068. LogMessage(cmStrCat("Source file: ",
  1069. this->ConvertToFastbuildPath(srcFile.GetFullPath())));
  1070. LogMessage("Language: " + language);
  1071. std::string const staticCheckOptions = ComputeCodeCheckOptions(srcFile);
  1072. for (auto const& arch : this->GetArches()) {
  1073. std::string const compileOptions = GetCompileOptions(srcFile, arch);
  1074. std::string objOutDirWithPossibleSubdir = ObjectOutDir;
  1075. // If object should be placed in some subdir in the output
  1076. // path. Tested in "SourceGroups" test.
  1077. auto const subdir = cmSystemTools::GetFilenamePath(
  1078. this->GeneratorTarget->GetObjectName(source));
  1079. if (!subdir.empty()) {
  1080. objOutDirWithPossibleSubdir += "/";
  1081. objOutDirWithPossibleSubdir += subdir;
  1082. }
  1083. std::string const objectListHash = hash.HashString(cmStrCat(
  1084. compileOptions, staticCheckOptions, objOutDirWithPossibleSubdir,
  1085. // If file does not need PCH - it must be in another ObjectList.
  1086. srcFile.GetProperty("SKIP_PRECOMPILE_HEADERS"),
  1087. srcFile.GetLanguage()));
  1088. LogMessage("ObjectList Hash: " + objectListHash);
  1089. FastbuildObjectListNode& objectListNode =
  1090. nodesPermutations[objectListHash];
  1091. // Absolute path needed in "RunCMake.SymlinkTrees" test.
  1092. objectListNode.CompilerInputFiles.push_back(srcFile.GetFullPath());
  1093. std::vector<std::string> const outputs =
  1094. GetSourceProperty(srcFile, "OBJECT_OUTPUTS");
  1095. objectListNode.ObjectOutputs.insert(outputs.begin(), outputs.end());
  1096. std::vector<std::string> const depends =
  1097. GetSourceProperty(srcFile, "OBJECT_DEPENDS");
  1098. objectListNode.ObjectDepends.insert(depends.begin(), depends.end());
  1099. // We have already computed properties that are computed below.
  1100. // (.CompilerOptions, .PCH*, etc.). Short circuit this iteration.
  1101. if (!objectListNode.CompilerOptions.empty()) {
  1102. continue;
  1103. }
  1104. objectListNode.CompilerOutputPath = objOutDirWithPossibleSubdir;
  1105. LogMessage(cmStrCat("Output path: ", objectListNode.CompilerOutputPath));
  1106. ComputeCompilerAndOptions(compileOptions, staticCheckOptions, language,
  1107. objectListNode);
  1108. ComputePCH(*source, objectListNode, createdPCH);
  1109. objectListNode.Name =
  1110. cmStrCat(language, "_ObjectGroup_", GetTargetName());
  1111. // TODO: Ask cmake the output objects and group by extension instead
  1112. // of doing this
  1113. if (language == "RC") {
  1114. objectListNode.CompilerOutputExtension = ".res";
  1115. } else {
  1116. if (!arch.empty()) {
  1117. objectListNode.CompilerOutputExtension = cmStrCat('.', arch);
  1118. objectListNode.arch = arch;
  1119. }
  1120. objectListNode.CompilerOutputExtension +=
  1121. this->GetMakefile()->GetSafeDefinition(
  1122. cmStrCat("CMAKE_", language, "_OUTPUT_EXTENSION"));
  1123. }
  1124. }
  1125. }
  1126. int groupNameCount = 1;
  1127. for (auto& val : nodesPermutations) {
  1128. auto& objectListNode = val.second;
  1129. objectListNode.Name =
  1130. cmStrCat(objectListNode.Name, "-", objectListNode.CompilerOutputPath,
  1131. "-", std::to_string(groupNameCount++));
  1132. LogMessage(cmStrCat("ObjectList name: ", objectListNode.Name));
  1133. }
  1134. std::vector<FastbuildObjectListNode> objects;
  1135. objects.reserve(nodesPermutations.size());
  1136. for (auto& val : nodesPermutations) {
  1137. auto& node = val.second;
  1138. objects.emplace_back(std::move(node));
  1139. if (!objects.back().PCHInputFile.empty()) {
  1140. // Node that produces PCH should be the first one, since other nodes
  1141. // might reuse this PCH.
  1142. std::swap(*objects.begin(), objects.back());
  1143. }
  1144. }
  1145. return objects;
  1146. }
  1147. std::string cmFastbuildNormalTargetGenerator::ResolveIfAlias(
  1148. std::string const& targetName) const
  1149. {
  1150. LogMessage("targetName: " + targetName);
  1151. std::map<std::string, std::string> const aliases =
  1152. this->Makefile->GetAliasTargets();
  1153. auto const iter = aliases.find(targetName);
  1154. if (iter != aliases.end()) {
  1155. LogMessage("Non alias name: " + iter->second);
  1156. return iter->second;
  1157. }
  1158. return targetName;
  1159. }
  1160. void cmFastbuildNormalTargetGenerator::AppendExternalObject(
  1161. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedDeps) const
  1162. {
  1163. // Different aspects of this logic exercised in "ObjectLibrary" and
  1164. // "ExportImport" test. When making changes here - verify that both of those
  1165. // tests are still passing.
  1166. LogMessage("AppendExternalObject(...)");
  1167. std::vector<cmSourceFile const*> extObjects;
  1168. this->GeneratorTarget->GetExternalObjects(extObjects, Config);
  1169. for (cmSourceFile const* src : extObjects) {
  1170. std::string const pathToObj =
  1171. this->ConvertToFastbuildPath(src->GetFullPath());
  1172. LogMessage("EXT OBJ: " + pathToObj);
  1173. std::string const objLibName = ResolveIfAlias(src->GetObjectLibrary());
  1174. LogMessage("GetObjectLibrary: " + objLibName);
  1175. // Tested in "ExternalOBJ" test.
  1176. cmTarget const* target =
  1177. this->GlobalCommonGenerator->FindTarget(objLibName);
  1178. if (objLibName.empty()) {
  1179. linkerNode.LibrarianAdditionalInputs.emplace_back(pathToObj);
  1180. }
  1181. // We know how to generate this target and haven't added this dependency
  1182. // yet.
  1183. else if (target) {
  1184. if (!linkedDeps.emplace(objLibName + FASTBUILD_OBJECTS_ALIAS_POSTFIX)
  1185. .second) {
  1186. LogMessage("Object Target: " + objLibName +
  1187. FASTBUILD_OBJECTS_ALIAS_POSTFIX " already linked");
  1188. continue;
  1189. }
  1190. linkerNode.LibrarianAdditionalInputs.emplace_back(
  1191. objLibName + FASTBUILD_OBJECTS_ALIAS_POSTFIX);
  1192. } else if (linkedDeps.emplace(pathToObj).second) {
  1193. LogMessage("Adding obj dep : " + pathToObj);
  1194. linkerNode.LibrarianAdditionalInputs.emplace_back(pathToObj);
  1195. }
  1196. }
  1197. }
  1198. void cmFastbuildNormalTargetGenerator::AppendExeToLink(
  1199. FastbuildLinkerNode& linkerNode,
  1200. cmComputeLinkInformation::Item const& item) const
  1201. {
  1202. std::string const decorated =
  1203. item.GetFormattedItem(this->ConvertToFastbuildPath(item.Value.Value))
  1204. .Value;
  1205. LogMessage("Linking to executable : " + decorated);
  1206. // Tested in "InterfaceLinkLibrariesDirect" and "Plugin" test.
  1207. linkerNode.LinkerOptions +=
  1208. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(decorated));
  1209. }
  1210. std::string cmFastbuildNormalTargetGenerator::GetImportedLoc(
  1211. cmComputeLinkInformation::Item const& item) const
  1212. {
  1213. // Link to import library when possible.
  1214. // Tested in "StagingPrefix" test on Windows/MSVC.
  1215. cmStateEnums::ArtifactType const artifact =
  1216. item.Target->HasImportLibrary(Config)
  1217. ? cmStateEnums::ImportLibraryArtifact
  1218. : cmStateEnums::RuntimeBinaryArtifact;
  1219. std::string importedLoc = this->ConvertToFastbuildPath(
  1220. item.Target->GetFullPath(Config, artifact, true));
  1221. LogMessage("ImportedGetLocation: " + importedLoc);
  1222. return importedLoc;
  1223. }
  1224. void cmFastbuildNormalTargetGenerator::AppendTargetDep(
  1225. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedObjects,
  1226. cmComputeLinkInformation::Item const& item) const
  1227. {
  1228. LogMessage("AppendTargetDep(...)");
  1229. cmStateEnums::TargetType const depType = item.Target->GetType();
  1230. LogMessage("Link dep type: " + std::to_string(depType));
  1231. LogMessage("Target name: " + item.Target->GetName());
  1232. auto const resolvedTargetName = ResolveIfAlias(item.Target->GetName());
  1233. LogMessage("Resolved: " + resolvedTargetName);
  1234. if (depType == cmStateEnums::INTERFACE_LIBRARY) {
  1235. return;
  1236. }
  1237. std::string const feature = item.GetFeatureName();
  1238. if (item.Target->IsImported()) {
  1239. if (feature == "FRAMEWORK") {
  1240. // Use just framework's name. The exact path where to look for the
  1241. // framework will be provided from "frameworkPath" in
  1242. // "cmFastbuildNormalTargetGenerator::DetectBaseLinkerCommand(...)".
  1243. // Tested in "RunCMake.Framework - ImportedFrameworkConsumption".
  1244. std::string const decorated =
  1245. item.GetFormattedItem(item.Value.Value).Value;
  1246. LogMessage("Adding framework dep <" + decorated + "> to command line");
  1247. linkerNode.LinkerOptions += (" " + decorated);
  1248. return;
  1249. }
  1250. if (depType == cmStateEnums::UNKNOWN_LIBRARY) {
  1251. LogMessage("Unknown library -- adding to LibrarianAdditionalInputs or "
  1252. "Libraries2");
  1253. if (UsingCommandLine) {
  1254. AppendCommandLineDep(linkerNode, item);
  1255. } else {
  1256. AppendLinkDep(linkerNode, GetImportedLoc(item));
  1257. }
  1258. return;
  1259. }
  1260. // Tested in "ExportImport" test.
  1261. if (depType == cmStateEnums::EXECUTABLE) {
  1262. AppendExeToLink(linkerNode, item);
  1263. return;
  1264. }
  1265. // Skip exported objects.
  1266. // Tested in "ExportImport" test.
  1267. if (depType == cmStateEnums::OBJECT_LIBRARY) {
  1268. LogMessage("target : " + item.Target->GetName() +
  1269. " already linked... Skipping");
  1270. return;
  1271. }
  1272. // Tested in "ExportImport" test.
  1273. cmList const list{ GetImportedLoc(item) };
  1274. for (std::string const& linkDep : list) {
  1275. AppendLinkDep(linkerNode, linkDep);
  1276. }
  1277. } else {
  1278. if (depType == cmStateEnums::SHARED_LIBRARY &&
  1279. this->GeneratorTarget->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED")) {
  1280. // It moves the dep outside of FASTBuild control, so the binary won't
  1281. // be re-built if the shared lib has changed.
  1282. // Tested in "BuildDepends" test.
  1283. LogMessage("LINK_DEPENDS_NO_SHARED is set on the target, adding dep" +
  1284. item.Value.Value + " as is");
  1285. linkerNode.LinkerOptions +=
  1286. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(item.Value.Value));
  1287. return;
  1288. }
  1289. // Just add path to binary artifact to command line (except for OBJECT
  1290. // libraries which we will link directly).
  1291. if (UsingCommandLine && depType != cmStateEnums::OBJECT_LIBRARY) {
  1292. AppendCommandLineDep(linkerNode, item);
  1293. return;
  1294. }
  1295. // This dep has a special way of linking to it (e.g.
  1296. // "CMAKE_LINK_LIBRARY_USING_<FEATURE>").
  1297. bool const isFeature = !feature.empty() && feature != "DEFAULT";
  1298. if (isFeature) {
  1299. std::string const decorated =
  1300. item.GetFormattedItem(this->ConvertToFastbuildPath(item.Value.Value))
  1301. .Value;
  1302. LogMessage("Prepending with feature: " + decorated);
  1303. linkerNode.LinkerOptions += (" " + decorated);
  1304. }
  1305. std::string dep = resolvedTargetName +
  1306. (depType == cmStateEnums::OBJECT_LIBRARY
  1307. ? FASTBUILD_OBJECTS_ALIAS_POSTFIX
  1308. : FASTBUILD_LINK_ARTIFACTS_ALIAS_POSTFIX);
  1309. if (!linkerNode.Arch.empty()) {
  1310. dep += cmStrCat('-', linkerNode.Arch);
  1311. }
  1312. // If we have a special way of linking the dep, we can't have it in
  1313. // ".Libraries" (since there might be multiple such deps, but
  1314. // FASTBuild expands ".Libraries" as a continuous array, so we can't
  1315. // inject any properties in between). Tested in
  1316. // "RunCMake.target_link_libraries-LINK_LIBRARY" test.
  1317. if (isFeature) {
  1318. LogMessage("AppendTargetDep: " + dep + " as prebuild");
  1319. linkerNode.PreBuildDependencies.emplace(dep);
  1320. return;
  1321. }
  1322. if (depType != cmStateEnums::OBJECT_LIBRARY ||
  1323. linkedObjects.emplace(dep).second) {
  1324. AppendLinkDep(linkerNode, dep);
  1325. }
  1326. AppendTransitivelyLinkedObjects(*item.Target, linkedObjects);
  1327. }
  1328. }
  1329. void cmFastbuildNormalTargetGenerator::AppendPrebuildDeps(
  1330. FastbuildLinkerNode& linkerNode,
  1331. cmComputeLinkInformation::Item const& item) const
  1332. {
  1333. if (!item.Target->IsImported()) {
  1334. return;
  1335. }
  1336. // In "RunCMake.FileAPI" imported object library "imported_object_lib" is
  1337. // added w/o import location...
  1338. if (item.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1339. return;
  1340. }
  1341. cmList const list{ GetImportedLoc(item) };
  1342. for (std::string const& linkDep : list) {
  1343. // In case we know how to generate this file (needed for proper
  1344. // sorting by deps). Tested in "RunCMake.target_link_libraries-ALIAS"
  1345. // test.
  1346. auto fastbuildTarget =
  1347. this->GetGlobalGenerator()->GetTargetByOutputName(linkDep);
  1348. std::string fastbuildTargetName;
  1349. if (fastbuildTarget) {
  1350. fastbuildTargetName = std::move(fastbuildTarget->Name);
  1351. }
  1352. if (!fastbuildTargetName.empty()) {
  1353. LogMessage("Adding dep to " + fastbuildTargetName);
  1354. linkerNode.PreBuildDependencies.insert(std::move(fastbuildTargetName));
  1355. } else {
  1356. LogMessage("Adding dep " + linkDep + " for sorting");
  1357. linkerNode.PreBuildDependencies.insert(linkDep);
  1358. }
  1359. }
  1360. }
  1361. void cmFastbuildNormalTargetGenerator::AppendTransitivelyLinkedObjects(
  1362. cmGeneratorTarget const& target, std::set<std::string>& linkedObjects) const
  1363. {
  1364. std::vector<std::string> objs;
  1365. // Consider that all those object are now linked as well.
  1366. // Tested in "ExportImport" test.
  1367. target.GetTargetObjectNames(Config, objs);
  1368. for (std::string const& obj : objs) {
  1369. std::string const pathToObj = this->ConvertToFastbuildPath(
  1370. cmStrCat(target.GetObjectDirectory(Config), '/', obj));
  1371. linkedObjects.insert(pathToObj);
  1372. }
  1373. // Object libs should not be propagated transitively. It's especially
  1374. // important for LinkObjRHSObject2 test where the absence of the propagation
  1375. // is tested.
  1376. for (auto const& linkedTarget :
  1377. target.Target->GetLinkImplementationEntries()) {
  1378. auto objAlias = linkedTarget.Value + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1379. LogMessage("Object target is linked transitively " + objAlias);
  1380. linkedObjects.emplace(std::move(objAlias));
  1381. }
  1382. }
  1383. void cmFastbuildNormalTargetGenerator::AppendCommandLineDep(
  1384. FastbuildLinkerNode& linkerNode,
  1385. cmComputeLinkInformation::Item const& item) const
  1386. {
  1387. LogMessage("AppendCommandLineDep(...)");
  1388. // Tested in:
  1389. // "LinkDirectory" (TargetType::EXECUTABLE),
  1390. // "ObjC.simple-build-test" (TargetType::SHARED_LIBRARY),
  1391. // "XCTest" (TargetType::MODULE_LIBRARY) tests.
  1392. std::string formatted;
  1393. if (item.Target && item.Target->IsImported()) {
  1394. formatted = GetImportedLoc(item);
  1395. } else {
  1396. formatted = item.GetFormattedItem(item.Value.Value).Value;
  1397. }
  1398. formatted = this->ConvertToFastbuildPath(formatted);
  1399. LogMessage("Unknown link dep: " + formatted + ", adding to command line");
  1400. // Only add real artifacts to .Libraries2, otherwise Fastbuild will always
  1401. // consider the target out-of-date (since its input doesn't exist).
  1402. if (item.IsPath == cmComputeLinkInformation::ItemIsPath::Yes &&
  1403. item.GetFeatureName() == "DEFAULT") {
  1404. linkerNode.LinkerOptions +=
  1405. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(formatted));
  1406. AppendToLibraries2IfApplicable(linkerNode, std::move(formatted));
  1407. } else {
  1408. // It's some link option, not a path.
  1409. linkerNode.LinkerOptions += (" " + formatted);
  1410. }
  1411. }
  1412. void cmFastbuildNormalTargetGenerator::AppendToLibraries2IfApplicable(
  1413. FastbuildLinkerNode& linkerNode, std::string dep) const
  1414. {
  1415. // Strings like "-framework Cocoa" in .Libraries2 node will always make the
  1416. // target out-of-date (since it never exists).
  1417. if (this->GeneratorTarget->IsApple() &&
  1418. cmSystemTools::StringStartsWith(dep, "-framework")) {
  1419. LogMessage("Not adding framework: " + dep + " to .Libraries2");
  1420. return;
  1421. }
  1422. auto const target = this->GetGlobalGenerator()->GetTargetByOutputName(dep);
  1423. // Fastbuild doesn't support executables in .Libraries2, though we can use
  1424. // Executables via "-bundle_loader" on Apple.
  1425. if (this->GeneratorTarget->IsApple() && target &&
  1426. !target->LinkerNode.empty() &&
  1427. target->LinkerNode[0].Type == FastbuildLinkerNode::EXECUTABLE) {
  1428. LogMessage("Not adding DLL/Executable(" + linkerNode.Name +
  1429. " to .Libraries2");
  1430. return;
  1431. }
  1432. // Additing to .Libraries2 for tracking.
  1433. LogMessage("Adding " + dep + " .Libraries2");
  1434. linkerNode.Libraries2.emplace_back(std::move(dep));
  1435. }
  1436. void cmFastbuildNormalTargetGenerator::AppendLINK_DEPENDS(
  1437. FastbuildLinkerNode& linkerNode) const
  1438. {
  1439. // LINK_DEPENDS and such.
  1440. // Tested in "BuildDepends" test.
  1441. for (std::string const& lang : Languages) {
  1442. for (BT<std::string> const& dep :
  1443. this->GeneratorTarget->GetLinkDepends(Config, lang)) {
  1444. // We can't add "LINK_DEPENDS" to .PreBuildDependencies, since FASTBuild
  1445. // only forces such targets to be built and doesn't force re-linking if
  1446. // they've changed.
  1447. linkerNode.Libraries2.emplace_back(
  1448. this->ConvertToFastbuildPath(dep.Value));
  1449. }
  1450. }
  1451. }
  1452. void cmFastbuildNormalTargetGenerator::AppendLinkDep(
  1453. FastbuildLinkerNode& linkerNode, std::string dep) const
  1454. {
  1455. LogMessage("AppendLinkDep: " + dep +
  1456. " to .LibrarianAdditionalInputs/.Libraries");
  1457. linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
  1458. }
  1459. void cmFastbuildNormalTargetGenerator::AppendDirectObjectLibs(
  1460. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedObjects)
  1461. {
  1462. auto const srcs = this->GeneratorTarget->GetSourceFiles(Config);
  1463. for (auto const& entry : srcs) {
  1464. auto const objLib = entry.Value->GetObjectLibrary();
  1465. auto const objPath = entry.Value->GetFullPath();
  1466. LogMessage("Source obj entry: " + objPath);
  1467. if (!objLib.empty()) {
  1468. auto* const objTarget =
  1469. this->LocalGenerator->FindGeneratorTargetToUse(objLib);
  1470. if (objTarget) {
  1471. LogMessage("Imported: " + std::to_string(objTarget->IsImported()));
  1472. std::string fastbuildTarget;
  1473. // If target is imported - we don't have it in our build file, so can't
  1474. // refer to it by name. Use file path to the object then.
  1475. // Tested in "ExportImport" test.
  1476. if (objTarget->IsImported()) {
  1477. fastbuildTarget = entry.Value->GetFullPath();
  1478. } else {
  1479. // Mark all target objects as linked.
  1480. linkedObjects.emplace(this->ConvertToFastbuildPath(objPath));
  1481. fastbuildTarget =
  1482. objTarget->GetName() + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1483. }
  1484. if (linkedObjects.emplace(fastbuildTarget).second) {
  1485. LogMessage("Adding object target: " + fastbuildTarget);
  1486. linkerNode.LibrarianAdditionalInputs.emplace_back(
  1487. std::move(fastbuildTarget));
  1488. }
  1489. }
  1490. }
  1491. }
  1492. }
  1493. void cmFastbuildNormalTargetGenerator::AppendLinkDeps(
  1494. std::set<FastbuildTargetDep>& preBuildDeps, FastbuildLinkerNode& linkerNode)
  1495. {
  1496. std::set<std::string> linkedObjects;
  1497. cmComputeLinkInformation const* linkInfo =
  1498. this->GeneratorTarget->GetLinkInformation(Config);
  1499. if (!linkInfo) {
  1500. return;
  1501. }
  1502. UsingCommandLine = false;
  1503. AppendLINK_DEPENDS(linkerNode);
  1504. // Object libs that are linked directly to target (e.g.
  1505. // add_executable(test_exe archiveObjs)
  1506. AppendDirectObjectLibs(linkerNode, linkedObjects);
  1507. // target_link_libraries.
  1508. cmComputeLinkInformation::ItemVector const items = linkInfo->GetItems();
  1509. LogMessage(cmStrCat("Link items size: ", items.size()));
  1510. for (cmComputeLinkInformation::Item const& item : items) {
  1511. std::string const feature = item.GetFeatureName();
  1512. LogMessage("GetFeatureName: " + feature);
  1513. if (!feature.empty()) {
  1514. LogMessage("GetFormattedItem: " +
  1515. item.GetFormattedItem(item.Value.Value).Value);
  1516. }
  1517. // We're linked to `$<TARGET_OBJECTS>`.
  1518. // Static libs transitively propagate such deps, see:
  1519. // https://cmake.org/cmake/help/latest/command/target_link_libraries.html#linking-object-libraries-via-target-objects
  1520. if (item.ObjectSource &&
  1521. linkerNode.Type != FastbuildLinkerNode::STATIC_LIBRARY) {
  1522. // Tested in "ObjectLibrary" test.
  1523. auto libName = item.ObjectSource->GetObjectLibrary();
  1524. std::string dep = libName + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1525. if (linkedObjects.emplace(dep).second) {
  1526. FastbuildTargetDep targetDep{ std::move(libName) };
  1527. targetDep.Type = FastbuildTargetDepType::ORDER_ONLY;
  1528. preBuildDeps.emplace(std::move(targetDep));
  1529. linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
  1530. }
  1531. } else if (linkerNode.Type == FastbuildLinkerNode::STATIC_LIBRARY) {
  1532. LogMessage("Skipping linking to STATIC_LIBRARY (" + linkerNode.Name +
  1533. ")");
  1534. continue;
  1535. }
  1536. // We're linked to exact target.
  1537. else if (item.Target) {
  1538. AppendTargetDep(linkerNode, linkedObjects, item);
  1539. AppendPrebuildDeps(linkerNode, item);
  1540. } else {
  1541. AppendCommandLineDep(linkerNode, item);
  1542. UsingCommandLine = true;
  1543. }
  1544. }
  1545. AppendExternalObject(linkerNode, linkedObjects);
  1546. }
  1547. void cmFastbuildNormalTargetGenerator::AddLipoCommand(FastbuildTarget& target)
  1548. {
  1549. static auto const lipo = cmSystemTools::FindProgram("lipo");
  1550. LogMessage("found lipo at " + lipo);
  1551. FastbuildExecNode exec;
  1552. exec.ExecExecutable = lipo;
  1553. exec.ExecOutput = target.RealOutput;
  1554. for (auto const& ArchSpecificTarget : target.LinkerNode) {
  1555. exec.ExecInput.emplace_back(ArchSpecificTarget.LinkerOutput);
  1556. }
  1557. exec.ExecArguments +=
  1558. "-create -output " + target.RealOutput + " " + cmJoin(exec.ExecInput, " ");
  1559. target.PostBuildExecNodes.Alias.PreBuildDependencies.emplace(
  1560. exec.ExecOutput);
  1561. target.PostBuildExecNodes.Nodes.emplace_back(std::move(exec));
  1562. }
  1563. void cmFastbuildNormalTargetGenerator::GenerateLink(
  1564. FastbuildTarget& target, std::vector<std::string> const& objectDepends)
  1565. {
  1566. std::string const targetName = this->GetTargetName();
  1567. cmGeneratorTarget::Names const targetNames = DetectOutput();
  1568. LogMessage("targetNames.Real: " + targetNames.Real);
  1569. LogMessage("targetNames.ImportOutput: " + targetNames.ImportOutput);
  1570. LogMessage("targetNames.SharedObject: " + targetNames.SharedObject);
  1571. LogMessage("targetNames.Base: " + targetNames.Base);
  1572. std::vector<std::string> allNodes;
  1573. auto const arches = this->GetArches();
  1574. for (std::size_t i = 0; i < arches.size(); ++i) {
  1575. auto const& arch = arches[i];
  1576. FastbuildLinkerNode linkerNode;
  1577. ProcessManifests(linkerNode);
  1578. // Objects built by the current target.
  1579. for (auto const& objectList : target.ObjectListNodes) {
  1580. if (objectList.arch.empty() || objectList.arch == arch) {
  1581. linkerNode.LibrarianAdditionalInputs.push_back(objectList.Name);
  1582. }
  1583. }
  1584. // Detection of the link command as follows:
  1585. auto const type = this->GeneratorTarget->GetType();
  1586. switch (type) {
  1587. case cmStateEnums::EXECUTABLE: {
  1588. LogMessage("Generating EXECUTABLE");
  1589. linkerNode.Type = FastbuildLinkerNode::EXECUTABLE;
  1590. break;
  1591. }
  1592. case cmStateEnums::MODULE_LIBRARY: {
  1593. LogMessage("Generating MODULE_LIBRARY");
  1594. linkerNode.Type = FastbuildLinkerNode::SHARED_LIBRARY;
  1595. break;
  1596. }
  1597. case cmStateEnums::SHARED_LIBRARY: {
  1598. LogMessage("Generating SHARED_LIBRARY");
  1599. linkerNode.Type = FastbuildLinkerNode::SHARED_LIBRARY;
  1600. break;
  1601. }
  1602. case cmStateEnums::STATIC_LIBRARY: {
  1603. LogMessage("Generating STATIC_LIBRARY");
  1604. linkerNode.Type = FastbuildLinkerNode::STATIC_LIBRARY;
  1605. break;
  1606. }
  1607. case cmStateEnums::OBJECT_LIBRARY: {
  1608. LogMessage("Generating OBJECT_LIBRARY");
  1609. return;
  1610. }
  1611. default: {
  1612. LogMessage("Skipping GenerateLink");
  1613. return;
  1614. }
  1615. }
  1616. std::string const targetOutput =
  1617. ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config));
  1618. std::string targetOutputReal = ConvertToFastbuildPath(
  1619. GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact,
  1620. /*realname=*/true));
  1621. LogMessage("targetOutput: " + targetOutput);
  1622. LogMessage("targetOutputReal: " + targetOutputReal);
  1623. std::string const output =
  1624. cmSystemTools::GetFilenameName(targetNames.Output);
  1625. std::string const outputReal =
  1626. cmSystemTools::GetFilenameName(targetNames.Real);
  1627. // Generate "Copy" nodes for copying Framework / Bundle resources.
  1628. AppendExtraResources(linkerNode.PreBuildDependencies);
  1629. if (type == cmStateEnums::EXECUTABLE ||
  1630. type == cmStateEnums::SHARED_LIBRARY) {
  1631. // Tested in "RunCMake.BuildDepends" test (we need to rebuild when
  1632. // manifest changes).
  1633. std::copy(objectDepends.begin(), objectDepends.end(),
  1634. std::back_inserter(linkerNode.Libraries2));
  1635. }
  1636. if (GeneratorTarget->IsAppBundleOnApple()) {
  1637. // Create the app bundle
  1638. std::string outpath = GeneratorTarget->GetDirectory(Config);
  1639. this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath,
  1640. Config);
  1641. targetOutputReal = outpath;
  1642. targetOutputReal += "/";
  1643. targetOutputReal += outputReal;
  1644. targetOutputReal = this->ConvertToFastbuildPath(targetOutputReal);
  1645. } else if (GeneratorTarget->IsFrameworkOnApple()) {
  1646. // Create the library framework.
  1647. this->OSXBundleGenerator->CreateFramework(
  1648. targetNames.Output, GeneratorTarget->GetDirectory(Config), Config);
  1649. } else if (GeneratorTarget->IsCFBundleOnApple()) {
  1650. // Create the core foundation bundle.
  1651. this->OSXBundleGenerator->CreateCFBundle(
  1652. targetNames.Output, GeneratorTarget->GetDirectory(Config), Config);
  1653. }
  1654. std::string linkCmd;
  1655. if (!DetectBaseLinkerCommand(linkCmd, arch, targetNames)) {
  1656. LogMessage("No linker command detected");
  1657. return;
  1658. }
  1659. std::string executable;
  1660. std::string linkerOptions;
  1661. std::string linkerType = "auto";
  1662. GetLinkerExecutableAndArgs(linkCmd, executable, linkerOptions);
  1663. linkerNode.Compiler = ".Compiler_dummy";
  1664. linkerNode.CompilerOptions = " ";
  1665. linkerNode.Name = targetName;
  1666. linkerNode.LinkerOutput = targetOutputReal;
  1667. this->GetGlobalGenerator()->AddFileToClean(linkerNode.LinkerOutput);
  1668. target.RealOutput = targetOutputReal;
  1669. if (!arch.empty()) {
  1670. linkerNode.Name += cmStrCat('-', arch);
  1671. linkerNode.LinkerOutput += cmStrCat('.', arch);
  1672. linkerNode.Arch = arch;
  1673. }
  1674. linkerNode.Linker = executable;
  1675. linkerNode.LinkerType = linkerType;
  1676. linkerNode.LinkerOptions += linkerOptions;
  1677. AppendLinkDeps(target.PreBuildDependencies, linkerNode);
  1678. ApplyLWYUToLinkerCommand(linkerNode);
  1679. // On macOS, only the last LinkerNode performs lipo in POST_BUILD.
  1680. // Make it depend on all previous nodes to ensure correct execution order.
  1681. if (i == arches.size() - 1) {
  1682. for (auto& prevNode : allNodes) {
  1683. linkerNode.PreBuildDependencies.emplace(std::move(prevNode));
  1684. }
  1685. } else {
  1686. allNodes.emplace_back(linkerNode.Name);
  1687. }
  1688. if (!target.ObjectListNodes.empty()) {
  1689. // Just reuse any of compiler options mainly for the correct IDE project
  1690. // generation.
  1691. linkerNode.CompilerOptions = target.ObjectListNodes[0].CompilerOptions;
  1692. }
  1693. target.LinkerNode.emplace_back(std::move(linkerNode));
  1694. }
  1695. }
  1696. std::vector<FastbuildExecNode>
  1697. cmFastbuildNormalTargetGenerator::GetSymlinkExecs() const
  1698. {
  1699. std::vector<FastbuildExecNode> res;
  1700. cmGeneratorTarget::Names const targetNames = DetectOutput();
  1701. LogMessage("targetNames.Real: " + targetNames.Real);
  1702. LogMessage("targetNames.ImportOutput: " + targetNames.ImportOutput);
  1703. LogMessage("targetNames.SharedObject: " + targetNames.SharedObject);
  1704. LogMessage("targetNames.Base: " + targetNames.Base);
  1705. std::string const targetOutput =
  1706. ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config));
  1707. std::string const targetOutputReal = ConvertToFastbuildPath(
  1708. GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact,
  1709. /*realname=*/true));
  1710. LogMessage("targetOutput: " + targetOutput);
  1711. LogMessage("targetOutputReal: " + targetOutputReal);
  1712. if (targetOutput != targetOutputReal &&
  1713. !GeneratorTarget->IsFrameworkOnApple()) {
  1714. auto const generateSymlinkCommand = [&](std::string const& from,
  1715. std::string const& to) {
  1716. if (from.empty() || to.empty() || from == to) {
  1717. return;
  1718. }
  1719. LogMessage("Symlinking " + from + " -> " + to);
  1720. FastbuildExecNode postBuildExecNode;
  1721. postBuildExecNode.Name = "cmake_symlink_" + to;
  1722. postBuildExecNode.ExecOutput =
  1723. cmJoin({ GeneratorTarget->GetDirectory(Config), to }, "/");
  1724. postBuildExecNode.ExecExecutable = cmSystemTools::GetCMakeCommand();
  1725. postBuildExecNode.ExecArguments =
  1726. "-E cmake_symlink_executable " +
  1727. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(from) + " " +
  1728. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(
  1729. this->ConvertToFastbuildPath(postBuildExecNode.ExecOutput));
  1730. res.emplace_back(std::move(postBuildExecNode));
  1731. };
  1732. generateSymlinkCommand(targetNames.Real, targetNames.Output);
  1733. generateSymlinkCommand(targetNames.Real, targetNames.SharedObject);
  1734. generateSymlinkCommand(targetNames.ImportReal, targetNames.ImportOutput);
  1735. }
  1736. return res;
  1737. }