cmGeneratorExpressionNode.cxx 64 KB

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