cmGeneratorExpressionNode.cxx 65 KB

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