cmGeneratorExpressionNode.cxx 64 KB

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