cmGeneratorExpressionNode.cxx 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  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 "cmOutputConverter.h"
  15. #include "cmPolicies.h"
  16. #include "cmStateTypes.h"
  17. #include "cmSystemTools.h"
  18. #include "cmTarget.h"
  19. #include "cmake.h"
  20. #include "cmsys/RegularExpression.hxx"
  21. #include "cmsys/String.h"
  22. #include <algorithm>
  23. #include <assert.h>
  24. #include <errno.h>
  25. #include <map>
  26. #include <memory> // IWYU pragma: keep
  27. #include <set>
  28. #include <sstream>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <utility>
  32. std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
  33. std::string const& prop, cmLocalGenerator* lg,
  34. cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
  35. cmGeneratorTarget const* currentTarget,
  36. cmGeneratorExpressionDAGChecker* dagChecker)
  37. {
  38. cmGeneratorExpression ge(context->Backtrace);
  39. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  40. cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
  41. std::string result =
  42. cge->Evaluate(lg, context->Config, context->Quiet, headTarget,
  43. currentTarget, dagChecker, context->Language);
  44. if (cge->GetHadContextSensitiveCondition()) {
  45. context->HadContextSensitiveCondition = true;
  46. }
  47. if (cge->GetHadHeadSensitiveCondition()) {
  48. context->HadHeadSensitiveCondition = true;
  49. }
  50. return result;
  51. }
  52. static const struct ZeroNode : public cmGeneratorExpressionNode
  53. {
  54. ZeroNode() {}
  55. bool GeneratesContent() const override { return false; }
  56. bool AcceptsArbitraryContentParameter() const override { return true; }
  57. std::string Evaluate(
  58. const std::vector<std::string>& /*parameters*/,
  59. cmGeneratorExpressionContext* /*context*/,
  60. const GeneratorExpressionContent* /*content*/,
  61. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  62. {
  63. return std::string();
  64. }
  65. } zeroNode;
  66. static const struct OneNode : public cmGeneratorExpressionNode
  67. {
  68. OneNode() {}
  69. bool AcceptsArbitraryContentParameter() const override { return true; }
  70. std::string Evaluate(
  71. const std::vector<std::string>& parameters,
  72. cmGeneratorExpressionContext* /*context*/,
  73. const GeneratorExpressionContent* /*content*/,
  74. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  75. {
  76. return parameters.front();
  77. }
  78. } oneNode;
  79. static const struct OneNode buildInterfaceNode;
  80. static const struct ZeroNode installInterfaceNode;
  81. #define BOOLEAN_OP_NODE(OPNAME, OP, SUCCESS_VALUE, FAILURE_VALUE) \
  82. static const struct OP##Node : public cmGeneratorExpressionNode \
  83. { \
  84. OP##Node() {} \
  85. virtual int NumExpectedParameters() const { return OneOrMoreParameters; } \
  86. \
  87. std::string Evaluate(const std::vector<std::string>& parameters, \
  88. cmGeneratorExpressionContext* context, \
  89. const GeneratorExpressionContent* content, \
  90. cmGeneratorExpressionDAGChecker*) const \
  91. { \
  92. std::vector<std::string>::const_iterator it = parameters.begin(); \
  93. const std::vector<std::string>::const_iterator end = parameters.end(); \
  94. for (; it != end; ++it) { \
  95. if (*it == #FAILURE_VALUE) { \
  96. return #FAILURE_VALUE; \
  97. } \
  98. if (*it != #SUCCESS_VALUE) { \
  99. reportError(context, content->GetOriginalExpression(), \
  100. "Parameters to $<" #OP \
  101. "> must resolve to either '0' or '1'."); \
  102. return std::string(); \
  103. } \
  104. } \
  105. return #SUCCESS_VALUE; \
  106. } \
  107. } OPNAME;
  108. BOOLEAN_OP_NODE(andNode, AND, 1, 0)
  109. BOOLEAN_OP_NODE(orNode, OR, 0, 1)
  110. #undef BOOLEAN_OP_NODE
  111. static const struct NotNode : public cmGeneratorExpressionNode
  112. {
  113. NotNode() {}
  114. std::string Evaluate(
  115. const std::vector<std::string>& parameters,
  116. cmGeneratorExpressionContext* context,
  117. const GeneratorExpressionContent* content,
  118. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  119. {
  120. if (*parameters.begin() != "0" && *parameters.begin() != "1") {
  121. reportError(
  122. context, content->GetOriginalExpression(),
  123. "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
  124. return std::string();
  125. }
  126. return *parameters.begin() == "0" ? "1" : "0";
  127. }
  128. } notNode;
  129. static const struct BoolNode : public cmGeneratorExpressionNode
  130. {
  131. BoolNode() {}
  132. int NumExpectedParameters() const override { return 1; }
  133. std::string Evaluate(
  134. const std::vector<std::string>& parameters,
  135. cmGeneratorExpressionContext* /*context*/,
  136. const GeneratorExpressionContent* /*content*/,
  137. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  138. {
  139. return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
  140. }
  141. } boolNode;
  142. static const struct IfNode : public cmGeneratorExpressionNode
  143. {
  144. IfNode() {}
  145. int NumExpectedParameters() const override { return 3; }
  146. std::string Evaluate(const std::vector<std::string>& parameters,
  147. cmGeneratorExpressionContext* context,
  148. const GeneratorExpressionContent* content,
  149. cmGeneratorExpressionDAGChecker*) const override
  150. {
  151. if (parameters[0] != "1" && parameters[0] != "0") {
  152. reportError(context, content->GetOriginalExpression(),
  153. "First parameter to $<IF> must resolve to exactly one '0' "
  154. "or '1' value.");
  155. return std::string();
  156. }
  157. return parameters[0] == "1" ? parameters[1] : parameters[2];
  158. }
  159. } ifNode;
  160. static const struct StrEqualNode : public cmGeneratorExpressionNode
  161. {
  162. StrEqualNode() {}
  163. int NumExpectedParameters() const override { return 2; }
  164. std::string Evaluate(
  165. const std::vector<std::string>& parameters,
  166. cmGeneratorExpressionContext* /*context*/,
  167. const GeneratorExpressionContent* /*content*/,
  168. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  169. {
  170. return *parameters.begin() == parameters[1] ? "1" : "0";
  171. }
  172. } strEqualNode;
  173. static const struct EqualNode : public cmGeneratorExpressionNode
  174. {
  175. EqualNode() {}
  176. int NumExpectedParameters() const override { return 2; }
  177. std::string Evaluate(
  178. const std::vector<std::string>& parameters,
  179. cmGeneratorExpressionContext* context,
  180. const GeneratorExpressionContent* content,
  181. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  182. {
  183. char* pEnd;
  184. int base = 0;
  185. bool flipSign = false;
  186. const char* lhs = parameters[0].c_str();
  187. if (cmHasLiteralPrefix(lhs, "0b") || cmHasLiteralPrefix(lhs, "0B")) {
  188. base = 2;
  189. lhs += 2;
  190. }
  191. if (cmHasLiteralPrefix(lhs, "-0b") || cmHasLiteralPrefix(lhs, "-0B")) {
  192. base = 2;
  193. lhs += 3;
  194. flipSign = true;
  195. }
  196. if (cmHasLiteralPrefix(lhs, "+0b") || cmHasLiteralPrefix(lhs, "+0B")) {
  197. base = 2;
  198. lhs += 3;
  199. }
  200. long lnum = strtol(lhs, &pEnd, base);
  201. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  202. reportError(context, content->GetOriginalExpression(),
  203. "$<EQUAL> parameter " + parameters[0] +
  204. " is not a valid integer.");
  205. return std::string();
  206. }
  207. if (flipSign) {
  208. lnum = -lnum;
  209. }
  210. base = 0;
  211. flipSign = false;
  212. const char* rhs = parameters[1].c_str();
  213. if (cmHasLiteralPrefix(rhs, "0b") || cmHasLiteralPrefix(rhs, "0B")) {
  214. base = 2;
  215. rhs += 2;
  216. }
  217. if (cmHasLiteralPrefix(rhs, "-0b") || cmHasLiteralPrefix(rhs, "-0B")) {
  218. base = 2;
  219. rhs += 3;
  220. flipSign = true;
  221. }
  222. if (cmHasLiteralPrefix(rhs, "+0b") || cmHasLiteralPrefix(rhs, "+0B")) {
  223. base = 2;
  224. rhs += 3;
  225. }
  226. long rnum = strtol(rhs, &pEnd, base);
  227. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  228. reportError(context, content->GetOriginalExpression(),
  229. "$<EQUAL> parameter " + parameters[1] +
  230. " is not a valid integer.");
  231. return std::string();
  232. }
  233. if (flipSign) {
  234. rnum = -rnum;
  235. }
  236. return lnum == rnum ? "1" : "0";
  237. }
  238. } equalNode;
  239. static const struct LowerCaseNode : public cmGeneratorExpressionNode
  240. {
  241. LowerCaseNode() {}
  242. bool AcceptsArbitraryContentParameter() const override { return true; }
  243. std::string Evaluate(
  244. const std::vector<std::string>& parameters,
  245. cmGeneratorExpressionContext* /*context*/,
  246. const GeneratorExpressionContent* /*content*/,
  247. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  248. {
  249. return cmSystemTools::LowerCase(parameters.front());
  250. }
  251. } lowerCaseNode;
  252. static const struct UpperCaseNode : public cmGeneratorExpressionNode
  253. {
  254. UpperCaseNode() {}
  255. bool AcceptsArbitraryContentParameter() const override { return true; }
  256. std::string Evaluate(
  257. const std::vector<std::string>& parameters,
  258. cmGeneratorExpressionContext* /*context*/,
  259. const GeneratorExpressionContent* /*content*/,
  260. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  261. {
  262. return cmSystemTools::UpperCase(parameters.front());
  263. }
  264. } upperCaseNode;
  265. static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
  266. {
  267. MakeCIdentifierNode() {}
  268. bool AcceptsArbitraryContentParameter() const override { return true; }
  269. std::string Evaluate(
  270. const std::vector<std::string>& parameters,
  271. cmGeneratorExpressionContext* /*context*/,
  272. const GeneratorExpressionContent* /*content*/,
  273. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  274. {
  275. return cmSystemTools::MakeCidentifier(parameters.front());
  276. }
  277. } makeCIdentifierNode;
  278. static const struct Angle_RNode : public cmGeneratorExpressionNode
  279. {
  280. Angle_RNode() {}
  281. int NumExpectedParameters() const override { return 0; }
  282. std::string Evaluate(
  283. const std::vector<std::string>& /*parameters*/,
  284. cmGeneratorExpressionContext* /*context*/,
  285. const GeneratorExpressionContent* /*content*/,
  286. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  287. {
  288. return ">";
  289. }
  290. } angle_rNode;
  291. static const struct CommaNode : public cmGeneratorExpressionNode
  292. {
  293. CommaNode() {}
  294. int NumExpectedParameters() const override { return 0; }
  295. std::string Evaluate(
  296. const std::vector<std::string>& /*parameters*/,
  297. cmGeneratorExpressionContext* /*context*/,
  298. const GeneratorExpressionContent* /*content*/,
  299. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  300. {
  301. return ",";
  302. }
  303. } commaNode;
  304. static const struct SemicolonNode : public cmGeneratorExpressionNode
  305. {
  306. SemicolonNode() {}
  307. int NumExpectedParameters() const override { return 0; }
  308. std::string Evaluate(
  309. const std::vector<std::string>& /*parameters*/,
  310. cmGeneratorExpressionContext* /*context*/,
  311. const GeneratorExpressionContent* /*content*/,
  312. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  313. {
  314. return ";";
  315. }
  316. } semicolonNode;
  317. struct CompilerIdNode : public cmGeneratorExpressionNode
  318. {
  319. CompilerIdNode() {}
  320. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  321. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  322. cmGeneratorExpressionContext* context,
  323. const GeneratorExpressionContent* content,
  324. cmGeneratorExpressionDAGChecker* /*unused*/,
  325. const std::string& lang) const
  326. {
  327. const char* compilerId = context->LG->GetMakefile()->GetSafeDefinition(
  328. "CMAKE_" + lang + "_COMPILER_ID");
  329. if (parameters.empty()) {
  330. return compilerId ? compilerId : "";
  331. }
  332. static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
  333. if (!compilerIdValidator.find(*parameters.begin())) {
  334. reportError(context, content->GetOriginalExpression(),
  335. "Expression syntax not recognized.");
  336. return std::string();
  337. }
  338. if (!compilerId) {
  339. return parameters.front().empty() ? "1" : "0";
  340. }
  341. if (strcmp(parameters.begin()->c_str(), compilerId) == 0) {
  342. return "1";
  343. }
  344. if (cmsysString_strcasecmp(parameters.begin()->c_str(), compilerId) == 0) {
  345. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
  346. case cmPolicies::WARN: {
  347. std::ostringstream e;
  348. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
  349. context->LG->GetCMakeInstance()->IssueMessage(
  350. cmake::AUTHOR_WARNING, e.str(), context->Backtrace);
  351. CM_FALLTHROUGH;
  352. }
  353. case cmPolicies::OLD:
  354. return "1";
  355. case cmPolicies::NEW:
  356. case cmPolicies::REQUIRED_ALWAYS:
  357. case cmPolicies::REQUIRED_IF_USED:
  358. break;
  359. }
  360. }
  361. return "0";
  362. }
  363. };
  364. static const struct CCompilerIdNode : public CompilerIdNode
  365. {
  366. CCompilerIdNode() {}
  367. std::string Evaluate(
  368. const std::vector<std::string>& parameters,
  369. cmGeneratorExpressionContext* context,
  370. const GeneratorExpressionContent* content,
  371. cmGeneratorExpressionDAGChecker* dagChecker) const override
  372. {
  373. if (!context->HeadTarget) {
  374. reportError(
  375. context, content->GetOriginalExpression(),
  376. "$<C_COMPILER_ID> may only be used with binary targets. It may "
  377. "not be used with add_custom_command or add_custom_target.");
  378. return std::string();
  379. }
  380. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  381. "C");
  382. }
  383. } cCompilerIdNode;
  384. static const struct CXXCompilerIdNode : public CompilerIdNode
  385. {
  386. CXXCompilerIdNode() {}
  387. std::string Evaluate(
  388. const std::vector<std::string>& parameters,
  389. cmGeneratorExpressionContext* context,
  390. const GeneratorExpressionContent* content,
  391. cmGeneratorExpressionDAGChecker* dagChecker) const override
  392. {
  393. if (!context->HeadTarget) {
  394. reportError(
  395. context, content->GetOriginalExpression(),
  396. "$<CXX_COMPILER_ID> may only be used with binary targets. It may "
  397. "not be used with add_custom_command or add_custom_target.");
  398. return std::string();
  399. }
  400. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  401. "CXX");
  402. }
  403. } cxxCompilerIdNode;
  404. struct CompilerVersionNode : public cmGeneratorExpressionNode
  405. {
  406. CompilerVersionNode() {}
  407. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  408. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  409. cmGeneratorExpressionContext* context,
  410. const GeneratorExpressionContent* content,
  411. cmGeneratorExpressionDAGChecker* /*unused*/,
  412. const std::string& lang) const
  413. {
  414. const char* compilerVersion =
  415. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
  416. "_COMPILER_VERSION");
  417. if (parameters.empty()) {
  418. return compilerVersion ? compilerVersion : "";
  419. }
  420. static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
  421. if (!compilerIdValidator.find(*parameters.begin())) {
  422. reportError(context, content->GetOriginalExpression(),
  423. "Expression syntax not recognized.");
  424. return std::string();
  425. }
  426. if (!compilerVersion) {
  427. return parameters.front().empty() ? "1" : "0";
  428. }
  429. return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
  430. parameters.begin()->c_str(),
  431. compilerVersion)
  432. ? "1"
  433. : "0";
  434. }
  435. };
  436. static const struct CCompilerVersionNode : public CompilerVersionNode
  437. {
  438. CCompilerVersionNode() {}
  439. std::string Evaluate(
  440. const std::vector<std::string>& parameters,
  441. cmGeneratorExpressionContext* context,
  442. const GeneratorExpressionContent* content,
  443. cmGeneratorExpressionDAGChecker* dagChecker) const override
  444. {
  445. if (!context->HeadTarget) {
  446. reportError(
  447. context, content->GetOriginalExpression(),
  448. "$<C_COMPILER_VERSION> may only be used with binary targets. It "
  449. "may not be used with add_custom_command or add_custom_target.");
  450. return std::string();
  451. }
  452. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  453. "C");
  454. }
  455. } cCompilerVersionNode;
  456. static const struct CxxCompilerVersionNode : public CompilerVersionNode
  457. {
  458. CxxCompilerVersionNode() {}
  459. std::string Evaluate(
  460. const std::vector<std::string>& parameters,
  461. cmGeneratorExpressionContext* context,
  462. const GeneratorExpressionContent* content,
  463. cmGeneratorExpressionDAGChecker* dagChecker) const override
  464. {
  465. if (!context->HeadTarget) {
  466. reportError(
  467. context, content->GetOriginalExpression(),
  468. "$<CXX_COMPILER_VERSION> may only be used with binary targets. It "
  469. "may not be used with add_custom_command or add_custom_target.");
  470. return std::string();
  471. }
  472. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  473. "CXX");
  474. }
  475. } cxxCompilerVersionNode;
  476. struct PlatformIdNode : public cmGeneratorExpressionNode
  477. {
  478. PlatformIdNode() {}
  479. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  480. std::string Evaluate(
  481. const std::vector<std::string>& parameters,
  482. cmGeneratorExpressionContext* context,
  483. const GeneratorExpressionContent* /*content*/,
  484. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  485. {
  486. const char* platformId =
  487. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  488. if (parameters.empty()) {
  489. return platformId ? platformId : "";
  490. }
  491. if (!platformId) {
  492. return parameters.front().empty() ? "1" : "0";
  493. }
  494. if (strcmp(parameters.begin()->c_str(), platformId) == 0) {
  495. return "1";
  496. }
  497. return "0";
  498. }
  499. } platformIdNode;
  500. static const struct VersionGreaterNode : public cmGeneratorExpressionNode
  501. {
  502. VersionGreaterNode() {}
  503. int NumExpectedParameters() const override { return 2; }
  504. std::string Evaluate(
  505. const std::vector<std::string>& parameters,
  506. cmGeneratorExpressionContext* /*context*/,
  507. const GeneratorExpressionContent* /*content*/,
  508. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  509. {
  510. return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER,
  511. parameters.front().c_str(),
  512. parameters[1].c_str())
  513. ? "1"
  514. : "0";
  515. }
  516. } versionGreaterNode;
  517. static const struct VersionGreaterEqNode : public cmGeneratorExpressionNode
  518. {
  519. VersionGreaterEqNode() {}
  520. int NumExpectedParameters() const override { return 2; }
  521. std::string Evaluate(
  522. const std::vector<std::string>& parameters,
  523. cmGeneratorExpressionContext* /*context*/,
  524. const GeneratorExpressionContent* /*content*/,
  525. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  526. {
  527. return cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
  528. parameters.front().c_str(),
  529. parameters[1].c_str())
  530. ? "1"
  531. : "0";
  532. }
  533. } versionGreaterEqNode;
  534. static const struct VersionLessNode : public cmGeneratorExpressionNode
  535. {
  536. VersionLessNode() {}
  537. int NumExpectedParameters() const override { return 2; }
  538. std::string Evaluate(
  539. const std::vector<std::string>& parameters,
  540. cmGeneratorExpressionContext* /*context*/,
  541. const GeneratorExpressionContent* /*content*/,
  542. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  543. {
  544. return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS,
  545. parameters.front().c_str(),
  546. parameters[1].c_str())
  547. ? "1"
  548. : "0";
  549. }
  550. } versionLessNode;
  551. static const struct VersionLessEqNode : public cmGeneratorExpressionNode
  552. {
  553. VersionLessEqNode() {}
  554. int NumExpectedParameters() const override { return 2; }
  555. std::string Evaluate(
  556. const std::vector<std::string>& parameters,
  557. cmGeneratorExpressionContext* /*context*/,
  558. const GeneratorExpressionContent* /*content*/,
  559. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  560. {
  561. return cmSystemTools::VersionCompare(cmSystemTools::OP_LESS_EQUAL,
  562. parameters.front().c_str(),
  563. parameters[1].c_str())
  564. ? "1"
  565. : "0";
  566. }
  567. } versionLessEqNode;
  568. static const struct VersionEqualNode : public cmGeneratorExpressionNode
  569. {
  570. VersionEqualNode() {}
  571. int NumExpectedParameters() const override { return 2; }
  572. std::string Evaluate(
  573. const std::vector<std::string>& parameters,
  574. cmGeneratorExpressionContext* /*context*/,
  575. const GeneratorExpressionContent* /*content*/,
  576. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  577. {
  578. return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
  579. parameters.front().c_str(),
  580. parameters[1].c_str())
  581. ? "1"
  582. : "0";
  583. }
  584. } versionEqualNode;
  585. static const struct LinkOnlyNode : public cmGeneratorExpressionNode
  586. {
  587. LinkOnlyNode() {}
  588. std::string Evaluate(
  589. const std::vector<std::string>& parameters,
  590. cmGeneratorExpressionContext* context,
  591. const GeneratorExpressionContent* content,
  592. cmGeneratorExpressionDAGChecker* dagChecker) const override
  593. {
  594. if (!dagChecker) {
  595. reportError(context, content->GetOriginalExpression(),
  596. "$<LINK_ONLY:...> may only be used for linking");
  597. return std::string();
  598. }
  599. if (!dagChecker->GetTransitivePropertiesOnly()) {
  600. return parameters.front();
  601. }
  602. return std::string();
  603. }
  604. } linkOnlyNode;
  605. static const struct ConfigurationNode : public cmGeneratorExpressionNode
  606. {
  607. ConfigurationNode() {}
  608. int NumExpectedParameters() const override { return 0; }
  609. std::string Evaluate(
  610. const std::vector<std::string>& /*parameters*/,
  611. cmGeneratorExpressionContext* context,
  612. const GeneratorExpressionContent* /*content*/,
  613. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  614. {
  615. context->HadContextSensitiveCondition = true;
  616. return context->Config;
  617. }
  618. } configurationNode;
  619. static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
  620. {
  621. ConfigurationTestNode() {}
  622. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  623. std::string Evaluate(
  624. const std::vector<std::string>& parameters,
  625. cmGeneratorExpressionContext* context,
  626. const GeneratorExpressionContent* content,
  627. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  628. {
  629. if (parameters.empty()) {
  630. return configurationNode.Evaluate(parameters, context, content, nullptr);
  631. }
  632. static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
  633. if (!configValidator.find(*parameters.begin())) {
  634. reportError(context, content->GetOriginalExpression(),
  635. "Expression syntax not recognized.");
  636. return std::string();
  637. }
  638. context->HadContextSensitiveCondition = true;
  639. if (context->Config.empty()) {
  640. return parameters.front().empty() ? "1" : "0";
  641. }
  642. if (cmsysString_strcasecmp(parameters.begin()->c_str(),
  643. context->Config.c_str()) == 0) {
  644. return "1";
  645. }
  646. if (context->CurrentTarget && context->CurrentTarget->IsImported()) {
  647. const char* loc = nullptr;
  648. const char* imp = nullptr;
  649. std::string suffix;
  650. if (context->CurrentTarget->Target->GetMappedConfig(
  651. context->Config, &loc, &imp, suffix)) {
  652. // This imported target has an appropriate location
  653. // for this (possibly mapped) config.
  654. // Check if there is a proper config mapping for the tested config.
  655. std::vector<std::string> mappedConfigs;
  656. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  657. mapProp += cmSystemTools::UpperCase(context->Config);
  658. if (const char* mapValue =
  659. context->CurrentTarget->GetProperty(mapProp)) {
  660. cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
  661. mappedConfigs);
  662. return std::find(mappedConfigs.begin(), mappedConfigs.end(),
  663. cmSystemTools::UpperCase(parameters.front())) !=
  664. mappedConfigs.end()
  665. ? "1"
  666. : "0";
  667. }
  668. }
  669. }
  670. return "0";
  671. }
  672. } configurationTestNode;
  673. static const struct JoinNode : public cmGeneratorExpressionNode
  674. {
  675. JoinNode() {}
  676. int NumExpectedParameters() const override { return 2; }
  677. bool AcceptsArbitraryContentParameter() const override { return true; }
  678. std::string Evaluate(
  679. const std::vector<std::string>& parameters,
  680. cmGeneratorExpressionContext* /*context*/,
  681. const GeneratorExpressionContent* /*content*/,
  682. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  683. {
  684. std::vector<std::string> list;
  685. cmSystemTools::ExpandListArgument(parameters.front(), list);
  686. return cmJoin(list, parameters[1]);
  687. }
  688. } joinNode;
  689. static const struct CompileLanguageNode : public cmGeneratorExpressionNode
  690. {
  691. CompileLanguageNode() {}
  692. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  693. std::string Evaluate(
  694. const std::vector<std::string>& parameters,
  695. cmGeneratorExpressionContext* context,
  696. const GeneratorExpressionContent* content,
  697. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  698. {
  699. if (context->Language.empty()) {
  700. reportError(
  701. context, content->GetOriginalExpression(),
  702. "$<COMPILE_LANGUAGE:...> may only be used to specify include "
  703. "directories, compile definitions, compile options, and to evaluate "
  704. "components of the file(GENERATE) command.");
  705. return std::string();
  706. }
  707. std::vector<std::string> enabledLanguages;
  708. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  709. gg->GetEnabledLanguages(enabledLanguages);
  710. if (!parameters.empty() &&
  711. std::find(enabledLanguages.begin(), enabledLanguages.end(),
  712. parameters.front()) == enabledLanguages.end()) {
  713. reportError(context, content->GetOriginalExpression(),
  714. "$<COMPILE_LANGUAGE:...> Unknown language.");
  715. return std::string();
  716. }
  717. std::string genName = gg->GetName();
  718. if (genName.find("Makefiles") == std::string::npos &&
  719. genName.find("Ninja") == std::string::npos &&
  720. genName.find("Visual Studio") == std::string::npos &&
  721. genName.find("Xcode") == std::string::npos &&
  722. genName.find("Watcom WMake") == std::string::npos) {
  723. reportError(context, content->GetOriginalExpression(),
  724. "$<COMPILE_LANGUAGE:...> not supported for this generator.");
  725. return std::string();
  726. }
  727. if (parameters.empty()) {
  728. return context->Language;
  729. }
  730. return context->Language == parameters.front() ? "1" : "0";
  731. }
  732. } languageNode;
  733. #define TRANSITIVE_PROPERTY_NAME(PROPERTY) , "INTERFACE_" #PROPERTY
  734. static const char* targetPropertyTransitiveWhitelist[] = {
  735. nullptr CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
  736. };
  737. #undef TRANSITIVE_PROPERTY_NAME
  738. template <typename T>
  739. std::string getLinkedTargetsContent(
  740. std::vector<T> const& libraries, cmGeneratorTarget const* target,
  741. cmGeneratorTarget const* headTarget, cmGeneratorExpressionContext* context,
  742. cmGeneratorExpressionDAGChecker* dagChecker,
  743. const std::string& interfacePropertyName)
  744. {
  745. std::string linkedTargetsContent;
  746. std::string sep;
  747. std::string depString;
  748. for (T const& l : libraries) {
  749. // Broken code can have a target in its own link interface.
  750. // Don't follow such link interface entries so as not to create a
  751. // self-referencing loop.
  752. if (l.Target && l.Target != target) {
  753. depString += sep + "$<TARGET_PROPERTY:" + l.Target->GetName() + "," +
  754. interfacePropertyName + ">";
  755. sep = ";";
  756. }
  757. }
  758. if (!depString.empty()) {
  759. linkedTargetsContent =
  760. cmGeneratorExpressionNode::EvaluateDependentExpression(
  761. depString, target->GetLocalGenerator(), context, headTarget, target,
  762. dagChecker);
  763. }
  764. linkedTargetsContent =
  765. cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);
  766. return linkedTargetsContent;
  767. }
  768. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  769. {
  770. TargetPropertyNode() {}
  771. // This node handles errors on parameter count itself.
  772. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  773. std::string Evaluate(
  774. const std::vector<std::string>& parameters,
  775. cmGeneratorExpressionContext* context,
  776. const GeneratorExpressionContent* content,
  777. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  778. {
  779. if (parameters.size() != 1 && parameters.size() != 2) {
  780. reportError(
  781. context, content->GetOriginalExpression(),
  782. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  783. return std::string();
  784. }
  785. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  786. cmGeneratorTarget const* target = context->HeadTarget;
  787. std::string propertyName = *parameters.begin();
  788. if (parameters.size() == 1) {
  789. context->HadHeadSensitiveCondition = true;
  790. }
  791. if (!target && parameters.size() == 1) {
  792. reportError(
  793. context, content->GetOriginalExpression(),
  794. "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
  795. "It may not be used with add_custom_command or add_custom_target. "
  796. "Specify the target to read a property from using the "
  797. "$<TARGET_PROPERTY:tgt,prop> signature instead.");
  798. return std::string();
  799. }
  800. if (parameters.size() == 2) {
  801. if (parameters.begin()->empty() && parameters[1].empty()) {
  802. reportError(
  803. context, content->GetOriginalExpression(),
  804. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  805. "target name and property name.");
  806. return std::string();
  807. }
  808. if (parameters.begin()->empty()) {
  809. reportError(
  810. context, content->GetOriginalExpression(),
  811. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  812. "target name.");
  813. return std::string();
  814. }
  815. std::string targetName = parameters.front();
  816. propertyName = parameters[1];
  817. if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
  818. if (!propertyNameValidator.find(propertyName.c_str())) {
  819. ::reportError(context, content->GetOriginalExpression(),
  820. "Target name and property name not supported.");
  821. return std::string();
  822. }
  823. ::reportError(context, content->GetOriginalExpression(),
  824. "Target name not supported.");
  825. return std::string();
  826. }
  827. static const std::string propALIASED_TARGET = "ALIASED_TARGET";
  828. if (propertyName == propALIASED_TARGET) {
  829. if (context->LG->GetMakefile()->IsAlias(targetName)) {
  830. if (cmGeneratorTarget* tgt =
  831. context->LG->FindGeneratorTargetToUse(targetName)) {
  832. return tgt->GetName();
  833. }
  834. }
  835. return "";
  836. }
  837. target = context->LG->FindGeneratorTargetToUse(targetName);
  838. if (!target) {
  839. std::ostringstream e;
  840. e << "Target \"" << targetName << "\" not found.";
  841. reportError(context, content->GetOriginalExpression(), e.str());
  842. return std::string();
  843. }
  844. context->AllTargets.insert(target);
  845. }
  846. if (target == context->HeadTarget) {
  847. // Keep track of the properties seen while processing.
  848. // The evaluation of the LINK_LIBRARIES generator expressions
  849. // will check this to ensure that properties have one consistent
  850. // value for all evaluations.
  851. context->SeenTargetProperties.insert(propertyName);
  852. }
  853. if (propertyName == "SOURCES") {
  854. context->SourceSensitiveTargets.insert(target);
  855. }
  856. if (propertyName.empty()) {
  857. reportError(
  858. context, content->GetOriginalExpression(),
  859. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  860. "name.");
  861. return std::string();
  862. }
  863. if (!propertyNameValidator.find(propertyName)) {
  864. ::reportError(context, content->GetOriginalExpression(),
  865. "Property name not supported.");
  866. return std::string();
  867. }
  868. assert(target);
  869. if (propertyName == "LINKER_LANGUAGE") {
  870. if (target->LinkLanguagePropagatesToDependents() && dagCheckerParent &&
  871. (dagCheckerParent->EvaluatingLinkLibraries() ||
  872. dagCheckerParent->EvaluatingSources())) {
  873. reportError(
  874. context, content->GetOriginalExpression(),
  875. "LINKER_LANGUAGE target property can not be used while evaluating "
  876. "link libraries for a static library");
  877. return std::string();
  878. }
  879. return target->GetLinkerLanguage(context->Config);
  880. }
  881. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
  882. target->GetName(), propertyName,
  883. content, dagCheckerParent);
  884. switch (dagChecker.Check()) {
  885. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  886. dagChecker.ReportError(context, content->GetOriginalExpression());
  887. return std::string();
  888. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  889. // No error. We just skip cyclic references.
  890. return std::string();
  891. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  892. for (size_t i = 1; i < cm::size(targetPropertyTransitiveWhitelist);
  893. ++i) {
  894. if (targetPropertyTransitiveWhitelist[i] == propertyName) {
  895. // No error. We're not going to find anything new here.
  896. return std::string();
  897. }
  898. }
  899. case cmGeneratorExpressionDAGChecker::DAG:
  900. break;
  901. }
  902. const char* prop = target->GetProperty(propertyName);
  903. if (dagCheckerParent) {
  904. if (dagCheckerParent->EvaluatingLinkLibraries()) {
  905. #define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \
  906. (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
  907. if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(
  908. TRANSITIVE_PROPERTY_COMPARE) false) { // NOLINT(clang-tidy)
  909. reportError(
  910. context, content->GetOriginalExpression(),
  911. "$<TARGET_PROPERTY:...> expression in link libraries "
  912. "evaluation depends on target property which is transitive "
  913. "over the link libraries, creating a recursion.");
  914. return std::string();
  915. }
  916. #undef TRANSITIVE_PROPERTY_COMPARE
  917. if (!prop) {
  918. return std::string();
  919. }
  920. } else {
  921. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
  922. assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  923. ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy)
  924. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  925. }
  926. }
  927. std::string linkedTargetsContent;
  928. std::string interfacePropertyName;
  929. bool isInterfaceProperty = false;
  930. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  931. if (propertyName == #prop) { \
  932. interfacePropertyName = "INTERFACE_" #prop; \
  933. } else if (propertyName == "INTERFACE_" #prop) { \
  934. interfacePropertyName = "INTERFACE_" #prop; \
  935. isInterfaceProperty = true; \
  936. } else
  937. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  938. // Note that the above macro terminates with an else
  939. /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
  940. cmPolicies::PolicyStatus polSt =
  941. context->LG->GetPolicyStatus(cmPolicies::CMP0043);
  942. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  943. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  944. }
  945. }
  946. #undef POPULATE_INTERFACE_PROPERTY_NAME
  947. cmGeneratorTarget const* headTarget =
  948. context->HeadTarget && isInterfaceProperty ? context->HeadTarget
  949. : target;
  950. if (isInterfaceProperty) {
  951. if (cmLinkInterfaceLibraries const* iface =
  952. target->GetLinkInterfaceLibraries(context->Config, headTarget,
  953. true)) {
  954. linkedTargetsContent =
  955. getLinkedTargetsContent(iface->Libraries, target, headTarget,
  956. context, &dagChecker, interfacePropertyName);
  957. }
  958. } else if (!interfacePropertyName.empty()) {
  959. if (cmLinkImplementationLibraries const* impl =
  960. target->GetLinkImplementationLibraries(context->Config)) {
  961. linkedTargetsContent =
  962. getLinkedTargetsContent(impl->Libraries, target, target, context,
  963. &dagChecker, interfacePropertyName);
  964. }
  965. }
  966. if (!prop) {
  967. if (target->IsImported() ||
  968. target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  969. return linkedTargetsContent;
  970. }
  971. if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
  972. context->Config)) {
  973. context->HadContextSensitiveCondition = true;
  974. return target->GetLinkInterfaceDependentBoolProperty(propertyName,
  975. context->Config)
  976. ? "1"
  977. : "0";
  978. }
  979. if (target->IsLinkInterfaceDependentStringProperty(propertyName,
  980. context->Config)) {
  981. context->HadContextSensitiveCondition = true;
  982. const char* propContent =
  983. target->GetLinkInterfaceDependentStringProperty(propertyName,
  984. context->Config);
  985. return propContent ? propContent : "";
  986. }
  987. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  988. context->Config)) {
  989. context->HadContextSensitiveCondition = true;
  990. const char* propContent =
  991. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  992. context->Config);
  993. return propContent ? propContent : "";
  994. }
  995. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  996. context->Config)) {
  997. context->HadContextSensitiveCondition = true;
  998. const char* propContent =
  999. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1000. context->Config);
  1001. return propContent ? propContent : "";
  1002. }
  1003. return linkedTargetsContent;
  1004. }
  1005. if (!target->IsImported() && dagCheckerParent &&
  1006. !dagCheckerParent->EvaluatingLinkLibraries()) {
  1007. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1008. context->Config)) {
  1009. context->HadContextSensitiveCondition = true;
  1010. const char* propContent =
  1011. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1012. context->Config);
  1013. return propContent ? propContent : "";
  1014. }
  1015. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1016. context->Config)) {
  1017. context->HadContextSensitiveCondition = true;
  1018. const char* propContent =
  1019. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1020. context->Config);
  1021. return propContent ? propContent : "";
  1022. }
  1023. }
  1024. if (!interfacePropertyName.empty()) {
  1025. std::string result = this->EvaluateDependentExpression(
  1026. prop, context->LG, context, headTarget, target, &dagChecker);
  1027. if (!linkedTargetsContent.empty()) {
  1028. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1029. }
  1030. return result;
  1031. }
  1032. return prop;
  1033. }
  1034. } targetPropertyNode;
  1035. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1036. {
  1037. TargetNameNode() {}
  1038. bool GeneratesContent() const override { return true; }
  1039. bool AcceptsArbitraryContentParameter() const override { return true; }
  1040. bool RequiresLiteralInput() const override { return true; }
  1041. std::string Evaluate(
  1042. const std::vector<std::string>& parameters,
  1043. cmGeneratorExpressionContext* /*context*/,
  1044. const GeneratorExpressionContent* /*content*/,
  1045. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1046. {
  1047. return parameters.front();
  1048. }
  1049. int NumExpectedParameters() const override { return 1; }
  1050. } targetNameNode;
  1051. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1052. {
  1053. TargetObjectsNode() {}
  1054. std::string Evaluate(
  1055. const std::vector<std::string>& parameters,
  1056. cmGeneratorExpressionContext* context,
  1057. const GeneratorExpressionContent* content,
  1058. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1059. {
  1060. std::string tgtName = parameters.front();
  1061. cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
  1062. if (!gt) {
  1063. std::ostringstream e;
  1064. e << "Objects of target \"" << tgtName
  1065. << "\" referenced but no such target exists.";
  1066. reportError(context, content->GetOriginalExpression(), e.str());
  1067. return std::string();
  1068. }
  1069. if (gt->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1070. std::ostringstream e;
  1071. e << "Objects of target \"" << tgtName
  1072. << "\" referenced but is not an OBJECT library.";
  1073. reportError(context, content->GetOriginalExpression(), e.str());
  1074. return std::string();
  1075. }
  1076. if (!context->EvaluateForBuildsystem) {
  1077. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  1078. std::string reason;
  1079. if (!gg->HasKnownObjectFileLocation(&reason)) {
  1080. std::ostringstream e;
  1081. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1082. "is only suitable for consumption by CMake (limited"
  1083. << reason << "). "
  1084. "It is not suitable for writing out elsewhere.";
  1085. reportError(context, content->GetOriginalExpression(), e.str());
  1086. return std::string();
  1087. }
  1088. }
  1089. std::vector<std::string> objects;
  1090. if (gt->IsImported()) {
  1091. const char* loc = nullptr;
  1092. const char* imp = nullptr;
  1093. std::string suffix;
  1094. if (gt->Target->GetMappedConfig(context->Config, &loc, &imp, suffix)) {
  1095. cmSystemTools::ExpandListArgument(loc, objects);
  1096. }
  1097. context->HadContextSensitiveCondition = true;
  1098. } else {
  1099. gt->GetTargetObjectNames(context->Config, objects);
  1100. std::string obj_dir;
  1101. if (context->EvaluateForBuildsystem) {
  1102. // Use object file directory with buildsystem placeholder.
  1103. obj_dir = gt->ObjectDirectory;
  1104. // Here we assume that the set of object files produced
  1105. // by an object library does not vary with configuration
  1106. // and do not set HadContextSensitiveCondition to true.
  1107. } else {
  1108. // Use object file directory with per-config location.
  1109. obj_dir = gt->GetObjectDirectory(context->Config);
  1110. context->HadContextSensitiveCondition = true;
  1111. }
  1112. for (std::string& o : objects) {
  1113. o = obj_dir + o;
  1114. }
  1115. }
  1116. // Create the cmSourceFile instances in the referencing directory.
  1117. cmMakefile* mf = context->LG->GetMakefile();
  1118. for (std::string& o : objects) {
  1119. mf->AddTargetObject(tgtName, o);
  1120. }
  1121. return cmJoin(objects, ";");
  1122. }
  1123. } targetObjectsNode;
  1124. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1125. {
  1126. CompileFeaturesNode() {}
  1127. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  1128. std::string Evaluate(
  1129. const std::vector<std::string>& parameters,
  1130. cmGeneratorExpressionContext* context,
  1131. const GeneratorExpressionContent* content,
  1132. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1133. {
  1134. cmGeneratorTarget const* target = context->HeadTarget;
  1135. if (!target) {
  1136. reportError(
  1137. context, content->GetOriginalExpression(),
  1138. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1139. "not be used with add_custom_command or add_custom_target.");
  1140. return std::string();
  1141. }
  1142. context->HadHeadSensitiveCondition = true;
  1143. typedef std::map<std::string, std::vector<std::string>> LangMap;
  1144. static LangMap availableFeatures;
  1145. LangMap testedFeatures;
  1146. for (std::string const& p : parameters) {
  1147. std::string error;
  1148. std::string lang;
  1149. if (!context->LG->GetMakefile()->CompileFeatureKnown(
  1150. context->HeadTarget->Target, p, lang, &error)) {
  1151. reportError(context, content->GetOriginalExpression(), error);
  1152. return std::string();
  1153. }
  1154. testedFeatures[lang].push_back(p);
  1155. if (availableFeatures.find(lang) == availableFeatures.end()) {
  1156. const char* featuresKnown =
  1157. context->LG->GetMakefile()->CompileFeaturesAvailable(lang, &error);
  1158. if (!featuresKnown) {
  1159. reportError(context, content->GetOriginalExpression(), error);
  1160. return std::string();
  1161. }
  1162. cmSystemTools::ExpandListArgument(featuresKnown,
  1163. availableFeatures[lang]);
  1164. }
  1165. }
  1166. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1167. for (auto const& lit : testedFeatures) {
  1168. std::vector<std::string> const& langAvailable =
  1169. availableFeatures[lit.first];
  1170. const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
  1171. "CMAKE_" + lit.first + "_STANDARD_DEFAULT");
  1172. for (std::string const& it : lit.second) {
  1173. if (std::find(langAvailable.begin(), langAvailable.end(), it) ==
  1174. langAvailable.end()) {
  1175. return "0";
  1176. }
  1177. if (standardDefault && !*standardDefault) {
  1178. // This compiler has no notion of language standard levels.
  1179. // All features known for the language are always available.
  1180. continue;
  1181. }
  1182. if (!context->LG->GetMakefile()->HaveStandardAvailable(
  1183. target->Target, lit.first, it)) {
  1184. if (evalLL) {
  1185. const char* l = target->GetProperty(lit.first + "_STANDARD");
  1186. if (!l) {
  1187. l = standardDefault;
  1188. }
  1189. assert(l);
  1190. context->MaxLanguageStandard[target][lit.first] = l;
  1191. } else {
  1192. return "0";
  1193. }
  1194. }
  1195. }
  1196. }
  1197. return "1";
  1198. }
  1199. } compileFeaturesNode;
  1200. static const char* targetPolicyWhitelist[] = {
  1201. nullptr
  1202. #define TARGET_POLICY_STRING(POLICY) , #POLICY
  1203. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1204. #undef TARGET_POLICY_STRING
  1205. };
  1206. cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
  1207. const char* policy)
  1208. {
  1209. #define RETURN_POLICY(POLICY) \
  1210. if (strcmp(policy, #POLICY) == 0) { \
  1211. return tgt->GetPolicyStatus##POLICY(); \
  1212. }
  1213. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1214. #undef RETURN_POLICY
  1215. assert(false && "Unreachable code. Not a valid policy");
  1216. return cmPolicies::WARN;
  1217. }
  1218. cmPolicies::PolicyID policyForString(const char* policy_id)
  1219. {
  1220. #define RETURN_POLICY_ID(POLICY_ID) \
  1221. if (strcmp(policy_id, #POLICY_ID) == 0) { \
  1222. return cmPolicies::POLICY_ID; \
  1223. }
  1224. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1225. #undef RETURN_POLICY_ID
  1226. assert(false && "Unreachable code. Not a valid policy");
  1227. return cmPolicies::CMP0002;
  1228. }
  1229. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1230. {
  1231. TargetPolicyNode() {}
  1232. int NumExpectedParameters() const override { return 1; }
  1233. std::string Evaluate(
  1234. const std::vector<std::string>& parameters,
  1235. cmGeneratorExpressionContext* context,
  1236. const GeneratorExpressionContent* content,
  1237. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1238. {
  1239. if (!context->HeadTarget) {
  1240. reportError(
  1241. context, content->GetOriginalExpression(),
  1242. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1243. "may not be used with add_custom_command or add_custom_target.");
  1244. return std::string();
  1245. }
  1246. context->HadContextSensitiveCondition = true;
  1247. context->HadHeadSensitiveCondition = true;
  1248. for (size_t i = 1; i < cm::size(targetPolicyWhitelist); ++i) {
  1249. const char* policy = targetPolicyWhitelist[i];
  1250. if (parameters.front() == policy) {
  1251. cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
  1252. switch (statusForTarget(context->HeadTarget, policy)) {
  1253. case cmPolicies::WARN:
  1254. lg->IssueMessage(
  1255. cmake::AUTHOR_WARNING,
  1256. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1257. CM_FALLTHROUGH;
  1258. case cmPolicies::REQUIRED_IF_USED:
  1259. case cmPolicies::REQUIRED_ALWAYS:
  1260. case cmPolicies::OLD:
  1261. return "0";
  1262. case cmPolicies::NEW:
  1263. return "1";
  1264. }
  1265. }
  1266. }
  1267. reportError(
  1268. context, content->GetOriginalExpression(),
  1269. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1270. "policies. Currently it may be used with the following policies:\n"
  1271. #define STRINGIFY_HELPER(X) #X
  1272. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1273. #define TARGET_POLICY_LIST_ITEM(POLICY) " * " STRINGIFY(POLICY) "\n"
  1274. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1275. #undef TARGET_POLICY_LIST_ITEM
  1276. );
  1277. return std::string();
  1278. }
  1279. } targetPolicyNode;
  1280. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1281. {
  1282. InstallPrefixNode() {}
  1283. bool GeneratesContent() const override { return true; }
  1284. int NumExpectedParameters() const override { return 0; }
  1285. std::string Evaluate(
  1286. const std::vector<std::string>& /*parameters*/,
  1287. cmGeneratorExpressionContext* context,
  1288. const GeneratorExpressionContent* content,
  1289. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1290. {
  1291. reportError(context, content->GetOriginalExpression(),
  1292. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1293. "should never be evaluated.");
  1294. return std::string();
  1295. }
  1296. } installPrefixNode;
  1297. class ArtifactDirTag;
  1298. class ArtifactLinkerTag;
  1299. class ArtifactNameTag;
  1300. class ArtifactPathTag;
  1301. class ArtifactPdbTag;
  1302. class ArtifactSonameTag;
  1303. class ArtifactBundleDirTag;
  1304. class ArtifactBundleContentDirTag;
  1305. template <typename ArtifactT>
  1306. struct TargetFilesystemArtifactResultCreator
  1307. {
  1308. static std::string Create(cmGeneratorTarget* target,
  1309. cmGeneratorExpressionContext* context,
  1310. const GeneratorExpressionContent* content);
  1311. };
  1312. template <>
  1313. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1314. {
  1315. static std::string Create(cmGeneratorTarget* target,
  1316. cmGeneratorExpressionContext* context,
  1317. const GeneratorExpressionContent* content)
  1318. {
  1319. // The target soname file (.so.1).
  1320. if (target->IsDLLPlatform()) {
  1321. ::reportError(context, content->GetOriginalExpression(),
  1322. "TARGET_SONAME_FILE is not allowed "
  1323. "for DLL target platforms.");
  1324. return std::string();
  1325. }
  1326. if (target->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1327. ::reportError(context, content->GetOriginalExpression(),
  1328. "TARGET_SONAME_FILE is allowed only for "
  1329. "SHARED libraries.");
  1330. return std::string();
  1331. }
  1332. std::string result = target->GetDirectory(context->Config);
  1333. result += "/";
  1334. result += target->GetSOName(context->Config);
  1335. return result;
  1336. }
  1337. };
  1338. template <>
  1339. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1340. {
  1341. static std::string Create(cmGeneratorTarget* target,
  1342. cmGeneratorExpressionContext* context,
  1343. const GeneratorExpressionContent* content)
  1344. {
  1345. if (target->IsImported()) {
  1346. ::reportError(context, content->GetOriginalExpression(),
  1347. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1348. return std::string();
  1349. }
  1350. std::string language = target->GetLinkerLanguage(context->Config);
  1351. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1352. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1353. ::reportError(context, content->GetOriginalExpression(),
  1354. "TARGET_PDB_FILE is not supported by the target linker.");
  1355. return std::string();
  1356. }
  1357. cmStateEnums::TargetType targetType = target->GetType();
  1358. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1359. targetType != cmStateEnums::MODULE_LIBRARY &&
  1360. targetType != cmStateEnums::EXECUTABLE) {
  1361. ::reportError(context, content->GetOriginalExpression(),
  1362. "TARGET_PDB_FILE is allowed only for "
  1363. "targets with linker created artifacts.");
  1364. return std::string();
  1365. }
  1366. std::string result = target->GetPDBDirectory(context->Config);
  1367. result += "/";
  1368. result += target->GetPDBName(context->Config);
  1369. return result;
  1370. }
  1371. };
  1372. template <>
  1373. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1374. {
  1375. static std::string Create(cmGeneratorTarget* target,
  1376. cmGeneratorExpressionContext* context,
  1377. const GeneratorExpressionContent* content)
  1378. {
  1379. // The file used to link to the target (.so, .lib, .a).
  1380. if (!target->IsLinkable()) {
  1381. ::reportError(context, content->GetOriginalExpression(),
  1382. "TARGET_LINKER_FILE is allowed only for libraries and "
  1383. "executables with ENABLE_EXPORTS.");
  1384. return std::string();
  1385. }
  1386. cmStateEnums::ArtifactType artifact = target->HasImportLibrary()
  1387. ? cmStateEnums::ImportLibraryArtifact
  1388. : cmStateEnums::RuntimeBinaryArtifact;
  1389. return target->GetFullPath(context->Config, artifact);
  1390. }
  1391. };
  1392. template <>
  1393. struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
  1394. {
  1395. static std::string Create(cmGeneratorTarget* target,
  1396. cmGeneratorExpressionContext* context,
  1397. const GeneratorExpressionContent* content)
  1398. {
  1399. if (target->IsImported()) {
  1400. ::reportError(context, content->GetOriginalExpression(),
  1401. "TARGET_BUNDLE_DIR not allowed for IMPORTED targets.");
  1402. return std::string();
  1403. }
  1404. if (!target->IsBundleOnApple()) {
  1405. ::reportError(context, content->GetOriginalExpression(),
  1406. "TARGET_BUNDLE_DIR is allowed only for Bundle targets.");
  1407. return std::string();
  1408. }
  1409. std::string outpath = target->GetDirectory(context->Config) + '/';
  1410. return target->BuildBundleDirectory(outpath, context->Config,
  1411. cmGeneratorTarget::BundleDirLevel);
  1412. }
  1413. };
  1414. template <>
  1415. struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
  1416. {
  1417. static std::string Create(cmGeneratorTarget* target,
  1418. cmGeneratorExpressionContext* context,
  1419. const GeneratorExpressionContent* content)
  1420. {
  1421. if (target->IsImported()) {
  1422. ::reportError(
  1423. context, content->GetOriginalExpression(),
  1424. "TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.");
  1425. return std::string();
  1426. }
  1427. if (!target->IsBundleOnApple()) {
  1428. ::reportError(
  1429. context, content->GetOriginalExpression(),
  1430. "TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.");
  1431. return std::string();
  1432. }
  1433. std::string outpath = target->GetDirectory(context->Config) + '/';
  1434. return target->BuildBundleDirectory(outpath, context->Config,
  1435. cmGeneratorTarget::ContentLevel);
  1436. }
  1437. };
  1438. template <>
  1439. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1440. {
  1441. static std::string Create(cmGeneratorTarget* target,
  1442. cmGeneratorExpressionContext* context,
  1443. const GeneratorExpressionContent* /*unused*/)
  1444. {
  1445. return target->GetFullPath(context->Config,
  1446. cmStateEnums::RuntimeBinaryArtifact, true);
  1447. }
  1448. };
  1449. template <typename ArtifactT>
  1450. struct TargetFilesystemArtifactResultGetter
  1451. {
  1452. static std::string Get(const std::string& result);
  1453. };
  1454. template <>
  1455. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1456. {
  1457. static std::string Get(const std::string& result)
  1458. {
  1459. return cmSystemTools::GetFilenameName(result);
  1460. }
  1461. };
  1462. template <>
  1463. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1464. {
  1465. static std::string Get(const std::string& result)
  1466. {
  1467. return cmSystemTools::GetFilenamePath(result);
  1468. }
  1469. };
  1470. template <>
  1471. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1472. {
  1473. static std::string Get(const std::string& result) { return result; }
  1474. };
  1475. template <typename ArtifactT, typename ComponentT>
  1476. struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
  1477. {
  1478. TargetFilesystemArtifact() {}
  1479. int NumExpectedParameters() const override { return 1; }
  1480. std::string Evaluate(
  1481. const std::vector<std::string>& parameters,
  1482. cmGeneratorExpressionContext* context,
  1483. const GeneratorExpressionContent* content,
  1484. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1485. {
  1486. // Lookup the referenced target.
  1487. std::string name = *parameters.begin();
  1488. if (!cmGeneratorExpression::IsValidTargetName(name)) {
  1489. ::reportError(context, content->GetOriginalExpression(),
  1490. "Expression syntax not recognized.");
  1491. return std::string();
  1492. }
  1493. cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
  1494. if (!target) {
  1495. ::reportError(context, content->GetOriginalExpression(),
  1496. "No target \"" + name + "\"");
  1497. return std::string();
  1498. }
  1499. if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY &&
  1500. target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) {
  1501. ::reportError(context, content->GetOriginalExpression(), "Target \"" +
  1502. name + "\" is not an executable or library.");
  1503. return std::string();
  1504. }
  1505. if (dagChecker && (dagChecker->EvaluatingLinkLibraries(name.c_str()) ||
  1506. (dagChecker->EvaluatingSources() &&
  1507. name == dagChecker->TopTarget()))) {
  1508. ::reportError(context, content->GetOriginalExpression(),
  1509. "Expressions which require the linker language may not "
  1510. "be used while evaluating link libraries");
  1511. return std::string();
  1512. }
  1513. context->DependTargets.insert(target);
  1514. context->AllTargets.insert(target);
  1515. std::string result =
  1516. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(target, context,
  1517. content);
  1518. if (context->HadError) {
  1519. return std::string();
  1520. }
  1521. return TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1522. }
  1523. };
  1524. template <typename ArtifactT>
  1525. struct TargetFilesystemArtifactNodeGroup
  1526. {
  1527. TargetFilesystemArtifactNodeGroup() {}
  1528. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1529. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1530. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1531. };
  1532. static const TargetFilesystemArtifactNodeGroup<ArtifactNameTag>
  1533. targetNodeGroup;
  1534. static const TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag>
  1535. targetLinkerNodeGroup;
  1536. static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
  1537. targetSoNameNodeGroup;
  1538. static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
  1539. targetPdbNodeGroup;
  1540. static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
  1541. targetBundleDirNode;
  1542. static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
  1543. ArtifactPathTag>
  1544. targetBundleContentDirNode;
  1545. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1546. {
  1547. ShellPathNode() {}
  1548. std::string Evaluate(
  1549. const std::vector<std::string>& parameters,
  1550. cmGeneratorExpressionContext* context,
  1551. const GeneratorExpressionContent* content,
  1552. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1553. {
  1554. if (!cmSystemTools::FileIsFullPath(parameters.front())) {
  1555. reportError(context, content->GetOriginalExpression(),
  1556. "\"" + parameters.front() + "\" is not an absolute path.");
  1557. return std::string();
  1558. }
  1559. cmOutputConverter converter(context->LG->GetStateSnapshot());
  1560. return converter.ConvertDirectorySeparatorsForShell(parameters.front());
  1561. }
  1562. } shellPathNode;
  1563. const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
  1564. const std::string& identifier)
  1565. {
  1566. typedef std::map<std::string, const cmGeneratorExpressionNode*> NodeMap;
  1567. static NodeMap nodeMap;
  1568. if (nodeMap.empty()) {
  1569. nodeMap["0"] = &zeroNode;
  1570. nodeMap["1"] = &oneNode;
  1571. nodeMap["AND"] = &andNode;
  1572. nodeMap["OR"] = &orNode;
  1573. nodeMap["NOT"] = &notNode;
  1574. nodeMap["C_COMPILER_ID"] = &cCompilerIdNode;
  1575. nodeMap["CXX_COMPILER_ID"] = &cxxCompilerIdNode;
  1576. nodeMap["VERSION_GREATER"] = &versionGreaterNode;
  1577. nodeMap["VERSION_GREATER_EQUAL"] = &versionGreaterEqNode;
  1578. nodeMap["VERSION_LESS"] = &versionLessNode;
  1579. nodeMap["VERSION_LESS_EQUAL"] = &versionLessEqNode;
  1580. nodeMap["VERSION_EQUAL"] = &versionEqualNode;
  1581. nodeMap["C_COMPILER_VERSION"] = &cCompilerVersionNode;
  1582. nodeMap["CXX_COMPILER_VERSION"] = &cxxCompilerVersionNode;
  1583. nodeMap["PLATFORM_ID"] = &platformIdNode;
  1584. nodeMap["COMPILE_FEATURES"] = &compileFeaturesNode;
  1585. nodeMap["CONFIGURATION"] = &configurationNode;
  1586. nodeMap["CONFIG"] = &configurationTestNode;
  1587. nodeMap["TARGET_FILE"] = &targetNodeGroup.File;
  1588. nodeMap["TARGET_LINKER_FILE"] = &targetLinkerNodeGroup.File;
  1589. nodeMap["TARGET_SONAME_FILE"] = &targetSoNameNodeGroup.File;
  1590. nodeMap["TARGET_PDB_FILE"] = &targetPdbNodeGroup.File;
  1591. nodeMap["TARGET_FILE_NAME"] = &targetNodeGroup.FileName;
  1592. nodeMap["TARGET_LINKER_FILE_NAME"] = &targetLinkerNodeGroup.FileName;
  1593. nodeMap["TARGET_SONAME_FILE_NAME"] = &targetSoNameNodeGroup.FileName;
  1594. nodeMap["TARGET_PDB_FILE_NAME"] = &targetPdbNodeGroup.FileName;
  1595. nodeMap["TARGET_FILE_DIR"] = &targetNodeGroup.FileDir;
  1596. nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir;
  1597. nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir;
  1598. nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir;
  1599. nodeMap["TARGET_BUNDLE_DIR"] = &targetBundleDirNode;
  1600. nodeMap["TARGET_BUNDLE_CONTENT_DIR"] = &targetBundleContentDirNode;
  1601. nodeMap["STREQUAL"] = &strEqualNode;
  1602. nodeMap["EQUAL"] = &equalNode;
  1603. nodeMap["LOWER_CASE"] = &lowerCaseNode;
  1604. nodeMap["UPPER_CASE"] = &upperCaseNode;
  1605. nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode;
  1606. nodeMap["BOOL"] = &boolNode;
  1607. nodeMap["IF"] = &ifNode;
  1608. nodeMap["ANGLE-R"] = &angle_rNode;
  1609. nodeMap["COMMA"] = &commaNode;
  1610. nodeMap["SEMICOLON"] = &semicolonNode;
  1611. nodeMap["TARGET_PROPERTY"] = &targetPropertyNode;
  1612. nodeMap["TARGET_NAME"] = &targetNameNode;
  1613. nodeMap["TARGET_OBJECTS"] = &targetObjectsNode;
  1614. nodeMap["TARGET_POLICY"] = &targetPolicyNode;
  1615. nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode;
  1616. nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode;
  1617. nodeMap["INSTALL_PREFIX"] = &installPrefixNode;
  1618. nodeMap["JOIN"] = &joinNode;
  1619. nodeMap["LINK_ONLY"] = &linkOnlyNode;
  1620. nodeMap["COMPILE_LANGUAGE"] = &languageNode;
  1621. nodeMap["SHELL_PATH"] = &shellPathNode;
  1622. }
  1623. NodeMap::const_iterator i = nodeMap.find(identifier);
  1624. if (i == nodeMap.end()) {
  1625. return nullptr;
  1626. }
  1627. return i->second;
  1628. }
  1629. void reportError(cmGeneratorExpressionContext* context,
  1630. const std::string& expr, const std::string& result)
  1631. {
  1632. context->HadError = true;
  1633. if (context->Quiet) {
  1634. return;
  1635. }
  1636. std::ostringstream e;
  1637. /* clang-format off */
  1638. e << "Error evaluating generator expression:\n"
  1639. << " " << expr << "\n"
  1640. << result;
  1641. /* clang-format on */
  1642. context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1643. context->Backtrace);
  1644. }