cmGeneratorExpressionNode.cxx 81 KB

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