cmFastbuildNormalTargetGenerator.cxx 72 KB

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