cmGeneratorExpressionNode.cxx 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmGeneratorExpressionNode.h"
  4. #include "cmAlgorithms.h"
  5. #include "cmGeneratorExpression.h"
  6. #include "cmGeneratorExpressionContext.h"
  7. #include "cmGeneratorExpressionDAGChecker.h"
  8. #include "cmGeneratorExpressionEvaluator.h"
  9. #include "cmGeneratorTarget.h"
  10. #include "cmGlobalGenerator.h"
  11. #include "cmLinkItem.h"
  12. #include "cmLocalGenerator.h"
  13. #include "cmMakefile.h"
  14. #include "cmMessageType.h"
  15. #include "cmOutputConverter.h"
  16. #include "cmPolicies.h"
  17. #include "cmRange.h"
  18. #include "cmState.h"
  19. #include "cmStateSnapshot.h"
  20. #include "cmStateTypes.h"
  21. #include "cmString.hxx"
  22. #include "cmStringAlgorithms.h"
  23. #include "cmSystemTools.h"
  24. #include "cmTarget.h"
  25. #include "cm_static_string_view.hxx"
  26. #include "cmake.h"
  27. #include "cmsys/RegularExpression.hxx"
  28. #include "cmsys/String.h"
  29. #include <cm/iterator>
  30. #include <algorithm>
  31. #include <cassert>
  32. #include <cerrno>
  33. #include <cstdlib>
  34. #include <cstring>
  35. #include <map>
  36. #include <memory>
  37. #include <set>
  38. #include <sstream>
  39. #include <utility>
  40. std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
  41. std::string const& prop, cmLocalGenerator* lg,
  42. cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
  43. cmGeneratorTarget const* currentTarget,
  44. cmGeneratorExpressionDAGChecker* dagChecker)
  45. {
  46. cmGeneratorExpression ge(context->Backtrace);
  47. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  48. cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
  49. cge->SetQuiet(context->Quiet);
  50. std::string result =
  51. cge->Evaluate(lg, context->Config, headTarget, currentTarget, dagChecker,
  52. context->Language);
  53. if (cge->GetHadContextSensitiveCondition()) {
  54. context->HadContextSensitiveCondition = true;
  55. }
  56. if (cge->GetHadHeadSensitiveCondition()) {
  57. context->HadHeadSensitiveCondition = true;
  58. }
  59. return result;
  60. }
  61. static const struct ZeroNode : public cmGeneratorExpressionNode
  62. {
  63. ZeroNode() {} // NOLINT(modernize-use-equals-default)
  64. bool GeneratesContent() const override { return false; }
  65. bool AcceptsArbitraryContentParameter() const override { return true; }
  66. std::string Evaluate(
  67. const std::vector<std::string>& /*parameters*/,
  68. cmGeneratorExpressionContext* /*context*/,
  69. const GeneratorExpressionContent* /*content*/,
  70. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  71. {
  72. return std::string();
  73. }
  74. } zeroNode;
  75. static const struct OneNode : public cmGeneratorExpressionNode
  76. {
  77. OneNode() {} // NOLINT(modernize-use-equals-default)
  78. bool AcceptsArbitraryContentParameter() const override { return true; }
  79. std::string Evaluate(
  80. const std::vector<std::string>& parameters,
  81. cmGeneratorExpressionContext* /*context*/,
  82. const GeneratorExpressionContent* /*content*/,
  83. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  84. {
  85. return parameters.front();
  86. }
  87. } oneNode;
  88. static const struct OneNode buildInterfaceNode;
  89. static const struct ZeroNode installInterfaceNode;
  90. struct BooleanOpNode : public cmGeneratorExpressionNode
  91. {
  92. BooleanOpNode(const char* op_, const char* successVal_,
  93. const char* failureVal_)
  94. : op(op_)
  95. , successVal(successVal_)
  96. , failureVal(failureVal_)
  97. {
  98. }
  99. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  100. std::string Evaluate(const std::vector<std::string>& parameters,
  101. cmGeneratorExpressionContext* context,
  102. const GeneratorExpressionContent* content,
  103. cmGeneratorExpressionDAGChecker*) const override
  104. {
  105. for (std::string const& param : parameters) {
  106. if (param == this->failureVal) {
  107. return this->failureVal;
  108. }
  109. if (param != this->successVal) {
  110. std::ostringstream e;
  111. e << "Parameters to $<" << this->op;
  112. e << "> must resolve to either '0' or '1'.";
  113. reportError(context, content->GetOriginalExpression(), e.str());
  114. return std::string();
  115. }
  116. }
  117. return this->successVal;
  118. }
  119. const char *const op, *const successVal, *const failureVal;
  120. };
  121. static const BooleanOpNode andNode("AND", "1", "0"), orNode("OR", "0", "1");
  122. static const struct NotNode : public cmGeneratorExpressionNode
  123. {
  124. NotNode() {} // NOLINT(modernize-use-equals-default)
  125. std::string Evaluate(
  126. const std::vector<std::string>& parameters,
  127. cmGeneratorExpressionContext* context,
  128. const GeneratorExpressionContent* content,
  129. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  130. {
  131. if (parameters.front() != "0" && parameters.front() != "1") {
  132. reportError(
  133. context, content->GetOriginalExpression(),
  134. "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
  135. return std::string();
  136. }
  137. return parameters.front() == "0" ? "1" : "0";
  138. }
  139. } notNode;
  140. static const struct BoolNode : public cmGeneratorExpressionNode
  141. {
  142. BoolNode() {} // NOLINT(modernize-use-equals-default)
  143. int NumExpectedParameters() const override { return 1; }
  144. std::string Evaluate(
  145. const std::vector<std::string>& parameters,
  146. cmGeneratorExpressionContext* /*context*/,
  147. const GeneratorExpressionContent* /*content*/,
  148. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  149. {
  150. return !cmIsOff(parameters.front()) ? "1" : "0";
  151. }
  152. } boolNode;
  153. static const struct IfNode : public cmGeneratorExpressionNode
  154. {
  155. IfNode() {} // NOLINT(modernize-use-equals-default)
  156. int NumExpectedParameters() const override { return 3; }
  157. std::string Evaluate(const std::vector<std::string>& parameters,
  158. cmGeneratorExpressionContext* context,
  159. const GeneratorExpressionContent* content,
  160. cmGeneratorExpressionDAGChecker*) const override
  161. {
  162. if (parameters[0] != "1" && parameters[0] != "0") {
  163. reportError(context, content->GetOriginalExpression(),
  164. "First parameter to $<IF> must resolve to exactly one '0' "
  165. "or '1' value.");
  166. return std::string();
  167. }
  168. return parameters[0] == "1" ? parameters[1] : parameters[2];
  169. }
  170. } ifNode;
  171. static const struct StrEqualNode : public cmGeneratorExpressionNode
  172. {
  173. StrEqualNode() {} // NOLINT(modernize-use-equals-default)
  174. int NumExpectedParameters() const override { return 2; }
  175. std::string Evaluate(
  176. const std::vector<std::string>& parameters,
  177. cmGeneratorExpressionContext* /*context*/,
  178. const GeneratorExpressionContent* /*content*/,
  179. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  180. {
  181. return parameters.front() == parameters[1] ? "1" : "0";
  182. }
  183. } strEqualNode;
  184. static const struct EqualNode : public cmGeneratorExpressionNode
  185. {
  186. EqualNode() {} // NOLINT(modernize-use-equals-default)
  187. int NumExpectedParameters() const override { return 2; }
  188. std::string Evaluate(
  189. const std::vector<std::string>& parameters,
  190. cmGeneratorExpressionContext* context,
  191. const GeneratorExpressionContent* content,
  192. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  193. {
  194. long numbers[2];
  195. for (int i = 0; i < 2; ++i) {
  196. if (!ParameterToLong(parameters[i].c_str(), &numbers[i])) {
  197. reportError(context, content->GetOriginalExpression(),
  198. "$<EQUAL> parameter " + parameters[i] +
  199. " is not a valid integer.");
  200. return {};
  201. }
  202. }
  203. return numbers[0] == numbers[1] ? "1" : "0";
  204. }
  205. static bool ParameterToLong(const char* param, long* outResult)
  206. {
  207. const char isNegative = param[0] == '-';
  208. int base = 0;
  209. if (cmHasLiteralPrefix(param, "0b") || cmHasLiteralPrefix(param, "0B")) {
  210. base = 2;
  211. param += 2;
  212. } else if (cmHasLiteralPrefix(param, "-0b") ||
  213. cmHasLiteralPrefix(param, "-0B") ||
  214. cmHasLiteralPrefix(param, "+0b") ||
  215. cmHasLiteralPrefix(param, "+0B")) {
  216. base = 2;
  217. param += 3;
  218. }
  219. char* pEnd;
  220. long result = strtol(param, &pEnd, base);
  221. if (pEnd == param || *pEnd != '\0' || errno == ERANGE) {
  222. return false;
  223. }
  224. if (isNegative && result > 0) {
  225. result *= -1;
  226. }
  227. *outResult = result;
  228. return true;
  229. }
  230. } equalNode;
  231. static const struct InListNode : public cmGeneratorExpressionNode
  232. {
  233. InListNode() {} // NOLINT(modernize-use-equals-default)
  234. int NumExpectedParameters() const override { return 2; }
  235. std::string Evaluate(
  236. const std::vector<std::string>& parameters,
  237. cmGeneratorExpressionContext* context,
  238. const GeneratorExpressionContent* /*content*/,
  239. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  240. {
  241. std::vector<std::string> values;
  242. std::vector<std::string> checkValues;
  243. bool check = false;
  244. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0085)) {
  245. case cmPolicies::WARN:
  246. if (parameters.front().empty()) {
  247. check = true;
  248. cmExpandList(parameters[1], checkValues, true);
  249. }
  250. CM_FALLTHROUGH;
  251. case cmPolicies::OLD:
  252. cmExpandList(parameters[1], values);
  253. if (check && values != checkValues) {
  254. std::ostringstream e;
  255. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0085)
  256. << "\nSearch Item:\n \"" << parameters.front()
  257. << "\"\nList:\n \"" << parameters[1] << "\"\n";
  258. context->LG->GetCMakeInstance()->IssueMessage(
  259. MessageType ::AUTHOR_WARNING, e.str(), context->Backtrace);
  260. return "0";
  261. }
  262. if (values.empty()) {
  263. return "0";
  264. }
  265. break;
  266. case cmPolicies::REQUIRED_IF_USED:
  267. case cmPolicies::REQUIRED_ALWAYS:
  268. case cmPolicies::NEW:
  269. cmExpandList(parameters[1], values, true);
  270. break;
  271. }
  272. return cmContains(values, parameters.front()) ? "1" : "0";
  273. }
  274. } inListNode;
  275. static const struct FilterNode : public cmGeneratorExpressionNode
  276. {
  277. FilterNode() {} // NOLINT(modernize-use-equals-default)
  278. int NumExpectedParameters() const override { return 3; }
  279. std::string Evaluate(
  280. const std::vector<std::string>& parameters,
  281. cmGeneratorExpressionContext* context,
  282. const GeneratorExpressionContent* content,
  283. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  284. {
  285. if (parameters.size() != 3) {
  286. reportError(context, content->GetOriginalExpression(),
  287. "$<FILTER:...> expression requires three parameters");
  288. return {};
  289. }
  290. if (parameters[1] != "INCLUDE" && parameters[1] != "EXCLUDE") {
  291. reportError(
  292. context, content->GetOriginalExpression(),
  293. "$<FILTER:...> second parameter must be either INCLUDE or EXCLUDE");
  294. return {};
  295. }
  296. const bool exclude = parameters[1] == "EXCLUDE";
  297. cmsys::RegularExpression re;
  298. if (!re.compile(parameters[2])) {
  299. reportError(context, content->GetOriginalExpression(),
  300. "$<FILTER:...> failed to compile regex");
  301. return {};
  302. }
  303. std::vector<std::string> values;
  304. std::vector<std::string> result;
  305. cmExpandList(parameters.front(), values, true);
  306. std::copy_if(values.cbegin(), values.cend(), std::back_inserter(result),
  307. [&re, exclude](std::string const& input) {
  308. return exclude ^ re.find(input);
  309. });
  310. return cmJoin(cmMakeRange(result.cbegin(), result.cend()), ";");
  311. }
  312. } filterNode;
  313. static const struct RemoveDuplicatesNode : public cmGeneratorExpressionNode
  314. {
  315. RemoveDuplicatesNode() {} // NOLINT(modernize-use-equals-default)
  316. int NumExpectedParameters() const override { return 1; }
  317. std::string Evaluate(
  318. const std::vector<std::string>& parameters,
  319. cmGeneratorExpressionContext* context,
  320. const GeneratorExpressionContent* content,
  321. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  322. {
  323. if (parameters.size() != 1) {
  324. reportError(
  325. context, content->GetOriginalExpression(),
  326. "$<REMOVE_DUPLICATES:...> expression requires one parameter");
  327. }
  328. std::vector<std::string> values = cmExpandedList(parameters.front(), true);
  329. auto valuesEnd = cmRemoveDuplicates(values);
  330. auto valuesBegin = values.cbegin();
  331. return cmJoin(cmMakeRange(valuesBegin, valuesEnd), ";");
  332. }
  333. } removeDuplicatesNode;
  334. static const struct TargetExistsNode : public cmGeneratorExpressionNode
  335. {
  336. TargetExistsNode() {} // NOLINT(modernize-use-equals-default)
  337. int NumExpectedParameters() const override { return 1; }
  338. std::string Evaluate(
  339. const std::vector<std::string>& parameters,
  340. cmGeneratorExpressionContext* context,
  341. const GeneratorExpressionContent* content,
  342. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  343. {
  344. if (parameters.size() != 1) {
  345. reportError(context, content->GetOriginalExpression(),
  346. "$<TARGET_EXISTS:...> expression requires one parameter");
  347. return std::string();
  348. }
  349. std::string targetName = parameters.front();
  350. if (targetName.empty() ||
  351. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  352. reportError(context, content->GetOriginalExpression(),
  353. "$<TARGET_EXISTS:tgt> expression requires a non-empty "
  354. "valid target name.");
  355. return std::string();
  356. }
  357. return context->LG->GetMakefile()->FindTargetToUse(targetName) ? "1" : "0";
  358. }
  359. } targetExistsNode;
  360. static const struct TargetNameIfExistsNode : public cmGeneratorExpressionNode
  361. {
  362. TargetNameIfExistsNode() {} // NOLINT(modernize-use-equals-default)
  363. int NumExpectedParameters() const override { return 1; }
  364. std::string Evaluate(
  365. const std::vector<std::string>& parameters,
  366. cmGeneratorExpressionContext* context,
  367. const GeneratorExpressionContent* content,
  368. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  369. {
  370. if (parameters.size() != 1) {
  371. reportError(context, content->GetOriginalExpression(),
  372. "$<TARGET_NAME_IF_EXISTS:...> expression requires one "
  373. "parameter");
  374. return std::string();
  375. }
  376. std::string targetName = parameters.front();
  377. if (targetName.empty() ||
  378. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  379. reportError(context, content->GetOriginalExpression(),
  380. "$<TARGET_NAME_IF_EXISTS:tgt> expression requires a "
  381. "non-empty valid target name.");
  382. return std::string();
  383. }
  384. return context->LG->GetMakefile()->FindTargetToUse(targetName)
  385. ? targetName
  386. : std::string();
  387. }
  388. } targetNameIfExistsNode;
  389. struct GenexEvaluator : public cmGeneratorExpressionNode
  390. {
  391. GenexEvaluator() {} // NOLINT(modernize-use-equals-default)
  392. protected:
  393. std::string EvaluateExpression(
  394. const std::string& genexOperator, const std::string& expression,
  395. cmGeneratorExpressionContext* context,
  396. const GeneratorExpressionContent* content,
  397. cmGeneratorExpressionDAGChecker* dagCheckerParent) const
  398. {
  399. if (context->HeadTarget) {
  400. cmGeneratorExpressionDAGChecker dagChecker(
  401. context->Backtrace, context->HeadTarget,
  402. genexOperator + ":" + expression, content, dagCheckerParent);
  403. switch (dagChecker.Check()) {
  404. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  405. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: {
  406. dagChecker.ReportError(context, content->GetOriginalExpression());
  407. return std::string();
  408. }
  409. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  410. case cmGeneratorExpressionDAGChecker::DAG:
  411. break;
  412. }
  413. return this->EvaluateDependentExpression(
  414. expression, context->LG, context, context->HeadTarget,
  415. context->CurrentTarget, &dagChecker);
  416. }
  417. return this->EvaluateDependentExpression(
  418. expression, context->LG, context, context->HeadTarget,
  419. context->CurrentTarget, dagCheckerParent);
  420. }
  421. };
  422. static const struct TargetGenexEvalNode : public GenexEvaluator
  423. {
  424. TargetGenexEvalNode() {} // NOLINT(modernize-use-equals-default)
  425. int NumExpectedParameters() const override { return 2; }
  426. bool AcceptsArbitraryContentParameter() const override { return true; }
  427. std::string Evaluate(
  428. const std::vector<std::string>& parameters,
  429. cmGeneratorExpressionContext* context,
  430. const GeneratorExpressionContent* content,
  431. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  432. {
  433. const std::string& targetName = parameters.front();
  434. if (targetName.empty() ||
  435. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  436. reportError(context, content->GetOriginalExpression(),
  437. "$<TARGET_GENEX_EVAL:tgt, ...> expression requires a "
  438. "non-empty valid target name.");
  439. return std::string();
  440. }
  441. const auto* target = context->LG->FindGeneratorTargetToUse(targetName);
  442. if (!target) {
  443. std::ostringstream e;
  444. e << "$<TARGET_GENEX_EVAL:tgt, ...> target \"" << targetName
  445. << "\" not found.";
  446. reportError(context, content->GetOriginalExpression(), e.str());
  447. return std::string();
  448. }
  449. const std::string& expression = parameters[1];
  450. if (expression.empty()) {
  451. return expression;
  452. }
  453. cmGeneratorExpressionContext targetContext(
  454. context->LG, context->Config, context->Quiet, target, target,
  455. context->EvaluateForBuildsystem, context->Backtrace, context->Language);
  456. return this->EvaluateExpression("TARGET_GENEX_EVAL", expression,
  457. &targetContext, content, dagCheckerParent);
  458. }
  459. } targetGenexEvalNode;
  460. static const struct GenexEvalNode : public GenexEvaluator
  461. {
  462. GenexEvalNode() {} // NOLINT(modernize-use-equals-default)
  463. int NumExpectedParameters() const override { return 1; }
  464. bool AcceptsArbitraryContentParameter() const override { return true; }
  465. std::string Evaluate(
  466. const std::vector<std::string>& parameters,
  467. cmGeneratorExpressionContext* context,
  468. const GeneratorExpressionContent* content,
  469. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  470. {
  471. const std::string& expression = parameters[0];
  472. if (expression.empty()) {
  473. return expression;
  474. }
  475. return this->EvaluateExpression("GENEX_EVAL", expression, context, content,
  476. dagCheckerParent);
  477. }
  478. } genexEvalNode;
  479. static const struct LowerCaseNode : public cmGeneratorExpressionNode
  480. {
  481. LowerCaseNode() {} // NOLINT(modernize-use-equals-default)
  482. bool AcceptsArbitraryContentParameter() const override { return true; }
  483. std::string Evaluate(
  484. const std::vector<std::string>& parameters,
  485. cmGeneratorExpressionContext* /*context*/,
  486. const GeneratorExpressionContent* /*content*/,
  487. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  488. {
  489. return cmSystemTools::LowerCase(parameters.front());
  490. }
  491. } lowerCaseNode;
  492. static const struct UpperCaseNode : public cmGeneratorExpressionNode
  493. {
  494. UpperCaseNode() {} // NOLINT(modernize-use-equals-default)
  495. bool AcceptsArbitraryContentParameter() const override { return true; }
  496. std::string Evaluate(
  497. const std::vector<std::string>& parameters,
  498. cmGeneratorExpressionContext* /*context*/,
  499. const GeneratorExpressionContent* /*content*/,
  500. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  501. {
  502. return cmSystemTools::UpperCase(parameters.front());
  503. }
  504. } upperCaseNode;
  505. static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
  506. {
  507. MakeCIdentifierNode() {} // NOLINT(modernize-use-equals-default)
  508. bool AcceptsArbitraryContentParameter() const override { return true; }
  509. std::string Evaluate(
  510. const std::vector<std::string>& parameters,
  511. cmGeneratorExpressionContext* /*context*/,
  512. const GeneratorExpressionContent* /*content*/,
  513. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  514. {
  515. return cmSystemTools::MakeCidentifier(parameters.front());
  516. }
  517. } makeCIdentifierNode;
  518. template <char C>
  519. struct CharacterNode : public cmGeneratorExpressionNode
  520. {
  521. CharacterNode() {} // NOLINT(modernize-use-equals-default)
  522. int NumExpectedParameters() const override { return 0; }
  523. std::string Evaluate(
  524. const std::vector<std::string>& /*parameters*/,
  525. cmGeneratorExpressionContext* /*context*/,
  526. const GeneratorExpressionContent* /*content*/,
  527. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  528. {
  529. return { C };
  530. }
  531. };
  532. static const CharacterNode<'>'> angle_rNode;
  533. static const CharacterNode<','> commaNode;
  534. static const CharacterNode<';'> semicolonNode;
  535. struct CompilerIdNode : public cmGeneratorExpressionNode
  536. {
  537. CompilerIdNode(const char* compilerLang)
  538. : CompilerLanguage(compilerLang)
  539. {
  540. }
  541. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  542. std::string Evaluate(
  543. const std::vector<std::string>& parameters,
  544. cmGeneratorExpressionContext* context,
  545. const GeneratorExpressionContent* content,
  546. cmGeneratorExpressionDAGChecker* dagChecker) const override
  547. {
  548. if (!context->HeadTarget) {
  549. std::ostringstream e;
  550. e << "$<" << this->CompilerLanguage
  551. << "_COMPILER_ID> may only be used with binary targets. It may "
  552. "not be used with add_custom_command or add_custom_target.";
  553. reportError(context, content->GetOriginalExpression(), e.str());
  554. return {};
  555. }
  556. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  557. this->CompilerLanguage);
  558. }
  559. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  560. cmGeneratorExpressionContext* context,
  561. const GeneratorExpressionContent* content,
  562. cmGeneratorExpressionDAGChecker* /*unused*/,
  563. const std::string& lang) const
  564. {
  565. std::string const& compilerId =
  566. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
  567. "_COMPILER_ID");
  568. if (parameters.empty()) {
  569. return compilerId;
  570. }
  571. if (compilerId.empty()) {
  572. return parameters.front().empty() ? "1" : "0";
  573. }
  574. static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
  575. for (auto& param : parameters) {
  576. if (!compilerIdValidator.find(param)) {
  577. reportError(context, content->GetOriginalExpression(),
  578. "Expression syntax not recognized.");
  579. return std::string();
  580. }
  581. if (strcmp(param.c_str(), compilerId.c_str()) == 0) {
  582. return "1";
  583. }
  584. if (cmsysString_strcasecmp(param.c_str(), compilerId.c_str()) == 0) {
  585. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
  586. case cmPolicies::WARN: {
  587. context->LG->GetCMakeInstance()->IssueMessage(
  588. MessageType::AUTHOR_WARNING,
  589. cmPolicies::GetPolicyWarning(cmPolicies::CMP0044),
  590. context->Backtrace);
  591. CM_FALLTHROUGH;
  592. }
  593. case cmPolicies::OLD:
  594. return "1";
  595. case cmPolicies::NEW:
  596. case cmPolicies::REQUIRED_ALWAYS:
  597. case cmPolicies::REQUIRED_IF_USED:
  598. break;
  599. }
  600. }
  601. }
  602. return "0";
  603. }
  604. const char* const CompilerLanguage;
  605. };
  606. static const CompilerIdNode cCompilerIdNode("C"), cxxCompilerIdNode("CXX"),
  607. cudaCompilerIdNode("CUDA"), fortranCompilerIdNode("Fortran");
  608. struct CompilerVersionNode : public cmGeneratorExpressionNode
  609. {
  610. CompilerVersionNode(const char* compilerLang)
  611. : CompilerLanguage(compilerLang)
  612. {
  613. }
  614. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  615. std::string Evaluate(
  616. const std::vector<std::string>& parameters,
  617. cmGeneratorExpressionContext* context,
  618. const GeneratorExpressionContent* content,
  619. cmGeneratorExpressionDAGChecker* dagChecker) const override
  620. {
  621. if (!context->HeadTarget) {
  622. std::ostringstream e;
  623. e << "$<" << this->CompilerLanguage
  624. << "_COMPILER_VERSION> may only be used with binary targets. It "
  625. "may not be used with add_custom_command or add_custom_target.";
  626. reportError(context, content->GetOriginalExpression(), e.str());
  627. return {};
  628. }
  629. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  630. this->CompilerLanguage);
  631. }
  632. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  633. cmGeneratorExpressionContext* context,
  634. const GeneratorExpressionContent* content,
  635. cmGeneratorExpressionDAGChecker* /*unused*/,
  636. const std::string& lang) const
  637. {
  638. std::string const& compilerVersion =
  639. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
  640. "_COMPILER_VERSION");
  641. if (parameters.empty()) {
  642. return compilerVersion;
  643. }
  644. static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
  645. if (!compilerIdValidator.find(parameters.front())) {
  646. reportError(context, content->GetOriginalExpression(),
  647. "Expression syntax not recognized.");
  648. return {};
  649. }
  650. if (compilerVersion.empty()) {
  651. return parameters.front().empty() ? "1" : "0";
  652. }
  653. return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
  654. parameters.front().c_str(),
  655. compilerVersion.c_str())
  656. ? "1"
  657. : "0";
  658. }
  659. const char* const CompilerLanguage;
  660. };
  661. static const CompilerVersionNode cCompilerVersionNode("C"),
  662. cxxCompilerVersionNode("CXX"), cudaCompilerVersionNode("CUDA"),
  663. fortranCompilerVersionNode("Fortran");
  664. struct PlatformIdNode : public cmGeneratorExpressionNode
  665. {
  666. PlatformIdNode() {} // NOLINT(modernize-use-equals-default)
  667. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  668. std::string Evaluate(
  669. const std::vector<std::string>& parameters,
  670. cmGeneratorExpressionContext* context,
  671. const GeneratorExpressionContent* /*content*/,
  672. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  673. {
  674. std::string const& platformId =
  675. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  676. if (parameters.empty()) {
  677. return platformId;
  678. }
  679. if (platformId.empty()) {
  680. return parameters.front().empty() ? "1" : "0";
  681. }
  682. for (auto& param : parameters) {
  683. if (param == platformId) {
  684. return "1";
  685. }
  686. }
  687. return "0";
  688. }
  689. } platformIdNode;
  690. template <cmSystemTools::CompareOp Op>
  691. struct VersionNode : public cmGeneratorExpressionNode
  692. {
  693. VersionNode() {} // NOLINT(modernize-use-equals-default)
  694. int NumExpectedParameters() const override { return 2; }
  695. std::string Evaluate(
  696. const std::vector<std::string>& parameters,
  697. cmGeneratorExpressionContext* /*context*/,
  698. const GeneratorExpressionContent* /*content*/,
  699. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  700. {
  701. return cmSystemTools::VersionCompare(Op, parameters.front().c_str(),
  702. parameters[1].c_str())
  703. ? "1"
  704. : "0";
  705. }
  706. };
  707. static const VersionNode<cmSystemTools::OP_GREATER> versionGreaterNode;
  708. static const VersionNode<cmSystemTools::OP_GREATER_EQUAL> versionGreaterEqNode;
  709. static const VersionNode<cmSystemTools::OP_LESS> versionLessNode;
  710. static const VersionNode<cmSystemTools::OP_LESS_EQUAL> versionLessEqNode;
  711. static const VersionNode<cmSystemTools::OP_EQUAL> versionEqualNode;
  712. static const struct LinkOnlyNode : public cmGeneratorExpressionNode
  713. {
  714. LinkOnlyNode() {} // NOLINT(modernize-use-equals-default)
  715. std::string Evaluate(
  716. const std::vector<std::string>& parameters,
  717. cmGeneratorExpressionContext* context,
  718. const GeneratorExpressionContent* content,
  719. cmGeneratorExpressionDAGChecker* dagChecker) const override
  720. {
  721. if (!dagChecker) {
  722. reportError(context, content->GetOriginalExpression(),
  723. "$<LINK_ONLY:...> may only be used for linking");
  724. return std::string();
  725. }
  726. if (!dagChecker->GetTransitivePropertiesOnly()) {
  727. return parameters.front();
  728. }
  729. return std::string();
  730. }
  731. } linkOnlyNode;
  732. static const struct ConfigurationNode : public cmGeneratorExpressionNode
  733. {
  734. ConfigurationNode() {} // NOLINT(modernize-use-equals-default)
  735. int NumExpectedParameters() const override { return 0; }
  736. std::string Evaluate(
  737. const std::vector<std::string>& /*parameters*/,
  738. cmGeneratorExpressionContext* context,
  739. const GeneratorExpressionContent* /*content*/,
  740. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  741. {
  742. context->HadContextSensitiveCondition = true;
  743. return context->Config;
  744. }
  745. } configurationNode;
  746. static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
  747. {
  748. ConfigurationTestNode() {} // NOLINT(modernize-use-equals-default)
  749. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  750. std::string Evaluate(
  751. const std::vector<std::string>& parameters,
  752. cmGeneratorExpressionContext* context,
  753. const GeneratorExpressionContent* content,
  754. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  755. {
  756. if (parameters.empty()) {
  757. return configurationNode.Evaluate(parameters, context, content, nullptr);
  758. }
  759. static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
  760. if (!configValidator.find(parameters.front())) {
  761. reportError(context, content->GetOriginalExpression(),
  762. "Expression syntax not recognized.");
  763. return std::string();
  764. }
  765. context->HadContextSensitiveCondition = true;
  766. if (context->Config.empty()) {
  767. return parameters.front().empty() ? "1" : "0";
  768. }
  769. if (cmsysString_strcasecmp(parameters.front().c_str(),
  770. context->Config.c_str()) == 0) {
  771. return "1";
  772. }
  773. if (context->CurrentTarget && context->CurrentTarget->IsImported()) {
  774. const char* loc = nullptr;
  775. const char* imp = nullptr;
  776. std::string suffix;
  777. if (context->CurrentTarget->Target->GetMappedConfig(
  778. context->Config, &loc, &imp, suffix)) {
  779. // This imported target has an appropriate location
  780. // for this (possibly mapped) config.
  781. // Check if there is a proper config mapping for the tested config.
  782. std::vector<std::string> mappedConfigs;
  783. std::string mapProp = cmStrCat(
  784. "MAP_IMPORTED_CONFIG_", cmSystemTools::UpperCase(context->Config));
  785. if (const char* mapValue =
  786. context->CurrentTarget->GetProperty(mapProp)) {
  787. cmExpandList(cmSystemTools::UpperCase(mapValue), mappedConfigs);
  788. return cmContains(mappedConfigs,
  789. cmSystemTools::UpperCase(parameters.front()))
  790. ? "1"
  791. : "0";
  792. }
  793. }
  794. }
  795. return "0";
  796. }
  797. } configurationTestNode;
  798. static const struct JoinNode : public cmGeneratorExpressionNode
  799. {
  800. JoinNode() {} // NOLINT(modernize-use-equals-default)
  801. int NumExpectedParameters() const override { return 2; }
  802. bool AcceptsArbitraryContentParameter() const override { return true; }
  803. std::string Evaluate(
  804. const std::vector<std::string>& parameters,
  805. cmGeneratorExpressionContext* /*context*/,
  806. const GeneratorExpressionContent* /*content*/,
  807. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  808. {
  809. std::vector<std::string> list = cmExpandedList(parameters.front());
  810. return cmJoin(list, parameters[1]);
  811. }
  812. } joinNode;
  813. static const struct CompileLanguageNode : public cmGeneratorExpressionNode
  814. {
  815. CompileLanguageNode() {} // NOLINT(modernize-use-equals-default)
  816. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  817. std::string Evaluate(
  818. const std::vector<std::string>& parameters,
  819. cmGeneratorExpressionContext* context,
  820. const GeneratorExpressionContent* content,
  821. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  822. {
  823. if (context->Language.empty()) {
  824. reportError(
  825. context, content->GetOriginalExpression(),
  826. "$<COMPILE_LANGUAGE:...> may only be used to specify include "
  827. "directories, compile definitions, compile options, and to evaluate "
  828. "components of the file(GENERATE) command.");
  829. return std::string();
  830. }
  831. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  832. std::string genName = gg->GetName();
  833. if (genName.find("Makefiles") == std::string::npos &&
  834. genName.find("Ninja") == std::string::npos &&
  835. genName.find("Visual Studio") == std::string::npos &&
  836. genName.find("Xcode") == std::string::npos &&
  837. genName.find("Watcom WMake") == std::string::npos) {
  838. reportError(context, content->GetOriginalExpression(),
  839. "$<COMPILE_LANGUAGE:...> not supported for this generator.");
  840. return std::string();
  841. }
  842. if (parameters.empty()) {
  843. return context->Language;
  844. }
  845. for (auto& param : parameters) {
  846. if (context->Language == param) {
  847. return "1";
  848. }
  849. }
  850. return "0";
  851. }
  852. } languageNode;
  853. static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
  854. {
  855. CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default)
  856. int NumExpectedParameters() const override { return TwoOrMoreParameters; }
  857. std::string Evaluate(
  858. const std::vector<std::string>& parameters,
  859. cmGeneratorExpressionContext* context,
  860. const GeneratorExpressionContent* content,
  861. cmGeneratorExpressionDAGChecker* dagChecker) const override
  862. {
  863. if (!context->HeadTarget || context->Language.empty()) {
  864. // reportError(context, content->GetOriginalExpression(), "");
  865. reportError(
  866. context, content->GetOriginalExpression(),
  867. "$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets "
  868. "to specify include directories, compile definitions, and compile "
  869. "options. It may not be used with the add_custom_command, "
  870. "add_custom_target, or file(GENERATE) commands.");
  871. return std::string();
  872. }
  873. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  874. std::string genName = gg->GetName();
  875. if (genName.find("Makefiles") == std::string::npos &&
  876. genName.find("Ninja") == std::string::npos &&
  877. genName.find("Visual Studio") == std::string::npos &&
  878. genName.find("Xcode") == std::string::npos &&
  879. genName.find("Watcom WMake") == std::string::npos) {
  880. reportError(
  881. context, content->GetOriginalExpression(),
  882. "$<COMPILE_LANG_AND_ID:lang,id> not supported for this generator.");
  883. return std::string();
  884. }
  885. const std::string& lang = context->Language;
  886. if (lang == parameters.front()) {
  887. std::vector<std::string> idParameter((parameters.cbegin() + 1),
  888. parameters.cend());
  889. return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage(
  890. idParameter, context, content, dagChecker, lang);
  891. }
  892. return "0";
  893. }
  894. } languageAndIdNode;
  895. std::string getLinkedTargetsContent(
  896. cmGeneratorTarget const* target, std::string const& prop,
  897. cmGeneratorExpressionContext* context,
  898. cmGeneratorExpressionDAGChecker* dagChecker)
  899. {
  900. std::string result;
  901. if (cmLinkImplementationLibraries const* impl =
  902. target->GetLinkImplementationLibraries(context->Config)) {
  903. for (cmLinkImplItem const& lib : impl->Libraries) {
  904. if (lib.Target) {
  905. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our
  906. // caller's property and hand-evaluate it as if it were compiled.
  907. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  908. cmGeneratorExpressionContext libContext(
  909. target->GetLocalGenerator(), context->Config, context->Quiet, target,
  910. target, context->EvaluateForBuildsystem, lib.Backtrace,
  911. context->Language);
  912. std::string libResult =
  913. lib.Target->EvaluateInterfaceProperty(prop, &libContext, dagChecker);
  914. if (!libResult.empty()) {
  915. if (result.empty()) {
  916. result = std::move(libResult);
  917. } else {
  918. result.reserve(result.size() + 1 + libResult.size());
  919. result += ";";
  920. result += libResult;
  921. }
  922. }
  923. }
  924. }
  925. }
  926. return result;
  927. }
  928. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  929. {
  930. TargetPropertyNode() {} // NOLINT(modernize-use-equals-default)
  931. // This node handles errors on parameter count itself.
  932. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  933. static const char* GetErrorText(std::string const& targetName,
  934. std::string const& propertyName)
  935. {
  936. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  937. if (targetName.empty() && propertyName.empty()) {
  938. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  939. "target name and property name.";
  940. }
  941. if (targetName.empty()) {
  942. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  943. "target name.";
  944. }
  945. if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
  946. if (!propertyNameValidator.find(propertyName)) {
  947. return "Target name and property name not supported.";
  948. }
  949. return "Target name not supported.";
  950. }
  951. return nullptr;
  952. }
  953. std::string Evaluate(
  954. const std::vector<std::string>& parameters,
  955. cmGeneratorExpressionContext* context,
  956. const GeneratorExpressionContent* content,
  957. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  958. {
  959. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  960. cmGeneratorTarget const* target = nullptr;
  961. std::string targetName;
  962. std::string propertyName;
  963. if (parameters.size() == 2) {
  964. targetName = parameters[0];
  965. propertyName = parameters[1];
  966. if (const char* e = GetErrorText(targetName, propertyName)) {
  967. reportError(context, content->GetOriginalExpression(), e);
  968. return std::string();
  969. }
  970. if (propertyName == "ALIASED_TARGET"_s) {
  971. if (context->LG->GetMakefile()->IsAlias(targetName)) {
  972. if (cmGeneratorTarget* tgt =
  973. context->LG->FindGeneratorTargetToUse(targetName)) {
  974. return tgt->GetName();
  975. }
  976. }
  977. return std::string();
  978. }
  979. target = context->LG->FindGeneratorTargetToUse(targetName);
  980. if (!target) {
  981. std::ostringstream e;
  982. e << "Target \"" << targetName << "\" not found.";
  983. reportError(context, content->GetOriginalExpression(), e.str());
  984. return std::string();
  985. }
  986. context->AllTargets.insert(target);
  987. } else if (parameters.size() == 1) {
  988. target = context->HeadTarget;
  989. propertyName = parameters[0];
  990. // Keep track of the properties seen while processing.
  991. // The evaluation of the LINK_LIBRARIES generator expressions
  992. // will check this to ensure that properties have one consistent
  993. // value for all evaluations.
  994. context->SeenTargetProperties.insert(propertyName);
  995. context->HadHeadSensitiveCondition = true;
  996. if (!target) {
  997. reportError(
  998. context, content->GetOriginalExpression(),
  999. "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
  1000. "It may not be used with add_custom_command or add_custom_target. "
  1001. "Specify the target to read a property from using the "
  1002. "$<TARGET_PROPERTY:tgt,prop> signature instead.");
  1003. return std::string();
  1004. }
  1005. } else {
  1006. reportError(
  1007. context, content->GetOriginalExpression(),
  1008. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  1009. return std::string();
  1010. }
  1011. if (propertyName == "SOURCES") {
  1012. context->SourceSensitiveTargets.insert(target);
  1013. }
  1014. if (propertyName.empty()) {
  1015. reportError(
  1016. context, content->GetOriginalExpression(),
  1017. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  1018. "name.");
  1019. return std::string();
  1020. }
  1021. if (!propertyNameValidator.find(propertyName)) {
  1022. ::reportError(context, content->GetOriginalExpression(),
  1023. "Property name not supported.");
  1024. return std::string();
  1025. }
  1026. assert(target);
  1027. if (propertyName == "LINKER_LANGUAGE") {
  1028. if (target->LinkLanguagePropagatesToDependents() && dagCheckerParent &&
  1029. (dagCheckerParent->EvaluatingLinkLibraries() ||
  1030. dagCheckerParent->EvaluatingSources())) {
  1031. reportError(
  1032. context, content->GetOriginalExpression(),
  1033. "LINKER_LANGUAGE target property can not be used while evaluating "
  1034. "link libraries for a static library");
  1035. return std::string();
  1036. }
  1037. return target->GetLinkerLanguage(context->Config);
  1038. }
  1039. std::string interfacePropertyName;
  1040. bool isInterfaceProperty = false;
  1041. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  1042. if (propertyName == #prop) { \
  1043. interfacePropertyName = "INTERFACE_" #prop; \
  1044. } else if (propertyName == "INTERFACE_" #prop) { \
  1045. interfacePropertyName = "INTERFACE_" #prop; \
  1046. isInterfaceProperty = true; \
  1047. } else
  1048. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  1049. // Note that the above macro terminates with an else
  1050. /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
  1051. cmPolicies::PolicyStatus polSt =
  1052. context->LG->GetPolicyStatus(cmPolicies::CMP0043);
  1053. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  1054. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  1055. }
  1056. }
  1057. #undef POPULATE_INTERFACE_PROPERTY_NAME
  1058. bool evaluatingLinkLibraries = false;
  1059. if (dagCheckerParent) {
  1060. if (dagCheckerParent->EvaluatingGenexExpression() ||
  1061. dagCheckerParent->EvaluatingPICExpression()) {
  1062. // No check required.
  1063. } else if (dagCheckerParent->EvaluatingLinkLibraries()) {
  1064. evaluatingLinkLibraries = true;
  1065. if (!interfacePropertyName.empty()) {
  1066. reportError(
  1067. context, content->GetOriginalExpression(),
  1068. "$<TARGET_PROPERTY:...> expression in link libraries "
  1069. "evaluation depends on target property which is transitive "
  1070. "over the link libraries, creating a recursion.");
  1071. return std::string();
  1072. }
  1073. } else {
  1074. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
  1075. assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  1076. ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy)
  1077. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  1078. }
  1079. }
  1080. if (isInterfaceProperty) {
  1081. return target->EvaluateInterfaceProperty(propertyName, context,
  1082. dagCheckerParent);
  1083. }
  1084. cmGeneratorExpressionDAGChecker dagChecker(
  1085. context->Backtrace, target, propertyName, content, dagCheckerParent);
  1086. switch (dagChecker.Check()) {
  1087. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1088. dagChecker.ReportError(context, content->GetOriginalExpression());
  1089. return std::string();
  1090. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1091. // No error. We just skip cyclic references.
  1092. return std::string();
  1093. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1094. // We handle transitive properties above. For non-transitive
  1095. // properties we accept repeats anyway.
  1096. case cmGeneratorExpressionDAGChecker::DAG:
  1097. break;
  1098. }
  1099. std::string result;
  1100. bool haveProp = false;
  1101. if (const char* p = target->GetProperty(propertyName)) {
  1102. result = p;
  1103. haveProp = true;
  1104. } else if (evaluatingLinkLibraries) {
  1105. return std::string();
  1106. }
  1107. if (!haveProp && !target->IsImported() &&
  1108. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1109. if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
  1110. context->Config)) {
  1111. context->HadContextSensitiveCondition = true;
  1112. return target->GetLinkInterfaceDependentBoolProperty(propertyName,
  1113. context->Config)
  1114. ? "1"
  1115. : "0";
  1116. }
  1117. if (target->IsLinkInterfaceDependentStringProperty(propertyName,
  1118. context->Config)) {
  1119. context->HadContextSensitiveCondition = true;
  1120. const char* propContent =
  1121. target->GetLinkInterfaceDependentStringProperty(propertyName,
  1122. context->Config);
  1123. return propContent ? propContent : "";
  1124. }
  1125. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1126. context->Config)) {
  1127. context->HadContextSensitiveCondition = true;
  1128. const char* propContent =
  1129. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1130. context->Config);
  1131. return propContent ? propContent : "";
  1132. }
  1133. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1134. context->Config)) {
  1135. context->HadContextSensitiveCondition = true;
  1136. const char* propContent =
  1137. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1138. context->Config);
  1139. return propContent ? propContent : "";
  1140. }
  1141. }
  1142. if (!target->IsImported() && dagCheckerParent &&
  1143. !dagCheckerParent->EvaluatingLinkLibraries()) {
  1144. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1145. context->Config)) {
  1146. context->HadContextSensitiveCondition = true;
  1147. const char* propContent =
  1148. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1149. context->Config);
  1150. return propContent ? propContent : "";
  1151. }
  1152. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1153. context->Config)) {
  1154. context->HadContextSensitiveCondition = true;
  1155. const char* propContent =
  1156. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1157. context->Config);
  1158. return propContent ? propContent : "";
  1159. }
  1160. }
  1161. if (!interfacePropertyName.empty()) {
  1162. result = this->EvaluateDependentExpression(result, context->LG, context,
  1163. target, target, &dagChecker);
  1164. std::string linkedTargetsContent = getLinkedTargetsContent(
  1165. target, interfacePropertyName, context, &dagChecker);
  1166. if (!linkedTargetsContent.empty()) {
  1167. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1168. }
  1169. }
  1170. return result;
  1171. }
  1172. } targetPropertyNode;
  1173. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1174. {
  1175. TargetNameNode() {} // NOLINT(modernize-use-equals-default)
  1176. bool GeneratesContent() const override { return true; }
  1177. bool AcceptsArbitraryContentParameter() const override { return true; }
  1178. bool RequiresLiteralInput() const override { return true; }
  1179. std::string Evaluate(
  1180. const std::vector<std::string>& parameters,
  1181. cmGeneratorExpressionContext* /*context*/,
  1182. const GeneratorExpressionContent* /*content*/,
  1183. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1184. {
  1185. return parameters.front();
  1186. }
  1187. int NumExpectedParameters() const override { return 1; }
  1188. } targetNameNode;
  1189. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1190. {
  1191. TargetObjectsNode() {} // NOLINT(modernize-use-equals-default)
  1192. std::string Evaluate(
  1193. const std::vector<std::string>& parameters,
  1194. cmGeneratorExpressionContext* context,
  1195. const GeneratorExpressionContent* content,
  1196. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1197. {
  1198. std::string tgtName = parameters.front();
  1199. cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
  1200. if (!gt) {
  1201. std::ostringstream e;
  1202. e << "Objects of target \"" << tgtName
  1203. << "\" referenced but no such target exists.";
  1204. reportError(context, content->GetOriginalExpression(), e.str());
  1205. return std::string();
  1206. }
  1207. cmStateEnums::TargetType type = gt->GetType();
  1208. if (type != cmStateEnums::EXECUTABLE &&
  1209. type != cmStateEnums::STATIC_LIBRARY &&
  1210. type != cmStateEnums::SHARED_LIBRARY &&
  1211. type != cmStateEnums::MODULE_LIBRARY &&
  1212. type != cmStateEnums::OBJECT_LIBRARY) {
  1213. std::ostringstream e;
  1214. e << "Objects of target \"" << tgtName
  1215. << "\" referenced but is not an allowed library types (EXECUTABLE, "
  1216. << "STATIC, SHARED, MODULE, OBJECT).";
  1217. reportError(context, content->GetOriginalExpression(), e.str());
  1218. return std::string();
  1219. }
  1220. if (!context->EvaluateForBuildsystem) {
  1221. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  1222. std::string reason;
  1223. if (!gg->HasKnownObjectFileLocation(&reason)) {
  1224. std::ostringstream e;
  1225. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1226. "is only suitable for consumption by CMake (limited"
  1227. << reason
  1228. << "). "
  1229. "It is not suitable for writing out elsewhere.";
  1230. reportError(context, content->GetOriginalExpression(), e.str());
  1231. return std::string();
  1232. }
  1233. }
  1234. std::vector<std::string> objects;
  1235. if (gt->IsImported()) {
  1236. const char* loc = nullptr;
  1237. const char* imp = nullptr;
  1238. std::string suffix;
  1239. if (gt->Target->GetMappedConfig(context->Config, &loc, &imp, suffix)) {
  1240. cmExpandList(loc, objects);
  1241. }
  1242. context->HadContextSensitiveCondition = true;
  1243. } else {
  1244. gt->GetTargetObjectNames(context->Config, objects);
  1245. std::string obj_dir;
  1246. if (context->EvaluateForBuildsystem) {
  1247. // Use object file directory with buildsystem placeholder.
  1248. obj_dir = gt->ObjectDirectory;
  1249. // Here we assume that the set of object files produced
  1250. // by an object library does not vary with configuration
  1251. // and do not set HadContextSensitiveCondition to true.
  1252. } else {
  1253. // Use object file directory with per-config location.
  1254. obj_dir = gt->GetObjectDirectory(context->Config);
  1255. context->HadContextSensitiveCondition = true;
  1256. }
  1257. for (std::string& o : objects) {
  1258. o = cmStrCat(obj_dir, o);
  1259. }
  1260. }
  1261. // Create the cmSourceFile instances in the referencing directory.
  1262. cmMakefile* mf = context->LG->GetMakefile();
  1263. for (std::string& o : objects) {
  1264. mf->AddTargetObject(tgtName, o);
  1265. }
  1266. return cmJoin(objects, ";");
  1267. }
  1268. } targetObjectsNode;
  1269. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1270. {
  1271. CompileFeaturesNode() {} // NOLINT(modernize-use-equals-default)
  1272. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  1273. std::string Evaluate(
  1274. const std::vector<std::string>& parameters,
  1275. cmGeneratorExpressionContext* context,
  1276. const GeneratorExpressionContent* content,
  1277. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1278. {
  1279. cmGeneratorTarget const* target = context->HeadTarget;
  1280. if (!target) {
  1281. reportError(
  1282. context, content->GetOriginalExpression(),
  1283. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1284. "not be used with add_custom_command or add_custom_target.");
  1285. return std::string();
  1286. }
  1287. context->HadHeadSensitiveCondition = true;
  1288. using LangMap = std::map<std::string, std::vector<std::string>>;
  1289. static LangMap availableFeatures;
  1290. LangMap testedFeatures;
  1291. for (std::string const& p : parameters) {
  1292. std::string error;
  1293. std::string lang;
  1294. if (!context->LG->GetMakefile()->CompileFeatureKnown(
  1295. context->HeadTarget->Target, p, lang, &error)) {
  1296. reportError(context, content->GetOriginalExpression(), error);
  1297. return std::string();
  1298. }
  1299. testedFeatures[lang].push_back(p);
  1300. if (availableFeatures.find(lang) == availableFeatures.end()) {
  1301. const char* featuresKnown =
  1302. context->LG->GetMakefile()->CompileFeaturesAvailable(lang, &error);
  1303. if (!featuresKnown) {
  1304. reportError(context, content->GetOriginalExpression(), error);
  1305. return std::string();
  1306. }
  1307. cmExpandList(featuresKnown, availableFeatures[lang]);
  1308. }
  1309. }
  1310. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1311. for (auto const& lit : testedFeatures) {
  1312. std::vector<std::string> const& langAvailable =
  1313. availableFeatures[lit.first];
  1314. const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
  1315. "CMAKE_" + lit.first + "_STANDARD_DEFAULT");
  1316. for (std::string const& it : lit.second) {
  1317. if (!cmContains(langAvailable, it)) {
  1318. return "0";
  1319. }
  1320. if (standardDefault && !*standardDefault) {
  1321. // This compiler has no notion of language standard levels.
  1322. // All features known for the language are always available.
  1323. continue;
  1324. }
  1325. if (!context->LG->GetMakefile()->HaveStandardAvailable(
  1326. target->Target, lit.first, it)) {
  1327. if (evalLL) {
  1328. const char* l = target->GetProperty(lit.first + "_STANDARD");
  1329. if (!l) {
  1330. l = standardDefault;
  1331. }
  1332. assert(l);
  1333. context->MaxLanguageStandard[target][lit.first] = l;
  1334. } else {
  1335. return "0";
  1336. }
  1337. }
  1338. }
  1339. }
  1340. return "1";
  1341. }
  1342. } compileFeaturesNode;
  1343. static const char* targetPolicyWhitelist[] = {
  1344. nullptr
  1345. #define TARGET_POLICY_STRING(POLICY) , #POLICY
  1346. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1347. #undef TARGET_POLICY_STRING
  1348. };
  1349. cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
  1350. const char* policy)
  1351. {
  1352. #define RETURN_POLICY(POLICY) \
  1353. if (strcmp(policy, #POLICY) == 0) { \
  1354. return tgt->GetPolicyStatus##POLICY(); \
  1355. }
  1356. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1357. #undef RETURN_POLICY
  1358. assert(false && "Unreachable code. Not a valid policy");
  1359. return cmPolicies::WARN;
  1360. }
  1361. cmPolicies::PolicyID policyForString(const char* policy_id)
  1362. {
  1363. #define RETURN_POLICY_ID(POLICY_ID) \
  1364. if (strcmp(policy_id, #POLICY_ID) == 0) { \
  1365. return cmPolicies::POLICY_ID; \
  1366. }
  1367. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1368. #undef RETURN_POLICY_ID
  1369. assert(false && "Unreachable code. Not a valid policy");
  1370. return cmPolicies::CMP0002;
  1371. }
  1372. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1373. {
  1374. TargetPolicyNode() {} // NOLINT(modernize-use-equals-default)
  1375. int NumExpectedParameters() const override { return 1; }
  1376. std::string Evaluate(
  1377. const std::vector<std::string>& parameters,
  1378. cmGeneratorExpressionContext* context,
  1379. const GeneratorExpressionContent* content,
  1380. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1381. {
  1382. if (!context->HeadTarget) {
  1383. reportError(
  1384. context, content->GetOriginalExpression(),
  1385. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1386. "may not be used with add_custom_command or add_custom_target.");
  1387. return std::string();
  1388. }
  1389. context->HadContextSensitiveCondition = true;
  1390. context->HadHeadSensitiveCondition = true;
  1391. for (size_t i = 1; i < cm::size(targetPolicyWhitelist); ++i) {
  1392. const char* policy = targetPolicyWhitelist[i];
  1393. if (parameters.front() == policy) {
  1394. cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
  1395. switch (statusForTarget(context->HeadTarget, policy)) {
  1396. case cmPolicies::WARN:
  1397. lg->IssueMessage(
  1398. MessageType::AUTHOR_WARNING,
  1399. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1400. CM_FALLTHROUGH;
  1401. case cmPolicies::REQUIRED_IF_USED:
  1402. case cmPolicies::REQUIRED_ALWAYS:
  1403. case cmPolicies::OLD:
  1404. return "0";
  1405. case cmPolicies::NEW:
  1406. return "1";
  1407. }
  1408. }
  1409. }
  1410. reportError(
  1411. context, content->GetOriginalExpression(),
  1412. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1413. "policies. Currently it may be used with the following policies:\n"
  1414. #define STRINGIFY_HELPER(X) #X
  1415. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1416. #define TARGET_POLICY_LIST_ITEM(POLICY) " * " STRINGIFY(POLICY) "\n"
  1417. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1418. #undef TARGET_POLICY_LIST_ITEM
  1419. );
  1420. return std::string();
  1421. }
  1422. } targetPolicyNode;
  1423. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1424. {
  1425. InstallPrefixNode() {} // NOLINT(modernize-use-equals-default)
  1426. bool GeneratesContent() const override { return true; }
  1427. int NumExpectedParameters() const override { return 0; }
  1428. std::string Evaluate(
  1429. const std::vector<std::string>& /*parameters*/,
  1430. cmGeneratorExpressionContext* context,
  1431. const GeneratorExpressionContent* content,
  1432. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1433. {
  1434. reportError(context, content->GetOriginalExpression(),
  1435. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1436. "should never be evaluated.");
  1437. return std::string();
  1438. }
  1439. } installPrefixNode;
  1440. class ArtifactDirTag;
  1441. class ArtifactLinkerTag;
  1442. class ArtifactNameTag;
  1443. class ArtifactPathTag;
  1444. class ArtifactPdbTag;
  1445. class ArtifactSonameTag;
  1446. class ArtifactBundleDirTag;
  1447. class ArtifactBundleContentDirTag;
  1448. template <typename ArtifactT>
  1449. struct TargetFilesystemArtifactResultCreator
  1450. {
  1451. static std::string Create(cmGeneratorTarget* target,
  1452. cmGeneratorExpressionContext* context,
  1453. const GeneratorExpressionContent* content);
  1454. };
  1455. template <>
  1456. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1457. {
  1458. static std::string Create(cmGeneratorTarget* target,
  1459. cmGeneratorExpressionContext* context,
  1460. const GeneratorExpressionContent* content)
  1461. {
  1462. // The target soname file (.so.1).
  1463. if (target->IsDLLPlatform()) {
  1464. ::reportError(context, content->GetOriginalExpression(),
  1465. "TARGET_SONAME_FILE is not allowed "
  1466. "for DLL target platforms.");
  1467. return std::string();
  1468. }
  1469. if (target->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1470. ::reportError(context, content->GetOriginalExpression(),
  1471. "TARGET_SONAME_FILE is allowed only for "
  1472. "SHARED libraries.");
  1473. return std::string();
  1474. }
  1475. std::string result = cmStrCat(target->GetDirectory(context->Config), '/',
  1476. target->GetSOName(context->Config));
  1477. return result;
  1478. }
  1479. };
  1480. template <>
  1481. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1482. {
  1483. static std::string Create(cmGeneratorTarget* target,
  1484. cmGeneratorExpressionContext* context,
  1485. const GeneratorExpressionContent* content)
  1486. {
  1487. if (target->IsImported()) {
  1488. ::reportError(context, content->GetOriginalExpression(),
  1489. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1490. return std::string();
  1491. }
  1492. std::string language = target->GetLinkerLanguage(context->Config);
  1493. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1494. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1495. ::reportError(context, content->GetOriginalExpression(),
  1496. "TARGET_PDB_FILE is not supported by the target linker.");
  1497. return std::string();
  1498. }
  1499. cmStateEnums::TargetType targetType = target->GetType();
  1500. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1501. targetType != cmStateEnums::MODULE_LIBRARY &&
  1502. targetType != cmStateEnums::EXECUTABLE) {
  1503. ::reportError(context, content->GetOriginalExpression(),
  1504. "TARGET_PDB_FILE is allowed only for "
  1505. "targets with linker created artifacts.");
  1506. return std::string();
  1507. }
  1508. std::string result = cmStrCat(target->GetPDBDirectory(context->Config),
  1509. '/', target->GetPDBName(context->Config));
  1510. return result;
  1511. }
  1512. };
  1513. template <>
  1514. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1515. {
  1516. static std::string Create(cmGeneratorTarget* target,
  1517. cmGeneratorExpressionContext* context,
  1518. const GeneratorExpressionContent* content)
  1519. {
  1520. // The file used to link to the target (.so, .lib, .a).
  1521. if (!target->IsLinkable()) {
  1522. ::reportError(context, content->GetOriginalExpression(),
  1523. "TARGET_LINKER_FILE is allowed only for libraries and "
  1524. "executables with ENABLE_EXPORTS.");
  1525. return std::string();
  1526. }
  1527. cmStateEnums::ArtifactType artifact =
  1528. target->HasImportLibrary(context->Config)
  1529. ? cmStateEnums::ImportLibraryArtifact
  1530. : cmStateEnums::RuntimeBinaryArtifact;
  1531. return target->GetFullPath(context->Config, artifact);
  1532. }
  1533. };
  1534. template <>
  1535. struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
  1536. {
  1537. static std::string Create(cmGeneratorTarget* target,
  1538. cmGeneratorExpressionContext* context,
  1539. const GeneratorExpressionContent* content)
  1540. {
  1541. if (target->IsImported()) {
  1542. ::reportError(context, content->GetOriginalExpression(),
  1543. "TARGET_BUNDLE_DIR not allowed for IMPORTED targets.");
  1544. return std::string();
  1545. }
  1546. if (!target->IsBundleOnApple()) {
  1547. ::reportError(context, content->GetOriginalExpression(),
  1548. "TARGET_BUNDLE_DIR is allowed only for Bundle targets.");
  1549. return std::string();
  1550. }
  1551. std::string outpath = target->GetDirectory(context->Config) + '/';
  1552. return target->BuildBundleDirectory(outpath, context->Config,
  1553. cmGeneratorTarget::BundleDirLevel);
  1554. }
  1555. };
  1556. template <>
  1557. struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
  1558. {
  1559. static std::string Create(cmGeneratorTarget* target,
  1560. cmGeneratorExpressionContext* context,
  1561. const GeneratorExpressionContent* content)
  1562. {
  1563. if (target->IsImported()) {
  1564. ::reportError(
  1565. context, content->GetOriginalExpression(),
  1566. "TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.");
  1567. return std::string();
  1568. }
  1569. if (!target->IsBundleOnApple()) {
  1570. ::reportError(
  1571. context, content->GetOriginalExpression(),
  1572. "TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.");
  1573. return std::string();
  1574. }
  1575. std::string outpath = target->GetDirectory(context->Config) + '/';
  1576. return target->BuildBundleDirectory(outpath, context->Config,
  1577. cmGeneratorTarget::ContentLevel);
  1578. }
  1579. };
  1580. template <>
  1581. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1582. {
  1583. static std::string Create(cmGeneratorTarget* target,
  1584. cmGeneratorExpressionContext* context,
  1585. const GeneratorExpressionContent* /*unused*/)
  1586. {
  1587. return target->GetFullPath(context->Config,
  1588. cmStateEnums::RuntimeBinaryArtifact, true);
  1589. }
  1590. };
  1591. template <typename ArtifactT>
  1592. struct TargetFilesystemArtifactResultGetter
  1593. {
  1594. static std::string Get(const std::string& result);
  1595. };
  1596. template <>
  1597. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1598. {
  1599. static std::string Get(const std::string& result)
  1600. {
  1601. return cmSystemTools::GetFilenameName(result);
  1602. }
  1603. };
  1604. template <>
  1605. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1606. {
  1607. static std::string Get(const std::string& result)
  1608. {
  1609. return cmSystemTools::GetFilenamePath(result);
  1610. }
  1611. };
  1612. template <>
  1613. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1614. {
  1615. static std::string Get(const std::string& result) { return result; }
  1616. };
  1617. struct TargetArtifactBase : public cmGeneratorExpressionNode
  1618. {
  1619. TargetArtifactBase() {} // NOLINT(modernize-use-equals-default)
  1620. protected:
  1621. cmGeneratorTarget* GetTarget(
  1622. const std::vector<std::string>& parameters,
  1623. cmGeneratorExpressionContext* context,
  1624. const GeneratorExpressionContent* content,
  1625. cmGeneratorExpressionDAGChecker* dagChecker) const
  1626. {
  1627. // Lookup the referenced target.
  1628. std::string name = parameters.front();
  1629. if (!cmGeneratorExpression::IsValidTargetName(name)) {
  1630. ::reportError(context, content->GetOriginalExpression(),
  1631. "Expression syntax not recognized.");
  1632. return nullptr;
  1633. }
  1634. cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
  1635. if (!target) {
  1636. ::reportError(context, content->GetOriginalExpression(),
  1637. "No target \"" + name + "\"");
  1638. return nullptr;
  1639. }
  1640. if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY &&
  1641. target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) {
  1642. ::reportError(context, content->GetOriginalExpression(),
  1643. "Target \"" + name +
  1644. "\" is not an executable or library.");
  1645. return nullptr;
  1646. }
  1647. if (dagChecker &&
  1648. (dagChecker->EvaluatingLinkLibraries(target) ||
  1649. (dagChecker->EvaluatingSources() &&
  1650. target == dagChecker->TopTarget()))) {
  1651. ::reportError(context, content->GetOriginalExpression(),
  1652. "Expressions which require the linker language may not "
  1653. "be used while evaluating link libraries");
  1654. return nullptr;
  1655. }
  1656. return target;
  1657. }
  1658. };
  1659. template <typename ArtifactT, typename ComponentT>
  1660. struct TargetFilesystemArtifact : public TargetArtifactBase
  1661. {
  1662. TargetFilesystemArtifact() {} // NOLINT(modernize-use-equals-default)
  1663. int NumExpectedParameters() const override { return 1; }
  1664. std::string Evaluate(
  1665. const std::vector<std::string>& parameters,
  1666. cmGeneratorExpressionContext* context,
  1667. const GeneratorExpressionContent* content,
  1668. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1669. {
  1670. cmGeneratorTarget* target =
  1671. this->GetTarget(parameters, context, content, dagChecker);
  1672. if (!target) {
  1673. return std::string();
  1674. }
  1675. context->DependTargets.insert(target);
  1676. context->AllTargets.insert(target);
  1677. std::string result =
  1678. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(target, context,
  1679. content);
  1680. if (context->HadError) {
  1681. return std::string();
  1682. }
  1683. return TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1684. }
  1685. };
  1686. template <typename ArtifactT>
  1687. struct TargetFilesystemArtifactNodeGroup
  1688. {
  1689. TargetFilesystemArtifactNodeGroup() // NOLINT(modernize-use-equals-default)
  1690. {
  1691. }
  1692. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1693. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1694. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1695. };
  1696. static const TargetFilesystemArtifactNodeGroup<ArtifactNameTag>
  1697. targetNodeGroup;
  1698. static const TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag>
  1699. targetLinkerNodeGroup;
  1700. static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
  1701. targetSoNameNodeGroup;
  1702. static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
  1703. targetPdbNodeGroup;
  1704. static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
  1705. targetBundleDirNode;
  1706. static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
  1707. ArtifactPathTag>
  1708. targetBundleContentDirNode;
  1709. //
  1710. // To retrieve base name for various artifacts
  1711. //
  1712. template <typename ArtifactT>
  1713. struct TargetOutputNameArtifactResultGetter
  1714. {
  1715. static std::string Get(cmGeneratorTarget* target,
  1716. cmGeneratorExpressionContext* context,
  1717. const GeneratorExpressionContent* content);
  1718. };
  1719. template <>
  1720. struct TargetOutputNameArtifactResultGetter<ArtifactNameTag>
  1721. {
  1722. static std::string Get(cmGeneratorTarget* target,
  1723. cmGeneratorExpressionContext* context,
  1724. const GeneratorExpressionContent* /*unused*/)
  1725. {
  1726. return target->GetOutputName(context->Config,
  1727. cmStateEnums::RuntimeBinaryArtifact) +
  1728. target->GetFilePostfix(context->Config);
  1729. }
  1730. };
  1731. template <>
  1732. struct TargetOutputNameArtifactResultGetter<ArtifactLinkerTag>
  1733. {
  1734. static std::string Get(cmGeneratorTarget* target,
  1735. cmGeneratorExpressionContext* context,
  1736. const GeneratorExpressionContent* content)
  1737. {
  1738. // The file used to link to the target (.so, .lib, .a).
  1739. if (!target->IsLinkable()) {
  1740. ::reportError(context, content->GetOriginalExpression(),
  1741. "TARGET_LINKER_FILE_BASE_NAME is allowed only for "
  1742. "libraries and executables with ENABLE_EXPORTS.");
  1743. return std::string();
  1744. }
  1745. cmStateEnums::ArtifactType artifact =
  1746. target->HasImportLibrary(context->Config)
  1747. ? cmStateEnums::ImportLibraryArtifact
  1748. : cmStateEnums::RuntimeBinaryArtifact;
  1749. return target->GetOutputName(context->Config, artifact) +
  1750. target->GetFilePostfix(context->Config);
  1751. }
  1752. };
  1753. template <>
  1754. struct TargetOutputNameArtifactResultGetter<ArtifactPdbTag>
  1755. {
  1756. static std::string Get(cmGeneratorTarget* target,
  1757. cmGeneratorExpressionContext* context,
  1758. const GeneratorExpressionContent* content)
  1759. {
  1760. if (target->IsImported()) {
  1761. ::reportError(
  1762. context, content->GetOriginalExpression(),
  1763. "TARGET_PDB_FILE_BASE_NAME not allowed for IMPORTED targets.");
  1764. return std::string();
  1765. }
  1766. std::string language = target->GetLinkerLanguage(context->Config);
  1767. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1768. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1769. ::reportError(
  1770. context, content->GetOriginalExpression(),
  1771. "TARGET_PDB_FILE_BASE_NAME is not supported by the target linker.");
  1772. return std::string();
  1773. }
  1774. cmStateEnums::TargetType targetType = target->GetType();
  1775. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1776. targetType != cmStateEnums::MODULE_LIBRARY &&
  1777. targetType != cmStateEnums::EXECUTABLE) {
  1778. ::reportError(context, content->GetOriginalExpression(),
  1779. "TARGET_PDB_FILE_BASE_NAME is allowed only for "
  1780. "targets with linker created artifacts.");
  1781. return std::string();
  1782. }
  1783. return target->GetPDBOutputName(context->Config) +
  1784. target->GetFilePostfix(context->Config);
  1785. }
  1786. };
  1787. template <typename ArtifactT>
  1788. struct TargetFileBaseNameArtifact : public TargetArtifactBase
  1789. {
  1790. TargetFileBaseNameArtifact() {} // NOLINT(modernize-use-equals-default)
  1791. int NumExpectedParameters() const override { return 1; }
  1792. std::string Evaluate(
  1793. const std::vector<std::string>& parameters,
  1794. cmGeneratorExpressionContext* context,
  1795. const GeneratorExpressionContent* content,
  1796. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1797. {
  1798. cmGeneratorTarget* target =
  1799. this->GetTarget(parameters, context, content, dagChecker);
  1800. if (!target) {
  1801. return std::string();
  1802. }
  1803. std::string result = TargetOutputNameArtifactResultGetter<ArtifactT>::Get(
  1804. target, context, content);
  1805. if (context->HadError) {
  1806. return std::string();
  1807. }
  1808. return result;
  1809. }
  1810. };
  1811. static const TargetFileBaseNameArtifact<ArtifactNameTag>
  1812. targetFileBaseNameNode;
  1813. static const TargetFileBaseNameArtifact<ArtifactLinkerTag>
  1814. targetLinkerFileBaseNameNode;
  1815. static const TargetFileBaseNameArtifact<ArtifactPdbTag>
  1816. targetPdbFileBaseNameNode;
  1817. class ArtifactFilePrefixTag;
  1818. class ArtifactLinkerFilePrefixTag;
  1819. class ArtifactFileSuffixTag;
  1820. class ArtifactLinkerFileSuffixTag;
  1821. template <typename ArtifactT>
  1822. struct TargetFileArtifactResultGetter
  1823. {
  1824. static std::string Get(cmGeneratorTarget* target,
  1825. cmGeneratorExpressionContext* context,
  1826. const GeneratorExpressionContent* content);
  1827. };
  1828. template <>
  1829. struct TargetFileArtifactResultGetter<ArtifactFilePrefixTag>
  1830. {
  1831. static std::string Get(cmGeneratorTarget* target,
  1832. cmGeneratorExpressionContext* context,
  1833. const GeneratorExpressionContent*)
  1834. {
  1835. return target->GetFilePrefix(context->Config);
  1836. }
  1837. };
  1838. template <>
  1839. struct TargetFileArtifactResultGetter<ArtifactLinkerFilePrefixTag>
  1840. {
  1841. static std::string Get(cmGeneratorTarget* target,
  1842. cmGeneratorExpressionContext* context,
  1843. const GeneratorExpressionContent* content)
  1844. {
  1845. if (!target->IsLinkable()) {
  1846. ::reportError(context, content->GetOriginalExpression(),
  1847. "TARGET_LINKER_PREFIX is allowed only for libraries and "
  1848. "executables with ENABLE_EXPORTS.");
  1849. return std::string();
  1850. }
  1851. cmStateEnums::ArtifactType artifact =
  1852. target->HasImportLibrary(context->Config)
  1853. ? cmStateEnums::ImportLibraryArtifact
  1854. : cmStateEnums::RuntimeBinaryArtifact;
  1855. return target->GetFilePrefix(context->Config, artifact);
  1856. }
  1857. };
  1858. template <>
  1859. struct TargetFileArtifactResultGetter<ArtifactFileSuffixTag>
  1860. {
  1861. static std::string Get(cmGeneratorTarget* target,
  1862. cmGeneratorExpressionContext* context,
  1863. const GeneratorExpressionContent*)
  1864. {
  1865. return target->GetFileSuffix(context->Config);
  1866. }
  1867. };
  1868. template <>
  1869. struct TargetFileArtifactResultGetter<ArtifactLinkerFileSuffixTag>
  1870. {
  1871. static std::string Get(cmGeneratorTarget* target,
  1872. cmGeneratorExpressionContext* context,
  1873. const GeneratorExpressionContent* content)
  1874. {
  1875. if (!target->IsLinkable()) {
  1876. ::reportError(context, content->GetOriginalExpression(),
  1877. "TARGET_LINKER_SUFFIX is allowed only for libraries and "
  1878. "executables with ENABLE_EXPORTS.");
  1879. return std::string();
  1880. }
  1881. cmStateEnums::ArtifactType artifact =
  1882. target->HasImportLibrary(context->Config)
  1883. ? cmStateEnums::ImportLibraryArtifact
  1884. : cmStateEnums::RuntimeBinaryArtifact;
  1885. return target->GetFileSuffix(context->Config, artifact);
  1886. }
  1887. };
  1888. template <typename ArtifactT>
  1889. struct TargetFileArtifact : public TargetArtifactBase
  1890. {
  1891. TargetFileArtifact() {} // NOLINT(modernize-use-equals-default)
  1892. int NumExpectedParameters() const override { return 1; }
  1893. std::string Evaluate(
  1894. const std::vector<std::string>& parameters,
  1895. cmGeneratorExpressionContext* context,
  1896. const GeneratorExpressionContent* content,
  1897. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1898. {
  1899. cmGeneratorTarget* target =
  1900. this->GetTarget(parameters, context, content, dagChecker);
  1901. if (!target) {
  1902. return std::string();
  1903. }
  1904. std::string result =
  1905. TargetFileArtifactResultGetter<ArtifactT>::Get(target, context, content);
  1906. if (context->HadError) {
  1907. return std::string();
  1908. }
  1909. return result;
  1910. }
  1911. };
  1912. static const TargetFileArtifact<ArtifactFilePrefixTag> targetFilePrefixNode;
  1913. static const TargetFileArtifact<ArtifactLinkerFilePrefixTag>
  1914. targetLinkerFilePrefixNode;
  1915. static const TargetFileArtifact<ArtifactFileSuffixTag> targetFileSuffixNode;
  1916. static const TargetFileArtifact<ArtifactLinkerFileSuffixTag>
  1917. targetLinkerFileSuffixNode;
  1918. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1919. {
  1920. ShellPathNode() {} // NOLINT(modernize-use-equals-default)
  1921. std::string Evaluate(
  1922. const std::vector<std::string>& parameters,
  1923. cmGeneratorExpressionContext* context,
  1924. const GeneratorExpressionContent* content,
  1925. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1926. {
  1927. std::vector<std::string> listIn = cmExpandedList(parameters.front());
  1928. if (listIn.empty()) {
  1929. reportError(context, content->GetOriginalExpression(),
  1930. "\"\" is not an absolute path.");
  1931. return std::string();
  1932. }
  1933. cmStateSnapshot snapshot = context->LG->GetStateSnapshot();
  1934. cmOutputConverter converter(snapshot);
  1935. const char* separator = snapshot.GetState()->UseWindowsShell() ? ";" : ":";
  1936. std::vector<std::string> listOut;
  1937. listOut.reserve(listIn.size());
  1938. for (auto const& in : listIn) {
  1939. if (!cmSystemTools::FileIsFullPath(in)) {
  1940. reportError(context, content->GetOriginalExpression(),
  1941. "\"" + in + "\" is not an absolute path.");
  1942. return std::string();
  1943. }
  1944. listOut.emplace_back(converter.ConvertDirectorySeparatorsForShell(in));
  1945. }
  1946. return cmJoin(listOut, separator);
  1947. }
  1948. } shellPathNode;
  1949. const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
  1950. const std::string& identifier)
  1951. {
  1952. static std::map<std::string, cmGeneratorExpressionNode const*> const nodeMap{
  1953. { "0", &zeroNode },
  1954. { "1", &oneNode },
  1955. { "AND", &andNode },
  1956. { "OR", &orNode },
  1957. { "NOT", &notNode },
  1958. { "C_COMPILER_ID", &cCompilerIdNode },
  1959. { "CXX_COMPILER_ID", &cxxCompilerIdNode },
  1960. { "CUDA_COMPILER_ID", &cudaCompilerIdNode },
  1961. { "Fortran_COMPILER_ID", &fortranCompilerIdNode },
  1962. { "VERSION_GREATER", &versionGreaterNode },
  1963. { "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
  1964. { "VERSION_LESS", &versionLessNode },
  1965. { "VERSION_LESS_EQUAL", &versionLessEqNode },
  1966. { "VERSION_EQUAL", &versionEqualNode },
  1967. { "C_COMPILER_VERSION", &cCompilerVersionNode },
  1968. { "CXX_COMPILER_VERSION", &cxxCompilerVersionNode },
  1969. { "CUDA_COMPILER_VERSION", &cudaCompilerVersionNode },
  1970. { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
  1971. { "PLATFORM_ID", &platformIdNode },
  1972. { "COMPILE_FEATURES", &compileFeaturesNode },
  1973. { "CONFIGURATION", &configurationNode },
  1974. { "CONFIG", &configurationTestNode },
  1975. { "TARGET_FILE", &targetNodeGroup.File },
  1976. { "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File },
  1977. { "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File },
  1978. { "TARGET_PDB_FILE", &targetPdbNodeGroup.File },
  1979. { "TARGET_FILE_BASE_NAME", &targetFileBaseNameNode },
  1980. { "TARGET_LINKER_FILE_BASE_NAME", &targetLinkerFileBaseNameNode },
  1981. { "TARGET_PDB_FILE_BASE_NAME", &targetPdbFileBaseNameNode },
  1982. { "TARGET_FILE_PREFIX", &targetFilePrefixNode },
  1983. { "TARGET_LINKER_FILE_PREFIX", &targetLinkerFilePrefixNode },
  1984. { "TARGET_FILE_SUFFIX", &targetFileSuffixNode },
  1985. { "TARGET_LINKER_FILE_SUFFIX", &targetLinkerFileSuffixNode },
  1986. { "TARGET_FILE_NAME", &targetNodeGroup.FileName },
  1987. { "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName },
  1988. { "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName },
  1989. { "TARGET_PDB_FILE_NAME", &targetPdbNodeGroup.FileName },
  1990. { "TARGET_FILE_DIR", &targetNodeGroup.FileDir },
  1991. { "TARGET_LINKER_FILE_DIR", &targetLinkerNodeGroup.FileDir },
  1992. { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir },
  1993. { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
  1994. { "TARGET_BUNDLE_DIR", &targetBundleDirNode },
  1995. { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
  1996. { "STREQUAL", &strEqualNode },
  1997. { "EQUAL", &equalNode },
  1998. { "IN_LIST", &inListNode },
  1999. { "FILTER", &filterNode },
  2000. { "REMOVE_DUPLICATES", &removeDuplicatesNode },
  2001. { "LOWER_CASE", &lowerCaseNode },
  2002. { "UPPER_CASE", &upperCaseNode },
  2003. { "MAKE_C_IDENTIFIER", &makeCIdentifierNode },
  2004. { "BOOL", &boolNode },
  2005. { "IF", &ifNode },
  2006. { "ANGLE-R", &angle_rNode },
  2007. { "COMMA", &commaNode },
  2008. { "SEMICOLON", &semicolonNode },
  2009. { "TARGET_PROPERTY", &targetPropertyNode },
  2010. { "TARGET_NAME", &targetNameNode },
  2011. { "TARGET_OBJECTS", &targetObjectsNode },
  2012. { "TARGET_POLICY", &targetPolicyNode },
  2013. { "TARGET_EXISTS", &targetExistsNode },
  2014. { "TARGET_NAME_IF_EXISTS", &targetNameIfExistsNode },
  2015. { "TARGET_GENEX_EVAL", &targetGenexEvalNode },
  2016. { "GENEX_EVAL", &genexEvalNode },
  2017. { "BUILD_INTERFACE", &buildInterfaceNode },
  2018. { "INSTALL_INTERFACE", &installInterfaceNode },
  2019. { "INSTALL_PREFIX", &installPrefixNode },
  2020. { "JOIN", &joinNode },
  2021. { "LINK_ONLY", &linkOnlyNode },
  2022. { "COMPILE_LANG_AND_ID", &languageAndIdNode },
  2023. { "COMPILE_LANGUAGE", &languageNode },
  2024. { "SHELL_PATH", &shellPathNode }
  2025. };
  2026. {
  2027. auto itr = nodeMap.find(identifier);
  2028. if (itr != nodeMap.end()) {
  2029. return itr->second;
  2030. }
  2031. }
  2032. return nullptr;
  2033. }
  2034. void reportError(cmGeneratorExpressionContext* context,
  2035. const std::string& expr, const std::string& result)
  2036. {
  2037. context->HadError = true;
  2038. if (context->Quiet) {
  2039. return;
  2040. }
  2041. std::ostringstream e;
  2042. /* clang-format off */
  2043. e << "Error evaluating generator expression:\n"
  2044. << " " << expr << "\n"
  2045. << result;
  2046. /* clang-format on */
  2047. context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
  2048. e.str(), context->Backtrace);
  2049. }