cmGeneratorExpressionNode.cxx 66 KB

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