cmGeneratorExpressionNode.cxx 80 KB

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