cmGeneratorExpressionNode.cxx 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344
  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 "cmSystemTools.h"
  22. #include "cmTarget.h"
  23. #include "cm_static_string_view.hxx"
  24. #include "cm_string_view.hxx"
  25. #include "cmake.h"
  26. #include "cmsys/RegularExpression.hxx"
  27. #include "cmsys/String.h"
  28. #include <algorithm>
  29. #include <assert.h>
  30. #include <errno.h>
  31. #include <iterator>
  32. #include <map>
  33. #include <memory>
  34. #include <set>
  35. #include <sstream>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <utility>
  39. std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
  40. std::string const& prop, cmLocalGenerator* lg,
  41. cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
  42. cmGeneratorTarget const* currentTarget,
  43. cmGeneratorExpressionDAGChecker* dagChecker)
  44. {
  45. cmGeneratorExpression ge(context->Backtrace);
  46. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  47. cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
  48. std::string result =
  49. cge->Evaluate(lg, context->Config, context->Quiet, headTarget,
  50. currentTarget, dagChecker, context->Language);
  51. if (cge->GetHadContextSensitiveCondition()) {
  52. context->HadContextSensitiveCondition = true;
  53. }
  54. if (cge->GetHadHeadSensitiveCondition()) {
  55. context->HadHeadSensitiveCondition = true;
  56. }
  57. return result;
  58. }
  59. static const struct ZeroNode : public cmGeneratorExpressionNode
  60. {
  61. ZeroNode() {} // NOLINT(modernize-use-equals-default)
  62. bool GeneratesContent() const override { return false; }
  63. bool AcceptsArbitraryContentParameter() const override { return true; }
  64. std::string Evaluate(
  65. const std::vector<std::string>& /*parameters*/,
  66. cmGeneratorExpressionContext* /*context*/,
  67. const GeneratorExpressionContent* /*content*/,
  68. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  69. {
  70. return std::string();
  71. }
  72. } zeroNode;
  73. static const struct OneNode : public cmGeneratorExpressionNode
  74. {
  75. OneNode() {} // NOLINT(modernize-use-equals-default)
  76. bool AcceptsArbitraryContentParameter() const override { return true; }
  77. std::string Evaluate(
  78. const std::vector<std::string>& parameters,
  79. cmGeneratorExpressionContext* /*context*/,
  80. const GeneratorExpressionContent* /*content*/,
  81. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  82. {
  83. return parameters.front();
  84. }
  85. } oneNode;
  86. static const struct OneNode buildInterfaceNode;
  87. static const struct ZeroNode installInterfaceNode;
  88. struct BooleanOpNode : public cmGeneratorExpressionNode
  89. {
  90. BooleanOpNode(const char* op_, const char* successVal_,
  91. const char* failureVal_)
  92. : op(op_)
  93. , successVal(successVal_)
  94. , failureVal(failureVal_)
  95. {
  96. }
  97. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  98. std::string Evaluate(const std::vector<std::string>& parameters,
  99. cmGeneratorExpressionContext* context,
  100. const GeneratorExpressionContent* content,
  101. cmGeneratorExpressionDAGChecker*) const override
  102. {
  103. for (std::string const& param : parameters) {
  104. if (param == this->failureVal) {
  105. return this->failureVal;
  106. }
  107. if (param != this->successVal) {
  108. std::ostringstream e;
  109. e << "Parameters to $<" << this->op;
  110. e << "> must resolve to either '0' or '1'.";
  111. reportError(context, content->GetOriginalExpression(), e.str());
  112. return std::string();
  113. }
  114. }
  115. return this->successVal;
  116. }
  117. const char *const op, *const successVal, *const failureVal;
  118. };
  119. static const BooleanOpNode andNode("AND", "1", "0"), orNode("OR", "0", "1");
  120. static const struct NotNode : public cmGeneratorExpressionNode
  121. {
  122. NotNode() {} // NOLINT(modernize-use-equals-default)
  123. std::string Evaluate(
  124. const std::vector<std::string>& parameters,
  125. cmGeneratorExpressionContext* context,
  126. const GeneratorExpressionContent* content,
  127. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  128. {
  129. if (parameters.front() != "0" && parameters.front() != "1") {
  130. reportError(
  131. context, content->GetOriginalExpression(),
  132. "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
  133. return std::string();
  134. }
  135. return parameters.front() == "0" ? "1" : "0";
  136. }
  137. } notNode;
  138. static const struct BoolNode : public cmGeneratorExpressionNode
  139. {
  140. BoolNode() {} // NOLINT(modernize-use-equals-default)
  141. int NumExpectedParameters() const override { return 1; }
  142. std::string Evaluate(
  143. const std::vector<std::string>& parameters,
  144. cmGeneratorExpressionContext* /*context*/,
  145. const GeneratorExpressionContent* /*content*/,
  146. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  147. {
  148. return !cmSystemTools::IsOff(parameters.front()) ? "1" : "0";
  149. }
  150. } boolNode;
  151. static const struct IfNode : public cmGeneratorExpressionNode
  152. {
  153. IfNode() {} // NOLINT(modernize-use-equals-default)
  154. int NumExpectedParameters() const override { return 3; }
  155. std::string Evaluate(const std::vector<std::string>& parameters,
  156. cmGeneratorExpressionContext* context,
  157. const GeneratorExpressionContent* content,
  158. cmGeneratorExpressionDAGChecker*) const override
  159. {
  160. if (parameters[0] != "1" && parameters[0] != "0") {
  161. reportError(context, content->GetOriginalExpression(),
  162. "First parameter to $<IF> must resolve to exactly one '0' "
  163. "or '1' value.");
  164. return std::string();
  165. }
  166. return parameters[0] == "1" ? parameters[1] : parameters[2];
  167. }
  168. } ifNode;
  169. static const struct StrEqualNode : public cmGeneratorExpressionNode
  170. {
  171. StrEqualNode() {} // NOLINT(modernize-use-equals-default)
  172. int NumExpectedParameters() const override { return 2; }
  173. std::string Evaluate(
  174. const std::vector<std::string>& parameters,
  175. cmGeneratorExpressionContext* /*context*/,
  176. const GeneratorExpressionContent* /*content*/,
  177. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  178. {
  179. return parameters.front() == parameters[1] ? "1" : "0";
  180. }
  181. } strEqualNode;
  182. static const struct EqualNode : public cmGeneratorExpressionNode
  183. {
  184. EqualNode() {} // NOLINT(modernize-use-equals-default)
  185. int NumExpectedParameters() const override { return 2; }
  186. std::string Evaluate(
  187. const std::vector<std::string>& parameters,
  188. cmGeneratorExpressionContext* context,
  189. const GeneratorExpressionContent* content,
  190. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  191. {
  192. long numbers[2];
  193. for (int i = 0; i < 2; ++i) {
  194. if (!ParameterToLong(parameters[i].c_str(), &numbers[i])) {
  195. reportError(context, content->GetOriginalExpression(),
  196. "$<EQUAL> parameter " + parameters[i] +
  197. " is not a valid integer.");
  198. return {};
  199. }
  200. }
  201. return numbers[0] == numbers[1] ? "1" : "0";
  202. }
  203. static bool ParameterToLong(const char* param, long* outResult)
  204. {
  205. const char isNegative = param[0] == '-';
  206. int base = 0;
  207. if (cmHasLiteralPrefix(param, "0b") || cmHasLiteralPrefix(param, "0B")) {
  208. base = 2;
  209. param += 2;
  210. } else if (cmHasLiteralPrefix(param, "-0b") ||
  211. cmHasLiteralPrefix(param, "-0B") ||
  212. cmHasLiteralPrefix(param, "+0b") ||
  213. cmHasLiteralPrefix(param, "+0B")) {
  214. base = 2;
  215. param += 3;
  216. }
  217. char* pEnd;
  218. long result = strtol(param, &pEnd, base);
  219. if (pEnd == param || *pEnd != '\0' || errno == ERANGE) {
  220. return false;
  221. }
  222. if (isNegative && result > 0) {
  223. result *= -1;
  224. }
  225. *outResult = result;
  226. return true;
  227. }
  228. } equalNode;
  229. static const struct InListNode : public cmGeneratorExpressionNode
  230. {
  231. InListNode() {} // NOLINT(modernize-use-equals-default)
  232. int NumExpectedParameters() const override { return 2; }
  233. std::string Evaluate(
  234. const std::vector<std::string>& parameters,
  235. cmGeneratorExpressionContext* context,
  236. const GeneratorExpressionContent* /*content*/,
  237. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  238. {
  239. std::vector<std::string> values, checkValues;
  240. bool check = false;
  241. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0085)) {
  242. case cmPolicies::WARN:
  243. if (parameters.front().empty()) {
  244. check = true;
  245. cmSystemTools::ExpandListArgument(parameters[1], checkValues, true);
  246. }
  247. CM_FALLTHROUGH;
  248. case cmPolicies::OLD:
  249. cmSystemTools::ExpandListArgument(parameters[1], values);
  250. if (check && values != checkValues) {
  251. std::ostringstream e;
  252. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0085)
  253. << "\nSearch Item:\n \"" << parameters.front()
  254. << "\"\nList:\n \"" << parameters[1] << "\"\n";
  255. context->LG->GetCMakeInstance()->IssueMessage(
  256. MessageType ::AUTHOR_WARNING, e.str(), context->Backtrace);
  257. return "0";
  258. }
  259. if (values.empty()) {
  260. return "0";
  261. }
  262. break;
  263. case cmPolicies::REQUIRED_IF_USED:
  264. case cmPolicies::REQUIRED_ALWAYS:
  265. case cmPolicies::NEW:
  266. cmSystemTools::ExpandListArgument(parameters[1], values, true);
  267. break;
  268. }
  269. return std::find(values.cbegin(), values.cend(), parameters.front()) ==
  270. values.cend()
  271. ? "0"
  272. : "1";
  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, result;
  304. cmSystemTools::ExpandListArgument(parameters.front(), values, true);
  305. std::copy_if(values.cbegin(), values.cend(), std::back_inserter(result),
  306. [&re, exclude](std::string const& input) {
  307. return exclude ^ re.find(input);
  308. });
  309. return cmJoin(cmMakeRange(result.cbegin(), result.cend()), ";");
  310. }
  311. } filterNode;
  312. static const struct RemoveDuplicatesNode : public cmGeneratorExpressionNode
  313. {
  314. RemoveDuplicatesNode() {} // NOLINT(modernize-use-equals-default)
  315. int NumExpectedParameters() const override { return 1; }
  316. std::string Evaluate(
  317. const std::vector<std::string>& parameters,
  318. cmGeneratorExpressionContext* context,
  319. const GeneratorExpressionContent* content,
  320. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  321. {
  322. if (parameters.size() != 1) {
  323. reportError(
  324. context, content->GetOriginalExpression(),
  325. "$<REMOVE_DUPLICATES:...> expression requires one parameter");
  326. }
  327. std::vector<std::string> values;
  328. cmSystemTools::ExpandListArgument(parameters.front(), values, 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. std::ostringstream e;
  588. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
  589. context->LG->GetCMakeInstance()->IssueMessage(
  590. MessageType::AUTHOR_WARNING, e.str(), 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 = "MAP_IMPORTED_CONFIG_";
  784. mapProp += cmSystemTools::UpperCase(context->Config);
  785. if (const char* mapValue =
  786. context->CurrentTarget->GetProperty(mapProp)) {
  787. cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
  788. mappedConfigs);
  789. return std::find(mappedConfigs.begin(), mappedConfigs.end(),
  790. cmSystemTools::UpperCase(parameters.front())) !=
  791. mappedConfigs.end()
  792. ? "1"
  793. : "0";
  794. }
  795. }
  796. }
  797. return "0";
  798. }
  799. } configurationTestNode;
  800. static const struct JoinNode : public cmGeneratorExpressionNode
  801. {
  802. JoinNode() {} // NOLINT(modernize-use-equals-default)
  803. int NumExpectedParameters() const override { return 2; }
  804. bool AcceptsArbitraryContentParameter() const override { return true; }
  805. std::string Evaluate(
  806. const std::vector<std::string>& parameters,
  807. cmGeneratorExpressionContext* /*context*/,
  808. const GeneratorExpressionContent* /*content*/,
  809. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  810. {
  811. std::vector<std::string> list;
  812. cmSystemTools::ExpandListArgument(parameters.front(), list);
  813. return cmJoin(list, parameters[1]);
  814. }
  815. } joinNode;
  816. static const struct CompileLanguageNode : public cmGeneratorExpressionNode
  817. {
  818. CompileLanguageNode() {} // NOLINT(modernize-use-equals-default)
  819. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  820. std::string Evaluate(
  821. const std::vector<std::string>& parameters,
  822. cmGeneratorExpressionContext* context,
  823. const GeneratorExpressionContent* content,
  824. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  825. {
  826. if (context->Language.empty()) {
  827. reportError(
  828. context, content->GetOriginalExpression(),
  829. "$<COMPILE_LANGUAGE:...> may only be used to specify include "
  830. "directories, compile definitions, compile options, and to evaluate "
  831. "components of the file(GENERATE) command.");
  832. return std::string();
  833. }
  834. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  835. std::string genName = gg->GetName();
  836. if (genName.find("Makefiles") == std::string::npos &&
  837. genName.find("Ninja") == std::string::npos &&
  838. genName.find("Visual Studio") == std::string::npos &&
  839. genName.find("Xcode") == std::string::npos &&
  840. genName.find("Watcom WMake") == std::string::npos) {
  841. reportError(context, content->GetOriginalExpression(),
  842. "$<COMPILE_LANGUAGE:...> not supported for this generator.");
  843. return std::string();
  844. }
  845. if (parameters.empty()) {
  846. return context->Language;
  847. }
  848. for (auto& param : parameters) {
  849. if (context->Language == param) {
  850. return "1";
  851. }
  852. }
  853. return "0";
  854. }
  855. } languageNode;
  856. static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
  857. {
  858. CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default)
  859. int NumExpectedParameters() const override { return TwoOrMoreParameters; }
  860. std::string Evaluate(
  861. const std::vector<std::string>& parameters,
  862. cmGeneratorExpressionContext* context,
  863. const GeneratorExpressionContent* content,
  864. cmGeneratorExpressionDAGChecker* dagChecker) const override
  865. {
  866. if (!context->HeadTarget || context->Language.empty()) {
  867. // reportError(context, content->GetOriginalExpression(), "");
  868. reportError(
  869. context, content->GetOriginalExpression(),
  870. "$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets "
  871. "to specify include directories, compile definitions, and compile "
  872. "options. It may not be used with the add_custom_command, "
  873. "add_custom_target, or file(GENERATE) commands.");
  874. return std::string();
  875. }
  876. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  877. std::string genName = gg->GetName();
  878. if (genName.find("Makefiles") == std::string::npos &&
  879. genName.find("Ninja") == std::string::npos &&
  880. genName.find("Visual Studio") == std::string::npos &&
  881. genName.find("Xcode") == std::string::npos &&
  882. genName.find("Watcom WMake") == std::string::npos) {
  883. reportError(
  884. context, content->GetOriginalExpression(),
  885. "$<COMPILE_LANG_AND_ID:lang,id> not supported for this generator.");
  886. return std::string();
  887. }
  888. const std::string& lang = context->Language;
  889. if (lang == parameters.front()) {
  890. std::vector<std::string> idParameter((parameters.cbegin() + 1),
  891. parameters.cend());
  892. return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage(
  893. idParameter, context, content, dagChecker, lang);
  894. }
  895. return "0";
  896. }
  897. } languageAndIdNode;
  898. std::string getLinkedTargetsContent(
  899. cmGeneratorTarget const* target, std::string const& prop,
  900. cmGeneratorExpressionContext* context,
  901. cmGeneratorExpressionDAGChecker* dagChecker)
  902. {
  903. std::string result;
  904. if (cmLinkImplementationLibraries const* impl =
  905. target->GetLinkImplementationLibraries(context->Config)) {
  906. for (cmLinkImplItem const& lib : impl->Libraries) {
  907. if (lib.Target) {
  908. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in our
  909. // caller's property and hand-evaluate it as if it were compiled.
  910. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  911. cmGeneratorExpressionContext libContext(
  912. target->GetLocalGenerator(), context->Config, context->Quiet, target,
  913. target, context->EvaluateForBuildsystem, lib.Backtrace,
  914. context->Language);
  915. std::string libResult =
  916. lib.Target->EvaluateInterfaceProperty(prop, &libContext, dagChecker);
  917. if (!libResult.empty()) {
  918. if (result.empty()) {
  919. result = std::move(libResult);
  920. } else {
  921. result.reserve(result.size() + 1 + libResult.size());
  922. result += ";";
  923. result += libResult;
  924. }
  925. }
  926. }
  927. }
  928. }
  929. return result;
  930. }
  931. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  932. {
  933. TargetPropertyNode() {} // NOLINT(modernize-use-equals-default)
  934. // This node handles errors on parameter count itself.
  935. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  936. static const char* GetErrorText(std::string const& targetName,
  937. std::string const& propertyName)
  938. {
  939. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  940. if (targetName.empty() && propertyName.empty()) {
  941. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  942. "target name and property name.";
  943. }
  944. if (targetName.empty()) {
  945. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  946. "target name.";
  947. }
  948. if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
  949. if (!propertyNameValidator.find(propertyName)) {
  950. return "Target name and property name not supported.";
  951. }
  952. return "Target name not supported.";
  953. }
  954. return nullptr;
  955. }
  956. std::string Evaluate(
  957. const std::vector<std::string>& parameters,
  958. cmGeneratorExpressionContext* context,
  959. const GeneratorExpressionContent* content,
  960. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  961. {
  962. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  963. cmGeneratorTarget const* target = nullptr;
  964. std::string targetName, propertyName;
  965. if (parameters.size() == 2) {
  966. targetName = parameters[0];
  967. propertyName = parameters[1];
  968. if (const char* e = GetErrorText(targetName, propertyName)) {
  969. reportError(context, content->GetOriginalExpression(), e);
  970. return std::string();
  971. }
  972. if (propertyName == "ALIASED_TARGET"_s) {
  973. if (context->LG->GetMakefile()->IsAlias(targetName)) {
  974. if (cmGeneratorTarget* tgt =
  975. context->LG->FindGeneratorTargetToUse(targetName)) {
  976. return tgt->GetName();
  977. }
  978. }
  979. return std::string();
  980. }
  981. target = context->LG->FindGeneratorTargetToUse(targetName);
  982. if (!target) {
  983. std::ostringstream e;
  984. e << "Target \"" << targetName << "\" not found.";
  985. reportError(context, content->GetOriginalExpression(), e.str());
  986. return std::string();
  987. }
  988. context->AllTargets.insert(target);
  989. } else if (parameters.size() == 1) {
  990. target = context->HeadTarget;
  991. propertyName = parameters[0];
  992. // Keep track of the properties seen while processing.
  993. // The evaluation of the LINK_LIBRARIES generator expressions
  994. // will check this to ensure that properties have one consistent
  995. // value for all evaluations.
  996. context->SeenTargetProperties.insert(propertyName);
  997. context->HadHeadSensitiveCondition = true;
  998. if (!target) {
  999. reportError(
  1000. context, content->GetOriginalExpression(),
  1001. "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
  1002. "It may not be used with add_custom_command or add_custom_target. "
  1003. "Specify the target to read a property from using the "
  1004. "$<TARGET_PROPERTY:tgt,prop> signature instead.");
  1005. return std::string();
  1006. }
  1007. } else {
  1008. reportError(
  1009. context, content->GetOriginalExpression(),
  1010. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  1011. return std::string();
  1012. }
  1013. if (propertyName == "SOURCES") {
  1014. context->SourceSensitiveTargets.insert(target);
  1015. }
  1016. if (propertyName.empty()) {
  1017. reportError(
  1018. context, content->GetOriginalExpression(),
  1019. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  1020. "name.");
  1021. return std::string();
  1022. }
  1023. if (!propertyNameValidator.find(propertyName)) {
  1024. ::reportError(context, content->GetOriginalExpression(),
  1025. "Property name not supported.");
  1026. return std::string();
  1027. }
  1028. assert(target);
  1029. if (propertyName == "LINKER_LANGUAGE") {
  1030. if (target->LinkLanguagePropagatesToDependents() && dagCheckerParent &&
  1031. (dagCheckerParent->EvaluatingLinkLibraries() ||
  1032. dagCheckerParent->EvaluatingSources())) {
  1033. reportError(
  1034. context, content->GetOriginalExpression(),
  1035. "LINKER_LANGUAGE target property can not be used while evaluating "
  1036. "link libraries for a static library");
  1037. return std::string();
  1038. }
  1039. return target->GetLinkerLanguage(context->Config);
  1040. }
  1041. std::string interfacePropertyName;
  1042. bool isInterfaceProperty = false;
  1043. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  1044. if (propertyName == #prop) { \
  1045. interfacePropertyName = "INTERFACE_" #prop; \
  1046. } else if (propertyName == "INTERFACE_" #prop) { \
  1047. interfacePropertyName = "INTERFACE_" #prop; \
  1048. isInterfaceProperty = true; \
  1049. } else
  1050. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  1051. // Note that the above macro terminates with an else
  1052. /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
  1053. cmPolicies::PolicyStatus polSt =
  1054. context->LG->GetPolicyStatus(cmPolicies::CMP0043);
  1055. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  1056. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  1057. }
  1058. }
  1059. #undef POPULATE_INTERFACE_PROPERTY_NAME
  1060. bool evaluatingLinkLibraries = false;
  1061. if (dagCheckerParent) {
  1062. if (dagCheckerParent->EvaluatingGenexExpression() ||
  1063. dagCheckerParent->EvaluatingPICExpression()) {
  1064. // No check required.
  1065. } else if (dagCheckerParent->EvaluatingLinkLibraries()) {
  1066. evaluatingLinkLibraries = true;
  1067. if (!interfacePropertyName.empty()) {
  1068. reportError(
  1069. context, content->GetOriginalExpression(),
  1070. "$<TARGET_PROPERTY:...> expression in link libraries "
  1071. "evaluation depends on target property which is transitive "
  1072. "over the link libraries, creating a recursion.");
  1073. return std::string();
  1074. }
  1075. } else {
  1076. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
  1077. assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  1078. ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy)
  1079. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  1080. }
  1081. }
  1082. if (isInterfaceProperty) {
  1083. return target->EvaluateInterfaceProperty(propertyName, context,
  1084. dagCheckerParent);
  1085. }
  1086. cmGeneratorExpressionDAGChecker dagChecker(
  1087. context->Backtrace, target, propertyName, content, dagCheckerParent);
  1088. switch (dagChecker.Check()) {
  1089. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1090. dagChecker.ReportError(context, content->GetOriginalExpression());
  1091. return std::string();
  1092. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1093. // No error. We just skip cyclic references.
  1094. return std::string();
  1095. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1096. // We handle transitive properties above. For non-transitive
  1097. // properties we accept repeats anyway.
  1098. case cmGeneratorExpressionDAGChecker::DAG:
  1099. break;
  1100. }
  1101. std::string result;
  1102. bool haveProp = false;
  1103. if (const char* p = target->GetProperty(propertyName)) {
  1104. result = p;
  1105. haveProp = true;
  1106. } else if (evaluatingLinkLibraries) {
  1107. return std::string();
  1108. }
  1109. if (!haveProp && !target->IsImported() &&
  1110. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1111. if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
  1112. context->Config)) {
  1113. context->HadContextSensitiveCondition = true;
  1114. return target->GetLinkInterfaceDependentBoolProperty(propertyName,
  1115. context->Config)
  1116. ? "1"
  1117. : "0";
  1118. }
  1119. if (target->IsLinkInterfaceDependentStringProperty(propertyName,
  1120. context->Config)) {
  1121. context->HadContextSensitiveCondition = true;
  1122. const char* propContent =
  1123. target->GetLinkInterfaceDependentStringProperty(propertyName,
  1124. context->Config);
  1125. return propContent ? propContent : "";
  1126. }
  1127. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1128. context->Config)) {
  1129. context->HadContextSensitiveCondition = true;
  1130. const char* propContent =
  1131. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1132. context->Config);
  1133. return propContent ? propContent : "";
  1134. }
  1135. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1136. context->Config)) {
  1137. context->HadContextSensitiveCondition = true;
  1138. const char* propContent =
  1139. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1140. context->Config);
  1141. return propContent ? propContent : "";
  1142. }
  1143. }
  1144. if (!target->IsImported() && dagCheckerParent &&
  1145. !dagCheckerParent->EvaluatingLinkLibraries()) {
  1146. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1147. context->Config)) {
  1148. context->HadContextSensitiveCondition = true;
  1149. const char* propContent =
  1150. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1151. context->Config);
  1152. return propContent ? propContent : "";
  1153. }
  1154. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1155. context->Config)) {
  1156. context->HadContextSensitiveCondition = true;
  1157. const char* propContent =
  1158. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1159. context->Config);
  1160. return propContent ? propContent : "";
  1161. }
  1162. }
  1163. if (!interfacePropertyName.empty()) {
  1164. result = this->EvaluateDependentExpression(result, context->LG, context,
  1165. target, target, &dagChecker);
  1166. std::string linkedTargetsContent = getLinkedTargetsContent(
  1167. target, interfacePropertyName, context, &dagChecker);
  1168. if (!linkedTargetsContent.empty()) {
  1169. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1170. }
  1171. }
  1172. return result;
  1173. }
  1174. } targetPropertyNode;
  1175. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1176. {
  1177. TargetNameNode() {} // NOLINT(modernize-use-equals-default)
  1178. bool GeneratesContent() const override { return true; }
  1179. bool AcceptsArbitraryContentParameter() const override { return true; }
  1180. bool RequiresLiteralInput() const override { return true; }
  1181. std::string Evaluate(
  1182. const std::vector<std::string>& parameters,
  1183. cmGeneratorExpressionContext* /*context*/,
  1184. const GeneratorExpressionContent* /*content*/,
  1185. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1186. {
  1187. return parameters.front();
  1188. }
  1189. int NumExpectedParameters() const override { return 1; }
  1190. } targetNameNode;
  1191. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1192. {
  1193. TargetObjectsNode() {} // NOLINT(modernize-use-equals-default)
  1194. std::string Evaluate(
  1195. const std::vector<std::string>& parameters,
  1196. cmGeneratorExpressionContext* context,
  1197. const GeneratorExpressionContent* content,
  1198. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1199. {
  1200. std::string tgtName = parameters.front();
  1201. cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
  1202. if (!gt) {
  1203. std::ostringstream e;
  1204. e << "Objects of target \"" << tgtName
  1205. << "\" referenced but no such target exists.";
  1206. reportError(context, content->GetOriginalExpression(), e.str());
  1207. return std::string();
  1208. }
  1209. cmStateEnums::TargetType type = gt->GetType();
  1210. if (type != cmStateEnums::EXECUTABLE &&
  1211. type != cmStateEnums::STATIC_LIBRARY &&
  1212. type != cmStateEnums::SHARED_LIBRARY &&
  1213. type != cmStateEnums::MODULE_LIBRARY &&
  1214. type != cmStateEnums::OBJECT_LIBRARY) {
  1215. std::ostringstream e;
  1216. e << "Objects of target \"" << tgtName
  1217. << "\" referenced but is not an allowed library types (EXECUTABLE, "
  1218. << "STATIC, SHARED, MODULE, OBJECT).";
  1219. reportError(context, content->GetOriginalExpression(), e.str());
  1220. return std::string();
  1221. }
  1222. if (!context->EvaluateForBuildsystem) {
  1223. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  1224. std::string reason;
  1225. if (!gg->HasKnownObjectFileLocation(&reason)) {
  1226. std::ostringstream e;
  1227. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1228. "is only suitable for consumption by CMake (limited"
  1229. << reason
  1230. << "). "
  1231. "It is not suitable for writing out elsewhere.";
  1232. reportError(context, content->GetOriginalExpression(), e.str());
  1233. return std::string();
  1234. }
  1235. }
  1236. std::vector<std::string> objects;
  1237. if (gt->IsImported()) {
  1238. const char* loc = nullptr;
  1239. const char* imp = nullptr;
  1240. std::string suffix;
  1241. if (gt->Target->GetMappedConfig(context->Config, &loc, &imp, suffix)) {
  1242. cmSystemTools::ExpandListArgument(loc, objects);
  1243. }
  1244. context->HadContextSensitiveCondition = true;
  1245. } else {
  1246. gt->GetTargetObjectNames(context->Config, objects);
  1247. std::string obj_dir;
  1248. if (context->EvaluateForBuildsystem) {
  1249. // Use object file directory with buildsystem placeholder.
  1250. obj_dir = gt->ObjectDirectory;
  1251. // Here we assume that the set of object files produced
  1252. // by an object library does not vary with configuration
  1253. // and do not set HadContextSensitiveCondition to true.
  1254. } else {
  1255. // Use object file directory with per-config location.
  1256. obj_dir = gt->GetObjectDirectory(context->Config);
  1257. context->HadContextSensitiveCondition = true;
  1258. }
  1259. for (std::string& o : objects) {
  1260. o = obj_dir + o;
  1261. }
  1262. }
  1263. // Create the cmSourceFile instances in the referencing directory.
  1264. cmMakefile* mf = context->LG->GetMakefile();
  1265. for (std::string& o : objects) {
  1266. mf->AddTargetObject(tgtName, o);
  1267. }
  1268. return cmJoin(objects, ";");
  1269. }
  1270. } targetObjectsNode;
  1271. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1272. {
  1273. CompileFeaturesNode() {} // NOLINT(modernize-use-equals-default)
  1274. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  1275. std::string Evaluate(
  1276. const std::vector<std::string>& parameters,
  1277. cmGeneratorExpressionContext* context,
  1278. const GeneratorExpressionContent* content,
  1279. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1280. {
  1281. cmGeneratorTarget const* target = context->HeadTarget;
  1282. if (!target) {
  1283. reportError(
  1284. context, content->GetOriginalExpression(),
  1285. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1286. "not be used with add_custom_command or add_custom_target.");
  1287. return std::string();
  1288. }
  1289. context->HadHeadSensitiveCondition = true;
  1290. typedef std::map<std::string, std::vector<std::string>> LangMap;
  1291. static LangMap availableFeatures;
  1292. LangMap testedFeatures;
  1293. for (std::string const& p : parameters) {
  1294. std::string error;
  1295. std::string lang;
  1296. if (!context->LG->GetMakefile()->CompileFeatureKnown(
  1297. context->HeadTarget->Target, p, lang, &error)) {
  1298. reportError(context, content->GetOriginalExpression(), error);
  1299. return std::string();
  1300. }
  1301. testedFeatures[lang].push_back(p);
  1302. if (availableFeatures.find(lang) == availableFeatures.end()) {
  1303. const char* featuresKnown =
  1304. context->LG->GetMakefile()->CompileFeaturesAvailable(lang, &error);
  1305. if (!featuresKnown) {
  1306. reportError(context, content->GetOriginalExpression(), error);
  1307. return std::string();
  1308. }
  1309. cmSystemTools::ExpandListArgument(featuresKnown,
  1310. availableFeatures[lang]);
  1311. }
  1312. }
  1313. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1314. for (auto const& lit : testedFeatures) {
  1315. std::vector<std::string> const& langAvailable =
  1316. availableFeatures[lit.first];
  1317. const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
  1318. "CMAKE_" + lit.first + "_STANDARD_DEFAULT");
  1319. for (std::string const& it : lit.second) {
  1320. if (std::find(langAvailable.begin(), langAvailable.end(), it) ==
  1321. langAvailable.end()) {
  1322. return "0";
  1323. }
  1324. if (standardDefault && !*standardDefault) {
  1325. // This compiler has no notion of language standard levels.
  1326. // All features known for the language are always available.
  1327. continue;
  1328. }
  1329. if (!context->LG->GetMakefile()->HaveStandardAvailable(
  1330. target->Target, lit.first, it)) {
  1331. if (evalLL) {
  1332. const char* l = target->GetProperty(lit.first + "_STANDARD");
  1333. if (!l) {
  1334. l = standardDefault;
  1335. }
  1336. assert(l);
  1337. context->MaxLanguageStandard[target][lit.first] = l;
  1338. } else {
  1339. return "0";
  1340. }
  1341. }
  1342. }
  1343. }
  1344. return "1";
  1345. }
  1346. } compileFeaturesNode;
  1347. static const char* targetPolicyWhitelist[] = {
  1348. nullptr
  1349. #define TARGET_POLICY_STRING(POLICY) , #POLICY
  1350. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1351. #undef TARGET_POLICY_STRING
  1352. };
  1353. cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
  1354. const char* policy)
  1355. {
  1356. #define RETURN_POLICY(POLICY) \
  1357. if (strcmp(policy, #POLICY) == 0) { \
  1358. return tgt->GetPolicyStatus##POLICY(); \
  1359. }
  1360. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1361. #undef RETURN_POLICY
  1362. assert(false && "Unreachable code. Not a valid policy");
  1363. return cmPolicies::WARN;
  1364. }
  1365. cmPolicies::PolicyID policyForString(const char* policy_id)
  1366. {
  1367. #define RETURN_POLICY_ID(POLICY_ID) \
  1368. if (strcmp(policy_id, #POLICY_ID) == 0) { \
  1369. return cmPolicies::POLICY_ID; \
  1370. }
  1371. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1372. #undef RETURN_POLICY_ID
  1373. assert(false && "Unreachable code. Not a valid policy");
  1374. return cmPolicies::CMP0002;
  1375. }
  1376. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1377. {
  1378. TargetPolicyNode() {} // NOLINT(modernize-use-equals-default)
  1379. int NumExpectedParameters() const override { return 1; }
  1380. std::string Evaluate(
  1381. const std::vector<std::string>& parameters,
  1382. cmGeneratorExpressionContext* context,
  1383. const GeneratorExpressionContent* content,
  1384. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1385. {
  1386. if (!context->HeadTarget) {
  1387. reportError(
  1388. context, content->GetOriginalExpression(),
  1389. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1390. "may not be used with add_custom_command or add_custom_target.");
  1391. return std::string();
  1392. }
  1393. context->HadContextSensitiveCondition = true;
  1394. context->HadHeadSensitiveCondition = true;
  1395. for (size_t i = 1; i < cm::size(targetPolicyWhitelist); ++i) {
  1396. const char* policy = targetPolicyWhitelist[i];
  1397. if (parameters.front() == policy) {
  1398. cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
  1399. switch (statusForTarget(context->HeadTarget, policy)) {
  1400. case cmPolicies::WARN:
  1401. lg->IssueMessage(
  1402. MessageType::AUTHOR_WARNING,
  1403. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1404. CM_FALLTHROUGH;
  1405. case cmPolicies::REQUIRED_IF_USED:
  1406. case cmPolicies::REQUIRED_ALWAYS:
  1407. case cmPolicies::OLD:
  1408. return "0";
  1409. case cmPolicies::NEW:
  1410. return "1";
  1411. }
  1412. }
  1413. }
  1414. reportError(
  1415. context, content->GetOriginalExpression(),
  1416. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1417. "policies. Currently it may be used with the following policies:\n"
  1418. #define STRINGIFY_HELPER(X) #X
  1419. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1420. #define TARGET_POLICY_LIST_ITEM(POLICY) " * " STRINGIFY(POLICY) "\n"
  1421. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1422. #undef TARGET_POLICY_LIST_ITEM
  1423. );
  1424. return std::string();
  1425. }
  1426. } targetPolicyNode;
  1427. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1428. {
  1429. InstallPrefixNode() {} // NOLINT(modernize-use-equals-default)
  1430. bool GeneratesContent() const override { return true; }
  1431. int NumExpectedParameters() const override { return 0; }
  1432. std::string Evaluate(
  1433. const std::vector<std::string>& /*parameters*/,
  1434. cmGeneratorExpressionContext* context,
  1435. const GeneratorExpressionContent* content,
  1436. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1437. {
  1438. reportError(context, content->GetOriginalExpression(),
  1439. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1440. "should never be evaluated.");
  1441. return std::string();
  1442. }
  1443. } installPrefixNode;
  1444. class ArtifactDirTag;
  1445. class ArtifactLinkerTag;
  1446. class ArtifactNameTag;
  1447. class ArtifactPathTag;
  1448. class ArtifactPdbTag;
  1449. class ArtifactSonameTag;
  1450. class ArtifactBundleDirTag;
  1451. class ArtifactBundleContentDirTag;
  1452. template <typename ArtifactT>
  1453. struct TargetFilesystemArtifactResultCreator
  1454. {
  1455. static std::string Create(cmGeneratorTarget* target,
  1456. cmGeneratorExpressionContext* context,
  1457. const GeneratorExpressionContent* content);
  1458. };
  1459. template <>
  1460. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1461. {
  1462. static std::string Create(cmGeneratorTarget* target,
  1463. cmGeneratorExpressionContext* context,
  1464. const GeneratorExpressionContent* content)
  1465. {
  1466. // The target soname file (.so.1).
  1467. if (target->IsDLLPlatform()) {
  1468. ::reportError(context, content->GetOriginalExpression(),
  1469. "TARGET_SONAME_FILE is not allowed "
  1470. "for DLL target platforms.");
  1471. return std::string();
  1472. }
  1473. if (target->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1474. ::reportError(context, content->GetOriginalExpression(),
  1475. "TARGET_SONAME_FILE is allowed only for "
  1476. "SHARED libraries.");
  1477. return std::string();
  1478. }
  1479. std::string result = target->GetDirectory(context->Config);
  1480. result += "/";
  1481. result += target->GetSOName(context->Config);
  1482. return result;
  1483. }
  1484. };
  1485. template <>
  1486. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1487. {
  1488. static std::string Create(cmGeneratorTarget* target,
  1489. cmGeneratorExpressionContext* context,
  1490. const GeneratorExpressionContent* content)
  1491. {
  1492. if (target->IsImported()) {
  1493. ::reportError(context, content->GetOriginalExpression(),
  1494. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1495. return std::string();
  1496. }
  1497. std::string language = target->GetLinkerLanguage(context->Config);
  1498. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1499. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1500. ::reportError(context, content->GetOriginalExpression(),
  1501. "TARGET_PDB_FILE is not supported by the target linker.");
  1502. return std::string();
  1503. }
  1504. cmStateEnums::TargetType targetType = target->GetType();
  1505. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1506. targetType != cmStateEnums::MODULE_LIBRARY &&
  1507. targetType != cmStateEnums::EXECUTABLE) {
  1508. ::reportError(context, content->GetOriginalExpression(),
  1509. "TARGET_PDB_FILE is allowed only for "
  1510. "targets with linker created artifacts.");
  1511. return std::string();
  1512. }
  1513. std::string result = target->GetPDBDirectory(context->Config);
  1514. result += "/";
  1515. result += target->GetPDBName(context->Config);
  1516. return result;
  1517. }
  1518. };
  1519. template <>
  1520. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1521. {
  1522. static std::string Create(cmGeneratorTarget* target,
  1523. cmGeneratorExpressionContext* context,
  1524. const GeneratorExpressionContent* content)
  1525. {
  1526. // The file used to link to the target (.so, .lib, .a).
  1527. if (!target->IsLinkable()) {
  1528. ::reportError(context, content->GetOriginalExpression(),
  1529. "TARGET_LINKER_FILE is allowed only for libraries and "
  1530. "executables with ENABLE_EXPORTS.");
  1531. return std::string();
  1532. }
  1533. cmStateEnums::ArtifactType artifact =
  1534. target->HasImportLibrary(context->Config)
  1535. ? cmStateEnums::ImportLibraryArtifact
  1536. : cmStateEnums::RuntimeBinaryArtifact;
  1537. return target->GetFullPath(context->Config, artifact);
  1538. }
  1539. };
  1540. template <>
  1541. struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
  1542. {
  1543. static std::string Create(cmGeneratorTarget* target,
  1544. cmGeneratorExpressionContext* context,
  1545. const GeneratorExpressionContent* content)
  1546. {
  1547. if (target->IsImported()) {
  1548. ::reportError(context, content->GetOriginalExpression(),
  1549. "TARGET_BUNDLE_DIR not allowed for IMPORTED targets.");
  1550. return std::string();
  1551. }
  1552. if (!target->IsBundleOnApple()) {
  1553. ::reportError(context, content->GetOriginalExpression(),
  1554. "TARGET_BUNDLE_DIR is allowed only for Bundle targets.");
  1555. return std::string();
  1556. }
  1557. std::string outpath = target->GetDirectory(context->Config) + '/';
  1558. return target->BuildBundleDirectory(outpath, context->Config,
  1559. cmGeneratorTarget::BundleDirLevel);
  1560. }
  1561. };
  1562. template <>
  1563. struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
  1564. {
  1565. static std::string Create(cmGeneratorTarget* target,
  1566. cmGeneratorExpressionContext* context,
  1567. const GeneratorExpressionContent* content)
  1568. {
  1569. if (target->IsImported()) {
  1570. ::reportError(
  1571. context, content->GetOriginalExpression(),
  1572. "TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.");
  1573. return std::string();
  1574. }
  1575. if (!target->IsBundleOnApple()) {
  1576. ::reportError(
  1577. context, content->GetOriginalExpression(),
  1578. "TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.");
  1579. return std::string();
  1580. }
  1581. std::string outpath = target->GetDirectory(context->Config) + '/';
  1582. return target->BuildBundleDirectory(outpath, context->Config,
  1583. cmGeneratorTarget::ContentLevel);
  1584. }
  1585. };
  1586. template <>
  1587. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1588. {
  1589. static std::string Create(cmGeneratorTarget* target,
  1590. cmGeneratorExpressionContext* context,
  1591. const GeneratorExpressionContent* /*unused*/)
  1592. {
  1593. return target->GetFullPath(context->Config,
  1594. cmStateEnums::RuntimeBinaryArtifact, true);
  1595. }
  1596. };
  1597. template <typename ArtifactT>
  1598. struct TargetFilesystemArtifactResultGetter
  1599. {
  1600. static std::string Get(const std::string& result);
  1601. };
  1602. template <>
  1603. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1604. {
  1605. static std::string Get(const std::string& result)
  1606. {
  1607. return cmSystemTools::GetFilenameName(result);
  1608. }
  1609. };
  1610. template <>
  1611. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1612. {
  1613. static std::string Get(const std::string& result)
  1614. {
  1615. return cmSystemTools::GetFilenamePath(result);
  1616. }
  1617. };
  1618. template <>
  1619. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1620. {
  1621. static std::string Get(const std::string& result) { return result; }
  1622. };
  1623. struct TargetArtifactBase : public cmGeneratorExpressionNode
  1624. {
  1625. TargetArtifactBase() {} // NOLINT(modernize-use-equals-default)
  1626. protected:
  1627. cmGeneratorTarget* GetTarget(
  1628. const std::vector<std::string>& parameters,
  1629. cmGeneratorExpressionContext* context,
  1630. const GeneratorExpressionContent* content,
  1631. cmGeneratorExpressionDAGChecker* dagChecker) const
  1632. {
  1633. // Lookup the referenced target.
  1634. std::string name = parameters.front();
  1635. if (!cmGeneratorExpression::IsValidTargetName(name)) {
  1636. ::reportError(context, content->GetOriginalExpression(),
  1637. "Expression syntax not recognized.");
  1638. return nullptr;
  1639. }
  1640. cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
  1641. if (!target) {
  1642. ::reportError(context, content->GetOriginalExpression(),
  1643. "No target \"" + name + "\"");
  1644. return nullptr;
  1645. }
  1646. if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY &&
  1647. target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) {
  1648. ::reportError(context, content->GetOriginalExpression(),
  1649. "Target \"" + name +
  1650. "\" is not an executable or library.");
  1651. return nullptr;
  1652. }
  1653. if (dagChecker &&
  1654. (dagChecker->EvaluatingLinkLibraries(target) ||
  1655. (dagChecker->EvaluatingSources() &&
  1656. target == dagChecker->TopTarget()))) {
  1657. ::reportError(context, content->GetOriginalExpression(),
  1658. "Expressions which require the linker language may not "
  1659. "be used while evaluating link libraries");
  1660. return nullptr;
  1661. }
  1662. return target;
  1663. }
  1664. };
  1665. template <typename ArtifactT, typename ComponentT>
  1666. struct TargetFilesystemArtifact : public TargetArtifactBase
  1667. {
  1668. TargetFilesystemArtifact() {} // NOLINT(modernize-use-equals-default)
  1669. int NumExpectedParameters() const override { return 1; }
  1670. std::string Evaluate(
  1671. const std::vector<std::string>& parameters,
  1672. cmGeneratorExpressionContext* context,
  1673. const GeneratorExpressionContent* content,
  1674. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1675. {
  1676. cmGeneratorTarget* target =
  1677. this->GetTarget(parameters, context, content, dagChecker);
  1678. if (!target) {
  1679. return std::string();
  1680. }
  1681. context->DependTargets.insert(target);
  1682. context->AllTargets.insert(target);
  1683. std::string result =
  1684. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(target, context,
  1685. content);
  1686. if (context->HadError) {
  1687. return std::string();
  1688. }
  1689. return TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1690. }
  1691. };
  1692. template <typename ArtifactT>
  1693. struct TargetFilesystemArtifactNodeGroup
  1694. {
  1695. TargetFilesystemArtifactNodeGroup() // NOLINT(modernize-use-equals-default)
  1696. {
  1697. }
  1698. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1699. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1700. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1701. };
  1702. static const TargetFilesystemArtifactNodeGroup<ArtifactNameTag>
  1703. targetNodeGroup;
  1704. static const TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag>
  1705. targetLinkerNodeGroup;
  1706. static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
  1707. targetSoNameNodeGroup;
  1708. static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
  1709. targetPdbNodeGroup;
  1710. static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
  1711. targetBundleDirNode;
  1712. static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
  1713. ArtifactPathTag>
  1714. targetBundleContentDirNode;
  1715. //
  1716. // To retrieve base name for various artifacts
  1717. //
  1718. template <typename ArtifactT>
  1719. struct TargetOutputNameArtifactResultGetter
  1720. {
  1721. static std::string Get(cmGeneratorTarget* target,
  1722. cmGeneratorExpressionContext* context,
  1723. const GeneratorExpressionContent* content);
  1724. };
  1725. template <>
  1726. struct TargetOutputNameArtifactResultGetter<ArtifactNameTag>
  1727. {
  1728. static std::string Get(cmGeneratorTarget* target,
  1729. cmGeneratorExpressionContext* context,
  1730. const GeneratorExpressionContent* /*unused*/)
  1731. {
  1732. return target->GetOutputName(context->Config,
  1733. cmStateEnums::RuntimeBinaryArtifact) +
  1734. target->GetFilePostfix(context->Config);
  1735. }
  1736. };
  1737. template <>
  1738. struct TargetOutputNameArtifactResultGetter<ArtifactLinkerTag>
  1739. {
  1740. static std::string Get(cmGeneratorTarget* target,
  1741. cmGeneratorExpressionContext* context,
  1742. const GeneratorExpressionContent* content)
  1743. {
  1744. // The file used to link to the target (.so, .lib, .a).
  1745. if (!target->IsLinkable()) {
  1746. ::reportError(context, content->GetOriginalExpression(),
  1747. "TARGET_LINKER_FILE_BASE_NAME is allowed only for "
  1748. "libraries and executables with ENABLE_EXPORTS.");
  1749. return std::string();
  1750. }
  1751. cmStateEnums::ArtifactType artifact =
  1752. target->HasImportLibrary(context->Config)
  1753. ? cmStateEnums::ImportLibraryArtifact
  1754. : cmStateEnums::RuntimeBinaryArtifact;
  1755. return target->GetOutputName(context->Config, artifact) +
  1756. target->GetFilePostfix(context->Config);
  1757. }
  1758. };
  1759. template <>
  1760. struct TargetOutputNameArtifactResultGetter<ArtifactPdbTag>
  1761. {
  1762. static std::string Get(cmGeneratorTarget* target,
  1763. cmGeneratorExpressionContext* context,
  1764. const GeneratorExpressionContent* content)
  1765. {
  1766. if (target->IsImported()) {
  1767. ::reportError(
  1768. context, content->GetOriginalExpression(),
  1769. "TARGET_PDB_FILE_BASE_NAME not allowed for IMPORTED targets.");
  1770. return std::string();
  1771. }
  1772. std::string language = target->GetLinkerLanguage(context->Config);
  1773. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1774. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1775. ::reportError(
  1776. context, content->GetOriginalExpression(),
  1777. "TARGET_PDB_FILE_BASE_NAME is not supported by the target linker.");
  1778. return std::string();
  1779. }
  1780. cmStateEnums::TargetType targetType = target->GetType();
  1781. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1782. targetType != cmStateEnums::MODULE_LIBRARY &&
  1783. targetType != cmStateEnums::EXECUTABLE) {
  1784. ::reportError(context, content->GetOriginalExpression(),
  1785. "TARGET_PDB_FILE_BASE_NAME is allowed only for "
  1786. "targets with linker created artifacts.");
  1787. return std::string();
  1788. }
  1789. return target->GetPDBOutputName(context->Config) +
  1790. target->GetFilePostfix(context->Config);
  1791. }
  1792. };
  1793. template <typename ArtifactT>
  1794. struct TargetFileBaseNameArtifact : public TargetArtifactBase
  1795. {
  1796. TargetFileBaseNameArtifact() {} // NOLINT(modernize-use-equals-default)
  1797. int NumExpectedParameters() const override { return 1; }
  1798. std::string Evaluate(
  1799. const std::vector<std::string>& parameters,
  1800. cmGeneratorExpressionContext* context,
  1801. const GeneratorExpressionContent* content,
  1802. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1803. {
  1804. cmGeneratorTarget* target =
  1805. this->GetTarget(parameters, context, content, dagChecker);
  1806. if (!target) {
  1807. return std::string();
  1808. }
  1809. std::string result = TargetOutputNameArtifactResultGetter<ArtifactT>::Get(
  1810. target, context, content);
  1811. if (context->HadError) {
  1812. return std::string();
  1813. }
  1814. return result;
  1815. }
  1816. };
  1817. static const TargetFileBaseNameArtifact<ArtifactNameTag>
  1818. targetFileBaseNameNode;
  1819. static const TargetFileBaseNameArtifact<ArtifactLinkerTag>
  1820. targetLinkerFileBaseNameNode;
  1821. static const TargetFileBaseNameArtifact<ArtifactPdbTag>
  1822. targetPdbFileBaseNameNode;
  1823. class ArtifactFilePrefixTag;
  1824. class ArtifactLinkerFilePrefixTag;
  1825. class ArtifactFileSuffixTag;
  1826. class ArtifactLinkerFileSuffixTag;
  1827. template <typename ArtifactT>
  1828. struct TargetFileArtifactResultGetter
  1829. {
  1830. static std::string Get(cmGeneratorTarget* target,
  1831. cmGeneratorExpressionContext* context,
  1832. const GeneratorExpressionContent* content);
  1833. };
  1834. template <>
  1835. struct TargetFileArtifactResultGetter<ArtifactFilePrefixTag>
  1836. {
  1837. static std::string Get(cmGeneratorTarget* target,
  1838. cmGeneratorExpressionContext* context,
  1839. const GeneratorExpressionContent*)
  1840. {
  1841. return target->GetFilePrefix(context->Config);
  1842. }
  1843. };
  1844. template <>
  1845. struct TargetFileArtifactResultGetter<ArtifactLinkerFilePrefixTag>
  1846. {
  1847. static std::string Get(cmGeneratorTarget* target,
  1848. cmGeneratorExpressionContext* context,
  1849. const GeneratorExpressionContent* content)
  1850. {
  1851. if (!target->IsLinkable()) {
  1852. ::reportError(context, content->GetOriginalExpression(),
  1853. "TARGET_LINKER_PREFIX is allowed only for libraries and "
  1854. "executables with ENABLE_EXPORTS.");
  1855. return std::string();
  1856. }
  1857. cmStateEnums::ArtifactType artifact =
  1858. target->HasImportLibrary(context->Config)
  1859. ? cmStateEnums::ImportLibraryArtifact
  1860. : cmStateEnums::RuntimeBinaryArtifact;
  1861. return target->GetFilePrefix(context->Config, artifact);
  1862. }
  1863. };
  1864. template <>
  1865. struct TargetFileArtifactResultGetter<ArtifactFileSuffixTag>
  1866. {
  1867. static std::string Get(cmGeneratorTarget* target,
  1868. cmGeneratorExpressionContext* context,
  1869. const GeneratorExpressionContent*)
  1870. {
  1871. return target->GetFileSuffix(context->Config);
  1872. }
  1873. };
  1874. template <>
  1875. struct TargetFileArtifactResultGetter<ArtifactLinkerFileSuffixTag>
  1876. {
  1877. static std::string Get(cmGeneratorTarget* target,
  1878. cmGeneratorExpressionContext* context,
  1879. const GeneratorExpressionContent* content)
  1880. {
  1881. if (!target->IsLinkable()) {
  1882. ::reportError(context, content->GetOriginalExpression(),
  1883. "TARGET_LINKER_SUFFIX is allowed only for libraries and "
  1884. "executables with ENABLE_EXPORTS.");
  1885. return std::string();
  1886. }
  1887. cmStateEnums::ArtifactType artifact =
  1888. target->HasImportLibrary(context->Config)
  1889. ? cmStateEnums::ImportLibraryArtifact
  1890. : cmStateEnums::RuntimeBinaryArtifact;
  1891. return target->GetFileSuffix(context->Config, artifact);
  1892. }
  1893. };
  1894. template <typename ArtifactT>
  1895. struct TargetFileArtifact : public TargetArtifactBase
  1896. {
  1897. TargetFileArtifact() {} // NOLINT(modernize-use-equals-default)
  1898. int NumExpectedParameters() const override { return 1; }
  1899. std::string Evaluate(
  1900. const std::vector<std::string>& parameters,
  1901. cmGeneratorExpressionContext* context,
  1902. const GeneratorExpressionContent* content,
  1903. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1904. {
  1905. cmGeneratorTarget* target =
  1906. this->GetTarget(parameters, context, content, dagChecker);
  1907. if (!target) {
  1908. return std::string();
  1909. }
  1910. std::string result =
  1911. TargetFileArtifactResultGetter<ArtifactT>::Get(target, context, content);
  1912. if (context->HadError) {
  1913. return std::string();
  1914. }
  1915. return result;
  1916. }
  1917. };
  1918. static const TargetFileArtifact<ArtifactFilePrefixTag> targetFilePrefixNode;
  1919. static const TargetFileArtifact<ArtifactLinkerFilePrefixTag>
  1920. targetLinkerFilePrefixNode;
  1921. static const TargetFileArtifact<ArtifactFileSuffixTag> targetFileSuffixNode;
  1922. static const TargetFileArtifact<ArtifactLinkerFileSuffixTag>
  1923. targetLinkerFileSuffixNode;
  1924. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1925. {
  1926. ShellPathNode() {} // NOLINT(modernize-use-equals-default)
  1927. std::string Evaluate(
  1928. const std::vector<std::string>& parameters,
  1929. cmGeneratorExpressionContext* context,
  1930. const GeneratorExpressionContent* content,
  1931. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1932. {
  1933. std::vector<std::string> listIn;
  1934. cmSystemTools::ExpandListArgument(parameters.front(), listIn);
  1935. if (listIn.empty()) {
  1936. reportError(context, content->GetOriginalExpression(),
  1937. "\"\" is not an absolute path.");
  1938. return std::string();
  1939. }
  1940. cmStateSnapshot snapshot = context->LG->GetStateSnapshot();
  1941. cmOutputConverter converter(snapshot);
  1942. const char* separator = snapshot.GetState()->UseWindowsShell() ? ";" : ":";
  1943. std::vector<std::string> listOut;
  1944. listOut.reserve(listIn.size());
  1945. for (auto const& in : listIn) {
  1946. if (!cmSystemTools::FileIsFullPath(in)) {
  1947. reportError(context, content->GetOriginalExpression(),
  1948. "\"" + in + "\" is not an absolute path.");
  1949. return std::string();
  1950. }
  1951. listOut.emplace_back(converter.ConvertDirectorySeparatorsForShell(in));
  1952. }
  1953. return cmJoin(listOut, separator);
  1954. }
  1955. } shellPathNode;
  1956. const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
  1957. const std::string& identifier)
  1958. {
  1959. static std::map<std::string, cmGeneratorExpressionNode const*> const nodeMap{
  1960. { "0", &zeroNode },
  1961. { "1", &oneNode },
  1962. { "AND", &andNode },
  1963. { "OR", &orNode },
  1964. { "NOT", &notNode },
  1965. { "C_COMPILER_ID", &cCompilerIdNode },
  1966. { "CXX_COMPILER_ID", &cxxCompilerIdNode },
  1967. { "CUDA_COMPILER_ID", &cudaCompilerIdNode },
  1968. { "Fortran_COMPILER_ID", &fortranCompilerIdNode },
  1969. { "VERSION_GREATER", &versionGreaterNode },
  1970. { "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
  1971. { "VERSION_LESS", &versionLessNode },
  1972. { "VERSION_LESS_EQUAL", &versionLessEqNode },
  1973. { "VERSION_EQUAL", &versionEqualNode },
  1974. { "C_COMPILER_VERSION", &cCompilerVersionNode },
  1975. { "CXX_COMPILER_VERSION", &cxxCompilerVersionNode },
  1976. { "CUDA_COMPILER_VERSION", &cudaCompilerVersionNode },
  1977. { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
  1978. { "PLATFORM_ID", &platformIdNode },
  1979. { "COMPILE_FEATURES", &compileFeaturesNode },
  1980. { "CONFIGURATION", &configurationNode },
  1981. { "CONFIG", &configurationTestNode },
  1982. { "TARGET_FILE", &targetNodeGroup.File },
  1983. { "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File },
  1984. { "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File },
  1985. { "TARGET_PDB_FILE", &targetPdbNodeGroup.File },
  1986. { "TARGET_FILE_BASE_NAME", &targetFileBaseNameNode },
  1987. { "TARGET_LINKER_FILE_BASE_NAME", &targetLinkerFileBaseNameNode },
  1988. { "TARGET_PDB_FILE_BASE_NAME", &targetPdbFileBaseNameNode },
  1989. { "TARGET_FILE_PREFIX", &targetFilePrefixNode },
  1990. { "TARGET_LINKER_FILE_PREFIX", &targetLinkerFilePrefixNode },
  1991. { "TARGET_FILE_SUFFIX", &targetFileSuffixNode },
  1992. { "TARGET_LINKER_FILE_SUFFIX", &targetLinkerFileSuffixNode },
  1993. { "TARGET_FILE_NAME", &targetNodeGroup.FileName },
  1994. { "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName },
  1995. { "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName },
  1996. { "TARGET_PDB_FILE_NAME", &targetPdbNodeGroup.FileName },
  1997. { "TARGET_FILE_DIR", &targetNodeGroup.FileDir },
  1998. { "TARGET_LINKER_FILE_DIR", &targetLinkerNodeGroup.FileDir },
  1999. { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir },
  2000. { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
  2001. { "TARGET_BUNDLE_DIR", &targetBundleDirNode },
  2002. { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
  2003. { "STREQUAL", &strEqualNode },
  2004. { "EQUAL", &equalNode },
  2005. { "IN_LIST", &inListNode },
  2006. { "FILTER", &filterNode },
  2007. { "REMOVE_DUPLICATES", &removeDuplicatesNode },
  2008. { "LOWER_CASE", &lowerCaseNode },
  2009. { "UPPER_CASE", &upperCaseNode },
  2010. { "MAKE_C_IDENTIFIER", &makeCIdentifierNode },
  2011. { "BOOL", &boolNode },
  2012. { "IF", &ifNode },
  2013. { "ANGLE-R", &angle_rNode },
  2014. { "COMMA", &commaNode },
  2015. { "SEMICOLON", &semicolonNode },
  2016. { "TARGET_PROPERTY", &targetPropertyNode },
  2017. { "TARGET_NAME", &targetNameNode },
  2018. { "TARGET_OBJECTS", &targetObjectsNode },
  2019. { "TARGET_POLICY", &targetPolicyNode },
  2020. { "TARGET_EXISTS", &targetExistsNode },
  2021. { "TARGET_NAME_IF_EXISTS", &targetNameIfExistsNode },
  2022. { "TARGET_GENEX_EVAL", &targetGenexEvalNode },
  2023. { "GENEX_EVAL", &genexEvalNode },
  2024. { "BUILD_INTERFACE", &buildInterfaceNode },
  2025. { "INSTALL_INTERFACE", &installInterfaceNode },
  2026. { "INSTALL_PREFIX", &installPrefixNode },
  2027. { "JOIN", &joinNode },
  2028. { "LINK_ONLY", &linkOnlyNode },
  2029. { "COMPILE_LANG_AND_ID", &languageAndIdNode },
  2030. { "COMPILE_LANGUAGE", &languageNode },
  2031. { "SHELL_PATH", &shellPathNode }
  2032. };
  2033. {
  2034. auto itr = nodeMap.find(identifier);
  2035. if (itr != nodeMap.end()) {
  2036. return itr->second;
  2037. }
  2038. }
  2039. return nullptr;
  2040. }
  2041. void reportError(cmGeneratorExpressionContext* context,
  2042. const std::string& expr, const std::string& result)
  2043. {
  2044. context->HadError = true;
  2045. if (context->Quiet) {
  2046. return;
  2047. }
  2048. std::ostringstream e;
  2049. /* clang-format off */
  2050. e << "Error evaluating generator expression:\n"
  2051. << " " << expr << "\n"
  2052. << result;
  2053. /* clang-format on */
  2054. context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
  2055. e.str(), context->Backtrace);
  2056. }