cmFastbuildNormalTargetGenerator.cxx 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  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, Config,
  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. auto const isDisabled = [this](char const* prop) {
  1076. auto const propValue = this->GeneratorTarget->GetProperty(prop);
  1077. return propValue && propValue.IsOff();
  1078. };
  1079. bool const disableCaching = isDisabled("FASTBUILD_CACHING");
  1080. bool const disableDistribution = isDisabled("FASTBUILD_DISTRIBUTION");
  1081. for (auto const& arch : this->GetArches()) {
  1082. std::string const compileOptions = GetCompileOptions(srcFile, arch);
  1083. std::string objOutDirWithPossibleSubdir = ObjectOutDir;
  1084. // If object should be placed in some subdir in the output
  1085. // path. Tested in "SourceGroups" test.
  1086. auto const subdir = cmSystemTools::GetFilenamePath(
  1087. this->GeneratorTarget->GetObjectName(source));
  1088. if (!subdir.empty()) {
  1089. objOutDirWithPossibleSubdir += "/";
  1090. objOutDirWithPossibleSubdir += subdir;
  1091. }
  1092. std::string const objectListHash = hash.HashString(cmStrCat(
  1093. compileOptions, staticCheckOptions, objOutDirWithPossibleSubdir,
  1094. // If file does not need PCH - it must be in another ObjectList.
  1095. srcFile.GetProperty("SKIP_PRECOMPILE_HEADERS"),
  1096. srcFile.GetLanguage()));
  1097. LogMessage("ObjectList Hash: " + objectListHash);
  1098. FastbuildObjectListNode& objectListNode =
  1099. nodesPermutations[objectListHash];
  1100. // Absolute path needed in "RunCMake.SymlinkTrees" test.
  1101. objectListNode.CompilerInputFiles.push_back(srcFile.GetFullPath());
  1102. std::vector<std::string> const outputs =
  1103. GetSourceProperty(srcFile, "OBJECT_OUTPUTS");
  1104. objectListNode.ObjectOutputs.insert(outputs.begin(), outputs.end());
  1105. std::vector<std::string> const depends =
  1106. GetSourceProperty(srcFile, "OBJECT_DEPENDS");
  1107. objectListNode.ObjectDepends.insert(depends.begin(), depends.end());
  1108. // We have already computed properties that are computed below.
  1109. // (.CompilerOptions, .PCH*, etc.). Short circuit this iteration.
  1110. if (!objectListNode.CompilerOptions.empty()) {
  1111. continue;
  1112. }
  1113. if (disableCaching) {
  1114. objectListNode.AllowCaching = false;
  1115. }
  1116. if (disableDistribution) {
  1117. objectListNode.AllowDistribution = false;
  1118. }
  1119. objectListNode.CompilerOutputPath = objOutDirWithPossibleSubdir;
  1120. LogMessage(cmStrCat("Output path: ", objectListNode.CompilerOutputPath));
  1121. ComputeCompilerAndOptions(compileOptions, staticCheckOptions, language,
  1122. objectListNode);
  1123. ComputePCH(*source, objectListNode, createdPCH);
  1124. objectListNode.Name =
  1125. cmStrCat(language, "_ObjectGroup_", GetTargetName());
  1126. // TODO: Ask cmake the output objects and group by extension instead
  1127. // of doing this
  1128. if (language == "RC") {
  1129. objectListNode.CompilerOutputExtension = ".res";
  1130. } else {
  1131. if (!arch.empty()) {
  1132. objectListNode.CompilerOutputExtension = cmStrCat('.', arch);
  1133. objectListNode.arch = arch;
  1134. }
  1135. objectListNode.CompilerOutputExtension +=
  1136. this->GetMakefile()->GetSafeDefinition(
  1137. cmStrCat("CMAKE_", language, "_OUTPUT_EXTENSION"));
  1138. }
  1139. }
  1140. }
  1141. int groupNameCount = 1;
  1142. for (auto& val : nodesPermutations) {
  1143. auto& objectListNode = val.second;
  1144. objectListNode.Name =
  1145. cmStrCat(objectListNode.Name, "-", objectListNode.CompilerOutputPath,
  1146. "-", std::to_string(groupNameCount++));
  1147. LogMessage(cmStrCat("ObjectList name: ", objectListNode.Name));
  1148. }
  1149. std::vector<FastbuildObjectListNode> objects;
  1150. objects.reserve(nodesPermutations.size());
  1151. for (auto& val : nodesPermutations) {
  1152. auto& node = val.second;
  1153. objects.emplace_back(std::move(node));
  1154. if (!objects.back().PCHInputFile.empty()) {
  1155. // Node that produces PCH should be the first one, since other nodes
  1156. // might reuse this PCH.
  1157. std::swap(*objects.begin(), objects.back());
  1158. }
  1159. }
  1160. return objects;
  1161. }
  1162. std::string cmFastbuildNormalTargetGenerator::ResolveIfAlias(
  1163. std::string const& targetName) const
  1164. {
  1165. LogMessage("targetName: " + targetName);
  1166. std::map<std::string, std::string> const aliases =
  1167. this->Makefile->GetAliasTargets();
  1168. auto const iter = aliases.find(targetName);
  1169. if (iter != aliases.end()) {
  1170. LogMessage("Non alias name: " + iter->second);
  1171. return iter->second;
  1172. }
  1173. return targetName;
  1174. }
  1175. void cmFastbuildNormalTargetGenerator::AppendExternalObject(
  1176. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedDeps) const
  1177. {
  1178. // Different aspects of this logic exercised in "ObjectLibrary" and
  1179. // "ExportImport" test. When making changes here - verify that both of those
  1180. // tests are still passing.
  1181. LogMessage("AppendExternalObject(...)");
  1182. std::vector<cmSourceFile const*> extObjects;
  1183. this->GeneratorTarget->GetExternalObjects(extObjects, Config);
  1184. for (cmSourceFile const* src : extObjects) {
  1185. std::string const pathToObj =
  1186. this->ConvertToFastbuildPath(src->GetFullPath());
  1187. LogMessage("EXT OBJ: " + pathToObj);
  1188. std::string const objLibName = ResolveIfAlias(src->GetObjectLibrary());
  1189. LogMessage("GetObjectLibrary: " + objLibName);
  1190. // Tested in "ExternalOBJ" test.
  1191. cmTarget const* target =
  1192. this->GlobalCommonGenerator->FindTarget(objLibName);
  1193. if (objLibName.empty()) {
  1194. linkerNode.LibrarianAdditionalInputs.emplace_back(pathToObj);
  1195. }
  1196. // We know how to generate this target and haven't added this dependency
  1197. // yet.
  1198. else if (target) {
  1199. if (!linkedDeps.emplace(objLibName + FASTBUILD_OBJECTS_ALIAS_POSTFIX)
  1200. .second) {
  1201. LogMessage("Object Target: " + objLibName +
  1202. FASTBUILD_OBJECTS_ALIAS_POSTFIX " already linked");
  1203. continue;
  1204. }
  1205. linkerNode.LibrarianAdditionalInputs.emplace_back(
  1206. objLibName + FASTBUILD_OBJECTS_ALIAS_POSTFIX);
  1207. } else if (linkedDeps.emplace(pathToObj).second) {
  1208. LogMessage("Adding obj dep : " + pathToObj);
  1209. linkerNode.LibrarianAdditionalInputs.emplace_back(pathToObj);
  1210. }
  1211. }
  1212. }
  1213. void cmFastbuildNormalTargetGenerator::AppendExeToLink(
  1214. FastbuildLinkerNode& linkerNode,
  1215. cmComputeLinkInformation::Item const& item) const
  1216. {
  1217. std::string const decorated =
  1218. item.GetFormattedItem(this->ConvertToFastbuildPath(item.Value.Value))
  1219. .Value;
  1220. LogMessage("Linking to executable : " + decorated);
  1221. // Tested in "InterfaceLinkLibrariesDirect" and "Plugin" test.
  1222. linkerNode.LinkerOptions +=
  1223. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(decorated));
  1224. }
  1225. std::string cmFastbuildNormalTargetGenerator::GetImportedLoc(
  1226. cmComputeLinkInformation::Item const& item) const
  1227. {
  1228. // Link to import library when possible.
  1229. // Tested in "StagingPrefix" test on Windows/MSVC.
  1230. cmStateEnums::ArtifactType const artifact =
  1231. item.Target->HasImportLibrary(Config)
  1232. ? cmStateEnums::ImportLibraryArtifact
  1233. : cmStateEnums::RuntimeBinaryArtifact;
  1234. std::string importedLoc = this->ConvertToFastbuildPath(
  1235. item.Target->GetFullPath(Config, artifact, true));
  1236. LogMessage("ImportedGetLocation: " + importedLoc);
  1237. return importedLoc;
  1238. }
  1239. void cmFastbuildNormalTargetGenerator::AppendTargetDep(
  1240. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedObjects,
  1241. cmComputeLinkInformation::Item const& item) const
  1242. {
  1243. LogMessage("AppendTargetDep(...)");
  1244. cmStateEnums::TargetType const depType = item.Target->GetType();
  1245. LogMessage("Link dep type: " + std::to_string(depType));
  1246. LogMessage("Target name: " + item.Target->GetName());
  1247. auto const resolvedTargetName = ResolveIfAlias(item.Target->GetName());
  1248. LogMessage("Resolved: " + resolvedTargetName);
  1249. if (depType == cmStateEnums::INTERFACE_LIBRARY) {
  1250. return;
  1251. }
  1252. std::string const feature = item.GetFeatureName();
  1253. if (item.Target->IsImported()) {
  1254. if (feature == "FRAMEWORK") {
  1255. // Use just framework's name. The exact path where to look for the
  1256. // framework will be provided from "frameworkPath" in
  1257. // "cmFastbuildNormalTargetGenerator::DetectBaseLinkerCommand(...)".
  1258. // Tested in "RunCMake.Framework - ImportedFrameworkConsumption".
  1259. std::string const decorated =
  1260. item.GetFormattedItem(item.Value.Value).Value;
  1261. LogMessage("Adding framework dep <" + decorated + "> to command line");
  1262. linkerNode.LinkerOptions += (" " + decorated);
  1263. return;
  1264. }
  1265. if (depType == cmStateEnums::UNKNOWN_LIBRARY) {
  1266. LogMessage("Unknown library -- adding to LibrarianAdditionalInputs or "
  1267. "Libraries2");
  1268. if (UsingCommandLine) {
  1269. AppendCommandLineDep(linkerNode, item);
  1270. } else {
  1271. AppendLinkDep(linkerNode, GetImportedLoc(item));
  1272. }
  1273. return;
  1274. }
  1275. // Tested in "ExportImport" test.
  1276. if (depType == cmStateEnums::EXECUTABLE) {
  1277. AppendExeToLink(linkerNode, item);
  1278. return;
  1279. }
  1280. // Skip exported objects.
  1281. // Tested in "ExportImport" test.
  1282. if (depType == cmStateEnums::OBJECT_LIBRARY) {
  1283. LogMessage("target : " + item.Target->GetName() +
  1284. " already linked... Skipping");
  1285. return;
  1286. }
  1287. // Tested in "ExportImport" test.
  1288. cmList const list{ GetImportedLoc(item) };
  1289. for (std::string const& linkDep : list) {
  1290. AppendLinkDep(linkerNode, linkDep);
  1291. }
  1292. } else {
  1293. if (depType == cmStateEnums::SHARED_LIBRARY &&
  1294. this->GeneratorTarget->GetPropertyAsBool("LINK_DEPENDS_NO_SHARED")) {
  1295. // It moves the dep outside of FASTBuild control, so the binary won't
  1296. // be re-built if the shared lib has changed.
  1297. // Tested in "BuildDepends" test.
  1298. LogMessage("LINK_DEPENDS_NO_SHARED is set on the target, adding dep" +
  1299. item.Value.Value + " as is");
  1300. linkerNode.LinkerOptions +=
  1301. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(item.Value.Value));
  1302. return;
  1303. }
  1304. // Just add path to binary artifact to command line (except for OBJECT
  1305. // libraries which we will link directly).
  1306. if (UsingCommandLine && depType != cmStateEnums::OBJECT_LIBRARY) {
  1307. AppendCommandLineDep(linkerNode, item);
  1308. return;
  1309. }
  1310. // This dep has a special way of linking to it (e.g.
  1311. // "CMAKE_LINK_LIBRARY_USING_<FEATURE>").
  1312. bool const isFeature = !feature.empty() && feature != "DEFAULT";
  1313. if (isFeature) {
  1314. std::string const decorated =
  1315. item.GetFormattedItem(this->ConvertToFastbuildPath(item.Value.Value))
  1316. .Value;
  1317. LogMessage("Prepending with feature: " + decorated);
  1318. linkerNode.LinkerOptions += (" " + decorated);
  1319. }
  1320. std::string dep = resolvedTargetName +
  1321. (depType == cmStateEnums::OBJECT_LIBRARY
  1322. ? FASTBUILD_OBJECTS_ALIAS_POSTFIX
  1323. : FASTBUILD_LINK_ARTIFACTS_ALIAS_POSTFIX);
  1324. if (!linkerNode.Arch.empty()) {
  1325. dep += cmStrCat('-', linkerNode.Arch);
  1326. }
  1327. // If we have a special way of linking the dep, we can't have it in
  1328. // ".Libraries" (since there might be multiple such deps, but
  1329. // FASTBuild expands ".Libraries" as a continuous array, so we can't
  1330. // inject any properties in between). Tested in
  1331. // "RunCMake.target_link_libraries-LINK_LIBRARY" test.
  1332. if (isFeature) {
  1333. LogMessage("AppendTargetDep: " + dep + " as prebuild");
  1334. linkerNode.PreBuildDependencies.emplace(dep);
  1335. return;
  1336. }
  1337. if (depType != cmStateEnums::OBJECT_LIBRARY ||
  1338. linkedObjects.emplace(dep).second) {
  1339. AppendLinkDep(linkerNode, dep);
  1340. }
  1341. AppendTransitivelyLinkedObjects(*item.Target, linkedObjects);
  1342. }
  1343. }
  1344. void cmFastbuildNormalTargetGenerator::AppendPrebuildDeps(
  1345. FastbuildLinkerNode& linkerNode,
  1346. cmComputeLinkInformation::Item const& item) const
  1347. {
  1348. if (!item.Target->IsImported()) {
  1349. return;
  1350. }
  1351. // In "RunCMake.FileAPI" imported object library "imported_object_lib" is
  1352. // added w/o import location...
  1353. if (item.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1354. return;
  1355. }
  1356. cmList const list{ GetImportedLoc(item) };
  1357. for (std::string const& linkDep : list) {
  1358. // In case we know how to generate this file (needed for proper
  1359. // sorting by deps). Tested in "RunCMake.target_link_libraries-ALIAS"
  1360. // test.
  1361. auto fastbuildTarget =
  1362. this->GetGlobalGenerator()->GetTargetByOutputName(linkDep);
  1363. std::string fastbuildTargetName;
  1364. if (fastbuildTarget) {
  1365. fastbuildTargetName = std::move(fastbuildTarget->Name);
  1366. }
  1367. if (!fastbuildTargetName.empty()) {
  1368. LogMessage("Adding dep to " + fastbuildTargetName);
  1369. linkerNode.PreBuildDependencies.insert(std::move(fastbuildTargetName));
  1370. } else {
  1371. LogMessage("Adding dep " + linkDep + " for sorting");
  1372. linkerNode.PreBuildDependencies.insert(linkDep);
  1373. }
  1374. }
  1375. }
  1376. void cmFastbuildNormalTargetGenerator::AppendTransitivelyLinkedObjects(
  1377. cmGeneratorTarget const& target, std::set<std::string>& linkedObjects) const
  1378. {
  1379. std::vector<std::string> objs;
  1380. // Consider that all those object are now linked as well.
  1381. // Tested in "ExportImport" test.
  1382. target.GetTargetObjectNames(Config, objs);
  1383. for (std::string const& obj : objs) {
  1384. std::string const pathToObj = this->ConvertToFastbuildPath(
  1385. cmStrCat(target.GetObjectDirectory(Config), '/', obj));
  1386. linkedObjects.insert(pathToObj);
  1387. }
  1388. // Object libs should not be propagated transitively. It's especially
  1389. // important for LinkObjRHSObject2 test where the absence of the propagation
  1390. // is tested.
  1391. for (auto const& linkedTarget :
  1392. target.Target->GetLinkImplementationEntries()) {
  1393. auto objAlias = linkedTarget.Value + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1394. LogMessage("Object target is linked transitively " + objAlias);
  1395. linkedObjects.emplace(std::move(objAlias));
  1396. }
  1397. }
  1398. void cmFastbuildNormalTargetGenerator::AppendCommandLineDep(
  1399. FastbuildLinkerNode& linkerNode,
  1400. cmComputeLinkInformation::Item const& item) const
  1401. {
  1402. LogMessage("AppendCommandLineDep(...)");
  1403. // Tested in:
  1404. // "LinkDirectory" (TargetType::EXECUTABLE),
  1405. // "ObjC.simple-build-test" (TargetType::SHARED_LIBRARY),
  1406. // "XCTest" (TargetType::MODULE_LIBRARY) tests.
  1407. std::string formatted;
  1408. if (item.Target && item.Target->IsImported()) {
  1409. formatted = GetImportedLoc(item);
  1410. } else {
  1411. formatted = item.GetFormattedItem(item.Value.Value).Value;
  1412. }
  1413. formatted = this->ConvertToFastbuildPath(formatted);
  1414. LogMessage("Unknown link dep: " + formatted + ", adding to command line");
  1415. // Only add real artifacts to .Libraries2, otherwise Fastbuild will always
  1416. // consider the target out-of-date (since its input doesn't exist).
  1417. if (item.IsPath == cmComputeLinkInformation::ItemIsPath::Yes &&
  1418. item.GetFeatureName() == "DEFAULT") {
  1419. linkerNode.LinkerOptions +=
  1420. (" " + cmGlobalFastbuildGenerator::QuoteIfHasSpaces(formatted));
  1421. AppendToLibraries2IfApplicable(linkerNode, std::move(formatted));
  1422. } else {
  1423. // It's some link option, not a path.
  1424. linkerNode.LinkerOptions += (" " + formatted);
  1425. }
  1426. }
  1427. void cmFastbuildNormalTargetGenerator::AppendToLibraries2IfApplicable(
  1428. FastbuildLinkerNode& linkerNode, std::string dep) const
  1429. {
  1430. // Strings like "-framework Cocoa" in .Libraries2 node will always make the
  1431. // target out-of-date (since it never exists).
  1432. if (this->GeneratorTarget->IsApple() &&
  1433. cmSystemTools::StringStartsWith(dep, "-framework")) {
  1434. LogMessage("Not adding framework: " + dep + " to .Libraries2");
  1435. return;
  1436. }
  1437. auto const target = this->GetGlobalGenerator()->GetTargetByOutputName(dep);
  1438. // Fastbuild doesn't support executables in .Libraries2, though we can use
  1439. // Executables via "-bundle_loader" on Apple.
  1440. if (this->GeneratorTarget->IsApple() && target &&
  1441. !target->LinkerNode.empty() &&
  1442. target->LinkerNode[0].Type == FastbuildLinkerNode::EXECUTABLE) {
  1443. LogMessage("Not adding DLL/Executable(" + linkerNode.Name +
  1444. " to .Libraries2");
  1445. return;
  1446. }
  1447. // Additing to .Libraries2 for tracking.
  1448. LogMessage("Adding " + dep + " .Libraries2");
  1449. linkerNode.Libraries2.emplace_back(std::move(dep));
  1450. }
  1451. void cmFastbuildNormalTargetGenerator::AppendLINK_DEPENDS(
  1452. FastbuildLinkerNode& linkerNode) const
  1453. {
  1454. // LINK_DEPENDS and such.
  1455. // Tested in "BuildDepends" test.
  1456. for (std::string const& lang : Languages) {
  1457. for (BT<std::string> const& dep :
  1458. this->GeneratorTarget->GetLinkDepends(Config, lang)) {
  1459. // We can't add "LINK_DEPENDS" to .PreBuildDependencies, since FASTBuild
  1460. // only forces such targets to be built and doesn't force re-linking if
  1461. // they've changed.
  1462. linkerNode.Libraries2.emplace_back(
  1463. this->ConvertToFastbuildPath(dep.Value));
  1464. }
  1465. }
  1466. }
  1467. void cmFastbuildNormalTargetGenerator::AppendLinkDep(
  1468. FastbuildLinkerNode& linkerNode, std::string dep) const
  1469. {
  1470. LogMessage("AppendLinkDep: " + dep +
  1471. " to .LibrarianAdditionalInputs/.Libraries");
  1472. linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
  1473. }
  1474. void cmFastbuildNormalTargetGenerator::AppendDirectObjectLibs(
  1475. FastbuildLinkerNode& linkerNode, std::set<std::string>& linkedObjects)
  1476. {
  1477. auto const srcs = this->GeneratorTarget->GetSourceFiles(Config);
  1478. for (auto const& entry : srcs) {
  1479. auto const objLib = entry.Value->GetObjectLibrary();
  1480. auto const objPath = entry.Value->GetFullPath();
  1481. LogMessage("Source obj entry: " + objPath);
  1482. if (!objLib.empty()) {
  1483. auto* const objTarget =
  1484. this->LocalGenerator->FindGeneratorTargetToUse(objLib);
  1485. if (objTarget) {
  1486. LogMessage("Imported: " + std::to_string(objTarget->IsImported()));
  1487. std::string fastbuildTarget;
  1488. // If target is imported - we don't have it in our build file, so can't
  1489. // refer to it by name. Use file path to the object then.
  1490. // Tested in "ExportImport" test.
  1491. if (objTarget->IsImported()) {
  1492. fastbuildTarget = entry.Value->GetFullPath();
  1493. } else {
  1494. // Mark all target objects as linked.
  1495. linkedObjects.emplace(this->ConvertToFastbuildPath(objPath));
  1496. fastbuildTarget =
  1497. objTarget->GetName() + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1498. }
  1499. if (linkedObjects.emplace(fastbuildTarget).second) {
  1500. LogMessage("Adding object target: " + fastbuildTarget);
  1501. linkerNode.LibrarianAdditionalInputs.emplace_back(
  1502. std::move(fastbuildTarget));
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. void cmFastbuildNormalTargetGenerator::AppendLinkDeps(
  1509. std::set<FastbuildTargetDep>& preBuildDeps, FastbuildLinkerNode& linkerNode)
  1510. {
  1511. std::set<std::string> linkedObjects;
  1512. cmComputeLinkInformation const* linkInfo =
  1513. this->GeneratorTarget->GetLinkInformation(Config);
  1514. if (!linkInfo) {
  1515. return;
  1516. }
  1517. UsingCommandLine = false;
  1518. AppendLINK_DEPENDS(linkerNode);
  1519. // Object libs that are linked directly to target (e.g.
  1520. // add_executable(test_exe archiveObjs)
  1521. AppendDirectObjectLibs(linkerNode, linkedObjects);
  1522. // target_link_libraries.
  1523. cmComputeLinkInformation::ItemVector const items = linkInfo->GetItems();
  1524. LogMessage(cmStrCat("Link items size: ", items.size()));
  1525. for (cmComputeLinkInformation::Item const& item : items) {
  1526. std::string const feature = item.GetFeatureName();
  1527. LogMessage("GetFeatureName: " + feature);
  1528. if (!feature.empty()) {
  1529. LogMessage("GetFormattedItem: " +
  1530. item.GetFormattedItem(item.Value.Value).Value);
  1531. }
  1532. // We're linked to `$<TARGET_OBJECTS>`.
  1533. // Static libs transitively propagate such deps, see:
  1534. // https://cmake.org/cmake/help/latest/command/target_link_libraries.html#linking-object-libraries-via-target-objects
  1535. if (item.ObjectSource &&
  1536. linkerNode.Type != FastbuildLinkerNode::STATIC_LIBRARY) {
  1537. // Tested in "ObjectLibrary" test.
  1538. auto libName = item.ObjectSource->GetObjectLibrary();
  1539. std::string dep = libName + FASTBUILD_OBJECTS_ALIAS_POSTFIX;
  1540. if (linkedObjects.emplace(dep).second) {
  1541. FastbuildTargetDep targetDep{ std::move(libName) };
  1542. targetDep.Type = FastbuildTargetDepType::ORDER_ONLY;
  1543. preBuildDeps.emplace(std::move(targetDep));
  1544. linkerNode.LibrarianAdditionalInputs.emplace_back(std::move(dep));
  1545. }
  1546. } else if (linkerNode.Type == FastbuildLinkerNode::STATIC_LIBRARY) {
  1547. LogMessage("Skipping linking to STATIC_LIBRARY (" + linkerNode.Name +
  1548. ")");
  1549. continue;
  1550. }
  1551. // We're linked to exact target.
  1552. else if (item.Target) {
  1553. AppendTargetDep(linkerNode, linkedObjects, item);
  1554. AppendPrebuildDeps(linkerNode, item);
  1555. } else {
  1556. AppendCommandLineDep(linkerNode, item);
  1557. UsingCommandLine = true;
  1558. }
  1559. }
  1560. AppendExternalObject(linkerNode, linkedObjects);
  1561. }
  1562. void cmFastbuildNormalTargetGenerator::AddLipoCommand(FastbuildTarget& target)
  1563. {
  1564. static auto const lipo = cmSystemTools::FindProgram("lipo");
  1565. LogMessage("found lipo at " + lipo);
  1566. FastbuildExecNode exec;
  1567. exec.ExecExecutable = lipo;
  1568. exec.ExecOutput = target.RealOutput;
  1569. for (auto const& ArchSpecificTarget : target.LinkerNode) {
  1570. exec.ExecInput.emplace_back(ArchSpecificTarget.LinkerOutput);
  1571. }
  1572. exec.ExecArguments +=
  1573. "-create -output " + target.RealOutput + " " + cmJoin(exec.ExecInput, " ");
  1574. target.PostBuildExecNodes.Alias.PreBuildDependencies.emplace(
  1575. exec.ExecOutput);
  1576. target.PostBuildExecNodes.Nodes.emplace_back(std::move(exec));
  1577. }
  1578. void cmFastbuildNormalTargetGenerator::GenerateLink(
  1579. FastbuildTarget& target, std::vector<std::string> const& objectDepends)
  1580. {
  1581. std::string const targetName = this->GetTargetName();
  1582. cmGeneratorTarget::Names const targetNames = DetectOutput();
  1583. LogMessage("targetNames.Real: " + targetNames.Real);
  1584. LogMessage("targetNames.ImportOutput: " + targetNames.ImportOutput);
  1585. LogMessage("targetNames.SharedObject: " + targetNames.SharedObject);
  1586. LogMessage("targetNames.Base: " + targetNames.Base);
  1587. std::vector<std::string> allNodes;
  1588. auto const arches = this->GetArches();
  1589. for (std::size_t i = 0; i < arches.size(); ++i) {
  1590. auto const& arch = arches[i];
  1591. FastbuildLinkerNode linkerNode;
  1592. ProcessManifests(linkerNode);
  1593. // Objects built by the current target.
  1594. for (auto const& objectList : target.ObjectListNodes) {
  1595. if (objectList.arch.empty() || objectList.arch == arch) {
  1596. linkerNode.LibrarianAdditionalInputs.push_back(objectList.Name);
  1597. }
  1598. }
  1599. // Detection of the link command as follows:
  1600. auto const type = this->GeneratorTarget->GetType();
  1601. switch (type) {
  1602. case cmStateEnums::EXECUTABLE: {
  1603. LogMessage("Generating EXECUTABLE");
  1604. linkerNode.Type = FastbuildLinkerNode::EXECUTABLE;
  1605. break;
  1606. }
  1607. case cmStateEnums::MODULE_LIBRARY: {
  1608. LogMessage("Generating MODULE_LIBRARY");
  1609. linkerNode.Type = FastbuildLinkerNode::SHARED_LIBRARY;
  1610. break;
  1611. }
  1612. case cmStateEnums::SHARED_LIBRARY: {
  1613. LogMessage("Generating SHARED_LIBRARY");
  1614. linkerNode.Type = FastbuildLinkerNode::SHARED_LIBRARY;
  1615. break;
  1616. }
  1617. case cmStateEnums::STATIC_LIBRARY: {
  1618. LogMessage("Generating STATIC_LIBRARY");
  1619. linkerNode.Type = FastbuildLinkerNode::STATIC_LIBRARY;
  1620. break;
  1621. }
  1622. case cmStateEnums::OBJECT_LIBRARY: {
  1623. LogMessage("Generating OBJECT_LIBRARY");
  1624. return;
  1625. }
  1626. default: {
  1627. LogMessage("Skipping GenerateLink");
  1628. return;
  1629. }
  1630. }
  1631. std::string const targetOutput =
  1632. ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config));
  1633. std::string targetOutputReal = ConvertToFastbuildPath(
  1634. GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact,
  1635. /*realname=*/true));
  1636. LogMessage("targetOutput: " + targetOutput);
  1637. LogMessage("targetOutputReal: " + targetOutputReal);
  1638. std::string const output =
  1639. cmSystemTools::GetFilenameName(targetNames.Output);
  1640. std::string const outputReal =
  1641. cmSystemTools::GetFilenameName(targetNames.Real);
  1642. // Generate "Copy" nodes for copying Framework / Bundle resources.
  1643. AppendExtraResources(linkerNode.PreBuildDependencies);
  1644. if (type == cmStateEnums::EXECUTABLE ||
  1645. type == cmStateEnums::SHARED_LIBRARY) {
  1646. // Tested in "RunCMake.BuildDepends" test (we need to rebuild when
  1647. // manifest changes).
  1648. std::copy(objectDepends.begin(), objectDepends.end(),
  1649. std::back_inserter(linkerNode.Libraries2));
  1650. }
  1651. if (GeneratorTarget->IsAppBundleOnApple()) {
  1652. // Create the app bundle
  1653. std::string outpath = GeneratorTarget->GetDirectory(Config);
  1654. this->OSXBundleGenerator->CreateAppBundle(targetNames.Output, outpath,
  1655. Config);
  1656. targetOutputReal = outpath;
  1657. targetOutputReal += "/";
  1658. targetOutputReal += outputReal;
  1659. targetOutputReal = this->ConvertToFastbuildPath(targetOutputReal);
  1660. } else if (GeneratorTarget->IsFrameworkOnApple()) {
  1661. // Create the library framework.
  1662. this->OSXBundleGenerator->CreateFramework(
  1663. targetNames.Output, GeneratorTarget->GetDirectory(Config), Config);
  1664. } else if (GeneratorTarget->IsCFBundleOnApple()) {
  1665. // Create the core foundation bundle.
  1666. this->OSXBundleGenerator->CreateCFBundle(
  1667. targetNames.Output, GeneratorTarget->GetDirectory(Config), Config);
  1668. }
  1669. std::string linkCmd;
  1670. if (!DetectBaseLinkerCommand(linkCmd, arch, targetNames)) {
  1671. LogMessage("No linker command detected");
  1672. return;
  1673. }
  1674. std::string executable;
  1675. std::string linkerOptions;
  1676. std::string linkerType = "auto";
  1677. GetLinkerExecutableAndArgs(linkCmd, executable, linkerOptions);
  1678. linkerNode.Compiler = ".Compiler_dummy";
  1679. linkerNode.CompilerOptions = " ";
  1680. linkerNode.Name = targetName;
  1681. linkerNode.LinkerOutput = targetOutputReal;
  1682. this->GetGlobalGenerator()->AddFileToClean(linkerNode.LinkerOutput);
  1683. target.RealOutput = targetOutputReal;
  1684. if (!arch.empty()) {
  1685. linkerNode.Name += cmStrCat('-', arch);
  1686. linkerNode.LinkerOutput += cmStrCat('.', arch);
  1687. linkerNode.Arch = arch;
  1688. }
  1689. linkerNode.Linker = executable;
  1690. linkerNode.LinkerType = linkerType;
  1691. linkerNode.LinkerOptions += linkerOptions;
  1692. AppendLinkDeps(target.PreBuildDependencies, linkerNode);
  1693. ApplyLWYUToLinkerCommand(linkerNode);
  1694. // On macOS, only the last LinkerNode performs lipo in POST_BUILD.
  1695. // Make it depend on all previous nodes to ensure correct execution order.
  1696. if (i == arches.size() - 1) {
  1697. for (auto& prevNode : allNodes) {
  1698. linkerNode.PreBuildDependencies.emplace(std::move(prevNode));
  1699. }
  1700. } else {
  1701. allNodes.emplace_back(linkerNode.Name);
  1702. }
  1703. if (!target.ObjectListNodes.empty()) {
  1704. // Just reuse any of compiler options mainly for the correct IDE project
  1705. // generation.
  1706. linkerNode.CompilerOptions = target.ObjectListNodes[0].CompilerOptions;
  1707. }
  1708. target.LinkerNode.emplace_back(std::move(linkerNode));
  1709. }
  1710. }
  1711. std::vector<FastbuildExecNode>
  1712. cmFastbuildNormalTargetGenerator::GetSymlinkExecs() const
  1713. {
  1714. std::vector<FastbuildExecNode> res;
  1715. cmGeneratorTarget::Names const targetNames = DetectOutput();
  1716. LogMessage("targetNames.Real: " + targetNames.Real);
  1717. LogMessage("targetNames.ImportOutput: " + targetNames.ImportOutput);
  1718. LogMessage("targetNames.SharedObject: " + targetNames.SharedObject);
  1719. LogMessage("targetNames.Base: " + targetNames.Base);
  1720. std::string const targetOutput =
  1721. ConvertToFastbuildPath(GeneratorTarget->GetFullPath(Config));
  1722. std::string const targetOutputReal = ConvertToFastbuildPath(
  1723. GeneratorTarget->GetFullPath(Config, cmStateEnums::RuntimeBinaryArtifact,
  1724. /*realname=*/true));
  1725. LogMessage("targetOutput: " + targetOutput);
  1726. LogMessage("targetOutputReal: " + targetOutputReal);
  1727. if (targetOutput != targetOutputReal &&
  1728. !GeneratorTarget->IsFrameworkOnApple()) {
  1729. auto const generateSymlinkCommand = [&](std::string const& from,
  1730. std::string const& to) {
  1731. if (from.empty() || to.empty() || from == to) {
  1732. return;
  1733. }
  1734. LogMessage("Symlinking " + from + " -> " + to);
  1735. FastbuildExecNode postBuildExecNode;
  1736. postBuildExecNode.Name = "cmake_symlink_" + to;
  1737. postBuildExecNode.ExecOutput =
  1738. cmJoin({ GeneratorTarget->GetDirectory(Config), to }, "/");
  1739. postBuildExecNode.ExecExecutable = cmSystemTools::GetCMakeCommand();
  1740. postBuildExecNode.ExecArguments =
  1741. "-E cmake_symlink_executable " +
  1742. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(from) + " " +
  1743. cmGlobalFastbuildGenerator::QuoteIfHasSpaces(
  1744. this->ConvertToFastbuildPath(postBuildExecNode.ExecOutput));
  1745. res.emplace_back(std::move(postBuildExecNode));
  1746. };
  1747. generateSymlinkCommand(targetNames.Real, targetNames.Output);
  1748. generateSymlinkCommand(targetNames.Real, targetNames.SharedObject);
  1749. generateSymlinkCommand(targetNames.ImportReal, targetNames.ImportOutput);
  1750. }
  1751. return res;
  1752. }