cmGeneratorTarget_Options.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  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 <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 "cmGlobalGenerator.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. std::vector<BT<std::string>> wrapOptions(
  86. std::vector<std::string>& options, const cmListFileBacktrace& bt,
  87. const std::vector<std::string>& wrapperFlag, const std::string& wrapperSep,
  88. bool concatFlagAndArgs)
  89. {
  90. std::vector<BT<std::string>> result;
  91. if (options.empty()) {
  92. return result;
  93. }
  94. if (wrapperFlag.empty()) {
  95. // nothing specified, insert elements as is
  96. result.reserve(options.size());
  97. for (std::string& o : options) {
  98. result.emplace_back(std::move(o), bt);
  99. }
  100. return result;
  101. }
  102. for (std::vector<std::string>::size_type index = 0; index < options.size();
  103. index++) {
  104. if (cmHasLiteralPrefix(options[index], "LINKER:")) {
  105. // LINKER wrapper specified, insert elements as is
  106. result.emplace_back(std::move(options[index]), bt);
  107. continue;
  108. }
  109. if (cmHasLiteralPrefix(options[index], "-Wl,")) {
  110. // replace option by LINKER wrapper
  111. result.emplace_back(options[index].replace(0, 4, "LINKER:"), bt);
  112. continue;
  113. }
  114. if (cmHasLiteralPrefix(options[index], "-Xlinker=")) {
  115. // replace option by LINKER wrapper
  116. result.emplace_back(options[index].replace(0, 9, "LINKER:"), bt);
  117. continue;
  118. }
  119. if (options[index] == "-Xlinker") {
  120. // replace option by LINKER wrapper
  121. if (index + 1 < options.size()) {
  122. result.emplace_back("LINKER:" + options[++index], bt);
  123. } else {
  124. result.emplace_back(std::move(options[index]), bt);
  125. }
  126. continue;
  127. }
  128. // collect all options which must be transformed
  129. std::vector<std::string> opts;
  130. while (index < options.size()) {
  131. if (!cmHasLiteralPrefix(options[index], "LINKER:") &&
  132. !cmHasLiteralPrefix(options[index], "-Wl,") &&
  133. !cmHasLiteralPrefix(options[index], "-Xlinker")) {
  134. opts.emplace_back(std::move(options[index++]));
  135. } else {
  136. --index;
  137. break;
  138. }
  139. }
  140. if (opts.empty()) {
  141. continue;
  142. }
  143. if (!wrapperSep.empty()) {
  144. if (concatFlagAndArgs) {
  145. // insert flag elements except last one
  146. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  147. result.emplace_back(*i, bt);
  148. }
  149. // concatenate last flag element and all list values
  150. // in one option
  151. result.emplace_back(wrapperFlag.back() + cmJoin(opts, wrapperSep), bt);
  152. } else {
  153. for (std::string const& i : wrapperFlag) {
  154. result.emplace_back(i, bt);
  155. }
  156. // concatenate all list values in one option
  157. result.emplace_back(cmJoin(opts, wrapperSep), bt);
  158. }
  159. } else {
  160. // prefix each element of list with wrapper
  161. if (concatFlagAndArgs) {
  162. std::transform(opts.begin(), opts.end(), opts.begin(),
  163. [&wrapperFlag](std::string const& o) -> std::string {
  164. return wrapperFlag.back() + o;
  165. });
  166. }
  167. for (std::string& o : opts) {
  168. for (auto i = wrapperFlag.begin(),
  169. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  170. : wrapperFlag.end();
  171. i != e; ++i) {
  172. result.emplace_back(*i, bt);
  173. }
  174. result.emplace_back(std::move(o), bt);
  175. }
  176. }
  177. }
  178. return result;
  179. }
  180. }
  181. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  182. const std::string& config,
  183. const std::string& language) const
  184. {
  185. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  186. result.reserve(tmp.size());
  187. for (BT<std::string>& v : tmp) {
  188. result.emplace_back(std::move(v.Value));
  189. }
  190. }
  191. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  192. std::string const& config, std::string const& language) const
  193. {
  194. ConfigAndLanguage cacheKey(config, language);
  195. {
  196. auto it = this->CompileOptionsCache.find(cacheKey);
  197. if (it != this->CompileOptionsCache.end()) {
  198. return it->second;
  199. }
  200. }
  201. std::vector<BT<std::string>> result;
  202. std::unordered_set<std::string> uniqueOptions;
  203. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
  204. nullptr, this->LocalGenerator);
  205. cmList debugProperties{ this->Makefile->GetDefinition(
  206. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  207. bool debugOptions = !this->DebugCompileOptionsDone &&
  208. cm::contains(debugProperties, "COMPILE_OPTIONS");
  209. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  210. this->DebugCompileOptionsDone = true;
  211. }
  212. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  213. this, config, language, &dagChecker, this->CompileOptionsEntries);
  214. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS", language,
  215. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  216. processOptions(this, entries, result, uniqueOptions, debugOptions,
  217. "compile options", OptionsParse::Shell);
  218. CompileOptionsCache.emplace(cacheKey, result);
  219. return result;
  220. }
  221. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  222. const std::string& config) const
  223. {
  224. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  225. result.reserve(tmp.size());
  226. for (BT<std::string>& v : tmp) {
  227. result.emplace_back(std::move(v.Value));
  228. }
  229. }
  230. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  231. std::string const& config) const
  232. {
  233. std::vector<BT<std::string>> result;
  234. std::unordered_set<std::string> uniqueFeatures;
  235. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
  236. nullptr, this->LocalGenerator);
  237. cmList debugProperties{ this->Makefile->GetDefinition(
  238. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  239. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  240. cm::contains(debugProperties, "COMPILE_FEATURES");
  241. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  242. this->DebugCompileFeaturesDone = true;
  243. }
  244. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  245. this, config, std::string(), &dagChecker, this->CompileFeaturesEntries);
  246. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  247. std::string(), &dagChecker, entries,
  248. IncludeRuntimeInterface::Yes);
  249. processOptions(this, entries, result, uniqueFeatures, debugFeatures,
  250. "compile features", OptionsParse::None);
  251. return result;
  252. }
  253. void cmGeneratorTarget::GetCompileDefinitions(
  254. std::vector<std::string>& result, const std::string& config,
  255. const std::string& language) const
  256. {
  257. std::vector<BT<std::string>> tmp =
  258. this->GetCompileDefinitions(config, language);
  259. result.reserve(tmp.size());
  260. for (BT<std::string>& v : tmp) {
  261. result.emplace_back(std::move(v.Value));
  262. }
  263. }
  264. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  265. std::string const& config, std::string const& language) const
  266. {
  267. ConfigAndLanguage cacheKey(config, language);
  268. {
  269. auto it = this->CompileDefinitionsCache.find(cacheKey);
  270. if (it != this->CompileDefinitionsCache.end()) {
  271. return it->second;
  272. }
  273. }
  274. std::vector<BT<std::string>> list;
  275. std::unordered_set<std::string> uniqueOptions;
  276. cmGeneratorExpressionDAGChecker dagChecker(
  277. this, "COMPILE_DEFINITIONS", nullptr, nullptr, this->LocalGenerator);
  278. cmList debugProperties{ this->Makefile->GetDefinition(
  279. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  280. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  281. cm::contains(debugProperties, "COMPILE_DEFINITIONS");
  282. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  283. this->DebugCompileDefinitionsDone = true;
  284. }
  285. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  286. this, config, language, &dagChecker, this->CompileDefinitionsEntries);
  287. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
  288. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  289. if (!config.empty()) {
  290. std::string configPropName =
  291. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  292. cmValue configProp = this->GetProperty(configPropName);
  293. if (configProp) {
  294. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  295. case cmPolicies::WARN: {
  296. this->LocalGenerator->IssueMessage(
  297. MessageType::AUTHOR_WARNING,
  298. cmPolicies::GetPolicyWarning(cmPolicies::CMP0043));
  299. CM_FALLTHROUGH;
  300. }
  301. case cmPolicies::OLD: {
  302. std::unique_ptr<TargetPropertyEntry> entry =
  303. TargetPropertyEntry::Create(
  304. *this->LocalGenerator->GetCMakeInstance(), *configProp);
  305. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  306. this, config, language, &dagChecker, *entry));
  307. } break;
  308. case cmPolicies::NEW:
  309. case cmPolicies::REQUIRED_ALWAYS:
  310. case cmPolicies::REQUIRED_IF_USED:
  311. break;
  312. }
  313. }
  314. }
  315. processOptions(this, entries, list, uniqueOptions, debugDefines,
  316. "compile definitions", OptionsParse::None);
  317. this->CompileDefinitionsCache.emplace(cacheKey, list);
  318. return list;
  319. }
  320. std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
  321. const std::string& config, const std::string& language) const
  322. {
  323. ConfigAndLanguage cacheKey(config, language);
  324. {
  325. auto it = this->PrecompileHeadersCache.find(cacheKey);
  326. if (it != this->PrecompileHeadersCache.end()) {
  327. return it->second;
  328. }
  329. }
  330. std::unordered_set<std::string> uniqueOptions;
  331. cmGeneratorExpressionDAGChecker dagChecker(
  332. this, "PRECOMPILE_HEADERS", nullptr, nullptr, this->LocalGenerator);
  333. cmList debugProperties{ this->Makefile->GetDefinition(
  334. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  335. bool debugDefines = !this->DebugPrecompileHeadersDone &&
  336. std::find(debugProperties.begin(), debugProperties.end(),
  337. "PRECOMPILE_HEADERS") != debugProperties.end();
  338. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  339. this->DebugPrecompileHeadersDone = true;
  340. }
  341. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  342. this, config, language, &dagChecker, this->PrecompileHeadersEntries);
  343. AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
  344. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  345. std::vector<BT<std::string>> list;
  346. processOptions(this, entries, list, uniqueOptions, debugDefines,
  347. "precompile headers", OptionsParse::None);
  348. this->PrecompileHeadersCache.emplace(cacheKey, list);
  349. return list;
  350. }
  351. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  352. const std::string& config,
  353. const std::string& language) const
  354. {
  355. if (this->IsDeviceLink() &&
  356. this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
  357. // link options are not propagated to the device link step
  358. return;
  359. }
  360. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  361. result.reserve(tmp.size());
  362. for (BT<std::string>& v : tmp) {
  363. result.emplace_back(std::move(v.Value));
  364. }
  365. }
  366. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  367. std::string const& config, std::string const& language) const
  368. {
  369. ConfigAndLanguage cacheKey(
  370. config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
  371. {
  372. auto it = this->LinkOptionsCache.find(cacheKey);
  373. if (it != this->LinkOptionsCache.end()) {
  374. return it->second;
  375. }
  376. }
  377. std::vector<BT<std::string>> result;
  378. std::unordered_set<std::string> uniqueOptions;
  379. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
  380. nullptr, this->LocalGenerator);
  381. cmList debugProperties{ this->Makefile->GetDefinition(
  382. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  383. bool debugOptions = !this->DebugLinkOptionsDone &&
  384. cm::contains(debugProperties, "LINK_OPTIONS");
  385. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  386. this->DebugLinkOptionsDone = true;
  387. }
  388. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  389. this, config, language, &dagChecker, this->LinkOptionsEntries);
  390. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
  391. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  392. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  393. ? UseTo::Link
  394. : UseTo::Compile);
  395. processOptions(this, entries, result, uniqueOptions, debugOptions,
  396. "link options", OptionsParse::Shell, this->IsDeviceLink());
  397. if (this->IsDeviceLink()) {
  398. // wrap host link options
  399. const std::string wrapper(this->Makefile->GetSafeDefinition(
  400. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG"));
  401. cmList wrapperFlag{ wrapper };
  402. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  403. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG_SEP"));
  404. bool concatFlagAndArgs = true;
  405. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  406. concatFlagAndArgs = false;
  407. wrapperFlag.pop_back();
  408. }
  409. auto it = result.begin();
  410. while (it != result.end()) {
  411. if (it->Value == DL_BEGIN) {
  412. // device link options, no treatment
  413. it = result.erase(it);
  414. it = std::find_if(it, result.end(), [](const BT<std::string>& item) {
  415. return item.Value == DL_END;
  416. });
  417. if (it != result.end()) {
  418. it = result.erase(it);
  419. }
  420. } else {
  421. // host link options must be wrapped
  422. std::vector<std::string> options;
  423. cmSystemTools::ParseUnixCommandLine(it->Value.c_str(), options);
  424. auto hostOptions = wrapOptions(options, it->Backtrace, wrapperFlag,
  425. wrapperSep, concatFlagAndArgs);
  426. it = result.erase(it);
  427. // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
  428. // C++11 standard: 'std::vector::insert()' do not returns an iterator,
  429. // so need to recompute the iterator after insertion.
  430. if (it == result.end()) {
  431. cm::append(result, hostOptions);
  432. it = result.end();
  433. } else {
  434. auto index = it - result.begin();
  435. result.insert(it, hostOptions.begin(), hostOptions.end());
  436. it = result.begin() + index + hostOptions.size();
  437. }
  438. }
  439. }
  440. }
  441. // Last step: replace "LINKER:" prefixed elements by
  442. // actual linker wrapper
  443. result = this->ResolveLinkerWrapper(result, language);
  444. this->LinkOptionsCache.emplace(cacheKey, result);
  445. return result;
  446. }
  447. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveLinkerWrapper(
  448. std::vector<BT<std::string>>& result, const std::string& language,
  449. bool joinItems) const
  450. {
  451. // replace "LINKER:" prefixed elements by actual linker wrapper
  452. const std::string wrapper(this->Makefile->GetSafeDefinition(
  453. "CMAKE_" + language +
  454. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG"
  455. : "_LINKER_WRAPPER_FLAG")));
  456. cmList wrapperFlag{ wrapper };
  457. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  458. "CMAKE_" + language +
  459. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG_SEP"
  460. : "_LINKER_WRAPPER_FLAG_SEP")));
  461. bool concatFlagAndArgs = true;
  462. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  463. concatFlagAndArgs = false;
  464. wrapperFlag.pop_back();
  465. }
  466. const std::string LINKER{ "LINKER:" };
  467. const std::string SHELL{ "SHELL:" };
  468. const std::string LINKER_SHELL = LINKER + SHELL;
  469. std::vector<BT<std::string>>::iterator entry;
  470. while ((entry = std::find_if(result.begin(), result.end(),
  471. [&LINKER](BT<std::string> const& item) -> bool {
  472. return item.Value.compare(0, LINKER.length(),
  473. LINKER) == 0;
  474. })) != result.end()) {
  475. std::string value = std::move(entry->Value);
  476. cmListFileBacktrace bt = std::move(entry->Backtrace);
  477. entry = result.erase(entry);
  478. std::vector<std::string> linkerOptions;
  479. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  480. cmSystemTools::ParseUnixCommandLine(
  481. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  482. } else {
  483. linkerOptions = cmTokenize(value.substr(LINKER.length()), ",");
  484. }
  485. if (linkerOptions.empty() ||
  486. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  487. continue;
  488. }
  489. // for now, raise an error if prefix SHELL: is part of arguments
  490. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  491. [&SHELL](const std::string& item) -> bool {
  492. return item.find(SHELL) != std::string::npos;
  493. }) != linkerOptions.end()) {
  494. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  495. MessageType::FATAL_ERROR,
  496. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  497. this->GetBacktrace());
  498. return result;
  499. }
  500. std::vector<BT<std::string>> options = wrapOptions(
  501. linkerOptions, bt, wrapperFlag, wrapperSep, concatFlagAndArgs);
  502. if (joinItems) {
  503. result.insert(entry,
  504. cmJoin(cmRange<decltype(options.cbegin())>(
  505. options.cbegin(), options.cend()),
  506. " "_s));
  507. } else {
  508. result.insert(entry, options.begin(), options.end());
  509. }
  510. }
  511. return result;
  512. }
  513. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  514. std::vector<std::string>& result, const std::string& config,
  515. const std::string& language) const
  516. {
  517. std::vector<BT<std::string>> tmp =
  518. this->GetStaticLibraryLinkOptions(config, language);
  519. result.reserve(tmp.size());
  520. for (BT<std::string>& v : tmp) {
  521. result.emplace_back(std::move(v.Value));
  522. }
  523. }
  524. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  525. std::string const& config, std::string const& language) const
  526. {
  527. std::vector<BT<std::string>> result;
  528. std::unordered_set<std::string> uniqueOptions;
  529. cmGeneratorExpressionDAGChecker dagChecker(
  530. this, "STATIC_LIBRARY_OPTIONS", nullptr, nullptr, this->LocalGenerator);
  531. EvaluatedTargetPropertyEntries entries;
  532. if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  533. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  534. *this->LocalGenerator->GetCMakeInstance(), *linkOptions);
  535. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  536. this, config, language, &dagChecker, *entry));
  537. }
  538. processOptions(this, entries, result, uniqueOptions, false,
  539. "static library link options", OptionsParse::Shell);
  540. return result;
  541. }
  542. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  543. const std::string& config,
  544. const std::string& language) const
  545. {
  546. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  547. result.reserve(tmp.size());
  548. for (BT<std::string>& v : tmp) {
  549. result.emplace_back(std::move(v.Value));
  550. }
  551. }
  552. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  553. std::string const& config, std::string const& language) const
  554. {
  555. std::vector<BT<std::string>> result;
  556. std::unordered_set<std::string> uniqueOptions;
  557. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
  558. nullptr, this->LocalGenerator);
  559. EvaluatedTargetPropertyEntries entries;
  560. if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
  561. cmList depends{ *linkDepends };
  562. for (const auto& depend : depends) {
  563. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  564. *this->LocalGenerator->GetCMakeInstance(), depend);
  565. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  566. this, config, language, &dagChecker, *entry));
  567. }
  568. }
  569. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
  570. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  571. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  572. ? UseTo::Link
  573. : UseTo::Compile);
  574. processOptions(this, entries, result, uniqueOptions, false, "link depends",
  575. OptionsParse::None);
  576. return result;
  577. }