cmComputeLinkDepends.cxx 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmComputeLinkDepends.h"
  4. #include <algorithm>
  5. #include <cassert>
  6. #include <cstddef>
  7. #include <cstdio>
  8. #include <iterator>
  9. #include <sstream>
  10. #include <type_traits>
  11. #include <unordered_map>
  12. #include <utility>
  13. #include <cm/memory>
  14. #include <cm/string_view>
  15. #include <cmext/string_view>
  16. #include "cmsys/RegularExpression.hxx"
  17. #include "cmComputeComponentGraph.h"
  18. #include "cmGenExContext.h"
  19. #include "cmGeneratorExpression.h"
  20. #include "cmGeneratorExpressionDAGChecker.h"
  21. #include "cmGeneratorTarget.h"
  22. #include "cmGlobalGenerator.h"
  23. #include "cmList.h"
  24. #include "cmListFileCache.h"
  25. #include "cmLocalGenerator.h"
  26. #include "cmMakefile.h"
  27. #include "cmMessageType.h"
  28. #include "cmPolicies.h"
  29. #include "cmRange.h"
  30. #include "cmState.h"
  31. #include "cmStateTypes.h"
  32. #include "cmStringAlgorithms.h"
  33. #include "cmTarget.h"
  34. #include "cmValue.h"
  35. #include "cmake.h"
  36. /*
  37. This file computes an ordered list of link items to use when linking a
  38. single target in one configuration. Each link item is identified by
  39. the string naming it. A graph of dependencies is created in which
  40. each node corresponds to one item and directed edges lead from nodes to
  41. those which must *follow* them on the link line. For example, the
  42. graph
  43. A -> B -> C
  44. will lead to the link line order
  45. A B C
  46. The set of items placed in the graph is formed with a breadth-first
  47. search of the link dependencies starting from the main target.
  48. There are two types of items: those with known direct dependencies and
  49. those without known dependencies. We will call the two types "known
  50. items" and "unknown items", respectively. Known items are those whose
  51. names correspond to targets (built or imported) and those for which an
  52. old-style <item>_LIB_DEPENDS variable is defined. All other items are
  53. unknown and we must infer dependencies for them. For items that look
  54. like flags (beginning with '-') we trivially infer no dependencies,
  55. and do not include them in the dependencies of other items.
  56. Known items have dependency lists ordered based on how the user
  57. specified them. We can use this order to infer potential dependencies
  58. of unknown items. For example, if link items A and B are unknown and
  59. items X and Y are known, then we might have the following dependency
  60. lists:
  61. X: Y A B
  62. Y: A B
  63. The explicitly known dependencies form graph edges
  64. X -> Y , X -> A , X -> B , Y -> A , Y -> B
  65. We can also infer the edge
  66. A -> B
  67. because *every* time A appears B is seen on its right. We do not know
  68. whether A really needs symbols from B to link, but it *might* so we
  69. must preserve their order. This is the case also for the following
  70. explicit lists:
  71. X: A B Y
  72. Y: A B
  73. Here, A is followed by the set {B,Y} in one list, and {B} in the other
  74. list. The intersection of these sets is {B}, so we can infer that A
  75. depends on at most B. Meanwhile B is followed by the set {Y} in one
  76. list and {} in the other. The intersection is {} so we can infer that
  77. B has no dependencies.
  78. Let's make a more complex example by adding unknown item C and
  79. considering these dependency lists:
  80. X: A B Y C
  81. Y: A C B
  82. The explicit edges are
  83. X -> Y , X -> A , X -> B , X -> C , Y -> A , Y -> B , Y -> C
  84. For the unknown items, we infer dependencies by looking at the
  85. "follow" sets:
  86. A: intersect( {B,Y,C} , {C,B} ) = {B,C} ; infer edges A -> B , A -> C
  87. B: intersect( {Y,C} , {} ) = {} ; infer no edges
  88. C: intersect( {} , {B} ) = {} ; infer no edges
  89. Note that targets are never inferred as dependees because outside
  90. libraries should not depend on them.
  91. ------------------------------------------------------------------------------
  92. The initial exploration of dependencies using a BFS associates an
  93. integer index with each link item. When the graph is built outgoing
  94. edges are sorted by this index.
  95. After the initial exploration of the link interface tree, any
  96. transitive (dependent) shared libraries that were encountered and not
  97. included in the interface are processed in their own BFS. This BFS
  98. follows only the dependent library lists and not the link interfaces.
  99. They are added to the link items with a mark indicating that the are
  100. transitive dependencies. Then cmComputeLinkInformation deals with
  101. them on a per-platform basis.
  102. The complete graph formed from all known and inferred dependencies may
  103. not be acyclic, so an acyclic version must be created.
  104. The original graph is converted to a directed acyclic graph in which
  105. each node corresponds to a strongly connected component of the
  106. original graph. For example, the dependency graph
  107. X -> A -> B -> C -> A -> Y
  108. contains strongly connected components {X}, {A,B,C}, and {Y}. The
  109. implied directed acyclic graph (DAG) is
  110. {X} -> {A,B,C} -> {Y}
  111. We then compute a topological order for the DAG nodes to serve as a
  112. reference for satisfying dependencies efficiently. We perform the DFS
  113. in reverse order and assign topological order indices counting down so
  114. that the result is as close to the original BFS order as possible
  115. without violating dependencies.
  116. ------------------------------------------------------------------------------
  117. The final link entry order is constructed as follows. We first walk
  118. through and emit the *original* link line as specified by the user.
  119. As each item is emitted, a set of pending nodes in the component DAG
  120. is maintained. When a pending component has been completely seen, it
  121. is removed from the pending set and its dependencies (following edges
  122. of the DAG) are added. A trivial component (those with one item) is
  123. complete as soon as its item is seen. A non-trivial component (one
  124. with more than one item; assumed to be static libraries) is complete
  125. when *all* its entries have been seen *twice* (all entries seen once,
  126. then all entries seen again, not just each entry twice). A pending
  127. component tracks which items have been seen and a count of how many
  128. times the component needs to be seen (once for trivial components,
  129. twice for non-trivial). If at any time another component finishes and
  130. re-adds an already pending component, the pending component is reset
  131. so that it needs to be seen in its entirety again. This ensures that
  132. all dependencies of a component are satisfied no matter where it
  133. appears.
  134. After the original link line has been completed, we append to it the
  135. remaining pending components and their dependencies. This is done by
  136. repeatedly emitting the first item from the first pending component
  137. and following the same update rules as when traversing the original
  138. link line. Since the pending components are kept in topological order
  139. they are emitted with minimal repeats (we do not want to emit a
  140. component just to have it added again when another component is
  141. completed later). This process continues until no pending components
  142. remain. We know it will terminate because the component graph is
  143. guaranteed to be acyclic.
  144. The final list of items produced by this procedure consists of the
  145. original user link line followed by minimal additional items needed to
  146. satisfy dependencies. The final list is then filtered to de-duplicate
  147. items that we know the linker will reuse automatically (shared libs).
  148. */
  149. namespace {
  150. // LINK_LIBRARY helpers
  151. bool IsFeatureSupported(cmMakefile* makefile, std::string const& linkLanguage,
  152. std::string const& feature)
  153. {
  154. auto featureSupported = cmStrCat(
  155. "CMAKE_", linkLanguage, "_LINK_LIBRARY_USING_", feature, "_SUPPORTED");
  156. if (cmValue perLangVar = makefile->GetDefinition(featureSupported)) {
  157. return perLangVar.IsOn();
  158. }
  159. featureSupported =
  160. cmStrCat("CMAKE_LINK_LIBRARY_USING_", feature, "_SUPPORTED");
  161. return makefile->GetDefinition(featureSupported).IsOn();
  162. }
  163. // LINK_LIBRARY feature attributes management
  164. struct LinkLibraryFeatureAttributeSet
  165. {
  166. std::set<cmStateEnums::TargetType> LibraryTypes = {
  167. cmStateEnums::EXECUTABLE, cmStateEnums::STATIC_LIBRARY,
  168. cmStateEnums::SHARED_LIBRARY, cmStateEnums::MODULE_LIBRARY,
  169. cmStateEnums::UNKNOWN_LIBRARY
  170. };
  171. std::set<std::string> Override;
  172. enum DeduplicationKind
  173. {
  174. Default,
  175. Yes,
  176. No
  177. };
  178. DeduplicationKind Deduplication = Default;
  179. };
  180. std::map<std::string, LinkLibraryFeatureAttributeSet>
  181. LinkLibraryFeatureAttributes;
  182. LinkLibraryFeatureAttributeSet const& GetLinkLibraryFeatureAttributes(
  183. cmMakefile* makefile, std::string const& linkLanguage,
  184. std::string const& feature)
  185. {
  186. auto it = LinkLibraryFeatureAttributes.find(feature);
  187. if (it != LinkLibraryFeatureAttributes.end()) {
  188. return it->second;
  189. }
  190. auto featureAttributesVariable =
  191. cmStrCat("CMAKE_", linkLanguage, "_LINK_LIBRARY_", feature, "_ATTRIBUTES");
  192. auto featureAttributesValues =
  193. makefile->GetDefinition(featureAttributesVariable);
  194. if (featureAttributesValues.IsEmpty()) {
  195. // try language agnostic definition
  196. featureAttributesVariable =
  197. cmStrCat("CMAKE_LINK_LIBRARY_", feature, "_ATTRIBUTES");
  198. featureAttributesValues =
  199. makefile->GetDefinition(featureAttributesVariable);
  200. }
  201. if (!featureAttributesValues.IsEmpty()) {
  202. LinkLibraryFeatureAttributeSet featureAttributes;
  203. cmsys::RegularExpression processingOption{
  204. "^(LIBRARY_TYPE|DEDUPLICATION|OVERRIDE)=((STATIC|SHARED|MODULE|"
  205. "EXECUTABLE)(,("
  206. "STATIC|"
  207. "SHARED|MODULE|EXECUTABLE)"
  208. ")*|YES|NO|DEFAULT|[A-Za-z0-9_]+(,[A-Za-z0-9_]+)*)$"
  209. };
  210. std::string errorMessage;
  211. for (auto const& option : cmList{ featureAttributesValues }) {
  212. if (processingOption.find(option)) {
  213. if (processingOption.match(1) == "LIBRARY_TYPE") {
  214. featureAttributes.LibraryTypes.clear();
  215. for (auto const& value :
  216. cmTokenize(processingOption.match(2), ',')) {
  217. if (value == "STATIC") {
  218. featureAttributes.LibraryTypes.emplace(
  219. cmStateEnums::STATIC_LIBRARY);
  220. } else if (value == "SHARED") {
  221. featureAttributes.LibraryTypes.emplace(
  222. cmStateEnums::SHARED_LIBRARY);
  223. } else if (value == "MODULE") {
  224. featureAttributes.LibraryTypes.emplace(
  225. cmStateEnums::MODULE_LIBRARY);
  226. } else if (value == "EXECUTABLE") {
  227. featureAttributes.LibraryTypes.emplace(cmStateEnums::EXECUTABLE);
  228. } else {
  229. errorMessage += cmStrCat(" ", option, '\n');
  230. break;
  231. }
  232. }
  233. // Always add UNKNOWN type
  234. featureAttributes.LibraryTypes.emplace(
  235. cmStateEnums::UNKNOWN_LIBRARY);
  236. } else if (processingOption.match(1) == "DEDUPLICATION") {
  237. if (processingOption.match(2) == "YES") {
  238. featureAttributes.Deduplication =
  239. LinkLibraryFeatureAttributeSet::Yes;
  240. } else if (processingOption.match(2) == "NO") {
  241. featureAttributes.Deduplication =
  242. LinkLibraryFeatureAttributeSet::No;
  243. } else if (processingOption.match(2) == "DEFAULT") {
  244. featureAttributes.Deduplication =
  245. LinkLibraryFeatureAttributeSet::Default;
  246. } else {
  247. errorMessage += cmStrCat(" ", option, '\n');
  248. }
  249. } else if (processingOption.match(1) == "OVERRIDE") {
  250. featureAttributes.Override.clear();
  251. std::vector<std::string> values =
  252. cmTokenize(processingOption.match(2), ',');
  253. featureAttributes.Override.insert(values.begin(), values.end());
  254. }
  255. } else {
  256. errorMessage += cmStrCat(" ", option, '\n');
  257. }
  258. }
  259. if (!errorMessage.empty()) {
  260. makefile->GetCMakeInstance()->IssueMessage(
  261. MessageType::FATAL_ERROR,
  262. cmStrCat("Erroneous option(s) for '", featureAttributesVariable,
  263. "':\n", errorMessage));
  264. }
  265. return LinkLibraryFeatureAttributes.emplace(feature, featureAttributes)
  266. .first->second;
  267. }
  268. return LinkLibraryFeatureAttributes
  269. .emplace(feature, LinkLibraryFeatureAttributeSet{})
  270. .first->second;
  271. }
  272. // LINK_GROUP helpers
  273. cm::string_view const LG_BEGIN = "<LINK_GROUP:"_s;
  274. cm::string_view const LG_END = "</LINK_GROUP:"_s;
  275. cm::string_view const LG_ITEM_BEGIN = "<LINK_GROUP>"_s;
  276. cm::string_view const LG_ITEM_END = "</LINK_GROUP>"_s;
  277. inline std::string ExtractGroupFeature(std::string const& item)
  278. {
  279. return item.substr(LG_BEGIN.length(),
  280. item.find(':', LG_BEGIN.length()) - LG_BEGIN.length());
  281. }
  282. bool IsGroupFeatureSupported(cmMakefile* makefile,
  283. std::string const& linkLanguage,
  284. std::string const& feature)
  285. {
  286. auto featureSupported = cmStrCat(
  287. "CMAKE_", linkLanguage, "_LINK_GROUP_USING_", feature, "_SUPPORTED");
  288. if (makefile->GetDefinition(featureSupported).IsOn()) {
  289. return true;
  290. }
  291. featureSupported =
  292. cmStrCat("CMAKE_LINK_GROUP_USING_", feature, "_SUPPORTED");
  293. return makefile->GetDefinition(featureSupported).IsOn();
  294. }
  295. class EntriesProcessing
  296. {
  297. public:
  298. using LinkEntry = cmComputeLinkDepends::LinkEntry;
  299. using EntryVector = cmComputeLinkDepends::EntryVector;
  300. EntriesProcessing(cmGeneratorTarget const* target,
  301. std::string const& linkLanguage, EntryVector& entries,
  302. EntryVector& finalEntries)
  303. : Target(target)
  304. , LinkLanguage(linkLanguage)
  305. , Entries(entries)
  306. , FinalEntries(finalEntries)
  307. {
  308. auto const* makefile = target->Makefile;
  309. switch (target->GetPolicyStatusCMP0156()) {
  310. case cmPolicies::WARN:
  311. if (!makefile->GetCMakeInstance()->GetIsInTryCompile() &&
  312. makefile->PolicyOptionalWarningEnabled(
  313. "CMAKE_POLICY_WARNING_CMP0156")) {
  314. makefile->GetCMakeInstance()->IssueMessage(
  315. MessageType::AUTHOR_WARNING,
  316. cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0156),
  317. "\nSince the policy is not set, legacy libraries "
  318. "de-duplication strategy will be applied."),
  319. target->GetBacktrace());
  320. }
  321. CM_FALLTHROUGH;
  322. case cmPolicies::OLD:
  323. // rely on default initialization of the class
  324. break;
  325. case cmPolicies::NEW: {
  326. // Policy 0179 applies only when policy 0156 is new
  327. if (target->GetPolicyStatusCMP0179() == cmPolicies::WARN &&
  328. !makefile->GetCMakeInstance()->GetIsInTryCompile() &&
  329. makefile->PolicyOptionalWarningEnabled(
  330. "CMAKE_POLICY_WARNING_CMP0179")) {
  331. makefile->GetCMakeInstance()->IssueMessage(
  332. MessageType::AUTHOR_WARNING,
  333. cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0179),
  334. "\nSince the policy is not set, static libraries "
  335. "de-duplication will keep the last occurrence of the "
  336. "static libraries."),
  337. target->GetBacktrace());
  338. }
  339. if (auto libProcessing = makefile->GetDefinition(cmStrCat(
  340. "CMAKE_", linkLanguage, "_LINK_LIBRARIES_PROCESSING"))) {
  341. // UNICITY keyword is just for compatibility with previous
  342. // implementation
  343. cmsys::RegularExpression processingOption{
  344. "^(ORDER|UNICITY|DEDUPLICATION)=(FORWARD|REVERSE|ALL|NONE|SHARED)$"
  345. };
  346. std::string errorMessage;
  347. for (auto const& option : cmList{ libProcessing }) {
  348. if (processingOption.find(option)) {
  349. if (processingOption.match(1) == "ORDER") {
  350. if (processingOption.match(2) == "FORWARD") {
  351. this->Order = Forward;
  352. } else if (processingOption.match(2) == "REVERSE") {
  353. this->Order = Reverse;
  354. } else {
  355. errorMessage += cmStrCat(" ", option, '\n');
  356. }
  357. } else if (processingOption.match(1) == "UNICITY" ||
  358. processingOption.match(1) == "DEDUPLICATION") {
  359. if (processingOption.match(2) == "ALL") {
  360. this->Deduplication = All;
  361. } else if (processingOption.match(2) == "NONE") {
  362. this->Deduplication = None;
  363. } else if (processingOption.match(2) == "SHARED") {
  364. this->Deduplication = Shared;
  365. } else {
  366. errorMessage += cmStrCat(" ", option, '\n');
  367. }
  368. }
  369. } else {
  370. errorMessage += cmStrCat(" ", option, '\n');
  371. }
  372. }
  373. if (!errorMessage.empty()) {
  374. makefile->GetCMakeInstance()->IssueMessage(
  375. MessageType::FATAL_ERROR,
  376. cmStrCat("Erroneous option(s) for 'CMAKE_", linkLanguage,
  377. "_LINK_LIBRARIES_PROCESSING':\n", errorMessage),
  378. target->GetBacktrace());
  379. }
  380. // For some environments, deduplication should be activated only if
  381. // both policies CMP0156 and CMP0179 are NEW
  382. if (makefile->GetDefinition(cmStrCat(
  383. "CMAKE_", linkLanguage, "_PLATFORM_LINKER_ID")) == "LLD"_s &&
  384. makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT") == "ELF"_s &&
  385. target->GetPolicyStatusCMP0179() != cmPolicies::NEW &&
  386. this->Deduplication == All) {
  387. this->Deduplication = Shared;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. void AddGroups(std::map<size_t, std::vector<size_t>> const& groups)
  394. {
  395. if (!groups.empty()) {
  396. this->Groups = &groups;
  397. // record all libraries as part of groups to ensure correct
  398. // deduplication: libraries as part of groups are always kept.
  399. for (auto const& g : groups) {
  400. for (auto index : g.second) {
  401. this->Emitted.insert(index);
  402. }
  403. }
  404. }
  405. }
  406. void AddLibraries(std::vector<size_t> const& libEntries)
  407. {
  408. if (this->Order == Reverse) {
  409. std::vector<size_t> entries;
  410. if (this->Deduplication == All &&
  411. this->Target->GetPolicyStatusCMP0179() == cmPolicies::NEW) {
  412. // keep the first occurrence of the static libraries
  413. std::set<size_t> emitted{ this->Emitted };
  414. for (auto index : libEntries) {
  415. LinkEntry const& entry = this->Entries[index];
  416. if (!entry.Target ||
  417. entry.Target->GetType() != cmStateEnums::STATIC_LIBRARY) {
  418. entries.emplace_back(index);
  419. continue;
  420. }
  421. if (this->IncludeEntry(entry) || emitted.insert(index).second) {
  422. entries.emplace_back(index);
  423. }
  424. }
  425. } else {
  426. entries = libEntries;
  427. }
  428. // Iterate in reverse order so we can keep only the last occurrence
  429. // of the shared libraries.
  430. this->AddLibraries(cmReverseRange(entries));
  431. } else {
  432. this->AddLibraries(cmMakeRange(libEntries));
  433. }
  434. }
  435. void AddObjects(std::vector<size_t> const& objectEntries)
  436. {
  437. // Place explicitly linked object files in the front. The linker will
  438. // always use them anyway, and they may depend on symbols from libraries.
  439. if (this->Order == Reverse) {
  440. // Append in reverse order at the end since we reverse the final order.
  441. for (auto index : cmReverseRange(objectEntries)) {
  442. this->FinalEntries.emplace_back(this->Entries[index]);
  443. }
  444. } else {
  445. // Append in reverse order to ensure correct final order
  446. for (auto index : cmReverseRange(objectEntries)) {
  447. this->FinalEntries.emplace(this->FinalEntries.begin(),
  448. this->Entries[index]);
  449. }
  450. }
  451. }
  452. void Finalize()
  453. {
  454. if (this->Order == Reverse) {
  455. // Reverse the resulting order since we iterated in reverse.
  456. std::reverse(this->FinalEntries.begin(), this->FinalEntries.end());
  457. }
  458. // expand groups
  459. if (this->Groups) {
  460. for (auto const& g : *this->Groups) {
  461. LinkEntry const& groupEntry = this->Entries[g.first];
  462. auto it = this->FinalEntries.begin();
  463. while (true) {
  464. it = std::find_if(it, this->FinalEntries.end(),
  465. [&groupEntry](LinkEntry const& entry) -> bool {
  466. return groupEntry.Item == entry.Item;
  467. });
  468. if (it == this->FinalEntries.end()) {
  469. break;
  470. }
  471. it->Item.Value = std::string(LG_ITEM_END);
  472. for (auto index = g.second.rbegin(); index != g.second.rend();
  473. ++index) {
  474. it = this->FinalEntries.insert(it, this->Entries[*index]);
  475. }
  476. it = this->FinalEntries.insert(it, groupEntry);
  477. it->Item.Value = std::string(LG_ITEM_BEGIN);
  478. }
  479. }
  480. }
  481. }
  482. private:
  483. enum OrderKind
  484. {
  485. Forward,
  486. Reverse
  487. };
  488. enum DeduplicationKind
  489. {
  490. None,
  491. Shared,
  492. All
  493. };
  494. bool IncludeEntry(LinkEntry const& entry) const
  495. {
  496. if (entry.Feature != cmComputeLinkDepends::LinkEntry::DEFAULT) {
  497. auto const& featureAttributes = GetLinkLibraryFeatureAttributes(
  498. this->Target->Makefile, this->LinkLanguage, entry.Feature);
  499. if ((!entry.Target ||
  500. featureAttributes.LibraryTypes.find(entry.Target->GetType()) !=
  501. featureAttributes.LibraryTypes.end()) &&
  502. featureAttributes.Deduplication !=
  503. LinkLibraryFeatureAttributeSet::Default) {
  504. return featureAttributes.Deduplication ==
  505. LinkLibraryFeatureAttributeSet::No;
  506. }
  507. }
  508. return this->Deduplication == None ||
  509. (this->Deduplication == Shared &&
  510. (!entry.Target ||
  511. entry.Target->GetType() != cmStateEnums::SHARED_LIBRARY)) ||
  512. (this->Deduplication == All && entry.Kind != LinkEntry::Library);
  513. }
  514. template <typename Range>
  515. void AddLibraries(Range const& libEntries)
  516. {
  517. for (auto index : libEntries) {
  518. LinkEntry const& entry = this->Entries[index];
  519. if (this->IncludeEntry(entry) || this->Emitted.insert(index).second) {
  520. this->FinalEntries.emplace_back(entry);
  521. }
  522. }
  523. }
  524. OrderKind Order = Reverse;
  525. DeduplicationKind Deduplication = Shared;
  526. cmGeneratorTarget const* Target;
  527. std::string const& LinkLanguage;
  528. EntryVector& Entries;
  529. EntryVector& FinalEntries;
  530. std::set<size_t> Emitted;
  531. std::map<size_t, std::vector<size_t>> const* Groups = nullptr;
  532. };
  533. }
  534. std::string const& cmComputeLinkDepends::LinkEntry::DEFAULT =
  535. cmLinkItem::DEFAULT;
  536. cmComputeLinkDepends::cmComputeLinkDepends(cmGeneratorTarget const* target,
  537. std::string config,
  538. std::string linkLanguage,
  539. LinkLibrariesStrategy strategy)
  540. : Target(target)
  541. , Makefile(this->Target->Target->GetMakefile())
  542. , GlobalGenerator(this->Target->GetLocalGenerator()->GetGlobalGenerator())
  543. , CMakeInstance(this->GlobalGenerator->GetCMakeInstance())
  544. , Config(std::move(config))
  545. , DebugMode(this->Makefile->IsOn("CMAKE_LINK_DEPENDS_DEBUG_MODE") ||
  546. this->Target->GetProperty("LINK_DEPENDS_DEBUG_MODE").IsOn())
  547. , LinkLanguage(std::move(linkLanguage))
  548. , LinkType(ComputeLinkType(
  549. this->Config, this->Makefile->GetCMakeInstance()->GetDebugConfigs()))
  550. , Strategy(strategy)
  551. {
  552. cm::GenEx::Context context(this->Target->LocalGenerator, this->Config,
  553. this->LinkLanguage);
  554. // target oriented feature override property takes precedence over
  555. // global override property
  556. cm::string_view lloPrefix = "LINK_LIBRARY_OVERRIDE_"_s;
  557. auto const& keys = this->Target->GetPropertyKeys();
  558. std::for_each(
  559. keys.cbegin(), keys.cend(),
  560. [this, &lloPrefix, &context](std::string const& key) {
  561. if (cmHasPrefix(key, lloPrefix)) {
  562. if (cmValue feature = this->Target->GetProperty(key)) {
  563. if (!feature->empty() && key.length() > lloPrefix.length()) {
  564. auto item = key.substr(lloPrefix.length());
  565. cmGeneratorExpressionDAGChecker dagChecker{
  566. this->Target, "LINK_LIBRARY_OVERRIDE", nullptr, nullptr,
  567. context, this->Target->GetBacktrace(),
  568. };
  569. auto overrideFeature = cmGeneratorExpression::Evaluate(
  570. *feature, context.LG, context.Config, this->Target, &dagChecker,
  571. this->Target, context.Language);
  572. this->LinkLibraryOverride.emplace(item, overrideFeature);
  573. }
  574. }
  575. }
  576. });
  577. // global override property
  578. if (cmValue linkLibraryOverride =
  579. this->Target->GetProperty("LINK_LIBRARY_OVERRIDE")) {
  580. cmGeneratorExpressionDAGChecker dagChecker{
  581. this->Target, "LINK_LIBRARY_OVERRIDE", nullptr, nullptr,
  582. context, this->Target->GetBacktrace(),
  583. };
  584. auto overrideValue = cmGeneratorExpression::Evaluate(
  585. *linkLibraryOverride, context.LG, context.Config, this->Target,
  586. &dagChecker, this->Target, context.Language);
  587. std::vector<std::string> overrideList =
  588. cmTokenize(overrideValue, ',', cmTokenizerMode::New);
  589. if (overrideList.size() >= 2) {
  590. auto const& feature = overrideList.front();
  591. std::for_each(overrideList.cbegin() + 1, overrideList.cend(),
  592. [this, &feature](std::string const& item) {
  593. this->LinkLibraryOverride.emplace(item, feature);
  594. });
  595. }
  596. }
  597. }
  598. cmComputeLinkDepends::~cmComputeLinkDepends() = default;
  599. std::vector<cmComputeLinkDepends::LinkEntry> const&
  600. cmComputeLinkDepends::Compute()
  601. {
  602. // Follow the link dependencies of the target to be linked.
  603. this->AddDirectLinkEntries();
  604. // Complete the breadth-first search of dependencies.
  605. while (!this->BFSQueue.empty()) {
  606. // Get the next entry.
  607. BFSEntry qe = this->BFSQueue.front();
  608. this->BFSQueue.pop();
  609. // Follow the entry's dependencies.
  610. this->FollowLinkEntry(qe);
  611. }
  612. // Complete the search of shared library dependencies.
  613. while (!this->SharedDepQueue.empty()) {
  614. // Handle the next entry.
  615. this->HandleSharedDependency(this->SharedDepQueue.front());
  616. this->SharedDepQueue.pop();
  617. }
  618. // Infer dependencies of targets for which they were not known.
  619. this->InferDependencies();
  620. // finalize groups dependencies
  621. // All dependencies which are raw items must be replaced by the group
  622. // it belongs to, if any.
  623. this->UpdateGroupDependencies();
  624. // Cleanup the constraint graph.
  625. this->CleanConstraintGraph();
  626. // Display the constraint graph.
  627. if (this->DebugMode) {
  628. fprintf(stderr,
  629. "---------------------------------------"
  630. "---------------------------------------\n");
  631. fprintf(stderr, "Link dependency analysis for target %s, config %s\n",
  632. this->Target->GetName().c_str(),
  633. this->Config.empty() ? "noconfig" : this->Config.c_str());
  634. this->DisplayConstraintGraph();
  635. }
  636. // Compute the DAG of strongly connected components. The algorithm
  637. // used by cmComputeComponentGraph should identify the components in
  638. // the same order in which the items were originally discovered in
  639. // the BFS. This should preserve the original order when no
  640. // constraints disallow it.
  641. this->CCG =
  642. cm::make_unique<cmComputeComponentGraph>(this->EntryConstraintGraph);
  643. this->CCG->Compute();
  644. if (!this->CheckCircularDependencies()) {
  645. return this->FinalLinkEntries;
  646. }
  647. // Compute the final ordering.
  648. this->OrderLinkEntries();
  649. // Display the final ordering.
  650. if (this->DebugMode) {
  651. this->DisplayOrderedEntries();
  652. }
  653. // Compute the final set of link entries.
  654. EntriesProcessing entriesProcessing{ this->Target, this->LinkLanguage,
  655. this->EntryList,
  656. this->FinalLinkEntries };
  657. // Add groups first, to ensure that libraries of the groups are always kept.
  658. entriesProcessing.AddGroups(this->GroupItems);
  659. entriesProcessing.AddLibraries(this->FinalLinkOrder);
  660. entriesProcessing.AddObjects(this->ObjectEntries);
  661. entriesProcessing.Finalize();
  662. // Display the final set.
  663. if (this->DebugMode) {
  664. this->DisplayFinalEntries();
  665. }
  666. return this->FinalLinkEntries;
  667. }
  668. std::string const& cmComputeLinkDepends::GetCurrentFeature(
  669. std::string const& item, std::string const& defaultFeature) const
  670. {
  671. auto it = this->LinkLibraryOverride.find(item);
  672. return it == this->LinkLibraryOverride.end() ? defaultFeature : it->second;
  673. }
  674. std::pair<std::map<cmLinkItem, size_t>::iterator, bool>
  675. cmComputeLinkDepends::AllocateLinkEntry(cmLinkItem const& item)
  676. {
  677. std::map<cmLinkItem, size_t>::value_type index_entry(
  678. item, static_cast<size_t>(this->EntryList.size()));
  679. auto lei = this->LinkEntryIndex.insert(index_entry);
  680. if (lei.second) {
  681. this->EntryList.emplace_back();
  682. this->InferredDependSets.emplace_back();
  683. this->EntryConstraintGraph.emplace_back();
  684. }
  685. return lei;
  686. }
  687. std::pair<size_t, bool> cmComputeLinkDepends::AddLinkEntry(
  688. cmLinkItem const& item, cm::optional<size_t> const& groupIndex)
  689. {
  690. // Allocate a spot for the item entry.
  691. auto lei = this->AllocateLinkEntry(item);
  692. // Check if the item entry has already been added.
  693. if (!lei.second) {
  694. // Yes. We do not need to follow the item's dependencies again.
  695. return { lei.first->second, false };
  696. }
  697. // Initialize the item entry.
  698. size_t index = lei.first->second;
  699. LinkEntry& entry = this->EntryList[index];
  700. entry.Item = BT<std::string>(item.AsStr(), item.Backtrace);
  701. entry.Target = item.Target;
  702. entry.Feature = item.Feature;
  703. if (!entry.Target && entry.Item.Value[0] == '-' &&
  704. entry.Item.Value[1] != 'l' &&
  705. entry.Item.Value.substr(0, 10) != "-framework") {
  706. entry.Kind = LinkEntry::Flag;
  707. entry.Feature = LinkEntry::DEFAULT;
  708. } else if (cmHasPrefix(entry.Item.Value, LG_BEGIN) &&
  709. cmHasSuffix(entry.Item.Value, '>')) {
  710. entry.Kind = LinkEntry::Group;
  711. }
  712. if (entry.Kind != LinkEntry::Group) {
  713. // If the item has dependencies queue it to follow them.
  714. if (entry.Target) {
  715. // Target dependencies are always known. Follow them.
  716. BFSEntry qe = { index, groupIndex, nullptr };
  717. this->BFSQueue.push(qe);
  718. } else {
  719. // Look for an old-style <item>_LIB_DEPENDS variable.
  720. std::string var = cmStrCat(entry.Item.Value, "_LIB_DEPENDS");
  721. if (cmValue val = this->Makefile->GetDefinition(var)) {
  722. // The item dependencies are known. Follow them.
  723. BFSEntry qe = { index, groupIndex, val->c_str() };
  724. this->BFSQueue.push(qe);
  725. } else if (entry.Kind != LinkEntry::Flag) {
  726. // The item dependencies are not known. We need to infer them.
  727. this->InferredDependSets[index].Initialized = true;
  728. }
  729. }
  730. }
  731. return { index, true };
  732. }
  733. void cmComputeLinkDepends::AddLinkObject(cmLinkItem const& item)
  734. {
  735. assert(!item.Target); // The item is an object file, not its target.
  736. // Allocate a spot for the item entry.
  737. auto lei = this->AllocateLinkEntry(item);
  738. // Check if the item entry has already been added.
  739. if (!lei.second) {
  740. return;
  741. }
  742. // Initialize the item entry.
  743. size_t index = lei.first->second;
  744. LinkEntry& entry = this->EntryList[index];
  745. entry.Item = BT<std::string>(item.AsStr(), item.Backtrace);
  746. entry.Kind = LinkEntry::Object;
  747. entry.ObjectSource = item.ObjectSource;
  748. // Record explicitly linked object files separately.
  749. this->ObjectEntries.emplace_back(index);
  750. }
  751. void cmComputeLinkDepends::FollowLinkEntry(BFSEntry qe)
  752. {
  753. // Get this entry representation.
  754. size_t depender_index = qe.GroupIndex ? *qe.GroupIndex : qe.Index;
  755. LinkEntry const& entry = this->EntryList[qe.Index];
  756. // Follow the item's dependencies.
  757. if (entry.Target) {
  758. // Follow the target dependencies.
  759. if (cmLinkInterface const* iface =
  760. entry.Target->GetLinkInterface(this->Config, this->Target)) {
  761. bool const isIface =
  762. entry.Target->GetType() == cmStateEnums::INTERFACE_LIBRARY;
  763. // This target provides its own link interface information.
  764. this->AddLinkEntries(depender_index, iface->Libraries);
  765. this->AddLinkObjects(iface->Objects);
  766. for (auto const& language : iface->Languages) {
  767. auto runtimeEntries = iface->LanguageRuntimeLibraries.find(language);
  768. if (runtimeEntries != iface->LanguageRuntimeLibraries.end()) {
  769. this->AddLinkEntries(depender_index, runtimeEntries->second);
  770. }
  771. }
  772. if (isIface) {
  773. return;
  774. }
  775. // Handle dependent shared libraries.
  776. this->FollowSharedDeps(depender_index, iface);
  777. }
  778. } else {
  779. // Follow the old-style dependency list.
  780. this->AddVarLinkEntries(depender_index, qe.LibDepends);
  781. }
  782. }
  783. void cmComputeLinkDepends::FollowSharedDeps(size_t depender_index,
  784. cmLinkInterface const* iface,
  785. bool follow_interface)
  786. {
  787. // Follow dependencies if we have not followed them already.
  788. if (this->SharedDepFollowed.insert(depender_index).second) {
  789. if (follow_interface) {
  790. this->QueueSharedDependencies(depender_index, iface->Libraries);
  791. }
  792. this->QueueSharedDependencies(depender_index, iface->SharedDeps);
  793. }
  794. }
  795. void cmComputeLinkDepends::QueueSharedDependencies(
  796. size_t depender_index, std::vector<cmLinkItem> const& deps)
  797. {
  798. for (cmLinkItem const& li : deps) {
  799. SharedDepEntry qe;
  800. qe.Item = li;
  801. qe.DependerIndex = depender_index;
  802. this->SharedDepQueue.push(qe);
  803. }
  804. }
  805. void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep)
  806. {
  807. // Allocate a spot for the item entry.
  808. auto lei = this->AllocateLinkEntry(dep.Item);
  809. size_t index = lei.first->second;
  810. // Check if the target does not already has an entry.
  811. if (lei.second) {
  812. // Initialize the item entry.
  813. LinkEntry& entry = this->EntryList[index];
  814. entry.Item = BT<std::string>(dep.Item.AsStr(), dep.Item.Backtrace);
  815. entry.Target = dep.Item.Target;
  816. // This item was added specifically because it is a dependent
  817. // shared library. It may get special treatment
  818. // in cmComputeLinkInformation.
  819. entry.Kind = LinkEntry::SharedDep;
  820. }
  821. // Get the link entry for this target.
  822. LinkEntry& entry = this->EntryList[index];
  823. // This shared library dependency must follow the item that listed
  824. // it.
  825. this->EntryConstraintGraph[dep.DependerIndex].emplace_back(
  826. index, true, false, cmListFileBacktrace());
  827. // Target items may have their own dependencies.
  828. if (entry.Target) {
  829. if (cmLinkInterface const* iface =
  830. entry.Target->GetLinkInterface(this->Config, this->Target)) {
  831. // Follow public and private dependencies transitively.
  832. this->FollowSharedDeps(index, iface, true);
  833. }
  834. }
  835. }
  836. void cmComputeLinkDepends::AddVarLinkEntries(
  837. cm::optional<size_t> const& depender_index, char const* value)
  838. {
  839. // This is called to add the dependencies named by
  840. // <item>_LIB_DEPENDS. The variable contains a semicolon-separated
  841. // list. The list contains link-type;item pairs and just items.
  842. cmList deplist{ value };
  843. // Look for entries meant for this configuration.
  844. std::vector<cmLinkItem> actual_libs;
  845. cmTargetLinkLibraryType llt = GENERAL_LibraryType;
  846. bool haveLLT = false;
  847. for (std::string const& d : deplist) {
  848. if (d == "debug") {
  849. llt = DEBUG_LibraryType;
  850. haveLLT = true;
  851. } else if (d == "optimized") {
  852. llt = OPTIMIZED_LibraryType;
  853. haveLLT = true;
  854. } else if (d == "general") {
  855. llt = GENERAL_LibraryType;
  856. haveLLT = true;
  857. } else if (!d.empty()) {
  858. // If no explicit link type was given prior to this entry then
  859. // check if the entry has its own link type variable. This is
  860. // needed for compatibility with dependency files generated by
  861. // the export_library_dependencies command from CMake 2.4 and
  862. // lower.
  863. if (!haveLLT) {
  864. std::string var = cmStrCat(d, "_LINK_TYPE");
  865. if (cmValue val = this->Makefile->GetDefinition(var)) {
  866. if (*val == "debug") {
  867. llt = DEBUG_LibraryType;
  868. } else if (*val == "optimized") {
  869. llt = OPTIMIZED_LibraryType;
  870. }
  871. }
  872. }
  873. // If the library is meant for this link type then use it.
  874. if (llt == GENERAL_LibraryType || llt == this->LinkType) {
  875. actual_libs.emplace_back(this->ResolveLinkItem(depender_index, d));
  876. }
  877. // Reset the link type until another explicit type is given.
  878. llt = GENERAL_LibraryType;
  879. haveLLT = false;
  880. }
  881. }
  882. // Add the entries from this list.
  883. this->AddLinkEntries(depender_index, actual_libs);
  884. }
  885. void cmComputeLinkDepends::AddDirectLinkEntries()
  886. {
  887. // Add direct link dependencies in this configuration.
  888. cmLinkImplementation const* impl = this->Target->GetLinkImplementation(
  889. this->Config, cmGeneratorTarget::UseTo::Link);
  890. this->AddLinkEntries(cm::nullopt, impl->Libraries);
  891. this->AddLinkObjects(impl->Objects);
  892. for (auto const& language : impl->Languages) {
  893. auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
  894. if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
  895. this->AddLinkEntries(cm::nullopt, runtimeEntries->second);
  896. }
  897. }
  898. }
  899. template <typename T>
  900. void cmComputeLinkDepends::AddLinkEntries(
  901. cm::optional<size_t> const& depender_index, std::vector<T> const& libs)
  902. {
  903. // Track inferred dependency sets implied by this list.
  904. std::map<size_t, DependSet> dependSets;
  905. cm::optional<std::pair<size_t, bool>> group;
  906. std::vector<size_t> groupItems;
  907. // Loop over the libraries linked directly by the depender.
  908. for (T const& l : libs) {
  909. // Skip entries that will resolve to the target getting linked or
  910. // are empty.
  911. cmLinkItem const& item = l;
  912. if (item.AsStr() == this->Target->GetName() || item.AsStr().empty()) {
  913. continue;
  914. }
  915. // emit a warning if an undefined feature is used as part of
  916. // an imported target
  917. if (item.Feature != LinkEntry::DEFAULT && depender_index) {
  918. auto const& depender = this->EntryList[*depender_index];
  919. if (depender.Target && depender.Target->IsImported() &&
  920. !IsFeatureSupported(this->Makefile, this->LinkLanguage,
  921. item.Feature)) {
  922. this->CMakeInstance->IssueMessage(
  923. MessageType::AUTHOR_ERROR,
  924. cmStrCat("The 'IMPORTED' target '", depender.Target->GetName(),
  925. "' uses the generator-expression '$<LINK_LIBRARY>' with "
  926. "the feature '",
  927. item.Feature,
  928. "', which is undefined or unsupported.\nDid you miss to "
  929. "define it by setting variables \"CMAKE_",
  930. this->LinkLanguage, "_LINK_LIBRARY_USING_", item.Feature,
  931. "\" and \"CMAKE_", this->LinkLanguage,
  932. "_LINK_LIBRARY_USING_", item.Feature, "_SUPPORTED\"?"),
  933. this->Target->GetBacktrace());
  934. }
  935. }
  936. if (cmHasPrefix(item.AsStr(), LG_BEGIN) &&
  937. cmHasSuffix(item.AsStr(), '>')) {
  938. group = this->AddLinkEntry(item, cm::nullopt);
  939. if (group->second) {
  940. LinkEntry& entry = this->EntryList[group->first];
  941. entry.Feature = ExtractGroupFeature(item.AsStr());
  942. }
  943. if (depender_index) {
  944. this->EntryConstraintGraph[*depender_index].emplace_back(
  945. group->first, false, false, cmListFileBacktrace());
  946. } else {
  947. // This is a direct dependency of the target being linked.
  948. this->OriginalEntries.push_back(group->first);
  949. }
  950. continue;
  951. }
  952. size_t dependee_index;
  953. if (cmHasPrefix(item.AsStr(), LG_END) && cmHasSuffix(item.AsStr(), '>')) {
  954. assert(group);
  955. dependee_index = group->first;
  956. if (group->second) {
  957. this->GroupItems.emplace(group->first, std::move(groupItems));
  958. }
  959. group = cm::nullopt;
  960. groupItems.clear();
  961. continue;
  962. }
  963. if (depender_index && group) {
  964. auto const& depender = this->EntryList[*depender_index];
  965. auto const& groupFeature = this->EntryList[group->first].Feature;
  966. if (depender.Target && depender.Target->IsImported() &&
  967. !IsGroupFeatureSupported(this->Makefile, this->LinkLanguage,
  968. groupFeature)) {
  969. this->CMakeInstance->IssueMessage(
  970. MessageType::AUTHOR_ERROR,
  971. cmStrCat("The 'IMPORTED' target '", depender.Target->GetName(),
  972. "' uses the generator-expression '$<LINK_GROUP>' with "
  973. "the feature '",
  974. groupFeature,
  975. "', which is undefined or unsupported.\nDid you miss to "
  976. "define it by setting variables \"CMAKE_",
  977. this->LinkLanguage, "_LINK_GROUP_USING_", groupFeature,
  978. "\" and \"CMAKE_", this->LinkLanguage, "_LINK_GROUP_USING_",
  979. groupFeature, "_SUPPORTED\"?"),
  980. this->Target->GetBacktrace());
  981. }
  982. }
  983. // Add a link entry for this item.
  984. auto ale = this->AddLinkEntry(
  985. item, group ? cm::optional<size_t>(group->first) : cm::nullopt);
  986. dependee_index = ale.first;
  987. LinkEntry& entry = this->EntryList[dependee_index];
  988. bool supportedItem = true;
  989. auto const& itemFeature =
  990. this->GetCurrentFeature(entry.Item.Value, item.Feature);
  991. if (group && ale.second && entry.Target &&
  992. (entry.Target->GetType() == cmStateEnums::TargetType::OBJECT_LIBRARY ||
  993. entry.Target->GetType() ==
  994. cmStateEnums::TargetType::INTERFACE_LIBRARY)) {
  995. supportedItem = false;
  996. auto const& groupFeature = this->EntryList[group->first].Feature;
  997. this->CMakeInstance->IssueMessage(
  998. MessageType::AUTHOR_WARNING,
  999. cmStrCat(
  1000. "The feature '", groupFeature,
  1001. "', specified as part of a generator-expression "
  1002. "'$",
  1003. LG_BEGIN, groupFeature, ">', will not be applied to the ",
  1004. (entry.Target->GetType() == cmStateEnums::TargetType::OBJECT_LIBRARY
  1005. ? "OBJECT"
  1006. : "INTERFACE"),
  1007. " library '", entry.Item.Value, "'."),
  1008. this->Target->GetBacktrace());
  1009. }
  1010. // check if feature is applicable to this item
  1011. if (itemFeature != LinkEntry::DEFAULT && entry.Target) {
  1012. auto const& featureAttributes = GetLinkLibraryFeatureAttributes(
  1013. this->Makefile, this->LinkLanguage, itemFeature);
  1014. if (featureAttributes.LibraryTypes.find(entry.Target->GetType()) ==
  1015. featureAttributes.LibraryTypes.end()) {
  1016. supportedItem = false;
  1017. this->CMakeInstance->IssueMessage(
  1018. MessageType::AUTHOR_WARNING,
  1019. cmStrCat("The feature '", itemFeature,
  1020. "', specified as part of a generator-expression "
  1021. "'$<LINK_LIBRARY:",
  1022. itemFeature, ">', will not be applied to the ",
  1023. cmState::GetTargetTypeName(entry.Target->GetType()), " '",
  1024. entry.Item.Value, "'."),
  1025. this->Target->GetBacktrace());
  1026. }
  1027. }
  1028. if (ale.second) {
  1029. // current item not yet defined
  1030. entry.Feature = itemFeature;
  1031. if (!supportedItem) {
  1032. entry.Feature = LinkEntry::DEFAULT;
  1033. }
  1034. }
  1035. if (supportedItem) {
  1036. if (group) {
  1037. auto const& currentFeature = this->EntryList[group->first].Feature;
  1038. for (auto const& g : this->GroupItems) {
  1039. auto const& groupFeature = this->EntryList[g.first].Feature;
  1040. if (groupFeature == currentFeature) {
  1041. continue;
  1042. }
  1043. if (std::find(g.second.cbegin(), g.second.cend(), dependee_index) !=
  1044. g.second.cend()) {
  1045. this->CMakeInstance->IssueMessage(
  1046. MessageType::FATAL_ERROR,
  1047. cmStrCat("Impossible to link target '", this->Target->GetName(),
  1048. "' because the link item '", entry.Item.Value,
  1049. "', specified with the group feature '", currentFeature,
  1050. "', has already occurred with the feature '",
  1051. groupFeature, "', which is not allowed."),
  1052. this->Target->GetBacktrace());
  1053. continue;
  1054. }
  1055. }
  1056. }
  1057. if (entry.Feature != itemFeature) {
  1058. bool incompatibleFeatures = true;
  1059. // check if an override is possible
  1060. auto const& entryFeatureAttributes = GetLinkLibraryFeatureAttributes(
  1061. this->Makefile, this->LinkLanguage, entry.Feature);
  1062. auto const& itemFeatureAttributes = GetLinkLibraryFeatureAttributes(
  1063. this->Makefile, this->LinkLanguage, itemFeature);
  1064. if (itemFeatureAttributes.Override.find(entry.Feature) !=
  1065. itemFeatureAttributes.Override.end() &&
  1066. entryFeatureAttributes.Override.find(itemFeature) !=
  1067. entryFeatureAttributes.Override.end()) {
  1068. // features override each other
  1069. this->CMakeInstance->IssueMessage(
  1070. MessageType::FATAL_ERROR,
  1071. cmStrCat("Impossible to link target '", this->Target->GetName(),
  1072. "' because the link item '", entry.Item.Value,
  1073. "' is specified with the features '", itemFeature,
  1074. "' and '", entry.Feature,
  1075. "'"
  1076. ", and both have an 'OVERRIDE' attribute that overrides "
  1077. "the other. Such cycles are not allowed."),
  1078. this->Target->GetBacktrace());
  1079. } else {
  1080. if (itemFeatureAttributes.Override.find(entry.Feature) !=
  1081. itemFeatureAttributes.Override.end()) {
  1082. entry.Feature = itemFeature;
  1083. incompatibleFeatures = false;
  1084. } else if (entryFeatureAttributes.Override.find(itemFeature) !=
  1085. entryFeatureAttributes.Override.end()) {
  1086. incompatibleFeatures = false;
  1087. }
  1088. if (incompatibleFeatures) {
  1089. // incompatibles features occurred
  1090. this->CMakeInstance->IssueMessage(
  1091. MessageType::FATAL_ERROR,
  1092. cmStrCat(
  1093. "Impossible to link target '", this->Target->GetName(),
  1094. "' because the link item '", entry.Item.Value, "', specified ",
  1095. (itemFeature == LinkEntry::DEFAULT
  1096. ? "without any feature or 'DEFAULT' feature"
  1097. : cmStrCat("with the feature '", itemFeature, '\'')),
  1098. ", has already occurred ",
  1099. (entry.Feature == LinkEntry::DEFAULT
  1100. ? "without any feature or 'DEFAULT' feature"
  1101. : cmStrCat("with the feature '", entry.Feature, '\'')),
  1102. ", which is not allowed."),
  1103. this->Target->GetBacktrace());
  1104. }
  1105. }
  1106. }
  1107. }
  1108. if (group) {
  1109. // store item index for dependencies handling
  1110. groupItems.push_back(dependee_index);
  1111. } else {
  1112. std::vector<size_t> indexes;
  1113. bool entryHandled = false;
  1114. // search any occurrence of the library in already defined groups
  1115. for (auto const& g : this->GroupItems) {
  1116. for (auto index : g.second) {
  1117. if (entry.Item.Value == this->EntryList[index].Item.Value) {
  1118. indexes.push_back(g.first);
  1119. entryHandled = true;
  1120. break;
  1121. }
  1122. }
  1123. }
  1124. if (!entryHandled) {
  1125. indexes.push_back(dependee_index);
  1126. }
  1127. for (auto index : indexes) {
  1128. // The dependee must come after the depender.
  1129. if (depender_index) {
  1130. this->EntryConstraintGraph[*depender_index].emplace_back(
  1131. index, false, false, cmListFileBacktrace());
  1132. } else {
  1133. // This is a direct dependency of the target being linked.
  1134. this->OriginalEntries.push_back(index);
  1135. }
  1136. // Update the inferred dependencies for earlier items.
  1137. for (auto& dependSet : dependSets) {
  1138. // Add this item to the inferred dependencies of other items.
  1139. // Target items are never inferred dependees because unknown
  1140. // items are outside libraries that should not be depending on
  1141. // targets.
  1142. if (!this->EntryList[index].Target &&
  1143. this->EntryList[index].Kind != LinkEntry::Flag &&
  1144. this->EntryList[index].Kind != LinkEntry::Group &&
  1145. dependee_index != dependSet.first) {
  1146. dependSet.second.insert(index);
  1147. }
  1148. }
  1149. // If this item needs to have dependencies inferred, do so.
  1150. if (this->InferredDependSets[index].Initialized) {
  1151. // Make sure an entry exists to hold the set for the item.
  1152. dependSets[index];
  1153. }
  1154. }
  1155. }
  1156. }
  1157. // Store the inferred dependency sets discovered for this list.
  1158. for (auto const& dependSet : dependSets) {
  1159. this->InferredDependSets[dependSet.first].push_back(dependSet.second);
  1160. }
  1161. }
  1162. void cmComputeLinkDepends::AddLinkObjects(std::vector<cmLinkItem> const& objs)
  1163. {
  1164. for (cmLinkItem const& obj : objs) {
  1165. this->AddLinkObject(obj);
  1166. }
  1167. }
  1168. cmLinkItem cmComputeLinkDepends::ResolveLinkItem(
  1169. cm::optional<size_t> const& depender_index, std::string const& name)
  1170. {
  1171. // Look for a target in the scope of the depender.
  1172. cmGeneratorTarget const* from = this->Target;
  1173. if (depender_index) {
  1174. if (cmGeneratorTarget const* depender =
  1175. this->EntryList[*depender_index].Target) {
  1176. from = depender;
  1177. }
  1178. }
  1179. return from->ResolveLinkItem(BT<std::string>(name));
  1180. }
  1181. void cmComputeLinkDepends::InferDependencies()
  1182. {
  1183. // The inferred dependency sets for each item list the possible
  1184. // dependencies. The intersection of the sets for one item form its
  1185. // inferred dependencies.
  1186. for (size_t depender_index = 0;
  1187. depender_index < this->InferredDependSets.size(); ++depender_index) {
  1188. // Skip items for which dependencies do not need to be inferred or
  1189. // for which the inferred dependency sets are empty.
  1190. DependSetList& sets = this->InferredDependSets[depender_index];
  1191. if (!sets.Initialized || sets.empty()) {
  1192. continue;
  1193. }
  1194. // Intersect the sets for this item.
  1195. DependSet common = sets.front();
  1196. for (DependSet const& i : cmMakeRange(sets).advance(1)) {
  1197. DependSet intersection;
  1198. std::set_intersection(common.begin(), common.end(), i.begin(), i.end(),
  1199. std::inserter(intersection, intersection.begin()));
  1200. common = intersection;
  1201. }
  1202. // Add the inferred dependencies to the graph.
  1203. cmGraphEdgeList& edges = this->EntryConstraintGraph[depender_index];
  1204. edges.reserve(edges.size() + common.size());
  1205. for (auto const& c : common) {
  1206. edges.emplace_back(c, true, false, cmListFileBacktrace());
  1207. }
  1208. }
  1209. }
  1210. void cmComputeLinkDepends::UpdateGroupDependencies()
  1211. {
  1212. if (this->GroupItems.empty()) {
  1213. return;
  1214. }
  1215. // Walks through all entries of the constraint graph to replace dependencies
  1216. // over raw items by the group it belongs to, if any.
  1217. for (auto& edgeList : this->EntryConstraintGraph) {
  1218. for (auto& edge : edgeList) {
  1219. size_t index = edge;
  1220. if (this->EntryList[index].Kind == LinkEntry::Group ||
  1221. this->EntryList[index].Kind == LinkEntry::Flag ||
  1222. this->EntryList[index].Kind == LinkEntry::Object) {
  1223. continue;
  1224. }
  1225. // search the item in the defined groups
  1226. for (auto const& groupItems : this->GroupItems) {
  1227. auto pos = std::find(groupItems.second.cbegin(),
  1228. groupItems.second.cend(), index);
  1229. if (pos != groupItems.second.cend()) {
  1230. // replace lib dependency by the group it belongs to
  1231. edge = cmGraphEdge{ groupItems.first, false, false,
  1232. cmListFileBacktrace() };
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. void cmComputeLinkDepends::CleanConstraintGraph()
  1239. {
  1240. for (cmGraphEdgeList& edgeList : this->EntryConstraintGraph) {
  1241. // Sort the outgoing edges for each graph node so that the
  1242. // original order will be preserved as much as possible.
  1243. std::sort(edgeList.begin(), edgeList.end());
  1244. // Make the edge list unique.
  1245. edgeList.erase(std::unique(edgeList.begin(), edgeList.end()),
  1246. edgeList.end());
  1247. }
  1248. }
  1249. bool cmComputeLinkDepends::CheckCircularDependencies() const
  1250. {
  1251. std::vector<NodeList> const& components = this->CCG->GetComponents();
  1252. size_t nc = components.size();
  1253. for (size_t c = 0; c < nc; ++c) {
  1254. // Get the current component.
  1255. NodeList const& nl = components[c];
  1256. // Skip trivial components.
  1257. if (nl.size() < 2) {
  1258. continue;
  1259. }
  1260. // no group must be evolved
  1261. bool cycleDetected = false;
  1262. for (size_t ni : nl) {
  1263. if (this->EntryList[ni].Kind == LinkEntry::Group) {
  1264. cycleDetected = true;
  1265. break;
  1266. }
  1267. }
  1268. if (!cycleDetected) {
  1269. continue;
  1270. }
  1271. // Construct the error message.
  1272. auto formatItem = [](LinkEntry const& entry) -> std::string {
  1273. if (entry.Kind == LinkEntry::Group) {
  1274. auto items =
  1275. entry.Item.Value.substr(entry.Item.Value.find(':', 12) + 1);
  1276. items.pop_back();
  1277. std::replace(items.begin(), items.end(), '|', ',');
  1278. return cmStrCat("group \"", ExtractGroupFeature(entry.Item.Value),
  1279. ":{", items, "}\"");
  1280. }
  1281. return cmStrCat('"', entry.Item.Value, '"');
  1282. };
  1283. std::ostringstream e;
  1284. e << "The inter-target dependency graph, for the target \""
  1285. << this->Target->GetName()
  1286. << "\", contains the following strongly connected component "
  1287. "(cycle):\n";
  1288. std::vector<size_t> const& cmap = this->CCG->GetComponentMap();
  1289. for (size_t i : nl) {
  1290. // Get the depender.
  1291. LinkEntry const& depender = this->EntryList[i];
  1292. // Describe the depender.
  1293. e << " " << formatItem(depender) << "\n";
  1294. // List its dependencies that are inside the component.
  1295. EdgeList const& el = this->EntryConstraintGraph[i];
  1296. for (cmGraphEdge const& ni : el) {
  1297. size_t j = ni;
  1298. if (cmap[j] == c) {
  1299. LinkEntry const& dependee = this->EntryList[j];
  1300. e << " depends on " << formatItem(dependee) << "\n";
  1301. }
  1302. }
  1303. }
  1304. this->CMakeInstance->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  1305. this->Target->GetBacktrace());
  1306. return false;
  1307. }
  1308. return true;
  1309. }
  1310. void cmComputeLinkDepends::DisplayConstraintGraph()
  1311. {
  1312. // Display the graph nodes and their edges.
  1313. std::ostringstream e;
  1314. for (size_t i = 0; i < this->EntryConstraintGraph.size(); ++i) {
  1315. EdgeList const& nl = this->EntryConstraintGraph[i];
  1316. e << "item " << i << " is [" << this->EntryList[i].Item << "]\n";
  1317. e << cmWrap(" item ", nl, " must follow it", "\n") << "\n";
  1318. }
  1319. fprintf(stderr, "%s\n", e.str().c_str());
  1320. }
  1321. void cmComputeLinkDepends::OrderLinkEntries()
  1322. {
  1323. // The component graph is guaranteed to be acyclic. Start a DFS
  1324. // from every entry to compute a topological order for the
  1325. // components.
  1326. Graph const& cgraph = this->CCG->GetComponentGraph();
  1327. size_t n = cgraph.size();
  1328. this->ComponentVisited.resize(cgraph.size(), 0);
  1329. this->ComponentOrder.resize(cgraph.size(), n);
  1330. this->ComponentOrderId = n;
  1331. // Run in reverse order so the topological order will preserve the
  1332. // original order where there are no constraints.
  1333. for (size_t c = n; c > 0; --c) {
  1334. this->VisitComponent(c - 1);
  1335. }
  1336. // Display the component graph.
  1337. if (this->DebugMode) {
  1338. this->DisplayComponents();
  1339. }
  1340. // Start with the original link line.
  1341. switch (this->Strategy) {
  1342. case LinkLibrariesStrategy::REORDER_MINIMALLY: {
  1343. // Emit the direct dependencies in their original order.
  1344. // This gives projects control over ordering.
  1345. for (size_t originalEntry : this->OriginalEntries) {
  1346. this->VisitEntry(originalEntry);
  1347. }
  1348. } break;
  1349. case LinkLibrariesStrategy::REORDER_FREELY: {
  1350. // Schedule the direct dependencies for emission in topo order.
  1351. // This may produce more efficient link lines.
  1352. for (size_t originalEntry : this->OriginalEntries) {
  1353. this->MakePendingComponent(
  1354. this->CCG->GetComponentMap()[originalEntry]);
  1355. }
  1356. } break;
  1357. }
  1358. // Now explore anything left pending. Since the component graph is
  1359. // guaranteed to be acyclic we know this will terminate.
  1360. while (!this->PendingComponents.empty()) {
  1361. // Visit one entry from the first pending component. The visit
  1362. // logic will update the pending components accordingly. Since
  1363. // the pending components are kept in topological order this will
  1364. // not repeat one.
  1365. size_t e = *this->PendingComponents.begin()->second.Entries.begin();
  1366. this->VisitEntry(e);
  1367. }
  1368. }
  1369. void cmComputeLinkDepends::DisplayComponents()
  1370. {
  1371. fprintf(stderr, "The strongly connected components are:\n");
  1372. std::vector<NodeList> const& components = this->CCG->GetComponents();
  1373. for (size_t c = 0; c < components.size(); ++c) {
  1374. fprintf(stderr, "Component (%zu):\n", c);
  1375. NodeList const& nl = components[c];
  1376. for (size_t i : nl) {
  1377. fprintf(stderr, " item %zu [%s]\n", i,
  1378. this->EntryList[i].Item.Value.c_str());
  1379. }
  1380. EdgeList const& ol = this->CCG->GetComponentGraphEdges(c);
  1381. for (cmGraphEdge const& oi : ol) {
  1382. size_t i = oi;
  1383. fprintf(stderr, " followed by Component (%zu)\n", i);
  1384. }
  1385. fprintf(stderr, " topo order index %zu\n", this->ComponentOrder[c]);
  1386. }
  1387. fprintf(stderr, "\n");
  1388. }
  1389. void cmComputeLinkDepends::VisitComponent(size_t c)
  1390. {
  1391. // Check if the node has already been visited.
  1392. if (this->ComponentVisited[c]) {
  1393. return;
  1394. }
  1395. // We are now visiting this component so mark it.
  1396. this->ComponentVisited[c] = 1;
  1397. // Visit the neighbors of the component first.
  1398. // Run in reverse order so the topological order will preserve the
  1399. // original order where there are no constraints.
  1400. EdgeList const& nl = this->CCG->GetComponentGraphEdges(c);
  1401. for (cmGraphEdge const& edge : cmReverseRange(nl)) {
  1402. this->VisitComponent(edge);
  1403. }
  1404. // Assign an ordering id to this component.
  1405. this->ComponentOrder[c] = --this->ComponentOrderId;
  1406. }
  1407. void cmComputeLinkDepends::VisitEntry(size_t index)
  1408. {
  1409. // Include this entry on the link line.
  1410. this->FinalLinkOrder.push_back(index);
  1411. // This entry has now been seen. Update its component.
  1412. bool completed = false;
  1413. size_t component = this->CCG->GetComponentMap()[index];
  1414. auto mi = this->PendingComponents.find(this->ComponentOrder[component]);
  1415. if (mi != this->PendingComponents.end()) {
  1416. // The entry is in an already pending component.
  1417. PendingComponent& pc = mi->second;
  1418. // Remove the entry from those pending in its component.
  1419. pc.Entries.erase(index);
  1420. if (pc.Entries.empty()) {
  1421. // The complete component has been seen since it was last needed.
  1422. --pc.Count;
  1423. if (pc.Count == 0) {
  1424. // The component has been completed.
  1425. this->PendingComponents.erase(mi);
  1426. completed = true;
  1427. } else {
  1428. // The whole component needs to be seen again.
  1429. NodeList const& nl = this->CCG->GetComponent(component);
  1430. assert(nl.size() > 1);
  1431. pc.Entries.insert(nl.begin(), nl.end());
  1432. }
  1433. }
  1434. } else {
  1435. // The entry is not in an already pending component.
  1436. NodeList const& nl = this->CCG->GetComponent(component);
  1437. if (nl.size() > 1) {
  1438. // This is a non-trivial component. It is now pending.
  1439. PendingComponent& pc = this->MakePendingComponent(component);
  1440. // The starting entry has already been seen.
  1441. pc.Entries.erase(index);
  1442. } else {
  1443. // This is a trivial component, so it is already complete.
  1444. completed = true;
  1445. }
  1446. }
  1447. // If the entry completed a component, the component's dependencies
  1448. // are now pending.
  1449. if (completed) {
  1450. EdgeList const& ol = this->CCG->GetComponentGraphEdges(component);
  1451. for (cmGraphEdge const& oi : ol) {
  1452. // This entire component is now pending no matter whether it has
  1453. // been partially seen already.
  1454. this->MakePendingComponent(oi);
  1455. }
  1456. }
  1457. }
  1458. cmComputeLinkDepends::PendingComponent&
  1459. cmComputeLinkDepends::MakePendingComponent(size_t component)
  1460. {
  1461. // Create an entry (in topological order) for the component.
  1462. PendingComponent& pc =
  1463. this->PendingComponents[this->ComponentOrder[component]];
  1464. pc.Id = component;
  1465. NodeList const& nl = this->CCG->GetComponent(component);
  1466. if (nl.size() == 1) {
  1467. // Trivial components need be seen only once.
  1468. pc.Count = 1;
  1469. } else {
  1470. // This is a non-trivial strongly connected component of the
  1471. // original graph. It consists of two or more libraries
  1472. // (archives) that mutually require objects from one another. In
  1473. // the worst case we may have to repeat the list of libraries as
  1474. // many times as there are object files in the biggest archive.
  1475. // For now we just list them twice.
  1476. //
  1477. // The list of items in the component has been sorted by the order
  1478. // of discovery in the original BFS of dependencies. This has the
  1479. // advantage that the item directly linked by a target requiring
  1480. // this component will come first which minimizes the number of
  1481. // repeats needed.
  1482. pc.Count = this->ComputeComponentCount(nl);
  1483. }
  1484. // Store the entries to be seen.
  1485. pc.Entries.insert(nl.begin(), nl.end());
  1486. return pc;
  1487. }
  1488. size_t cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl)
  1489. {
  1490. size_t count = 2;
  1491. for (size_t ni : nl) {
  1492. if (cmGeneratorTarget const* target = this->EntryList[ni].Target) {
  1493. if (cmLinkInterface const* iface =
  1494. target->GetLinkInterface(this->Config, this->Target)) {
  1495. if (iface->Multiplicity > count) {
  1496. count = iface->Multiplicity;
  1497. }
  1498. }
  1499. }
  1500. }
  1501. return count;
  1502. }
  1503. namespace {
  1504. void DisplayLinkEntry(int& count, cmComputeLinkDepends::LinkEntry const& entry)
  1505. {
  1506. if (entry.Kind == cmComputeLinkDepends::LinkEntry::Group) {
  1507. if (entry.Item.Value == LG_ITEM_BEGIN) {
  1508. fprintf(stderr, " start group");
  1509. count = 4;
  1510. } else if (entry.Item.Value == LG_ITEM_END) {
  1511. fprintf(stderr, " end group");
  1512. count = 2;
  1513. } else {
  1514. fprintf(stderr, " group");
  1515. }
  1516. } else if (entry.Target) {
  1517. fprintf(stderr, "%*starget [%s]", count, "",
  1518. entry.Target->GetName().c_str());
  1519. } else {
  1520. fprintf(stderr, "%*sitem [%s]", count, "", entry.Item.Value.c_str());
  1521. }
  1522. if (entry.Feature != cmComputeLinkDepends::LinkEntry::DEFAULT) {
  1523. fprintf(stderr, ", feature [%s]", entry.Feature.c_str());
  1524. }
  1525. fprintf(stderr, "\n");
  1526. }
  1527. }
  1528. void cmComputeLinkDepends::DisplayOrderedEntries()
  1529. {
  1530. fprintf(stderr, "target [%s] link dependency ordering:\n",
  1531. this->Target->GetName().c_str());
  1532. int count = 2;
  1533. for (auto index : this->FinalLinkOrder) {
  1534. DisplayLinkEntry(count, this->EntryList[index]);
  1535. }
  1536. fprintf(stderr, "\n");
  1537. }
  1538. void cmComputeLinkDepends::DisplayFinalEntries()
  1539. {
  1540. fprintf(stderr, "target [%s] link line:\n", this->Target->GetName().c_str());
  1541. int count = 2;
  1542. for (LinkEntry const& entry : this->FinalLinkEntries) {
  1543. DisplayLinkEntry(count, entry);
  1544. }
  1545. fprintf(stderr, "\n");
  1546. }