cmGeneratorExpressionNode.cxx 64 KB

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