cmGeneratorTarget_Options.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. /* clang-format off */
  4. #include "cmGeneratorTarget.h"
  5. /* clang-format on */
  6. #include <algorithm>
  7. #include <iterator>
  8. #include <map>
  9. #include <memory>
  10. #include <string>
  11. #include <unordered_set>
  12. #include <utility>
  13. #include <vector>
  14. #include <cm/string_view>
  15. #include <cmext/algorithm>
  16. #include <cmext/string_view>
  17. #include "cmEvaluatedTargetProperty.h"
  18. #include "cmGeneratorExpressionDAGChecker.h"
  19. #include "cmList.h"
  20. #include "cmListFileCache.h"
  21. #include "cmLocalGenerator.h"
  22. #include "cmMakefile.h"
  23. #include "cmMessageType.h"
  24. #include "cmPolicies.h"
  25. #include "cmRange.h"
  26. #include "cmStringAlgorithms.h"
  27. #include "cmSystemTools.h"
  28. #include "cmValue.h"
  29. #include "cmake.h"
  30. enum class OptionsParse
  31. {
  32. None,
  33. Shell
  34. };
  35. namespace {
  36. auto const DL_BEGIN = "<DEVICE_LINK>"_s;
  37. auto const DL_END = "</DEVICE_LINK>"_s;
  38. void processOptions(cmGeneratorTarget const* tgt,
  39. EvaluatedTargetPropertyEntries const& entries,
  40. std::vector<BT<std::string>>& options,
  41. std::unordered_set<std::string>& uniqueOptions,
  42. bool debugOptions, char const* logName, OptionsParse parse,
  43. bool processDeviceOptions = false)
  44. {
  45. bool splitOption = !processDeviceOptions;
  46. for (EvaluatedTargetPropertyEntry const& entry : entries.Entries) {
  47. std::string usedOptions;
  48. for (std::string const& opt : entry.Values) {
  49. if (processDeviceOptions && (opt == DL_BEGIN || opt == DL_END)) {
  50. options.emplace_back(opt, entry.Backtrace);
  51. splitOption = opt == DL_BEGIN;
  52. continue;
  53. }
  54. if (uniqueOptions.insert(opt).second) {
  55. if (parse == OptionsParse::Shell &&
  56. cmHasLiteralPrefix(opt, "SHELL:")) {
  57. if (splitOption) {
  58. std::vector<std::string> tmp;
  59. cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
  60. for (std::string& o : tmp) {
  61. options.emplace_back(std::move(o), entry.Backtrace);
  62. }
  63. } else {
  64. options.emplace_back(std::string(opt.c_str() + 6),
  65. entry.Backtrace);
  66. }
  67. } else {
  68. options.emplace_back(opt, entry.Backtrace);
  69. }
  70. if (debugOptions) {
  71. usedOptions += " * " + opt + "\n";
  72. }
  73. }
  74. }
  75. if (!usedOptions.empty()) {
  76. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  77. MessageType::LOG,
  78. std::string("Used ") + logName + std::string(" for target ") +
  79. tgt->GetName() + ":\n" + usedOptions,
  80. entry.Backtrace);
  81. }
  82. }
  83. }
  84. enum class NestedLinkerFlags
  85. {
  86. PreserveAsSpelled,
  87. Normalize
  88. };
  89. std::vector<BT<std::string>> wrapOptions(
  90. std::vector<std::string>& options, cmListFileBacktrace const& bt,
  91. std::vector<std::string> const& wrapperFlag, std::string const& wrapperSep,
  92. bool concatFlagAndArgs, NestedLinkerFlags nestedLinkerFlags)
  93. {
  94. std::vector<BT<std::string>> result;
  95. if (options.empty()) {
  96. return result;
  97. }
  98. if (wrapperFlag.empty()) {
  99. // nothing specified, insert elements as is
  100. result.reserve(options.size());
  101. for (std::string& o : options) {
  102. result.emplace_back(std::move(o), bt);
  103. }
  104. return result;
  105. }
  106. auto insertWrapped = [&](std::vector<std::string>& opts) {
  107. if (!wrapperSep.empty()) {
  108. if (concatFlagAndArgs) {
  109. // insert flag elements except last one
  110. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  111. result.emplace_back(*i, bt);
  112. }
  113. // concatenate last flag element and all list values
  114. // in one option
  115. result.emplace_back(wrapperFlag.back() + cmJoin(opts, wrapperSep), bt);
  116. } else {
  117. for (std::string const& i : wrapperFlag) {
  118. result.emplace_back(i, bt);
  119. }
  120. // concatenate all list values in one option
  121. result.emplace_back(cmJoin(opts, wrapperSep), bt);
  122. }
  123. } else {
  124. // prefix each element of list with wrapper
  125. if (concatFlagAndArgs) {
  126. std::transform(opts.begin(), opts.end(), opts.begin(),
  127. [&wrapperFlag](std::string const& o) -> std::string {
  128. return wrapperFlag.back() + o;
  129. });
  130. }
  131. for (std::string& o : opts) {
  132. for (auto i = wrapperFlag.begin(),
  133. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  134. : wrapperFlag.end();
  135. i != e; ++i) {
  136. result.emplace_back(*i, bt);
  137. }
  138. result.emplace_back(std::move(o), bt);
  139. }
  140. }
  141. };
  142. if (nestedLinkerFlags == NestedLinkerFlags::PreserveAsSpelled) {
  143. insertWrapped(options);
  144. return result;
  145. }
  146. for (std::vector<std::string>::size_type index = 0; index < options.size();
  147. index++) {
  148. if (cmHasLiteralPrefix(options[index], "LINKER:")) {
  149. // LINKER wrapper specified, insert elements as is
  150. result.emplace_back(std::move(options[index]), bt);
  151. continue;
  152. }
  153. if (cmHasLiteralPrefix(options[index], "-Wl,")) {
  154. // replace option by LINKER wrapper
  155. result.emplace_back(options[index].replace(0, 4, "LINKER:"), bt);
  156. continue;
  157. }
  158. if (cmHasLiteralPrefix(options[index], "-Xlinker=")) {
  159. // replace option by LINKER wrapper
  160. result.emplace_back(options[index].replace(0, 9, "LINKER:"), bt);
  161. continue;
  162. }
  163. if (options[index] == "-Xlinker") {
  164. // replace option by LINKER wrapper
  165. if (index + 1 < options.size()) {
  166. result.emplace_back("LINKER:" + options[++index], bt);
  167. } else {
  168. result.emplace_back(std::move(options[index]), bt);
  169. }
  170. continue;
  171. }
  172. // collect all options which must be transformed
  173. std::vector<std::string> opts;
  174. while (index < options.size()) {
  175. if (!cmHasLiteralPrefix(options[index], "LINKER:") &&
  176. !cmHasLiteralPrefix(options[index], "-Wl,") &&
  177. !cmHasLiteralPrefix(options[index], "-Xlinker")) {
  178. opts.emplace_back(std::move(options[index++]));
  179. } else {
  180. --index;
  181. break;
  182. }
  183. }
  184. if (opts.empty()) {
  185. continue;
  186. }
  187. insertWrapped(opts);
  188. }
  189. return result;
  190. }
  191. }
  192. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  193. std::string const& config,
  194. std::string const& language) const
  195. {
  196. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  197. result.reserve(tmp.size());
  198. for (BT<std::string>& v : tmp) {
  199. result.emplace_back(std::move(v.Value));
  200. }
  201. }
  202. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  203. std::string const& config, std::string const& language) const
  204. {
  205. ConfigAndLanguage cacheKey(config, language);
  206. {
  207. auto it = this->CompileOptionsCache.find(cacheKey);
  208. if (it != this->CompileOptionsCache.end()) {
  209. return it->second;
  210. }
  211. }
  212. std::vector<BT<std::string>> result;
  213. std::unordered_set<std::string> uniqueOptions;
  214. cmGeneratorExpressionDAGChecker dagChecker{
  215. this, "COMPILE_OPTIONS", nullptr, nullptr, this->LocalGenerator, config,
  216. };
  217. cmList debugProperties{ this->Makefile->GetDefinition(
  218. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  219. bool debugOptions = !this->DebugCompileOptionsDone &&
  220. cm::contains(debugProperties, "COMPILE_OPTIONS");
  221. this->DebugCompileOptionsDone = true;
  222. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  223. this, config, language, &dagChecker, this->CompileOptionsEntries);
  224. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS", language,
  225. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  226. processOptions(this, entries, result, uniqueOptions, debugOptions,
  227. "compile options", OptionsParse::Shell);
  228. CompileOptionsCache.emplace(cacheKey, result);
  229. return result;
  230. }
  231. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  232. std::string const& config) const
  233. {
  234. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  235. result.reserve(tmp.size());
  236. for (BT<std::string>& v : tmp) {
  237. result.emplace_back(std::move(v.Value));
  238. }
  239. }
  240. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  241. std::string const& config) const
  242. {
  243. std::vector<BT<std::string>> result;
  244. std::unordered_set<std::string> uniqueFeatures;
  245. cmGeneratorExpressionDAGChecker dagChecker{
  246. this, "COMPILE_FEATURES", nullptr, nullptr, this->LocalGenerator, config,
  247. };
  248. cmList debugProperties{ this->Makefile->GetDefinition(
  249. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  250. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  251. cm::contains(debugProperties, "COMPILE_FEATURES");
  252. this->DebugCompileFeaturesDone = true;
  253. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  254. this, config, std::string(), &dagChecker, this->CompileFeaturesEntries);
  255. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  256. std::string(), &dagChecker, entries,
  257. IncludeRuntimeInterface::Yes);
  258. processOptions(this, entries, result, uniqueFeatures, debugFeatures,
  259. "compile features", OptionsParse::None);
  260. return result;
  261. }
  262. void cmGeneratorTarget::GetCompileDefinitions(
  263. std::vector<std::string>& result, std::string const& config,
  264. std::string const& language) const
  265. {
  266. std::vector<BT<std::string>> tmp =
  267. this->GetCompileDefinitions(config, language);
  268. result.reserve(tmp.size());
  269. for (BT<std::string>& v : tmp) {
  270. result.emplace_back(std::move(v.Value));
  271. }
  272. }
  273. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  274. std::string const& config, std::string const& language) const
  275. {
  276. ConfigAndLanguage cacheKey(config, language);
  277. {
  278. auto it = this->CompileDefinitionsCache.find(cacheKey);
  279. if (it != this->CompileDefinitionsCache.end()) {
  280. return it->second;
  281. }
  282. }
  283. std::vector<BT<std::string>> list;
  284. std::unordered_set<std::string> uniqueOptions;
  285. cmGeneratorExpressionDAGChecker dagChecker{
  286. this, "COMPILE_DEFINITIONS", nullptr,
  287. nullptr, this->LocalGenerator, config,
  288. };
  289. cmList debugProperties{ this->Makefile->GetDefinition(
  290. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  291. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  292. cm::contains(debugProperties, "COMPILE_DEFINITIONS");
  293. this->DebugCompileDefinitionsDone = true;
  294. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  295. this, config, language, &dagChecker, this->CompileDefinitionsEntries);
  296. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
  297. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  298. processOptions(this, entries, list, uniqueOptions, debugDefines,
  299. "compile definitions", OptionsParse::None);
  300. this->CompileDefinitionsCache.emplace(cacheKey, list);
  301. return list;
  302. }
  303. std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
  304. std::string const& config, std::string const& language) const
  305. {
  306. ConfigAndLanguage cacheKey(config, language);
  307. {
  308. auto it = this->PrecompileHeadersCache.find(cacheKey);
  309. if (it != this->PrecompileHeadersCache.end()) {
  310. return it->second;
  311. }
  312. }
  313. std::unordered_set<std::string> uniqueOptions;
  314. cmGeneratorExpressionDAGChecker dagChecker{
  315. this, "PRECOMPILE_HEADERS", nullptr, nullptr, this->LocalGenerator, config,
  316. };
  317. cmList debugProperties{ this->Makefile->GetDefinition(
  318. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  319. bool debugDefines = !this->DebugPrecompileHeadersDone &&
  320. std::find(debugProperties.begin(), debugProperties.end(),
  321. "PRECOMPILE_HEADERS") != debugProperties.end();
  322. this->DebugPrecompileHeadersDone = true;
  323. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  324. this, config, language, &dagChecker, this->PrecompileHeadersEntries);
  325. AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
  326. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  327. std::vector<BT<std::string>> list;
  328. processOptions(this, entries, list, uniqueOptions, debugDefines,
  329. "precompile headers", OptionsParse::None);
  330. this->PrecompileHeadersCache.emplace(cacheKey, list);
  331. return list;
  332. }
  333. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  334. std::string const& config,
  335. std::string const& language) const
  336. {
  337. if (this->IsDeviceLink() &&
  338. this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
  339. // link options are not propagated to the device link step
  340. return;
  341. }
  342. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  343. result.reserve(tmp.size());
  344. for (BT<std::string>& v : tmp) {
  345. result.emplace_back(std::move(v.Value));
  346. }
  347. }
  348. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  349. std::string const& config, std::string const& language) const
  350. {
  351. ConfigAndLanguage cacheKey(
  352. config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
  353. {
  354. auto it = this->LinkOptionsCache.find(cacheKey);
  355. if (it != this->LinkOptionsCache.end()) {
  356. return it->second;
  357. }
  358. }
  359. std::vector<BT<std::string>> result;
  360. std::unordered_set<std::string> uniqueOptions;
  361. cmGeneratorExpressionDAGChecker dagChecker{
  362. this, "LINK_OPTIONS", nullptr, nullptr, this->LocalGenerator, config,
  363. };
  364. cmList debugProperties{ this->Makefile->GetDefinition(
  365. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  366. bool debugOptions = !this->DebugLinkOptionsDone &&
  367. cm::contains(debugProperties, "LINK_OPTIONS");
  368. this->DebugLinkOptionsDone = true;
  369. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  370. this, config, language, &dagChecker, this->LinkOptionsEntries);
  371. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
  372. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  373. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  374. ? UseTo::Link
  375. : UseTo::Compile);
  376. processOptions(this, entries, result, uniqueOptions, debugOptions,
  377. "link options", OptionsParse::Shell, this->IsDeviceLink());
  378. if (this->IsDeviceLink()) {
  379. // wrap host link options
  380. std::string const wrapper(this->Makefile->GetSafeDefinition(
  381. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG"));
  382. cmList wrapperFlag{ wrapper };
  383. std::string const wrapperSep(this->Makefile->GetSafeDefinition(
  384. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG_SEP"));
  385. bool concatFlagAndArgs = true;
  386. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  387. concatFlagAndArgs = false;
  388. wrapperFlag.pop_back();
  389. }
  390. auto it = result.begin();
  391. while (it != result.end()) {
  392. if (it->Value == DL_BEGIN) {
  393. // device link options, no treatment
  394. it = result.erase(it);
  395. it = std::find_if(it, result.end(), [](const BT<std::string>& item) {
  396. return item.Value == DL_END;
  397. });
  398. if (it != result.end()) {
  399. it = result.erase(it);
  400. }
  401. } else {
  402. // host link options must be wrapped
  403. std::vector<std::string> options;
  404. cmSystemTools::ParseUnixCommandLine(it->Value.c_str(), options);
  405. auto hostOptions =
  406. wrapOptions(options, it->Backtrace, wrapperFlag, wrapperSep,
  407. concatFlagAndArgs, NestedLinkerFlags::Normalize);
  408. it = result.erase(it);
  409. // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
  410. // C++11 standard: 'std::vector::insert()' do not returns an iterator,
  411. // so need to recompute the iterator after insertion.
  412. if (it == result.end()) {
  413. cm::append(result, hostOptions);
  414. it = result.end();
  415. } else {
  416. auto index = it - result.begin();
  417. result.insert(it, hostOptions.begin(), hostOptions.end());
  418. it = result.begin() + index + hostOptions.size();
  419. }
  420. }
  421. }
  422. }
  423. // Last step: replace "LINKER:" prefixed elements by
  424. // actual linker wrapper
  425. result = this->ResolveLinkerWrapper(result, language);
  426. this->LinkOptionsCache.emplace(cacheKey, result);
  427. return result;
  428. }
  429. std::vector<BT<std::string>>& cmGeneratorTarget::ResolvePrefixWrapper(
  430. std::vector<BT<std::string>>& result, cm::string_view prefix,
  431. std::string const& language, bool joinItems) const
  432. {
  433. // replace "LINKER:" or "ARCHIVER:" prefixed elements by actual linker or
  434. // archiver wrapper
  435. std::string const wrapper(this->Makefile->GetSafeDefinition(
  436. cmStrCat("CMAKE_", language, (this->IsDeviceLink() ? "_DEVICE_" : "_"),
  437. prefix, "_WRAPPER_FLAG")));
  438. cmList wrapperFlag{ wrapper };
  439. std::string const wrapperSep(this->Makefile->GetSafeDefinition(
  440. cmStrCat("CMAKE_", language, (this->IsDeviceLink() ? "_DEVICE_" : "_"),
  441. prefix, "_WRAPPER_FLAG_SEP")));
  442. bool concatFlagAndArgs = true;
  443. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  444. concatFlagAndArgs = false;
  445. wrapperFlag.pop_back();
  446. }
  447. std::string const PREFIX{ cmStrCat(prefix, ':') };
  448. std::string const SHELL{ "SHELL:" };
  449. std::string const PREFIX_SHELL = cmStrCat(PREFIX, SHELL);
  450. for (auto entry = result.begin(); entry != result.end();) {
  451. if (entry->Value.compare(0, PREFIX.length(), PREFIX) != 0) {
  452. ++entry;
  453. continue;
  454. }
  455. std::string value = std::move(entry->Value);
  456. cmListFileBacktrace bt = std::move(entry->Backtrace);
  457. entry = result.erase(entry);
  458. std::vector<std::string> options;
  459. if (value.compare(0, PREFIX_SHELL.length(), PREFIX_SHELL) == 0) {
  460. cmSystemTools::ParseUnixCommandLine(
  461. value.c_str() + PREFIX_SHELL.length(), options);
  462. } else {
  463. options =
  464. cmTokenize(value.substr(PREFIX.length()), ',', cmTokenizerMode::New);
  465. }
  466. if (options.empty()) {
  467. continue;
  468. }
  469. // for now, raise an error if prefix SHELL: is part of arguments
  470. if (std::find_if(options.begin(), options.end(),
  471. [&SHELL](std::string const& item) -> bool {
  472. return item.find(SHELL) != std::string::npos;
  473. }) != options.end()) {
  474. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  475. MessageType::FATAL_ERROR,
  476. cmStrCat("'SHELL:' prefix is not supported as part of '", prefix,
  477. ":' arguments."),
  478. this->GetBacktrace());
  479. return result;
  480. }
  481. // Very old versions of the C++ standard library return void for insert, so
  482. // can't use it to get the new iterator
  483. auto const index = entry - result.begin();
  484. std::vector<BT<std::string>> processedOptions =
  485. wrapOptions(options, bt, wrapperFlag, wrapperSep, concatFlagAndArgs,
  486. NestedLinkerFlags::PreserveAsSpelled);
  487. if (joinItems) {
  488. result.insert(
  489. entry,
  490. cmJoin(cmMakeRange(processedOptions.begin(), processedOptions.end()),
  491. " "_s));
  492. entry = std::next(result.begin(), index + 1);
  493. } else {
  494. result.insert(entry, processedOptions.begin(), processedOptions.end());
  495. entry = std::next(result.begin(), index + processedOptions.size());
  496. }
  497. }
  498. return result;
  499. }
  500. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveLinkerWrapper(
  501. std::vector<BT<std::string>>& result, std::string const& language,
  502. bool joinItems) const
  503. {
  504. return this->ResolvePrefixWrapper(result, "LINKER"_s, language, joinItems);
  505. }
  506. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  507. std::vector<std::string>& result, std::string const& config,
  508. std::string const& language) const
  509. {
  510. std::vector<BT<std::string>> tmp =
  511. this->GetStaticLibraryLinkOptions(config, language);
  512. result.reserve(tmp.size());
  513. for (BT<std::string>& v : tmp) {
  514. result.emplace_back(std::move(v.Value));
  515. }
  516. }
  517. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  518. std::string const& config, std::string const& language) const
  519. {
  520. std::vector<BT<std::string>> result;
  521. std::unordered_set<std::string> uniqueOptions;
  522. cmGeneratorExpressionDAGChecker dagChecker{
  523. this, "STATIC_LIBRARY_OPTIONS", nullptr,
  524. nullptr, this->LocalGenerator, config,
  525. };
  526. EvaluatedTargetPropertyEntries entries;
  527. if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  528. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  529. *this->LocalGenerator->GetCMakeInstance(), *linkOptions);
  530. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  531. this, config, language, &dagChecker, *entry));
  532. }
  533. processOptions(this, entries, result, uniqueOptions, false,
  534. "static library link options", OptionsParse::Shell);
  535. // Last step: replace "ARCHIVER:" prefixed elements by
  536. // actual archiver wrapper
  537. this->ResolveArchiverWrapper(result, language);
  538. return result;
  539. }
  540. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveArchiverWrapper(
  541. std::vector<BT<std::string>>& result, std::string const& language,
  542. bool joinItems) const
  543. {
  544. return this->ResolvePrefixWrapper(result, "ARCHIVER"_s, language, joinItems);
  545. }
  546. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  547. std::string const& config,
  548. std::string const& language) const
  549. {
  550. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  551. result.reserve(tmp.size());
  552. for (BT<std::string>& v : tmp) {
  553. result.emplace_back(std::move(v.Value));
  554. }
  555. }
  556. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  557. std::string const& config, std::string const& language) const
  558. {
  559. std::vector<BT<std::string>> result;
  560. std::unordered_set<std::string> uniqueOptions;
  561. cmGeneratorExpressionDAGChecker dagChecker{
  562. this, "LINK_DEPENDS", nullptr, nullptr, this->LocalGenerator, config,
  563. };
  564. EvaluatedTargetPropertyEntries entries;
  565. if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
  566. cmList depends{ *linkDepends };
  567. for (auto const& depend : depends) {
  568. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  569. *this->LocalGenerator->GetCMakeInstance(), depend);
  570. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  571. this, config, language, &dagChecker, *entry));
  572. }
  573. }
  574. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
  575. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  576. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  577. ? UseTo::Link
  578. : UseTo::Compile);
  579. processOptions(this, entries, result, uniqueOptions, false, "link depends",
  580. OptionsParse::None);
  581. return result;
  582. }