cmGeneratorExpressionNode.cxx 64 KB

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