cmGeneratorExpressionNode.cxx 66 KB

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