cmGeneratorExpressionNode.cxx 64 KB

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