cmMakefileLibraryTargetGenerator.cxx 40 KB

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