cmGeneratorExpressionEvaluator.cxx 65 KB

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