cmFastbuildNormalTargetGenerator.cxx 73 KB

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