cmTargetLinkLibrariesCommand.cxx 21 KB

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