cmGeneratorTarget_Options.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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(
  204. this, "COMPILE_OPTIONS", nullptr, nullptr, this->LocalGenerator, config);
  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(
  236. this, "COMPILE_FEATURES", nullptr, nullptr, this->LocalGenerator, config);
  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(this, "COMPILE_DEFINITIONS",
  277. nullptr, nullptr,
  278. this->LocalGenerator, config);
  279. cmList debugProperties{ this->Makefile->GetDefinition(
  280. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  281. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  282. cm::contains(debugProperties, "COMPILE_DEFINITIONS");
  283. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  284. this->DebugCompileDefinitionsDone = true;
  285. }
  286. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  287. this, config, language, &dagChecker, this->CompileDefinitionsEntries);
  288. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
  289. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  290. if (!config.empty()) {
  291. std::string configPropName =
  292. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  293. cmValue configProp = this->GetProperty(configPropName);
  294. if (configProp) {
  295. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  296. case cmPolicies::WARN: {
  297. this->LocalGenerator->IssueMessage(
  298. MessageType::AUTHOR_WARNING,
  299. cmPolicies::GetPolicyWarning(cmPolicies::CMP0043));
  300. CM_FALLTHROUGH;
  301. }
  302. case cmPolicies::OLD: {
  303. std::unique_ptr<TargetPropertyEntry> entry =
  304. TargetPropertyEntry::Create(
  305. *this->LocalGenerator->GetCMakeInstance(), *configProp);
  306. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  307. this, config, language, &dagChecker, *entry));
  308. } break;
  309. case cmPolicies::NEW:
  310. case cmPolicies::REQUIRED_ALWAYS:
  311. case cmPolicies::REQUIRED_IF_USED:
  312. break;
  313. }
  314. }
  315. }
  316. processOptions(this, entries, list, uniqueOptions, debugDefines,
  317. "compile definitions", OptionsParse::None);
  318. this->CompileDefinitionsCache.emplace(cacheKey, list);
  319. return list;
  320. }
  321. std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
  322. const std::string& config, const std::string& language) const
  323. {
  324. ConfigAndLanguage cacheKey(config, language);
  325. {
  326. auto it = this->PrecompileHeadersCache.find(cacheKey);
  327. if (it != this->PrecompileHeadersCache.end()) {
  328. return it->second;
  329. }
  330. }
  331. std::unordered_set<std::string> uniqueOptions;
  332. cmGeneratorExpressionDAGChecker dagChecker(this, "PRECOMPILE_HEADERS",
  333. nullptr, nullptr,
  334. this->LocalGenerator, config);
  335. cmList debugProperties{ this->Makefile->GetDefinition(
  336. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  337. bool debugDefines = !this->DebugPrecompileHeadersDone &&
  338. std::find(debugProperties.begin(), debugProperties.end(),
  339. "PRECOMPILE_HEADERS") != debugProperties.end();
  340. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  341. this->DebugPrecompileHeadersDone = true;
  342. }
  343. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  344. this, config, language, &dagChecker, this->PrecompileHeadersEntries);
  345. AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
  346. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  347. std::vector<BT<std::string>> list;
  348. processOptions(this, entries, list, uniqueOptions, debugDefines,
  349. "precompile headers", OptionsParse::None);
  350. this->PrecompileHeadersCache.emplace(cacheKey, list);
  351. return list;
  352. }
  353. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  354. const std::string& config,
  355. const std::string& language) const
  356. {
  357. if (this->IsDeviceLink() &&
  358. this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
  359. // link options are not propagated to the device link step
  360. return;
  361. }
  362. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  363. result.reserve(tmp.size());
  364. for (BT<std::string>& v : tmp) {
  365. result.emplace_back(std::move(v.Value));
  366. }
  367. }
  368. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  369. std::string const& config, std::string const& language) const
  370. {
  371. ConfigAndLanguage cacheKey(
  372. config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
  373. {
  374. auto it = this->LinkOptionsCache.find(cacheKey);
  375. if (it != this->LinkOptionsCache.end()) {
  376. return it->second;
  377. }
  378. }
  379. std::vector<BT<std::string>> result;
  380. std::unordered_set<std::string> uniqueOptions;
  381. cmGeneratorExpressionDAGChecker dagChecker(
  382. this, "LINK_OPTIONS", nullptr, nullptr, this->LocalGenerator, config);
  383. cmList debugProperties{ this->Makefile->GetDefinition(
  384. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  385. bool debugOptions = !this->DebugLinkOptionsDone &&
  386. cm::contains(debugProperties, "LINK_OPTIONS");
  387. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  388. this->DebugLinkOptionsDone = true;
  389. }
  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 = wrapOptions(options, it->Backtrace, wrapperFlag,
  427. wrapperSep, concatFlagAndArgs);
  428. it = result.erase(it);
  429. // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
  430. // C++11 standard: 'std::vector::insert()' do not returns an iterator,
  431. // so need to recompute the iterator after insertion.
  432. if (it == result.end()) {
  433. cm::append(result, hostOptions);
  434. it = result.end();
  435. } else {
  436. auto index = it - result.begin();
  437. result.insert(it, hostOptions.begin(), hostOptions.end());
  438. it = result.begin() + index + hostOptions.size();
  439. }
  440. }
  441. }
  442. }
  443. // Last step: replace "LINKER:" prefixed elements by
  444. // actual linker wrapper
  445. result = this->ResolveLinkerWrapper(result, language);
  446. this->LinkOptionsCache.emplace(cacheKey, result);
  447. return result;
  448. }
  449. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveLinkerWrapper(
  450. std::vector<BT<std::string>>& result, const std::string& language,
  451. bool joinItems) const
  452. {
  453. // replace "LINKER:" prefixed elements by actual linker wrapper
  454. const std::string wrapper(this->Makefile->GetSafeDefinition(
  455. "CMAKE_" + language +
  456. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG"
  457. : "_LINKER_WRAPPER_FLAG")));
  458. cmList wrapperFlag{ wrapper };
  459. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  460. "CMAKE_" + language +
  461. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG_SEP"
  462. : "_LINKER_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 LINKER{ "LINKER:" };
  469. const std::string SHELL{ "SHELL:" };
  470. const std::string LINKER_SHELL = LINKER + SHELL;
  471. std::vector<BT<std::string>>::iterator entry;
  472. while ((entry = std::find_if(result.begin(), result.end(),
  473. [&LINKER](BT<std::string> const& item) -> bool {
  474. return item.Value.compare(0, LINKER.length(),
  475. LINKER) == 0;
  476. })) != result.end()) {
  477. std::string value = std::move(entry->Value);
  478. cmListFileBacktrace bt = std::move(entry->Backtrace);
  479. entry = result.erase(entry);
  480. std::vector<std::string> linkerOptions;
  481. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  482. cmSystemTools::ParseUnixCommandLine(
  483. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  484. } else {
  485. linkerOptions = cmTokenize(value.substr(LINKER.length()), ",");
  486. }
  487. if (linkerOptions.empty() ||
  488. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  489. continue;
  490. }
  491. // for now, raise an error if prefix SHELL: is part of arguments
  492. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  493. [&SHELL](const std::string& item) -> bool {
  494. return item.find(SHELL) != std::string::npos;
  495. }) != linkerOptions.end()) {
  496. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  497. MessageType::FATAL_ERROR,
  498. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  499. this->GetBacktrace());
  500. return result;
  501. }
  502. std::vector<BT<std::string>> options = wrapOptions(
  503. linkerOptions, bt, wrapperFlag, wrapperSep, concatFlagAndArgs);
  504. if (joinItems) {
  505. result.insert(entry,
  506. cmJoin(cmRange<decltype(options.cbegin())>(
  507. options.cbegin(), options.cend()),
  508. " "_s));
  509. } else {
  510. result.insert(entry, options.begin(), options.end());
  511. }
  512. }
  513. return result;
  514. }
  515. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  516. std::vector<std::string>& result, const std::string& config,
  517. const std::string& language) const
  518. {
  519. std::vector<BT<std::string>> tmp =
  520. this->GetStaticLibraryLinkOptions(config, language);
  521. result.reserve(tmp.size());
  522. for (BT<std::string>& v : tmp) {
  523. result.emplace_back(std::move(v.Value));
  524. }
  525. }
  526. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  527. std::string const& config, std::string const& language) const
  528. {
  529. std::vector<BT<std::string>> result;
  530. std::unordered_set<std::string> uniqueOptions;
  531. cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
  532. nullptr, nullptr,
  533. this->LocalGenerator, config);
  534. EvaluatedTargetPropertyEntries entries;
  535. if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  536. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  537. *this->LocalGenerator->GetCMakeInstance(), *linkOptions);
  538. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  539. this, config, language, &dagChecker, *entry));
  540. }
  541. processOptions(this, entries, result, uniqueOptions, false,
  542. "static library link options", OptionsParse::Shell);
  543. return result;
  544. }
  545. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  546. const std::string& config,
  547. const std::string& language) const
  548. {
  549. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  550. result.reserve(tmp.size());
  551. for (BT<std::string>& v : tmp) {
  552. result.emplace_back(std::move(v.Value));
  553. }
  554. }
  555. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  556. std::string const& config, std::string const& language) const
  557. {
  558. std::vector<BT<std::string>> result;
  559. std::unordered_set<std::string> uniqueOptions;
  560. cmGeneratorExpressionDAGChecker dagChecker(
  561. this, "LINK_DEPENDS", nullptr, nullptr, this->LocalGenerator, config);
  562. EvaluatedTargetPropertyEntries entries;
  563. if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
  564. cmList depends{ *linkDepends };
  565. for (const auto& depend : depends) {
  566. std::unique_ptr<TargetPropertyEntry> entry = TargetPropertyEntry::Create(
  567. *this->LocalGenerator->GetCMakeInstance(), depend);
  568. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  569. this, config, language, &dagChecker, *entry));
  570. }
  571. }
  572. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
  573. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  574. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  575. ? UseTo::Link
  576. : UseTo::Compile);
  577. processOptions(this, entries, result, uniqueOptions, false, "link depends",
  578. OptionsParse::None);
  579. return result;
  580. }