cmGeneratorExpressionNode.cxx 66 KB

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