1
0

cmGeneratorExpressionNode.cxx 82 KB

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