cmGeneratorExpressionNode.cxx 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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->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. cmTarget 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(cmTarget* tgt =
  833. context->LG->GetMakefile()->FindTargetToUse(targetName))
  834. {
  835. return tgt->GetName();
  836. }
  837. }
  838. return "";
  839. }
  840. target = context->LG->GetMakefile()->FindTargetToUse(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. cmGeneratorTarget* gtgt =
  879. context->LG->GetGlobalGenerator()->GetGeneratorTarget(target);
  880. if (propertyName == "LINKER_LANGUAGE")
  881. {
  882. if (target->LinkLanguagePropagatesToDependents() &&
  883. dagCheckerParent && (dagCheckerParent->EvaluatingLinkLibraries()
  884. || dagCheckerParent->EvaluatingSources()))
  885. {
  886. reportError(context, content->GetOriginalExpression(),
  887. "LINKER_LANGUAGE target property can not be used while evaluating "
  888. "link libraries for a static library");
  889. return std::string();
  890. }
  891. return gtgt->GetLinkerLanguage(context->Config);
  892. }
  893. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
  894. target->GetName(),
  895. propertyName,
  896. content,
  897. dagCheckerParent);
  898. switch (dagChecker.Check())
  899. {
  900. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  901. dagChecker.ReportError(context, content->GetOriginalExpression());
  902. return std::string();
  903. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  904. // No error. We just skip cyclic references.
  905. return std::string();
  906. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  907. for (size_t i = 1;
  908. i < cmArraySize(targetPropertyTransitiveWhitelist);
  909. ++i)
  910. {
  911. if (targetPropertyTransitiveWhitelist[i] == propertyName)
  912. {
  913. // No error. We're not going to find anything new here.
  914. return std::string();
  915. }
  916. }
  917. case cmGeneratorExpressionDAGChecker::DAG:
  918. break;
  919. }
  920. const char *prop = target->GetProperty(propertyName);
  921. if (dagCheckerParent)
  922. {
  923. if (dagCheckerParent->EvaluatingLinkLibraries())
  924. {
  925. #define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \
  926. (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
  927. if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_COMPARE)
  928. false)
  929. {
  930. reportError(context, content->GetOriginalExpression(),
  931. "$<TARGET_PROPERTY:...> expression in link libraries "
  932. "evaluation depends on target property which is transitive "
  933. "over the link libraries, creating a recursion.");
  934. return std::string();
  935. }
  936. #undef TRANSITIVE_PROPERTY_COMPARE
  937. if(!prop)
  938. {
  939. return std::string();
  940. }
  941. }
  942. else
  943. {
  944. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) \
  945. dagCheckerParent->METHOD () ||
  946. assert(
  947. CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  948. ASSERT_TRANSITIVE_PROPERTY_METHOD)
  949. false);
  950. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  951. }
  952. }
  953. std::string linkedTargetsContent;
  954. std::string interfacePropertyName;
  955. bool isInterfaceProperty = false;
  956. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  957. if (propertyName == #prop) \
  958. { \
  959. interfacePropertyName = "INTERFACE_" #prop; \
  960. } \
  961. else if (propertyName == "INTERFACE_" #prop) \
  962. { \
  963. interfacePropertyName = "INTERFACE_" #prop; \
  964. isInterfaceProperty = true; \
  965. } \
  966. else
  967. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  968. // Note that the above macro terminates with an else
  969. /* else */ if (cmHasLiteralPrefix(propertyName.c_str(),
  970. "COMPILE_DEFINITIONS_"))
  971. {
  972. cmPolicies::PolicyStatus polSt =
  973. context->LG->GetMakefile()->GetPolicyStatus(cmPolicies::CMP0043);
  974. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD)
  975. {
  976. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  977. }
  978. }
  979. #undef POPULATE_INTERFACE_PROPERTY_NAME
  980. cmTarget const* headTarget = context->HeadTarget && isInterfaceProperty
  981. ? context->HeadTarget : target;
  982. if(isInterfaceProperty)
  983. {
  984. cmGeneratorTarget* gHeadTarget =
  985. context->LG->GetGlobalGenerator()
  986. ->GetGeneratorTarget(headTarget);
  987. if(cmLinkInterfaceLibraries const* iface =
  988. gtgt->GetLinkInterfaceLibraries(context->Config, gHeadTarget, true))
  989. {
  990. linkedTargetsContent =
  991. getLinkedTargetsContent(iface->Libraries, gtgt,
  992. gHeadTarget,
  993. context, &dagChecker,
  994. interfacePropertyName);
  995. }
  996. }
  997. else if(!interfacePropertyName.empty())
  998. {
  999. if(cmLinkImplementationLibraries const* impl =
  1000. gtgt->GetLinkImplementationLibraries(context->Config))
  1001. {
  1002. linkedTargetsContent =
  1003. getLinkedTargetsContent(impl->Libraries, gtgt,
  1004. gtgt,
  1005. context, &dagChecker,
  1006. interfacePropertyName);
  1007. }
  1008. }
  1009. if (!prop)
  1010. {
  1011. if (target->IsImported()
  1012. || target->GetType() == cmState::INTERFACE_LIBRARY)
  1013. {
  1014. return linkedTargetsContent;
  1015. }
  1016. if (gtgt->IsLinkInterfaceDependentBoolProperty(propertyName,
  1017. context->Config))
  1018. {
  1019. context->HadContextSensitiveCondition = true;
  1020. return gtgt->GetLinkInterfaceDependentBoolProperty(
  1021. propertyName,
  1022. context->Config) ? "1" : "0";
  1023. }
  1024. if (gtgt->IsLinkInterfaceDependentStringProperty(propertyName,
  1025. context->Config))
  1026. {
  1027. context->HadContextSensitiveCondition = true;
  1028. const char *propContent =
  1029. gtgt->GetLinkInterfaceDependentStringProperty(
  1030. propertyName,
  1031. context->Config);
  1032. return propContent ? propContent : "";
  1033. }
  1034. if (gtgt->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1035. context->Config))
  1036. {
  1037. context->HadContextSensitiveCondition = true;
  1038. const char *propContent =
  1039. gtgt->GetLinkInterfaceDependentNumberMinProperty(
  1040. propertyName,
  1041. context->Config);
  1042. return propContent ? propContent : "";
  1043. }
  1044. if (gtgt->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1045. context->Config))
  1046. {
  1047. context->HadContextSensitiveCondition = true;
  1048. const char *propContent =
  1049. gtgt->GetLinkInterfaceDependentNumberMaxProperty(
  1050. propertyName,
  1051. context->Config);
  1052. return propContent ? propContent : "";
  1053. }
  1054. return linkedTargetsContent;
  1055. }
  1056. if (!target->IsImported()
  1057. && dagCheckerParent && !dagCheckerParent->EvaluatingLinkLibraries())
  1058. {
  1059. if (gtgt->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1060. context->Config))
  1061. {
  1062. context->HadContextSensitiveCondition = true;
  1063. const char *propContent =
  1064. gtgt->GetLinkInterfaceDependentNumberMinProperty(
  1065. propertyName,
  1066. context->Config);
  1067. return propContent ? propContent : "";
  1068. }
  1069. if (gtgt->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1070. context->Config))
  1071. {
  1072. context->HadContextSensitiveCondition = true;
  1073. const char *propContent =
  1074. gtgt->GetLinkInterfaceDependentNumberMaxProperty(
  1075. propertyName,
  1076. context->Config);
  1077. return propContent ? propContent : "";
  1078. }
  1079. }
  1080. if(!interfacePropertyName.empty())
  1081. {
  1082. cmGeneratorTarget* gHeadTarget =
  1083. context->LG->GetGlobalGenerator()->GetGeneratorTarget(headTarget);
  1084. std::string result = this->EvaluateDependentExpression(prop,
  1085. context->LG, context,
  1086. gHeadTarget, gtgt, &dagChecker);
  1087. if (!linkedTargetsContent.empty())
  1088. {
  1089. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1090. }
  1091. return result;
  1092. }
  1093. return prop;
  1094. }
  1095. } targetPropertyNode;
  1096. //----------------------------------------------------------------------------
  1097. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1098. {
  1099. TargetNameNode() {}
  1100. virtual bool GeneratesContent() const { return true; }
  1101. virtual bool AcceptsArbitraryContentParameter() const { return true; }
  1102. virtual bool RequiresLiteralInput() const { return true; }
  1103. std::string Evaluate(const std::vector<std::string> &parameters,
  1104. cmGeneratorExpressionContext *,
  1105. const GeneratorExpressionContent *,
  1106. cmGeneratorExpressionDAGChecker *) const
  1107. {
  1108. return parameters.front();
  1109. }
  1110. virtual int NumExpectedParameters() const { return 1; }
  1111. } targetNameNode;
  1112. //----------------------------------------------------------------------------
  1113. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1114. {
  1115. TargetObjectsNode() {}
  1116. std::string Evaluate(const std::vector<std::string> &parameters,
  1117. cmGeneratorExpressionContext *context,
  1118. const GeneratorExpressionContent *content,
  1119. cmGeneratorExpressionDAGChecker *) const
  1120. {
  1121. if (!context->EvaluateForBuildsystem)
  1122. {
  1123. std::ostringstream e;
  1124. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1125. "is only suitable for consumption by CMake. It is not suitable "
  1126. "for writing out elsewhere.";
  1127. reportError(context, content->GetOriginalExpression(), e.str());
  1128. return std::string();
  1129. }
  1130. std::string tgtName = parameters.front();
  1131. cmGeneratorTarget* gt =
  1132. context->LG->FindGeneratorTargetToUse(tgtName);
  1133. if (!gt)
  1134. {
  1135. std::ostringstream e;
  1136. e << "Objects of target \"" << tgtName
  1137. << "\" referenced but no such target exists.";
  1138. reportError(context, content->GetOriginalExpression(), e.str());
  1139. return std::string();
  1140. }
  1141. if (gt->GetType() != cmState::OBJECT_LIBRARY)
  1142. {
  1143. std::ostringstream e;
  1144. e << "Objects of target \"" << tgtName
  1145. << "\" referenced but is not an OBJECT library.";
  1146. reportError(context, content->GetOriginalExpression(), e.str());
  1147. return std::string();
  1148. }
  1149. std::vector<cmSourceFile const*> objectSources;
  1150. gt->GetObjectSources(objectSources, context->Config);
  1151. std::map<cmSourceFile const*, std::string> mapping;
  1152. for(std::vector<cmSourceFile const*>::const_iterator it
  1153. = objectSources.begin(); it != objectSources.end(); ++it)
  1154. {
  1155. mapping[*it];
  1156. }
  1157. gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
  1158. std::string obj_dir = gt->ObjectDirectory;
  1159. std::string result;
  1160. const char* sep = "";
  1161. for(std::vector<cmSourceFile const*>::const_iterator it
  1162. = objectSources.begin(); it != objectSources.end(); ++it)
  1163. {
  1164. // Find the object file name corresponding to this source file.
  1165. std::map<cmSourceFile const*, std::string>::const_iterator
  1166. map_it = mapping.find(*it);
  1167. // It must exist because we populated the mapping just above.
  1168. assert(!map_it->second.empty());
  1169. result += sep;
  1170. std::string objFile = obj_dir + map_it->second;
  1171. cmSourceFile* sf =
  1172. context->LG->GetMakefile()->GetOrCreateSource(objFile, true);
  1173. sf->SetObjectLibrary(tgtName);
  1174. sf->SetProperty("EXTERNAL_OBJECT", "1");
  1175. result += objFile;
  1176. sep = ";";
  1177. }
  1178. return result;
  1179. }
  1180. } targetObjectsNode;
  1181. //----------------------------------------------------------------------------
  1182. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1183. {
  1184. CompileFeaturesNode() {}
  1185. virtual int NumExpectedParameters() const { return OneOrMoreParameters; }
  1186. std::string Evaluate(const std::vector<std::string> &parameters,
  1187. cmGeneratorExpressionContext *context,
  1188. const GeneratorExpressionContent *content,
  1189. cmGeneratorExpressionDAGChecker *dagChecker) const
  1190. {
  1191. cmTarget const* target = context->HeadTarget;
  1192. if (!target)
  1193. {
  1194. reportError(context, content->GetOriginalExpression(),
  1195. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1196. "not be used with add_custom_command or add_custom_target.");
  1197. return std::string();
  1198. }
  1199. context->HadHeadSensitiveCondition = true;
  1200. typedef std::map<std::string, std::vector<std::string> > LangMap;
  1201. static LangMap availableFeatures;
  1202. LangMap testedFeatures;
  1203. for (std::vector<std::string>::const_iterator it = parameters.begin();
  1204. it != parameters.end(); ++it)
  1205. {
  1206. std::string error;
  1207. std::string lang;
  1208. if (!context->LG->GetMakefile()->CompileFeatureKnown(context->HeadTarget,
  1209. *it, lang, &error))
  1210. {
  1211. reportError(context, content->GetOriginalExpression(), error);
  1212. return std::string();
  1213. }
  1214. testedFeatures[lang].push_back(*it);
  1215. if (availableFeatures.find(lang) == availableFeatures.end())
  1216. {
  1217. const char* featuresKnown
  1218. = context->LG->GetMakefile()->CompileFeaturesAvailable(lang,
  1219. &error);
  1220. if (!featuresKnown)
  1221. {
  1222. reportError(context, content->GetOriginalExpression(), error);
  1223. return std::string();
  1224. }
  1225. cmSystemTools::ExpandListArgument(featuresKnown,
  1226. availableFeatures[lang]);
  1227. }
  1228. }
  1229. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1230. for (LangMap::const_iterator lit = testedFeatures.begin();
  1231. lit != testedFeatures.end(); ++lit)
  1232. {
  1233. std::vector<std::string> const& langAvailable
  1234. = availableFeatures[lit->first];
  1235. const char* standardDefault = context->LG->GetMakefile()
  1236. ->GetDefinition("CMAKE_" + lit->first + "_STANDARD_DEFAULT");
  1237. for (std::vector<std::string>::const_iterator it = lit->second.begin();
  1238. it != lit->second.end(); ++it)
  1239. {
  1240. if (std::find(langAvailable.begin(), langAvailable.end(), *it)
  1241. == langAvailable.end())
  1242. {
  1243. return "0";
  1244. }
  1245. if (standardDefault && !*standardDefault)
  1246. {
  1247. // This compiler has no notion of language standard levels.
  1248. // All features known for the language are always available.
  1249. continue;
  1250. }
  1251. if (!context->LG->GetMakefile()->HaveStandardAvailable(target,
  1252. lit->first, *it))
  1253. {
  1254. if (evalLL)
  1255. {
  1256. const char* l = target->GetProperty(lit->first + "_STANDARD");
  1257. if (!l)
  1258. {
  1259. l = standardDefault;
  1260. }
  1261. assert(l);
  1262. context->MaxLanguageStandard[target][lit->first] = l;
  1263. }
  1264. else
  1265. {
  1266. return "0";
  1267. }
  1268. }
  1269. }
  1270. }
  1271. return "1";
  1272. }
  1273. } compileFeaturesNode;
  1274. //----------------------------------------------------------------------------
  1275. static const char* targetPolicyWhitelist[] = {
  1276. 0
  1277. #define TARGET_POLICY_STRING(POLICY) \
  1278. , #POLICY
  1279. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1280. #undef TARGET_POLICY_STRING
  1281. };
  1282. cmPolicies::PolicyStatus statusForTarget(cmTarget const* tgt,
  1283. const char *policy)
  1284. {
  1285. #define RETURN_POLICY(POLICY) \
  1286. if (strcmp(policy, #POLICY) == 0) \
  1287. { \
  1288. return tgt->GetPolicyStatus ## POLICY (); \
  1289. } \
  1290. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1291. #undef RETURN_POLICY
  1292. assert(0 && "Unreachable code. Not a valid policy");
  1293. return cmPolicies::WARN;
  1294. }
  1295. cmPolicies::PolicyID policyForString(const char *policy_id)
  1296. {
  1297. #define RETURN_POLICY_ID(POLICY_ID) \
  1298. if (strcmp(policy_id, #POLICY_ID) == 0) \
  1299. { \
  1300. return cmPolicies:: POLICY_ID; \
  1301. } \
  1302. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1303. #undef RETURN_POLICY_ID
  1304. assert(0 && "Unreachable code. Not a valid policy");
  1305. return cmPolicies::CMP0002;
  1306. }
  1307. //----------------------------------------------------------------------------
  1308. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1309. {
  1310. TargetPolicyNode() {}
  1311. virtual int NumExpectedParameters() const { return 1; }
  1312. std::string Evaluate(const std::vector<std::string> &parameters,
  1313. cmGeneratorExpressionContext *context ,
  1314. const GeneratorExpressionContent *content,
  1315. cmGeneratorExpressionDAGChecker *) const
  1316. {
  1317. if (!context->HeadTarget)
  1318. {
  1319. reportError(context, content->GetOriginalExpression(),
  1320. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1321. "may not be used with add_custom_command or add_custom_target.");
  1322. return std::string();
  1323. }
  1324. context->HadContextSensitiveCondition = true;
  1325. context->HadHeadSensitiveCondition = true;
  1326. for (size_t i = 1; i < cmArraySize(targetPolicyWhitelist); ++i)
  1327. {
  1328. const char *policy = targetPolicyWhitelist[i];
  1329. if (parameters.front() == policy)
  1330. {
  1331. cmMakefile *mf = context->HeadTarget->GetMakefile();
  1332. switch(statusForTarget(context->HeadTarget, policy))
  1333. {
  1334. case cmPolicies::WARN:
  1335. mf->IssueMessage(cmake::AUTHOR_WARNING,
  1336. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1337. case cmPolicies::REQUIRED_IF_USED:
  1338. case cmPolicies::REQUIRED_ALWAYS:
  1339. case cmPolicies::OLD:
  1340. return "0";
  1341. case cmPolicies::NEW:
  1342. return "1";
  1343. }
  1344. }
  1345. }
  1346. reportError(context, content->GetOriginalExpression(),
  1347. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1348. "policies. Currently it may be used with the following policies:\n"
  1349. #define STRINGIFY_HELPER(X) #X
  1350. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1351. #define TARGET_POLICY_LIST_ITEM(POLICY) \
  1352. " * " STRINGIFY(POLICY) "\n"
  1353. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1354. #undef TARGET_POLICY_LIST_ITEM
  1355. );
  1356. return std::string();
  1357. }
  1358. } targetPolicyNode;
  1359. //----------------------------------------------------------------------------
  1360. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1361. {
  1362. InstallPrefixNode() {}
  1363. virtual bool GeneratesContent() const { return true; }
  1364. virtual int NumExpectedParameters() const { return 0; }
  1365. std::string Evaluate(const std::vector<std::string> &,
  1366. cmGeneratorExpressionContext *context,
  1367. const GeneratorExpressionContent *content,
  1368. cmGeneratorExpressionDAGChecker *) const
  1369. {
  1370. reportError(context, content->GetOriginalExpression(),
  1371. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1372. "should never be evaluated.");
  1373. return std::string();
  1374. }
  1375. } installPrefixNode;
  1376. //----------------------------------------------------------------------------
  1377. class ArtifactNameTag;
  1378. class ArtifactLinkerTag;
  1379. class ArtifactSonameTag;
  1380. class ArtifactPdbTag;
  1381. class ArtifactPathTag;
  1382. class ArtifactDirTag;
  1383. //----------------------------------------------------------------------------
  1384. template<typename ArtifactT>
  1385. struct TargetFilesystemArtifactResultCreator
  1386. {
  1387. static std::string Create(cmGeneratorTarget* target,
  1388. cmGeneratorExpressionContext *context,
  1389. const GeneratorExpressionContent *content);
  1390. };
  1391. //----------------------------------------------------------------------------
  1392. template<>
  1393. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1394. {
  1395. static std::string Create(cmGeneratorTarget* target,
  1396. cmGeneratorExpressionContext *context,
  1397. const GeneratorExpressionContent *content)
  1398. {
  1399. // The target soname file (.so.1).
  1400. if(target->Target->IsDLLPlatform())
  1401. {
  1402. ::reportError(context, content->GetOriginalExpression(),
  1403. "TARGET_SONAME_FILE is not allowed "
  1404. "for DLL target platforms.");
  1405. return std::string();
  1406. }
  1407. if(target->GetType() != cmState::SHARED_LIBRARY)
  1408. {
  1409. ::reportError(context, content->GetOriginalExpression(),
  1410. "TARGET_SONAME_FILE is allowed only for "
  1411. "SHARED libraries.");
  1412. return std::string();
  1413. }
  1414. std::string result = target->GetDirectory(context->Config);
  1415. result += "/";
  1416. result += target->GetSOName(context->Config);
  1417. return result;
  1418. }
  1419. };
  1420. //----------------------------------------------------------------------------
  1421. template<>
  1422. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1423. {
  1424. static std::string Create(cmGeneratorTarget* target,
  1425. cmGeneratorExpressionContext *context,
  1426. const GeneratorExpressionContent *content)
  1427. {
  1428. if (target->IsImported())
  1429. {
  1430. ::reportError(context, content->GetOriginalExpression(),
  1431. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1432. return std::string();
  1433. }
  1434. std::string language = target->GetLinkerLanguage(context->Config);
  1435. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1436. if(!context->LG->GetMakefile()->IsOn(pdbSupportVar))
  1437. {
  1438. ::reportError(context, content->GetOriginalExpression(),
  1439. "TARGET_PDB_FILE is not supported by the target linker.");
  1440. return std::string();
  1441. }
  1442. cmState::TargetType targetType = target->GetType();
  1443. if(targetType != cmState::SHARED_LIBRARY &&
  1444. targetType != cmState::MODULE_LIBRARY &&
  1445. targetType != cmState::EXECUTABLE)
  1446. {
  1447. ::reportError(context, content->GetOriginalExpression(),
  1448. "TARGET_PDB_FILE is allowed only for "
  1449. "targets with linker created artifacts.");
  1450. return std::string();
  1451. }
  1452. std::string result = target->GetPDBDirectory(context->Config);
  1453. result += "/";
  1454. result += target->GetPDBName(context->Config);
  1455. return result;
  1456. }
  1457. };
  1458. //----------------------------------------------------------------------------
  1459. template<>
  1460. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1461. {
  1462. static std::string Create(cmGeneratorTarget* target,
  1463. cmGeneratorExpressionContext *context,
  1464. const GeneratorExpressionContent *content)
  1465. {
  1466. // The file used to link to the target (.so, .lib, .a).
  1467. if(!target->Target->IsLinkable())
  1468. {
  1469. ::reportError(context, content->GetOriginalExpression(),
  1470. "TARGET_LINKER_FILE is allowed only for libraries and "
  1471. "executables with ENABLE_EXPORTS.");
  1472. return std::string();
  1473. }
  1474. return target->GetFullPath(context->Config,
  1475. target->HasImportLibrary());
  1476. }
  1477. };
  1478. //----------------------------------------------------------------------------
  1479. template<>
  1480. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1481. {
  1482. static std::string Create(cmGeneratorTarget* target,
  1483. cmGeneratorExpressionContext *context,
  1484. const GeneratorExpressionContent *)
  1485. {
  1486. return target->GetFullPath(context->Config, false, true);
  1487. }
  1488. };
  1489. //----------------------------------------------------------------------------
  1490. template<typename ArtifactT>
  1491. struct TargetFilesystemArtifactResultGetter
  1492. {
  1493. static std::string Get(const std::string &result);
  1494. };
  1495. //----------------------------------------------------------------------------
  1496. template<>
  1497. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1498. {
  1499. static std::string Get(const std::string &result)
  1500. { return cmSystemTools::GetFilenameName(result); }
  1501. };
  1502. //----------------------------------------------------------------------------
  1503. template<>
  1504. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1505. {
  1506. static std::string Get(const std::string &result)
  1507. { return cmSystemTools::GetFilenamePath(result); }
  1508. };
  1509. //----------------------------------------------------------------------------
  1510. template<>
  1511. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1512. {
  1513. static std::string Get(const std::string &result)
  1514. { return result; }
  1515. };
  1516. //----------------------------------------------------------------------------
  1517. template<typename ArtifactT, typename ComponentT>
  1518. struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
  1519. {
  1520. TargetFilesystemArtifact() {}
  1521. virtual int NumExpectedParameters() const { return 1; }
  1522. std::string Evaluate(const std::vector<std::string> &parameters,
  1523. cmGeneratorExpressionContext *context,
  1524. const GeneratorExpressionContent *content,
  1525. cmGeneratorExpressionDAGChecker *dagChecker) const
  1526. {
  1527. // Lookup the referenced target.
  1528. std::string name = *parameters.begin();
  1529. if (!cmGeneratorExpression::IsValidTargetName(name))
  1530. {
  1531. ::reportError(context, content->GetOriginalExpression(),
  1532. "Expression syntax not recognized.");
  1533. return std::string();
  1534. }
  1535. cmGeneratorTarget* target =
  1536. context->LG->FindGeneratorTargetToUse(name);
  1537. if(!target)
  1538. {
  1539. ::reportError(context, content->GetOriginalExpression(),
  1540. "No target \"" + name + "\"");
  1541. return std::string();
  1542. }
  1543. if(target->GetType() >= cmState::OBJECT_LIBRARY &&
  1544. target->GetType() != cmState::UNKNOWN_LIBRARY)
  1545. {
  1546. ::reportError(context, content->GetOriginalExpression(),
  1547. "Target \"" + name + "\" is not an executable or library.");
  1548. return std::string();
  1549. }
  1550. if (dagChecker && (dagChecker->EvaluatingLinkLibraries(name.c_str())
  1551. || (dagChecker->EvaluatingSources()
  1552. && name == dagChecker->TopTarget())))
  1553. {
  1554. ::reportError(context, content->GetOriginalExpression(),
  1555. "Expressions which require the linker language may not "
  1556. "be used while evaluating link libraries");
  1557. return std::string();
  1558. }
  1559. context->DependTargets.insert(target->Target);
  1560. context->AllTargets.insert(target->Target);
  1561. std::string result =
  1562. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(
  1563. target,
  1564. context,
  1565. content);
  1566. if (context->HadError)
  1567. {
  1568. return std::string();
  1569. }
  1570. return
  1571. TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1572. }
  1573. };
  1574. //----------------------------------------------------------------------------
  1575. template<typename ArtifactT>
  1576. struct TargetFilesystemArtifactNodeGroup
  1577. {
  1578. TargetFilesystemArtifactNodeGroup()
  1579. {
  1580. }
  1581. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1582. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1583. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1584. };
  1585. //----------------------------------------------------------------------------
  1586. static const
  1587. TargetFilesystemArtifactNodeGroup<ArtifactNameTag> targetNodeGroup;
  1588. static const
  1589. TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag> targetLinkerNodeGroup;
  1590. static const
  1591. TargetFilesystemArtifactNodeGroup<ArtifactSonameTag> targetSoNameNodeGroup;
  1592. static const
  1593. TargetFilesystemArtifactNodeGroup<ArtifactPdbTag> targetPdbNodeGroup;
  1594. //----------------------------------------------------------------------------
  1595. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1596. {
  1597. ShellPathNode() {}
  1598. std::string Evaluate(const std::vector<std::string> &parameters,
  1599. cmGeneratorExpressionContext *context,
  1600. const GeneratorExpressionContent *content,
  1601. cmGeneratorExpressionDAGChecker *) const
  1602. {
  1603. if (!cmSystemTools::FileIsFullPath(parameters.front()))
  1604. {
  1605. reportError(context, content->GetOriginalExpression(),
  1606. "\"" + parameters.front() + "\" is not an absolute path.");
  1607. return std::string();
  1608. }
  1609. cmOutputConverter converter(context->LG->GetStateSnapshot());
  1610. return converter.ConvertDirectorySeparatorsForShell(parameters.front());
  1611. }
  1612. } shellPathNode;
  1613. //----------------------------------------------------------------------------
  1614. const cmGeneratorExpressionNode*
  1615. cmGeneratorExpressionNode::GetNode(const std::string &identifier)
  1616. {
  1617. typedef std::map<std::string, const cmGeneratorExpressionNode*> NodeMap;
  1618. static NodeMap nodeMap;
  1619. if (nodeMap.empty())
  1620. {
  1621. nodeMap["0"] = &zeroNode;
  1622. nodeMap["1"] = &oneNode;
  1623. nodeMap["AND"] = &andNode;
  1624. nodeMap["OR"] = &orNode;
  1625. nodeMap["NOT"] = &notNode;
  1626. nodeMap["C_COMPILER_ID"] = &cCompilerIdNode;
  1627. nodeMap["CXX_COMPILER_ID"] = &cxxCompilerIdNode;
  1628. nodeMap["VERSION_GREATER"] = &versionGreaterNode;
  1629. nodeMap["VERSION_LESS"] = &versionLessNode;
  1630. nodeMap["VERSION_EQUAL"] = &versionEqualNode;
  1631. nodeMap["C_COMPILER_VERSION"] = &cCompilerVersionNode;
  1632. nodeMap["CXX_COMPILER_VERSION"] = &cxxCompilerVersionNode;
  1633. nodeMap["PLATFORM_ID"] = &platformIdNode;
  1634. nodeMap["COMPILE_FEATURES"] = &compileFeaturesNode;
  1635. nodeMap["CONFIGURATION"] = &configurationNode;
  1636. nodeMap["CONFIG"] = &configurationTestNode;
  1637. nodeMap["TARGET_FILE"] = &targetNodeGroup.File;
  1638. nodeMap["TARGET_LINKER_FILE"] = &targetLinkerNodeGroup.File;
  1639. nodeMap["TARGET_SONAME_FILE"] = &targetSoNameNodeGroup.File;
  1640. nodeMap["TARGET_PDB_FILE"] = &targetPdbNodeGroup.File;
  1641. nodeMap["TARGET_FILE_NAME"] = &targetNodeGroup.FileName;
  1642. nodeMap["TARGET_LINKER_FILE_NAME"] = &targetLinkerNodeGroup.FileName;
  1643. nodeMap["TARGET_SONAME_FILE_NAME"] = &targetSoNameNodeGroup.FileName;
  1644. nodeMap["TARGET_PDB_FILE_NAME"] = &targetPdbNodeGroup.FileName;
  1645. nodeMap["TARGET_FILE_DIR"] = &targetNodeGroup.FileDir;
  1646. nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir;
  1647. nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir;
  1648. nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir;
  1649. nodeMap["STREQUAL"] = &strEqualNode;
  1650. nodeMap["EQUAL"] = &equalNode;
  1651. nodeMap["LOWER_CASE"] = &lowerCaseNode;
  1652. nodeMap["UPPER_CASE"] = &upperCaseNode;
  1653. nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode;
  1654. nodeMap["BOOL"] = &boolNode;
  1655. nodeMap["ANGLE-R"] = &angle_rNode;
  1656. nodeMap["COMMA"] = &commaNode;
  1657. nodeMap["SEMICOLON"] = &semicolonNode;
  1658. nodeMap["TARGET_PROPERTY"] = &targetPropertyNode;
  1659. nodeMap["TARGET_NAME"] = &targetNameNode;
  1660. nodeMap["TARGET_OBJECTS"] = &targetObjectsNode;
  1661. nodeMap["TARGET_POLICY"] = &targetPolicyNode;
  1662. nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode;
  1663. nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode;
  1664. nodeMap["INSTALL_PREFIX"] = &installPrefixNode;
  1665. nodeMap["JOIN"] = &joinNode;
  1666. nodeMap["LINK_ONLY"] = &linkOnlyNode;
  1667. nodeMap["COMPILE_LANGUAGE"] = &languageNode;
  1668. nodeMap["SHELL_PATH"] = &shellPathNode;
  1669. }
  1670. NodeMap::const_iterator i = nodeMap.find(identifier);
  1671. if (i == nodeMap.end())
  1672. {
  1673. return 0;
  1674. }
  1675. return i->second;
  1676. }
  1677. //----------------------------------------------------------------------------
  1678. void reportError(cmGeneratorExpressionContext *context,
  1679. const std::string &expr, const std::string &result)
  1680. {
  1681. context->HadError = true;
  1682. if (context->Quiet)
  1683. {
  1684. return;
  1685. }
  1686. std::ostringstream e;
  1687. e << "Error evaluating generator expression:\n"
  1688. << " " << expr << "\n"
  1689. << result;
  1690. context->LG->GetCMakeInstance()
  1691. ->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1692. context->Backtrace);
  1693. }