cmMakefileLibraryTargetGenerator.cxx 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmMakefileLibraryTargetGenerator.h"
  4. #include <cstddef>
  5. #include <set>
  6. #include <sstream>
  7. #include <utility>
  8. #include <vector>
  9. #include <cm/memory>
  10. #include <cmext/algorithm>
  11. #include "cmGeneratedFileStream.h"
  12. #include "cmGeneratorTarget.h"
  13. #include "cmGlobalUnixMakefileGenerator3.h"
  14. #include "cmLinkLineComputer.h"
  15. #include "cmLinkLineDeviceComputer.h"
  16. #include "cmLocalGenerator.h"
  17. #include "cmLocalUnixMakefileGenerator3.h"
  18. #include "cmMakefile.h"
  19. #include "cmOSXBundleGenerator.h"
  20. #include "cmOutputConverter.h"
  21. #include "cmRulePlaceholderExpander.h"
  22. #include "cmState.h"
  23. #include "cmStateDirectory.h"
  24. #include "cmStateSnapshot.h"
  25. #include "cmStateTypes.h"
  26. #include "cmStringAlgorithms.h"
  27. #include "cmSystemTools.h"
  28. #include "cmValue.h"
  29. cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
  30. cmGeneratorTarget* target)
  31. : cmMakefileTargetGenerator(target)
  32. {
  33. this->CustomCommandDriver = OnDepends;
  34. if (this->GeneratorTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  35. this->TargetNames =
  36. this->GeneratorTarget->GetLibraryNames(this->GetConfigName());
  37. }
  38. this->OSXBundleGenerator = cm::make_unique<cmOSXBundleGenerator>(target);
  39. this->OSXBundleGenerator->SetMacContentFolders(&this->MacContentFolders);
  40. }
  41. cmMakefileLibraryTargetGenerator::~cmMakefileLibraryTargetGenerator() =
  42. default;
  43. void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
  44. {
  45. // create the build.make file and directory, put in the common blocks
  46. this->CreateRuleFile();
  47. // write rules used to help build object files
  48. this->WriteCommonCodeRules();
  49. // write the per-target per-language flags
  50. this->WriteTargetLanguageFlags();
  51. // write in rules for object files and custom commands
  52. this->WriteTargetBuildRules();
  53. // write the link rules
  54. // Write the rule for this target type.
  55. switch (this->GeneratorTarget->GetType()) {
  56. case cmStateEnums::STATIC_LIBRARY:
  57. this->WriteStaticLibraryRules();
  58. break;
  59. case cmStateEnums::SHARED_LIBRARY:
  60. this->WriteSharedLibraryRules(false);
  61. if (this->GeneratorTarget->NeedRelinkBeforeInstall(
  62. this->GetConfigName())) {
  63. // Write rules to link an installable version of the target.
  64. this->WriteSharedLibraryRules(true);
  65. }
  66. break;
  67. case cmStateEnums::MODULE_LIBRARY:
  68. this->WriteModuleLibraryRules(false);
  69. if (this->GeneratorTarget->NeedRelinkBeforeInstall(
  70. this->GetConfigName())) {
  71. // Write rules to link an installable version of the target.
  72. this->WriteModuleLibraryRules(true);
  73. }
  74. break;
  75. case cmStateEnums::OBJECT_LIBRARY:
  76. this->WriteObjectLibraryRules();
  77. break;
  78. default:
  79. // If language is not known, this is an error.
  80. cmSystemTools::Error("Unknown Library Type");
  81. break;
  82. }
  83. // Write clean target
  84. this->WriteTargetCleanRules();
  85. // Write the dependency generation rule. This must be done last so
  86. // that multiple output pair information is available.
  87. this->WriteTargetDependRules();
  88. // close the streams
  89. this->CloseFileStreams();
  90. }
  91. void cmMakefileLibraryTargetGenerator::WriteObjectLibraryRules()
  92. {
  93. std::vector<std::string> commands;
  94. std::vector<std::string> depends;
  95. // Add post-build rules.
  96. this->LocalGenerator->AppendCustomCommands(
  97. commands, this->GeneratorTarget->GetPostBuildCommands(),
  98. this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
  99. // Depend on the object files.
  100. this->AppendObjectDepends(depends);
  101. // Write the rule.
  102. this->LocalGenerator->WriteMakeRule(*this->BuildFileStream, nullptr,
  103. this->GeneratorTarget->GetName(),
  104. depends, commands, true);
  105. // Write the main driver rule to build everything in this target.
  106. this->WriteTargetDriverRule(this->GeneratorTarget->GetName(), false);
  107. }
  108. void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
  109. {
  110. const bool requiresDeviceLinking = requireDeviceLinking(
  111. *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
  112. if (requiresDeviceLinking) {
  113. this->WriteDeviceLibraryRules("CMAKE_CUDA_DEVICE_LINK_LIBRARY", false);
  114. }
  115. std::string linkLanguage =
  116. this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
  117. std::string linkRuleVar = this->GeneratorTarget->GetCreateRuleVariable(
  118. linkLanguage, this->GetConfigName());
  119. std::string extraFlags;
  120. this->LocalGenerator->GetStaticLibraryFlags(
  121. extraFlags, this->GetConfigName(), linkLanguage, this->GeneratorTarget);
  122. this->WriteLibraryRules(linkRuleVar, extraFlags, false);
  123. }
  124. void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
  125. {
  126. if (this->GeneratorTarget->IsFrameworkOnApple()) {
  127. this->WriteFrameworkRules(relink);
  128. return;
  129. }
  130. if (!relink) {
  131. const bool requiresDeviceLinking = requireDeviceLinking(
  132. *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
  133. if (requiresDeviceLinking) {
  134. this->WriteDeviceLibraryRules("CMAKE_CUDA_DEVICE_LINK_LIBRARY", relink);
  135. }
  136. }
  137. std::string linkLanguage =
  138. this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
  139. std::string linkRuleVar =
  140. cmStrCat("CMAKE_", linkLanguage, "_CREATE_SHARED_LIBRARY");
  141. std::string extraFlags;
  142. this->GetTargetLinkFlags(extraFlags, linkLanguage);
  143. this->LocalGenerator->AddConfigVariableFlags(
  144. extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->GetConfigName());
  145. std::unique_ptr<cmLinkLineComputer> linkLineComputer =
  146. this->CreateLinkLineComputer(
  147. this->LocalGenerator,
  148. this->LocalGenerator->GetStateSnapshot().GetDirectory());
  149. this->LocalGenerator->AppendModuleDefinitionFlag(
  150. extraFlags, this->GeneratorTarget, linkLineComputer.get(),
  151. this->GetConfigName());
  152. this->UseLWYU = this->LocalGenerator->AppendLWYUFlags(
  153. extraFlags, this->GeneratorTarget, linkLanguage);
  154. this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
  155. }
  156. void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
  157. {
  158. if (!relink) {
  159. const bool requiresDeviceLinking = requireDeviceLinking(
  160. *this->GeneratorTarget, *this->LocalGenerator, this->GetConfigName());
  161. if (requiresDeviceLinking) {
  162. this->WriteDeviceLibraryRules("CMAKE_CUDA_DEVICE_LINK_LIBRARY", relink);
  163. }
  164. }
  165. std::string linkLanguage =
  166. this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
  167. std::string linkRuleVar =
  168. cmStrCat("CMAKE_", linkLanguage, "_CREATE_SHARED_MODULE");
  169. std::string extraFlags;
  170. this->GetTargetLinkFlags(extraFlags, linkLanguage);
  171. this->LocalGenerator->AddConfigVariableFlags(
  172. extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->GetConfigName());
  173. std::unique_ptr<cmLinkLineComputer> linkLineComputer =
  174. this->CreateLinkLineComputer(
  175. this->LocalGenerator,
  176. this->LocalGenerator->GetStateSnapshot().GetDirectory());
  177. this->LocalGenerator->AppendModuleDefinitionFlag(
  178. extraFlags, this->GeneratorTarget, linkLineComputer.get(),
  179. this->GetConfigName());
  180. this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
  181. }
  182. void cmMakefileLibraryTargetGenerator::WriteFrameworkRules(bool relink)
  183. {
  184. std::string linkLanguage =
  185. this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
  186. std::string linkRuleVar =
  187. cmStrCat("CMAKE_", linkLanguage, "_CREATE_MACOSX_FRAMEWORK");
  188. std::string extraFlags;
  189. this->GetTargetLinkFlags(extraFlags, linkLanguage);
  190. this->LocalGenerator->AddConfigVariableFlags(
  191. extraFlags, "CMAKE_MACOSX_FRAMEWORK_LINKER_FLAGS", this->GetConfigName());
  192. this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
  193. }
  194. void cmMakefileLibraryTargetGenerator::WriteDeviceLibraryRules(
  195. const std::string& linkRuleVar, bool relink)
  196. {
  197. #ifndef CMAKE_BOOTSTRAP
  198. // TODO: Merge the methods that call this method to avoid
  199. // code duplication.
  200. std::vector<std::string> commands;
  201. std::string const objExt =
  202. this->Makefile->GetSafeDefinition("CMAKE_CUDA_OUTPUT_EXTENSION");
  203. // Get the name of the device object to generate.
  204. std::string const targetOutput =
  205. this->GeneratorTarget->ObjectDirectory + "cmake_device_link" + objExt;
  206. this->DeviceLinkObject = targetOutput;
  207. this->NumberOfProgressActions++;
  208. if (!this->NoRuleMessages) {
  209. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  210. this->MakeEchoProgress(progress);
  211. // Add the link message.
  212. std::string buildEcho = cmStrCat(
  213. "Linking CUDA device code ",
  214. this->LocalGenerator->ConvertToOutputFormat(
  215. this->LocalGenerator->MaybeRelativeToCurBinDir(this->DeviceLinkObject),
  216. cmOutputConverter::SHELL));
  217. this->LocalGenerator->AppendEcho(
  218. commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
  219. }
  220. if (this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID") == "Clang") {
  221. this->WriteDeviceLinkRule(commands, targetOutput);
  222. } else {
  223. this->WriteNvidiaDeviceLibraryRules(linkRuleVar, relink, commands,
  224. targetOutput);
  225. }
  226. // Write the main driver rule to build everything in this target.
  227. this->WriteTargetDriverRule(targetOutput, relink);
  228. }
  229. void cmMakefileLibraryTargetGenerator::WriteNvidiaDeviceLibraryRules(
  230. const std::string& linkRuleVar, bool relink,
  231. std::vector<std::string>& commands, const std::string& targetOutput)
  232. {
  233. std::string linkLanguage = "CUDA";
  234. // Build list of dependencies.
  235. std::vector<std::string> depends;
  236. this->AppendLinkDepends(depends, linkLanguage);
  237. // Add language-specific flags.
  238. std::string langFlags;
  239. this->LocalGenerator->AddLanguageFlagsForLinking(
  240. langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
  241. // Clean files associated with this library.
  242. std::set<std::string> libCleanFiles;
  243. libCleanFiles.insert(
  244. this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput));
  245. // Determine whether a link script will be used.
  246. bool useLinkScript = this->GlobalGenerator->GetUseLinkScript();
  247. bool useResponseFileForObjects =
  248. this->CheckUseResponseFileForObjects(linkLanguage);
  249. bool const useResponseFileForLibs =
  250. this->CheckUseResponseFileForLibraries(linkLanguage);
  251. cmRulePlaceholderExpander::RuleVariables vars;
  252. vars.Language = linkLanguage.c_str();
  253. // Expand the rule variables.
  254. std::vector<std::string> real_link_commands;
  255. {
  256. // Set path conversion for link script shells.
  257. this->LocalGenerator->SetLinkScriptShell(useLinkScript);
  258. // Collect up flags to link in needed libraries.
  259. std::string linkLibs;
  260. std::unique_ptr<cmLinkLineDeviceComputer> linkLineComputer(
  261. new cmLinkLineDeviceComputer(
  262. this->LocalGenerator,
  263. this->LocalGenerator->GetStateSnapshot().GetDirectory()));
  264. linkLineComputer->SetForResponse(useResponseFileForLibs);
  265. linkLineComputer->SetRelink(relink);
  266. // Create set of linking flags.
  267. std::string linkFlags;
  268. std::string ignored_;
  269. this->LocalGenerator->GetDeviceLinkFlags(
  270. *linkLineComputer, this->GetConfigName(), ignored_, linkFlags, ignored_,
  271. ignored_, this->GeneratorTarget);
  272. this->CreateLinkLibs(
  273. linkLineComputer.get(), linkLibs, useResponseFileForLibs, depends,
  274. cmMakefileTargetGenerator::ResponseFlagFor::DeviceLink);
  275. // Construct object file lists that may be needed to expand the
  276. // rule.
  277. std::string buildObjs;
  278. this->CreateObjectLists(
  279. useLinkScript, false, // useArchiveRules
  280. useResponseFileForObjects, buildObjs, depends, false,
  281. cmMakefileTargetGenerator::ResponseFlagFor::DeviceLink);
  282. std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
  283. objectDir = this->LocalGenerator->ConvertToOutputFormat(
  284. this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir),
  285. cmOutputConverter::SHELL);
  286. std::string target = this->LocalGenerator->ConvertToOutputFormat(
  287. this->LocalGenerator->MaybeRelativeToCurBinDir(targetOutput),
  288. cmOutputConverter::SHELL);
  289. std::string targetFullPathCompilePDB =
  290. this->ComputeTargetCompilePDB(this->GetConfigName());
  291. std::string targetOutPathCompilePDB =
  292. this->LocalGenerator->ConvertToOutputFormat(targetFullPathCompilePDB,
  293. cmOutputConverter::SHELL);
  294. vars.Objects = buildObjs.c_str();
  295. vars.ObjectDir = objectDir.c_str();
  296. vars.Target = target.c_str();
  297. vars.LinkLibraries = linkLibs.c_str();
  298. vars.ObjectsQuoted = buildObjs.c_str();
  299. vars.LanguageCompileFlags = langFlags.c_str();
  300. vars.LinkFlags = linkFlags.c_str();
  301. vars.TargetCompilePDB = targetOutPathCompilePDB.c_str();
  302. std::string launcher;
  303. std::string val = this->LocalGenerator->GetRuleLauncher(
  304. this->GeneratorTarget, "RULE_LAUNCH_LINK",
  305. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  306. if (cmNonempty(val)) {
  307. launcher = cmStrCat(val, ' ');
  308. }
  309. std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
  310. this->LocalGenerator->CreateRulePlaceholderExpander());
  311. // Construct the main link rule and expand placeholders.
  312. rulePlaceholderExpander->SetTargetImpLib(targetOutput);
  313. std::string linkRule = this->GetLinkRule(linkRuleVar);
  314. cmExpandList(linkRule, real_link_commands);
  315. // Expand placeholders.
  316. for (std::string& real_link_command : real_link_commands) {
  317. real_link_command = cmStrCat(launcher, real_link_command);
  318. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
  319. real_link_command, vars);
  320. }
  321. // Restore path conversion to normal shells.
  322. this->LocalGenerator->SetLinkScriptShell(false);
  323. // Clean all the possible library names and symlinks.
  324. this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end());
  325. }
  326. std::vector<std::string> commands1;
  327. // Optionally convert the build rule to use a script to avoid long
  328. // command lines in the make shell.
  329. if (useLinkScript) {
  330. // Use a link script.
  331. const char* name = (relink ? "drelink.txt" : "dlink.txt");
  332. this->CreateLinkScript(name, real_link_commands, commands1, depends);
  333. } else {
  334. // No link script. Just use the link rule directly.
  335. commands1 = real_link_commands;
  336. }
  337. this->LocalGenerator->CreateCDCommand(
  338. commands1, this->Makefile->GetCurrentBinaryDirectory(),
  339. this->LocalGenerator->GetBinaryDirectory());
  340. cm::append(commands, commands1);
  341. commands1.clear();
  342. // Compute the list of outputs.
  343. std::vector<std::string> outputs(1, targetOutput);
  344. // Write the build rule.
  345. this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
  346. commands, false);
  347. #else
  348. static_cast<void>(linkRuleVar);
  349. static_cast<void>(relink);
  350. #endif
  351. }
  352. void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
  353. const std::string& linkRuleVar, const std::string& extraFlags, bool relink)
  354. {
  355. // TODO: Merge the methods that call this method to avoid
  356. // code duplication.
  357. std::vector<std::string> commands;
  358. // Get the language to use for linking this library.
  359. std::string linkLanguage =
  360. this->GeneratorTarget->GetLinkerLanguage(this->GetConfigName());
  361. // Make sure we have a link language.
  362. if (linkLanguage.empty()) {
  363. cmSystemTools::Error("Cannot determine link language for target \"" +
  364. this->GeneratorTarget->GetName() + "\".");
  365. return;
  366. }
  367. // Build list of dependencies.
  368. std::vector<std::string> depends;
  369. this->AppendLinkDepends(depends, linkLanguage);
  370. if (!this->DeviceLinkObject.empty()) {
  371. depends.push_back(this->DeviceLinkObject);
  372. }
  373. // Create set of linking flags.
  374. std::string linkFlags;
  375. this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
  376. this->LocalGenerator->AppendIPOLinkerFlags(
  377. linkFlags, this->GeneratorTarget, this->GetConfigName(), linkLanguage);
  378. // Add OSX version flags, if any.
  379. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
  380. this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
  381. this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true);
  382. this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false);
  383. }
  384. // Construct the name of the library.
  385. this->GeneratorTarget->GetLibraryNames(this->GetConfigName());
  386. // Construct the full path version of the names.
  387. std::string outpath;
  388. std::string outpathImp;
  389. if (this->GeneratorTarget->IsFrameworkOnApple()) {
  390. outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
  391. cmOSXBundleGenerator::SkipParts bundleSkipParts;
  392. if (this->GeneratorTarget->HasImportLibrary(this->GetConfigName())) {
  393. bundleSkipParts.TextStubs = false;
  394. }
  395. this->OSXBundleGenerator->CreateFramework(this->TargetNames.Output,
  396. outpath, this->GetConfigName(),
  397. bundleSkipParts);
  398. outpath += '/';
  399. if (!this->TargetNames.ImportLibrary.empty()) {
  400. outpathImp = this->GeneratorTarget->GetDirectory(
  401. this->GetConfigName(), cmStateEnums::ImportLibraryArtifact);
  402. cmSystemTools::MakeDirectory(outpathImp);
  403. outpathImp += '/';
  404. }
  405. } else if (this->GeneratorTarget->IsCFBundleOnApple()) {
  406. outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
  407. this->OSXBundleGenerator->CreateCFBundle(this->TargetNames.Output, outpath,
  408. this->GetConfigName());
  409. outpath += '/';
  410. } else if (relink) {
  411. outpath = cmStrCat(this->Makefile->GetCurrentBinaryDirectory(),
  412. "/CMakeFiles/CMakeRelink.dir");
  413. cmSystemTools::MakeDirectory(outpath);
  414. outpath += '/';
  415. if (!this->TargetNames.ImportLibrary.empty()) {
  416. outpathImp = outpath;
  417. }
  418. } else {
  419. outpath = this->GeneratorTarget->GetDirectory(this->GetConfigName());
  420. cmSystemTools::MakeDirectory(outpath);
  421. outpath += '/';
  422. if (!this->TargetNames.ImportLibrary.empty()) {
  423. outpathImp = this->GeneratorTarget->GetDirectory(
  424. this->GetConfigName(), cmStateEnums::ImportLibraryArtifact);
  425. cmSystemTools::MakeDirectory(outpathImp);
  426. outpathImp += '/';
  427. }
  428. }
  429. std::string compilePdbOutputPath =
  430. this->GeneratorTarget->GetCompilePDBDirectory(this->GetConfigName());
  431. cmSystemTools::MakeDirectory(compilePdbOutputPath);
  432. std::string pdbOutputPath =
  433. this->GeneratorTarget->GetPDBDirectory(this->GetConfigName());
  434. cmSystemTools::MakeDirectory(pdbOutputPath);
  435. pdbOutputPath += "/";
  436. std::string targetFullPath = outpath + this->TargetNames.Output;
  437. std::string targetFullPathPDB = pdbOutputPath + this->TargetNames.PDB;
  438. std::string targetFullPathSO = outpath + this->TargetNames.SharedObject;
  439. std::string targetFullPathReal = outpath + this->TargetNames.Real;
  440. std::string targetFullPathImport =
  441. outpathImp + this->TargetNames.ImportLibrary;
  442. // Construct the output path version of the names for use in command
  443. // arguments.
  444. std::string targetOutPathPDB = this->LocalGenerator->ConvertToOutputFormat(
  445. targetFullPathPDB, cmOutputConverter::SHELL);
  446. std::string targetOutPath = this->LocalGenerator->ConvertToOutputFormat(
  447. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPath),
  448. cmOutputConverter::SHELL);
  449. std::string targetOutPathSO = this->LocalGenerator->ConvertToOutputFormat(
  450. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathSO),
  451. cmOutputConverter::SHELL);
  452. std::string targetOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
  453. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathReal),
  454. cmOutputConverter::SHELL);
  455. std::string targetOutPathImport =
  456. this->LocalGenerator->ConvertToOutputFormat(
  457. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathImport),
  458. cmOutputConverter::SHELL);
  459. this->NumberOfProgressActions++;
  460. if (!this->NoRuleMessages) {
  461. cmLocalUnixMakefileGenerator3::EchoProgress progress;
  462. this->MakeEchoProgress(progress);
  463. // Add the link message.
  464. std::string buildEcho = cmStrCat("Linking ", linkLanguage);
  465. switch (this->GeneratorTarget->GetType()) {
  466. case cmStateEnums::STATIC_LIBRARY:
  467. buildEcho += " static library ";
  468. break;
  469. case cmStateEnums::SHARED_LIBRARY:
  470. buildEcho += " shared library ";
  471. break;
  472. case cmStateEnums::MODULE_LIBRARY:
  473. if (this->GeneratorTarget->IsCFBundleOnApple()) {
  474. buildEcho += " CFBundle";
  475. }
  476. buildEcho += " shared module ";
  477. break;
  478. default:
  479. buildEcho += " library ";
  480. break;
  481. }
  482. buildEcho += targetOutPath;
  483. this->LocalGenerator->AppendEcho(
  484. commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
  485. }
  486. // Clean files associated with this library.
  487. std::set<std::string> libCleanFiles;
  488. libCleanFiles.insert(
  489. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathReal));
  490. std::vector<std::string> commands1;
  491. // Add a command to remove any existing files for this library.
  492. // for static libs only
  493. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  494. this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
  495. this->GeneratorTarget, "target");
  496. this->LocalGenerator->CreateCDCommand(
  497. commands1, this->Makefile->GetCurrentBinaryDirectory(),
  498. this->LocalGenerator->GetBinaryDirectory());
  499. cm::append(commands, commands1);
  500. commands1.clear();
  501. }
  502. if (this->TargetNames.Output != this->TargetNames.Real) {
  503. libCleanFiles.insert(
  504. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPath));
  505. }
  506. if (this->TargetNames.SharedObject != this->TargetNames.Real &&
  507. this->TargetNames.SharedObject != this->TargetNames.Output) {
  508. libCleanFiles.insert(
  509. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathSO));
  510. }
  511. if (!this->TargetNames.ImportLibrary.empty()) {
  512. libCleanFiles.insert(
  513. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathImport));
  514. std::string implib;
  515. if (this->GeneratorTarget->GetImplibGNUtoMS(
  516. this->GetConfigName(), targetFullPathImport, implib)) {
  517. libCleanFiles.insert(
  518. this->LocalGenerator->MaybeRelativeToCurBinDir(implib));
  519. }
  520. }
  521. // List the PDB for cleaning only when the whole target is
  522. // cleaned. We do not want to delete the .pdb file just before
  523. // linking the target.
  524. this->CleanFiles.insert(
  525. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathPDB));
  526. #ifdef _WIN32
  527. // There may be a manifest file for this target. Add it to the
  528. // clean set just in case.
  529. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
  530. libCleanFiles.insert(this->LocalGenerator->MaybeRelativeToCurBinDir(
  531. targetFullPath + ".manifest"));
  532. }
  533. #endif
  534. // Add the pre-build and pre-link rules building but not when relinking.
  535. if (!relink) {
  536. this->LocalGenerator->AppendCustomCommands(
  537. commands, this->GeneratorTarget->GetPreBuildCommands(),
  538. this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
  539. this->LocalGenerator->AppendCustomCommands(
  540. commands, this->GeneratorTarget->GetPreLinkCommands(),
  541. this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
  542. }
  543. // Determine whether a link script will be used.
  544. bool useLinkScript = this->GlobalGenerator->GetUseLinkScript();
  545. bool useResponseFileForObjects =
  546. this->CheckUseResponseFileForObjects(linkLanguage);
  547. bool const useResponseFileForLibs =
  548. this->CheckUseResponseFileForLibraries(linkLanguage);
  549. // For static libraries there might be archiving rules.
  550. bool haveStaticLibraryRule = false;
  551. std::vector<std::string> archiveCreateCommands;
  552. std::vector<std::string> archiveAppendCommands;
  553. std::vector<std::string> archiveFinishCommands;
  554. std::string::size_type archiveCommandLimit = std::string::npos;
  555. if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
  556. haveStaticLibraryRule = this->Makefile->IsDefinitionSet(linkRuleVar);
  557. std::string arCreateVar =
  558. cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_CREATE");
  559. arCreateVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
  560. arCreateVar, linkLanguage, this->GetConfigName());
  561. this->Makefile->GetDefExpandList(arCreateVar, archiveCreateCommands);
  562. std::string arAppendVar =
  563. cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_APPEND");
  564. arAppendVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
  565. arAppendVar, linkLanguage, this->GetConfigName());
  566. this->Makefile->GetDefExpandList(arAppendVar, archiveAppendCommands);
  567. std::string arFinishVar =
  568. cmStrCat("CMAKE_", linkLanguage, "_ARCHIVE_FINISH");
  569. arFinishVar = this->GeneratorTarget->GetFeatureSpecificLinkRuleVariable(
  570. arFinishVar, linkLanguage, this->GetConfigName());
  571. this->Makefile->GetDefExpandList(arFinishVar, archiveFinishCommands);
  572. }
  573. // Decide whether to use archiving rules.
  574. bool useArchiveRules = !haveStaticLibraryRule &&
  575. !archiveCreateCommands.empty() && !archiveAppendCommands.empty();
  576. if (useArchiveRules) {
  577. // Archiving rules are always run with a link script.
  578. useLinkScript = true;
  579. // Archiving rules never use a response file.
  580. useResponseFileForObjects = false;
  581. // Limit the length of individual object lists to less than half of
  582. // the command line length limit (leaving half for other flags).
  583. // This may result in several calls to the archiver.
  584. if (size_t limit = cmSystemTools::CalculateCommandLineLengthLimit()) {
  585. archiveCommandLimit = limit / 2;
  586. } else {
  587. archiveCommandLimit = 8000;
  588. }
  589. }
  590. // Expand the rule variables.
  591. std::unique_ptr<cmRulePlaceholderExpander> rulePlaceholderExpander(
  592. this->LocalGenerator->CreateRulePlaceholderExpander());
  593. bool useWatcomQuote =
  594. this->Makefile->IsOn(linkRuleVar + "_USE_WATCOM_QUOTE");
  595. std::vector<std::string> real_link_commands;
  596. {
  597. // Set path conversion for link script shells.
  598. this->LocalGenerator->SetLinkScriptShell(useLinkScript);
  599. // Collect up flags to link in needed libraries.
  600. std::string linkLibs;
  601. if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
  602. std::unique_ptr<cmLinkLineComputer> linkLineComputer =
  603. this->CreateLinkLineComputer(
  604. this->LocalGenerator,
  605. this->LocalGenerator->GetStateSnapshot().GetDirectory());
  606. linkLineComputer->SetForResponse(useResponseFileForLibs);
  607. linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
  608. linkLineComputer->SetRelink(relink);
  609. this->CreateLinkLibs(linkLineComputer.get(), linkLibs,
  610. useResponseFileForLibs, depends);
  611. }
  612. // Construct object file lists that may be needed to expand the
  613. // rule.
  614. std::string buildObjs;
  615. this->CreateObjectLists(useLinkScript, useArchiveRules,
  616. useResponseFileForObjects, buildObjs, depends,
  617. useWatcomQuote);
  618. if (!this->DeviceLinkObject.empty()) {
  619. buildObjs += " " +
  620. this->LocalGenerator->ConvertToOutputFormat(
  621. this->LocalGenerator->MaybeRelativeToCurBinDir(
  622. this->DeviceLinkObject),
  623. cmOutputConverter::SHELL);
  624. }
  625. std::string const& aixExports = this->GetAIXExports(this->GetConfigName());
  626. // maybe create .def file from list of objects
  627. this->GenDefFile(real_link_commands);
  628. std::string manifests = this->GetManifests(this->GetConfigName());
  629. cmRulePlaceholderExpander::RuleVariables vars;
  630. vars.TargetPDB = targetOutPathPDB.c_str();
  631. // Setup the target version.
  632. std::string targetVersionMajor;
  633. std::string targetVersionMinor;
  634. {
  635. std::ostringstream majorStream;
  636. std::ostringstream minorStream;
  637. int major;
  638. int minor;
  639. this->GeneratorTarget->GetTargetVersion(major, minor);
  640. majorStream << major;
  641. minorStream << minor;
  642. targetVersionMajor = majorStream.str();
  643. targetVersionMinor = minorStream.str();
  644. }
  645. vars.TargetVersionMajor = targetVersionMajor.c_str();
  646. vars.TargetVersionMinor = targetVersionMinor.c_str();
  647. vars.CMTargetName = this->GeneratorTarget->GetName().c_str();
  648. vars.CMTargetType =
  649. cmState::GetTargetTypeName(this->GeneratorTarget->GetType()).c_str();
  650. vars.Language = linkLanguage.c_str();
  651. vars.AIXExports = aixExports.c_str();
  652. vars.Objects = buildObjs.c_str();
  653. std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
  654. objectDir = this->LocalGenerator->ConvertToOutputFormat(
  655. this->LocalGenerator->MaybeRelativeToCurBinDir(objectDir),
  656. cmOutputConverter::SHELL);
  657. vars.ObjectDir = objectDir.c_str();
  658. std::string target = this->LocalGenerator->ConvertToOutputFormat(
  659. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathReal),
  660. cmOutputConverter::SHELL, useWatcomQuote);
  661. vars.Target = target.c_str();
  662. vars.LinkLibraries = linkLibs.c_str();
  663. vars.ObjectsQuoted = buildObjs.c_str();
  664. std::string targetOutSOName;
  665. if (this->GeneratorTarget->HasSOName(this->GetConfigName())) {
  666. vars.SONameFlag = this->Makefile->GetSONameFlag(linkLanguage);
  667. targetOutSOName = this->LocalGenerator->ConvertToOutputFormat(
  668. this->TargetNames.SharedObject.c_str(), cmOutputConverter::SHELL);
  669. vars.TargetSOName = targetOutSOName.c_str();
  670. }
  671. vars.LinkFlags = linkFlags.c_str();
  672. vars.Manifests = manifests.c_str();
  673. // Compute the directory portion of the install_name setting.
  674. std::string install_name_dir;
  675. if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY) {
  676. // Get the install_name directory for the build tree.
  677. install_name_dir = this->GeneratorTarget->GetInstallNameDirForBuildTree(
  678. this->GetConfigName());
  679. // Set the rule variable replacement value.
  680. if (install_name_dir.empty()) {
  681. vars.TargetInstallNameDir = "";
  682. } else {
  683. // Convert to a path for the native build tool.
  684. install_name_dir = this->LocalGenerator->ConvertToOutputFormat(
  685. install_name_dir, cmOutputConverter::SHELL);
  686. vars.TargetInstallNameDir = install_name_dir.c_str();
  687. }
  688. }
  689. // Add language-specific flags.
  690. std::string langFlags;
  691. this->LocalGenerator->AddLanguageFlagsForLinking(
  692. langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
  693. this->LocalGenerator->AddArchitectureFlags(
  694. langFlags, this->GeneratorTarget, linkLanguage, this->GetConfigName());
  695. vars.LanguageCompileFlags = langFlags.c_str();
  696. std::string linkerLauncher =
  697. this->GetLinkerLauncher(this->GetConfigName());
  698. if (cmNonempty(linkerLauncher)) {
  699. vars.Launcher = linkerLauncher.c_str();
  700. }
  701. std::string launcher;
  702. std::string val = this->LocalGenerator->GetRuleLauncher(
  703. this->GeneratorTarget, "RULE_LAUNCH_LINK",
  704. this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"));
  705. if (cmNonempty(val)) {
  706. launcher = cmStrCat(val, ' ');
  707. }
  708. // Construct the main link rule and expand placeholders.
  709. rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
  710. if (useArchiveRules) {
  711. // Construct the individual object list strings.
  712. std::vector<std::string> object_strings;
  713. this->WriteObjectsStrings(object_strings, false, archiveCommandLimit);
  714. // Add the cuda device object to the list of archive files. This will
  715. // only occur on archives which have CUDA_RESOLVE_DEVICE_SYMBOLS enabled
  716. if (!this->DeviceLinkObject.empty()) {
  717. object_strings.push_back(this->LocalGenerator->ConvertToOutputFormat(
  718. this->LocalGenerator->MaybeRelativeToCurBinDir(
  719. this->DeviceLinkObject),
  720. cmOutputConverter::SHELL));
  721. }
  722. // Create the archive with the first set of objects.
  723. auto osi = object_strings.begin();
  724. {
  725. vars.Objects = osi->c_str();
  726. for (std::string const& acc : archiveCreateCommands) {
  727. std::string cmd = launcher + acc;
  728. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
  729. cmd, vars);
  730. real_link_commands.push_back(std::move(cmd));
  731. }
  732. }
  733. // Append to the archive with the other object sets.
  734. for (++osi; osi != object_strings.end(); ++osi) {
  735. vars.Objects = osi->c_str();
  736. for (std::string const& aac : archiveAppendCommands) {
  737. std::string cmd = launcher + aac;
  738. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
  739. cmd, vars);
  740. real_link_commands.push_back(std::move(cmd));
  741. }
  742. }
  743. // Finish the archive.
  744. vars.Objects = "";
  745. for (std::string const& afc : archiveFinishCommands) {
  746. std::string cmd = launcher + afc;
  747. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, cmd,
  748. vars);
  749. // If there is no ranlib the command will be ":". Skip it.
  750. if (!cmd.empty() && cmd[0] != ':') {
  751. real_link_commands.push_back(std::move(cmd));
  752. }
  753. }
  754. } else {
  755. // Get the set of commands.
  756. std::string linkRule = this->GetLinkRule(linkRuleVar);
  757. cmExpandList(linkRule, real_link_commands);
  758. if (this->UseLWYU) {
  759. cmValue lwyuCheck =
  760. this->Makefile->GetDefinition("CMAKE_LINK_WHAT_YOU_USE_CHECK");
  761. if (lwyuCheck) {
  762. std::string cmakeCommand = cmStrCat(
  763. this->LocalGenerator->ConvertToOutputFormat(
  764. cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL),
  765. " -E __run_co_compile --lwyu=");
  766. cmakeCommand += this->LocalGenerator->EscapeForShell(*lwyuCheck);
  767. cmakeCommand += cmStrCat(" --source=", targetOutPathReal);
  768. real_link_commands.push_back(std::move(cmakeCommand));
  769. }
  770. }
  771. // Expand placeholders.
  772. for (std::string& real_link_command : real_link_commands) {
  773. real_link_command = cmStrCat(launcher, real_link_command);
  774. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
  775. real_link_command, vars);
  776. }
  777. }
  778. // Restore path conversion to normal shells.
  779. this->LocalGenerator->SetLinkScriptShell(false);
  780. }
  781. // Optionally convert the build rule to use a script to avoid long
  782. // command lines in the make shell.
  783. if (useLinkScript) {
  784. // Use a link script.
  785. const char* name = (relink ? "relink.txt" : "link.txt");
  786. this->CreateLinkScript(name, real_link_commands, commands1, depends);
  787. } else {
  788. // No link script. Just use the link rule directly.
  789. commands1 = real_link_commands;
  790. }
  791. this->LocalGenerator->CreateCDCommand(
  792. commands1, this->Makefile->GetCurrentBinaryDirectory(),
  793. this->LocalGenerator->GetBinaryDirectory());
  794. cm::append(commands, commands1);
  795. commands1.clear();
  796. // Add a rule to create necessary symlinks for the library.
  797. // Frameworks are handled by cmOSXBundleGenerator.
  798. if (targetOutPath != targetOutPathReal &&
  799. !this->GeneratorTarget->IsFrameworkOnApple()) {
  800. std::string symlink =
  801. cmStrCat("$(CMAKE_COMMAND) -E cmake_symlink_library ", targetOutPathReal,
  802. ' ', targetOutPathSO, ' ', targetOutPath);
  803. commands1.push_back(std::move(symlink));
  804. this->LocalGenerator->CreateCDCommand(
  805. commands1, this->Makefile->GetCurrentBinaryDirectory(),
  806. this->LocalGenerator->GetBinaryDirectory());
  807. cm::append(commands, commands1);
  808. commands1.clear();
  809. }
  810. // Add the post-build rules when building but not when relinking.
  811. if (!relink) {
  812. this->LocalGenerator->AppendCustomCommands(
  813. commands, this->GeneratorTarget->GetPostBuildCommands(),
  814. this->GeneratorTarget, this->LocalGenerator->GetBinaryDirectory());
  815. }
  816. // Compute the list of outputs.
  817. std::vector<std::string> outputs;
  818. outputs.reserve(3);
  819. outputs.push_back(targetFullPathReal);
  820. if (this->TargetNames.SharedObject != this->TargetNames.Real) {
  821. outputs.push_back(targetFullPathSO);
  822. }
  823. if (this->TargetNames.Output != this->TargetNames.SharedObject &&
  824. this->TargetNames.Output != this->TargetNames.Real) {
  825. outputs.push_back(targetFullPath);
  826. }
  827. // Write the build rule.
  828. this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
  829. commands, false);
  830. // Add rule to generate text-based stubs, if required
  831. if (this->GeneratorTarget->IsApple() &&
  832. this->GeneratorTarget->HasImportLibrary(this->GetConfigName())) {
  833. auto genStubsRule =
  834. this->Makefile->GetDefinition("CMAKE_CREATE_TEXT_STUBS");
  835. auto genStubs_commands = cmExpandedList(genStubsRule);
  836. std::string TBDFullPath =
  837. cmStrCat(outpathImp, this->TargetNames.ImportOutput);
  838. std::string TBDFullPathReal =
  839. cmStrCat(outpathImp, this->TargetNames.ImportReal);
  840. std::string TBDFullPathSO =
  841. cmStrCat(outpathImp, this->TargetNames.ImportLibrary);
  842. // Expand placeholders.
  843. cmRulePlaceholderExpander::RuleVariables vars;
  844. std::string target = this->LocalGenerator->ConvertToOutputFormat(
  845. this->LocalGenerator->MaybeRelativeToCurBinDir(targetFullPathReal),
  846. cmOutputConverter::SHELL, useWatcomQuote);
  847. vars.Target = target.c_str();
  848. std::string TBDOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
  849. this->LocalGenerator->MaybeRelativeToCurBinDir(TBDFullPathReal),
  850. cmOutputConverter::SHELL, useWatcomQuote);
  851. rulePlaceholderExpander->SetTargetImpLib(TBDOutPathReal);
  852. for (std::string& command : genStubs_commands) {
  853. rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
  854. command, vars);
  855. }
  856. outputs.clear();
  857. outputs.push_back(TBDFullPathReal);
  858. if (this->TargetNames.ImportLibrary != this->TargetNames.ImportReal) {
  859. outputs.push_back(TBDFullPathSO);
  860. }
  861. if (this->TargetNames.ImportOutput != this->TargetNames.ImportLibrary &&
  862. this->TargetNames.ImportOutput != this->TargetNames.ImportReal) {
  863. outputs.push_back(TBDFullPath);
  864. }
  865. this->ExtraFiles.insert(TBDFullPath);
  866. depends.clear();
  867. depends.push_back(targetFullPathReal);
  868. // Add a rule to create necessary symlinks for the library.
  869. // Frameworks are handled by cmOSXBundleGenerator.
  870. if (TBDFullPath != TBDFullPathReal &&
  871. !this->GeneratorTarget->IsFrameworkOnApple()) {
  872. auto TBDOutPathSO = this->LocalGenerator->ConvertToOutputFormat(
  873. this->LocalGenerator->MaybeRelativeToCurBinDir(TBDFullPathSO),
  874. cmOutputConverter::SHELL, useWatcomQuote);
  875. auto TBDOutPath = this->LocalGenerator->ConvertToOutputFormat(
  876. this->LocalGenerator->MaybeRelativeToCurBinDir(TBDFullPath),
  877. cmOutputConverter::SHELL, useWatcomQuote);
  878. std::string symlink =
  879. cmStrCat("$(CMAKE_COMMAND) -E cmake_symlink_library ", TBDOutPathReal,
  880. ' ', TBDOutPathSO, ' ', TBDOutPath);
  881. commands1.push_back(std::move(symlink));
  882. this->LocalGenerator->CreateCDCommand(
  883. commands1, this->Makefile->GetCurrentBinaryDirectory(),
  884. this->LocalGenerator->GetBinaryDirectory());
  885. cm::append(genStubs_commands, commands1);
  886. commands1.clear();
  887. }
  888. this->WriteMakeRule(*this->BuildFileStream, nullptr, outputs, depends,
  889. genStubs_commands, false);
  890. // clean actions for apple specific outputs
  891. // clean actions for ImportLibrary are already specified
  892. if (this->TargetNames.ImportReal != this->TargetNames.ImportLibrary) {
  893. libCleanFiles.insert(
  894. this->LocalGenerator->MaybeRelativeToCurBinDir(TBDFullPathReal));
  895. }
  896. if (this->TargetNames.ImportOutput != this->TargetNames.ImportReal &&
  897. this->TargetNames.ImportOutput != this->TargetNames.ImportLibrary) {
  898. libCleanFiles.insert(
  899. this->LocalGenerator->MaybeRelativeToCurBinDir(TBDFullPath));
  900. }
  901. }
  902. // Write the main driver rule to build everything in this target.
  903. this->WriteTargetDriverRule(targetFullPath, relink);
  904. // Clean all the possible library names and symlinks.
  905. this->CleanFiles.insert(libCleanFiles.begin(), libCleanFiles.end());
  906. }