cmGeneratorExpressionNode.cxx 80 KB

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