cmGeneratorExpressionNode.cxx 64 KB

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