cmGeneratorExpressionNode.cxx 65 KB

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