cmGeneratorExpressionNode.cxx 65 KB

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