cmMakefileLibraryTargetGenerator.cxx 40 KB

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