cmTargetLinkLibrariesCommand.cxx 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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 "cmTargetLinkLibrariesCommand.h"
  4. #include <cassert>
  5. #include <memory>
  6. #include <sstream>
  7. #include <unordered_set>
  8. #include <utility>
  9. #include <cm/optional>
  10. #include "cmExecutionStatus.h"
  11. #include "cmGeneratorExpression.h"
  12. #include "cmGlobalGenerator.h"
  13. #include "cmListFileCache.h"
  14. #include "cmMakefile.h"
  15. #include "cmMessageType.h"
  16. #include "cmPolicies.h"
  17. #include "cmState.h"
  18. #include "cmStateTypes.h"
  19. #include "cmStringAlgorithms.h"
  20. #include "cmSystemTools.h"
  21. #include "cmTarget.h"
  22. #include "cmTargetLinkLibraryType.h"
  23. #include "cmValue.h"
  24. #include "cmake.h"
  25. namespace {
  26. enum ProcessingState
  27. {
  28. ProcessingLinkLibraries,
  29. ProcessingPlainLinkInterface,
  30. ProcessingKeywordLinkInterface,
  31. ProcessingPlainPublicInterface,
  32. ProcessingKeywordPublicInterface,
  33. ProcessingPlainPrivateInterface,
  34. ProcessingKeywordPrivateInterface
  35. };
  36. const char* LinkLibraryTypeNames[3] = { "general", "debug", "optimized" };
  37. struct TLL
  38. {
  39. cmMakefile& Makefile;
  40. cmTarget* Target;
  41. bool WarnRemoteInterface = false;
  42. bool RejectRemoteLinking = false;
  43. bool EncodeRemoteReference = false;
  44. std::string DirectoryId;
  45. std::unordered_set<std::string> Props;
  46. TLL(cmMakefile& mf, cmTarget* target);
  47. ~TLL();
  48. bool HandleLibrary(ProcessingState currentProcessingState,
  49. const std::string& lib, cmTargetLinkLibraryType llt);
  50. void AppendProperty(std::string const& prop, std::string const& value);
  51. void AffectsProperty(std::string const& prop);
  52. };
  53. } // namespace
  54. static void LinkLibraryTypeSpecifierWarning(cmMakefile& mf, int left,
  55. int right);
  56. bool cmTargetLinkLibrariesCommand(std::vector<std::string> const& args,
  57. cmExecutionStatus& status)
  58. {
  59. // Must have at least one argument.
  60. if (args.empty()) {
  61. status.SetError("called with incorrect number of arguments");
  62. return false;
  63. }
  64. cmMakefile& mf = status.GetMakefile();
  65. // Alias targets cannot be on the LHS of this command.
  66. if (mf.IsAlias(args[0])) {
  67. status.SetError("can not be used on an ALIAS target.");
  68. return false;
  69. }
  70. // Lookup the target for which libraries are specified.
  71. cmTarget* target =
  72. mf.GetCMakeInstance()->GetGlobalGenerator()->FindTarget(args[0]);
  73. if (!target) {
  74. for (const auto& importedTarget : mf.GetOwnedImportedTargets()) {
  75. if (importedTarget->GetName() == args[0]) {
  76. target = importedTarget.get();
  77. break;
  78. }
  79. }
  80. }
  81. if (!target) {
  82. MessageType t = MessageType::FATAL_ERROR; // fail by default
  83. std::ostringstream e;
  84. e << "Cannot specify link libraries for target \"" << args[0] << "\" "
  85. << "which is not built by this project.";
  86. // The bad target is the only argument. Check how policy CMP0016 is set,
  87. // and accept, warn or fail respectively:
  88. if (args.size() < 2) {
  89. switch (mf.GetPolicyStatus(cmPolicies::CMP0016)) {
  90. case cmPolicies::WARN:
  91. t = MessageType::AUTHOR_WARNING;
  92. // Print the warning.
  93. e << "\n"
  94. << "CMake does not support this but it used to work accidentally "
  95. << "and is being allowed for compatibility."
  96. << "\n"
  97. << cmPolicies::GetPolicyWarning(cmPolicies::CMP0016);
  98. break;
  99. case cmPolicies::OLD: // OLD behavior does not warn.
  100. t = MessageType::MESSAGE;
  101. break;
  102. case cmPolicies::REQUIRED_IF_USED:
  103. case cmPolicies::REQUIRED_ALWAYS:
  104. e << "\n" << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0016);
  105. break;
  106. case cmPolicies::NEW: // NEW behavior prints the error.
  107. break;
  108. }
  109. }
  110. // Now actually print the message.
  111. switch (t) {
  112. case MessageType::AUTHOR_WARNING:
  113. mf.IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  114. break;
  115. case MessageType::FATAL_ERROR:
  116. mf.IssueMessage(MessageType::FATAL_ERROR, e.str());
  117. cmSystemTools::SetFatalErrorOccured();
  118. break;
  119. default:
  120. break;
  121. }
  122. return true;
  123. }
  124. // Having a UTILITY library on the LHS is a bug.
  125. if (target->GetType() == cmStateEnums::UTILITY) {
  126. std::ostringstream e;
  127. const char* modal = nullptr;
  128. MessageType messageType = MessageType::AUTHOR_WARNING;
  129. switch (mf.GetPolicyStatus(cmPolicies::CMP0039)) {
  130. case cmPolicies::WARN:
  131. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0039) << "\n";
  132. modal = "should";
  133. CM_FALLTHROUGH;
  134. case cmPolicies::OLD:
  135. break;
  136. case cmPolicies::REQUIRED_ALWAYS:
  137. case cmPolicies::REQUIRED_IF_USED:
  138. case cmPolicies::NEW:
  139. modal = "must";
  140. messageType = MessageType::FATAL_ERROR;
  141. break;
  142. }
  143. if (modal) {
  144. e << "Utility target \"" << target->GetName() << "\" " << modal
  145. << " not be used as the target of a target_link_libraries call.";
  146. mf.IssueMessage(messageType, e.str());
  147. if (messageType == MessageType::FATAL_ERROR) {
  148. return false;
  149. }
  150. }
  151. }
  152. // But we might not have any libs after variable expansion.
  153. if (args.size() < 2) {
  154. return true;
  155. }
  156. TLL tll(mf, target);
  157. // Keep track of link configuration specifiers.
  158. cmTargetLinkLibraryType llt = GENERAL_LibraryType;
  159. bool haveLLT = false;
  160. // Start with primary linking and switch to link interface
  161. // specification if the keyword is encountered as the first argument.
  162. ProcessingState currentProcessingState = ProcessingLinkLibraries;
  163. // Accumulate consectuive non-keyword arguments into one entry in
  164. // order to handle unquoted generator expressions containing ';'.
  165. cm::optional<std::string> currentEntry;
  166. auto processCurrentEntry = [&]() -> bool {
  167. if (currentEntry) {
  168. assert(!haveLLT);
  169. if (!tll.HandleLibrary(currentProcessingState, *currentEntry,
  170. GENERAL_LibraryType)) {
  171. return false;
  172. }
  173. currentEntry = cm::nullopt;
  174. }
  175. return true;
  176. };
  177. auto extendCurrentEntry = [&currentEntry](std::string const& arg) {
  178. if (currentEntry) {
  179. currentEntry = cmStrCat(*currentEntry, ';', arg);
  180. } else {
  181. currentEntry = arg;
  182. }
  183. };
  184. // Keep this list in sync with the keyword dispatch below.
  185. static std::unordered_set<std::string> const keywords{
  186. "LINK_INTERFACE_LIBRARIES",
  187. "INTERFACE",
  188. "LINK_PUBLIC",
  189. "PUBLIC",
  190. "LINK_PRIVATE",
  191. "PRIVATE",
  192. "debug",
  193. "optimized",
  194. "general",
  195. };
  196. // Add libraries, note that there is an optional prefix
  197. // of debug and optimized that can be used.
  198. for (unsigned int i = 1; i < args.size(); ++i) {
  199. if (keywords.count(args[i])) {
  200. // A keyword argument terminates any preceding accumulated entry.
  201. if (!processCurrentEntry()) {
  202. return false;
  203. }
  204. // Process this keyword argument.
  205. if (args[i] == "LINK_INTERFACE_LIBRARIES") {
  206. currentProcessingState = ProcessingPlainLinkInterface;
  207. if (i != 1) {
  208. mf.IssueMessage(
  209. MessageType::FATAL_ERROR,
  210. "The LINK_INTERFACE_LIBRARIES option must appear as the "
  211. "second argument, just after the target name.");
  212. return true;
  213. }
  214. } else if (args[i] == "INTERFACE") {
  215. if (i != 1 &&
  216. currentProcessingState != ProcessingKeywordPrivateInterface &&
  217. currentProcessingState != ProcessingKeywordPublicInterface &&
  218. currentProcessingState != ProcessingKeywordLinkInterface) {
  219. mf.IssueMessage(MessageType::FATAL_ERROR,
  220. "The INTERFACE, PUBLIC or PRIVATE option must "
  221. "appear as the second argument, just after the "
  222. "target name.");
  223. return true;
  224. }
  225. currentProcessingState = ProcessingKeywordLinkInterface;
  226. } else if (args[i] == "LINK_PUBLIC") {
  227. if (i != 1 &&
  228. currentProcessingState != ProcessingPlainPrivateInterface &&
  229. currentProcessingState != ProcessingPlainPublicInterface) {
  230. mf.IssueMessage(
  231. MessageType::FATAL_ERROR,
  232. "The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
  233. "second argument, just after the target name.");
  234. return true;
  235. }
  236. currentProcessingState = ProcessingPlainPublicInterface;
  237. } else if (args[i] == "PUBLIC") {
  238. if (i != 1 &&
  239. currentProcessingState != ProcessingKeywordPrivateInterface &&
  240. currentProcessingState != ProcessingKeywordPublicInterface &&
  241. currentProcessingState != ProcessingKeywordLinkInterface) {
  242. mf.IssueMessage(MessageType::FATAL_ERROR,
  243. "The INTERFACE, PUBLIC or PRIVATE option must "
  244. "appear as the second argument, just after the "
  245. "target name.");
  246. return true;
  247. }
  248. currentProcessingState = ProcessingKeywordPublicInterface;
  249. } else if (args[i] == "LINK_PRIVATE") {
  250. if (i != 1 &&
  251. currentProcessingState != ProcessingPlainPublicInterface &&
  252. currentProcessingState != ProcessingPlainPrivateInterface) {
  253. mf.IssueMessage(
  254. MessageType::FATAL_ERROR,
  255. "The LINK_PUBLIC or LINK_PRIVATE option must appear as the "
  256. "second argument, just after the target name.");
  257. return true;
  258. }
  259. currentProcessingState = ProcessingPlainPrivateInterface;
  260. } else if (args[i] == "PRIVATE") {
  261. if (i != 1 &&
  262. currentProcessingState != ProcessingKeywordPrivateInterface &&
  263. currentProcessingState != ProcessingKeywordPublicInterface &&
  264. currentProcessingState != ProcessingKeywordLinkInterface) {
  265. mf.IssueMessage(MessageType::FATAL_ERROR,
  266. "The INTERFACE, PUBLIC or PRIVATE option must "
  267. "appear as the second argument, just after the "
  268. "target name.");
  269. return true;
  270. }
  271. currentProcessingState = ProcessingKeywordPrivateInterface;
  272. } else if (args[i] == "debug") {
  273. if (haveLLT) {
  274. LinkLibraryTypeSpecifierWarning(mf, llt, DEBUG_LibraryType);
  275. }
  276. llt = DEBUG_LibraryType;
  277. haveLLT = true;
  278. } else if (args[i] == "optimized") {
  279. if (haveLLT) {
  280. LinkLibraryTypeSpecifierWarning(mf, llt, OPTIMIZED_LibraryType);
  281. }
  282. llt = OPTIMIZED_LibraryType;
  283. haveLLT = true;
  284. } else if (args[i] == "general") {
  285. if (haveLLT) {
  286. LinkLibraryTypeSpecifierWarning(mf, llt, GENERAL_LibraryType);
  287. }
  288. llt = GENERAL_LibraryType;
  289. haveLLT = true;
  290. }
  291. } else if (haveLLT) {
  292. // The link type was specified by the previous argument.
  293. haveLLT = false;
  294. assert(!currentEntry);
  295. if (!tll.HandleLibrary(currentProcessingState, args[i], llt)) {
  296. return false;
  297. }
  298. llt = GENERAL_LibraryType;
  299. } else {
  300. // Accumulate this argument in the current entry.
  301. extendCurrentEntry(args[i]);
  302. }
  303. }
  304. // Process the last accumulated entry, if any.
  305. if (!processCurrentEntry()) {
  306. return false;
  307. }
  308. // Make sure the last argument was not a library type specifier.
  309. if (haveLLT) {
  310. mf.IssueMessage(MessageType::FATAL_ERROR,
  311. cmStrCat("The \"", LinkLibraryTypeNames[llt],
  312. "\" argument must be followed by a library."));
  313. cmSystemTools::SetFatalErrorOccured();
  314. }
  315. const cmPolicies::PolicyStatus policy22Status =
  316. target->GetPolicyStatusCMP0022();
  317. // If any of the LINK_ options were given, make sure the
  318. // LINK_INTERFACE_LIBRARIES target property exists.
  319. // Use of any of the new keywords implies awareness of
  320. // this property. And if no libraries are named, it should
  321. // result in an empty link interface.
  322. if ((policy22Status == cmPolicies::OLD ||
  323. policy22Status == cmPolicies::WARN) &&
  324. currentProcessingState != ProcessingLinkLibraries &&
  325. !target->GetProperty("LINK_INTERFACE_LIBRARIES")) {
  326. target->SetProperty("LINK_INTERFACE_LIBRARIES", "");
  327. }
  328. return true;
  329. }
  330. static void LinkLibraryTypeSpecifierWarning(cmMakefile& mf, int left,
  331. int right)
  332. {
  333. mf.IssueMessage(
  334. MessageType::AUTHOR_WARNING,
  335. cmStrCat(
  336. "Link library type specifier \"", LinkLibraryTypeNames[left],
  337. "\" is followed by specifier \"", LinkLibraryTypeNames[right],
  338. "\" instead of a library name. The first specifier will be ignored."));
  339. }
  340. namespace {
  341. TLL::TLL(cmMakefile& mf, cmTarget* target)
  342. : Makefile(mf)
  343. , Target(target)
  344. {
  345. if (&this->Makefile != this->Target->GetMakefile()) {
  346. // The LHS target was created in another directory.
  347. switch (this->Makefile.GetPolicyStatus(cmPolicies::CMP0079)) {
  348. case cmPolicies::WARN:
  349. this->WarnRemoteInterface = true;
  350. CM_FALLTHROUGH;
  351. case cmPolicies::OLD:
  352. this->RejectRemoteLinking = true;
  353. break;
  354. case cmPolicies::REQUIRED_ALWAYS:
  355. case cmPolicies::REQUIRED_IF_USED:
  356. case cmPolicies::NEW:
  357. this->EncodeRemoteReference = true;
  358. break;
  359. }
  360. }
  361. if (this->EncodeRemoteReference) {
  362. cmDirectoryId const dirId = this->Makefile.GetDirectoryId();
  363. this->DirectoryId = cmStrCat(CMAKE_DIRECTORY_ID_SEP, dirId.String);
  364. }
  365. }
  366. bool TLL::HandleLibrary(ProcessingState currentProcessingState,
  367. const std::string& lib, cmTargetLinkLibraryType llt)
  368. {
  369. if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY &&
  370. currentProcessingState != ProcessingKeywordLinkInterface) {
  371. this->Makefile.IssueMessage(
  372. MessageType::FATAL_ERROR,
  373. "INTERFACE library can only be used with the INTERFACE keyword of "
  374. "target_link_libraries");
  375. return false;
  376. }
  377. if (this->Target->IsImported() &&
  378. currentProcessingState != ProcessingKeywordLinkInterface) {
  379. this->Makefile.IssueMessage(
  380. MessageType::FATAL_ERROR,
  381. "IMPORTED library can only be used with the INTERFACE keyword of "
  382. "target_link_libraries");
  383. return false;
  384. }
  385. cmTarget::TLLSignature sig =
  386. (currentProcessingState == ProcessingPlainPrivateInterface ||
  387. currentProcessingState == ProcessingPlainPublicInterface ||
  388. currentProcessingState == ProcessingKeywordPrivateInterface ||
  389. currentProcessingState == ProcessingKeywordPublicInterface ||
  390. currentProcessingState == ProcessingKeywordLinkInterface)
  391. ? cmTarget::KeywordTLLSignature
  392. : cmTarget::PlainTLLSignature;
  393. if (!this->Target->PushTLLCommandTrace(
  394. sig, this->Makefile.GetBacktrace().Top())) {
  395. std::ostringstream e;
  396. const char* modal = nullptr;
  397. MessageType messageType = MessageType::AUTHOR_WARNING;
  398. switch (this->Makefile.GetPolicyStatus(cmPolicies::CMP0023)) {
  399. case cmPolicies::WARN:
  400. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0023) << "\n";
  401. modal = "should";
  402. CM_FALLTHROUGH;
  403. case cmPolicies::OLD:
  404. break;
  405. case cmPolicies::REQUIRED_ALWAYS:
  406. case cmPolicies::REQUIRED_IF_USED:
  407. case cmPolicies::NEW:
  408. modal = "must";
  409. messageType = MessageType::FATAL_ERROR;
  410. break;
  411. }
  412. if (modal) {
  413. // If the sig is a keyword form and there is a conflict, the existing
  414. // form must be the plain form.
  415. const char* existingSig =
  416. (sig == cmTarget::KeywordTLLSignature ? "plain" : "keyword");
  417. e << "The " << existingSig
  418. << " signature for target_link_libraries has "
  419. "already been used with the target \""
  420. << this->Target->GetName()
  421. << "\". All uses of target_link_libraries with a target " << modal
  422. << " be either all-keyword or all-plain.\n";
  423. this->Target->GetTllSignatureTraces(e,
  424. sig == cmTarget::KeywordTLLSignature
  425. ? cmTarget::PlainTLLSignature
  426. : cmTarget::KeywordTLLSignature);
  427. this->Makefile.IssueMessage(messageType, e.str());
  428. if (messageType == MessageType::FATAL_ERROR) {
  429. return false;
  430. }
  431. }
  432. }
  433. // Handle normal case where the command was called with another keyword than
  434. // INTERFACE / LINK_INTERFACE_LIBRARIES or none at all. (The "LINK_LIBRARIES"
  435. // property of the target on the LHS shall be populated.)
  436. if (currentProcessingState != ProcessingKeywordLinkInterface &&
  437. currentProcessingState != ProcessingPlainLinkInterface) {
  438. if (this->RejectRemoteLinking) {
  439. this->Makefile.IssueMessage(
  440. MessageType::FATAL_ERROR,
  441. cmStrCat("Attempt to add link library \"", lib, "\" to target \"",
  442. this->Target->GetName(),
  443. "\" which is not built in this "
  444. "directory.\nThis is allowed only when policy CMP0079 "
  445. "is set to NEW."));
  446. return false;
  447. }
  448. cmTarget* tgt = this->Makefile.GetGlobalGenerator()->FindTarget(lib);
  449. if (tgt && (tgt->GetType() != cmStateEnums::STATIC_LIBRARY) &&
  450. (tgt->GetType() != cmStateEnums::SHARED_LIBRARY) &&
  451. (tgt->GetType() != cmStateEnums::UNKNOWN_LIBRARY) &&
  452. (tgt->GetType() != cmStateEnums::OBJECT_LIBRARY) &&
  453. (tgt->GetType() != cmStateEnums::INTERFACE_LIBRARY) &&
  454. !tgt->IsExecutableWithExports()) {
  455. this->Makefile.IssueMessage(
  456. MessageType::FATAL_ERROR,
  457. cmStrCat(
  458. "Target \"", lib, "\" of type ",
  459. cmState::GetTargetTypeName(tgt->GetType()),
  460. " may not be linked into another target. One may link only to "
  461. "INTERFACE, OBJECT, STATIC or SHARED libraries, or to ",
  462. "executables with the ENABLE_EXPORTS property set."));
  463. }
  464. this->AffectsProperty("LINK_LIBRARIES");
  465. this->Target->AddLinkLibrary(this->Makefile, lib, llt);
  466. }
  467. if (this->WarnRemoteInterface) {
  468. this->Makefile.IssueMessage(
  469. MessageType::AUTHOR_WARNING,
  470. cmStrCat(
  471. cmPolicies::GetPolicyWarning(cmPolicies::CMP0079), "\nTarget\n ",
  472. this->Target->GetName(),
  473. "\nis not created in this "
  474. "directory. For compatibility with older versions of CMake, link "
  475. "library\n ",
  476. lib,
  477. "\nwill be looked up in the directory in which "
  478. "the target was created rather than in this calling directory."));
  479. }
  480. // Handle (additional) case where the command was called with PRIVATE /
  481. // LINK_PRIVATE and stop its processing. (The "INTERFACE_LINK_LIBRARIES"
  482. // property of the target on the LHS shall only be populated if it is a
  483. // STATIC library.)
  484. if (currentProcessingState == ProcessingKeywordPrivateInterface ||
  485. currentProcessingState == ProcessingPlainPrivateInterface) {
  486. if (this->Target->GetType() == cmStateEnums::STATIC_LIBRARY ||
  487. this->Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  488. std::string configLib =
  489. this->Target->GetDebugGeneratorExpressions(lib, llt);
  490. if (cmGeneratorExpression::IsValidTargetName(lib) ||
  491. cmGeneratorExpression::Find(lib) != std::string::npos) {
  492. configLib = "$<LINK_ONLY:" + configLib + ">";
  493. }
  494. this->AppendProperty("INTERFACE_LINK_LIBRARIES", configLib);
  495. }
  496. return true;
  497. }
  498. // Handle general case where the command was called with another keyword than
  499. // PRIVATE / LINK_PRIVATE or none at all. (The "INTERFACE_LINK_LIBRARIES"
  500. // property of the target on the LHS shall be populated.)
  501. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  502. this->Target->GetDebugGeneratorExpressions(lib, llt));
  503. // Stop processing if called without any keyword.
  504. if (currentProcessingState == ProcessingLinkLibraries) {
  505. return true;
  506. }
  507. // Stop processing if policy CMP0022 is set to NEW.
  508. const cmPolicies::PolicyStatus policy22Status =
  509. this->Target->GetPolicyStatusCMP0022();
  510. if (policy22Status != cmPolicies::OLD &&
  511. policy22Status != cmPolicies::WARN) {
  512. return true;
  513. }
  514. // Stop processing if called with an INTERFACE library on the LHS.
  515. if (this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  516. return true;
  517. }
  518. // Handle (additional) backward-compatibility case where the command was
  519. // called with PUBLIC / INTERFACE / LINK_PUBLIC / LINK_INTERFACE_LIBRARIES.
  520. // (The policy CMP0022 is not set to NEW.)
  521. {
  522. // Get the list of configurations considered to be DEBUG.
  523. std::vector<std::string> debugConfigs =
  524. this->Makefile.GetCMakeInstance()->GetDebugConfigs();
  525. std::string prop;
  526. // Include this library in the link interface for the target.
  527. if (llt == DEBUG_LibraryType || llt == GENERAL_LibraryType) {
  528. // Put in the DEBUG configuration interfaces.
  529. for (std::string const& dc : debugConfigs) {
  530. prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc);
  531. this->AppendProperty(prop, lib);
  532. }
  533. }
  534. if (llt == OPTIMIZED_LibraryType || llt == GENERAL_LibraryType) {
  535. // Put in the non-DEBUG configuration interfaces.
  536. this->AppendProperty("LINK_INTERFACE_LIBRARIES", lib);
  537. // Make sure the DEBUG configuration interfaces exist so that the
  538. // general one will not be used as a fall-back.
  539. for (std::string const& dc : debugConfigs) {
  540. prop = cmStrCat("LINK_INTERFACE_LIBRARIES_", dc);
  541. if (!this->Target->GetProperty(prop)) {
  542. this->Target->SetProperty(prop, "");
  543. }
  544. }
  545. }
  546. }
  547. return true;
  548. }
  549. void TLL::AppendProperty(std::string const& prop, std::string const& value)
  550. {
  551. this->AffectsProperty(prop);
  552. this->Target->AppendProperty(prop, value);
  553. }
  554. void TLL::AffectsProperty(std::string const& prop)
  555. {
  556. if (!this->EncodeRemoteReference) {
  557. return;
  558. }
  559. // Add a wrapper to the expression to tell LookupLinkItem to look up
  560. // names in the caller's directory.
  561. if (this->Props.insert(prop).second) {
  562. this->Target->AppendProperty(prop, this->DirectoryId);
  563. }
  564. }
  565. TLL::~TLL()
  566. {
  567. for (std::string const& prop : this->Props) {
  568. this->Target->AppendProperty(prop, CMAKE_DIRECTORY_ID_SEP);
  569. }
  570. }
  571. } // namespace