cmMakefileLibraryTargetGenerator.cxx 40 KB

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