cmGeneratorExpressionNode.cxx 64 KB

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