cmGeneratorExpressionNode.cxx 80 KB

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