cmGeneratorExpressionNode.cxx 81 KB

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