cmGeneratorTarget_Options.cxx 23 KB

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