cmGeneratorTarget_Options.cxx 24 KB

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