cmGeneratorExpressionNode.cxx 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  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->GetTransitivePropertiesOnly()) {
  585. return parameters.front();
  586. }
  587. return "";
  588. }
  589. } linkOnlyNode;
  590. static const struct ConfigurationNode : public cmGeneratorExpressionNode
  591. {
  592. ConfigurationNode() {}
  593. int NumExpectedParameters() const CM_OVERRIDE { return 0; }
  594. std::string Evaluate(const std::vector<std::string>& /*parameters*/,
  595. cmGeneratorExpressionContext* context,
  596. const GeneratorExpressionContent* /*content*/,
  597. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  598. CM_OVERRIDE
  599. {
  600. context->HadContextSensitiveCondition = true;
  601. return context->Config;
  602. }
  603. } configurationNode;
  604. static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
  605. {
  606. ConfigurationTestNode() {}
  607. int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
  608. std::string Evaluate(const std::vector<std::string>& parameters,
  609. cmGeneratorExpressionContext* context,
  610. const GeneratorExpressionContent* content,
  611. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  612. CM_OVERRIDE
  613. {
  614. if (parameters.empty()) {
  615. return configurationNode.Evaluate(parameters, context, content,
  616. CM_NULLPTR);
  617. }
  618. static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
  619. if (!configValidator.find(*parameters.begin())) {
  620. reportError(context, content->GetOriginalExpression(),
  621. "Expression syntax not recognized.");
  622. return std::string();
  623. }
  624. context->HadContextSensitiveCondition = true;
  625. if (context->Config.empty()) {
  626. return parameters.front().empty() ? "1" : "0";
  627. }
  628. if (cmsysString_strcasecmp(parameters.begin()->c_str(),
  629. context->Config.c_str()) == 0) {
  630. return "1";
  631. }
  632. if (context->CurrentTarget && context->CurrentTarget->IsImported()) {
  633. const char* loc = CM_NULLPTR;
  634. const char* imp = CM_NULLPTR;
  635. std::string suffix;
  636. if (context->CurrentTarget->Target->GetMappedConfig(
  637. context->Config, &loc, &imp, suffix)) {
  638. // This imported target has an appropriate location
  639. // for this (possibly mapped) config.
  640. // Check if there is a proper config mapping for the tested config.
  641. std::vector<std::string> mappedConfigs;
  642. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  643. mapProp += cmSystemTools::UpperCase(context->Config);
  644. if (const char* mapValue =
  645. context->CurrentTarget->GetProperty(mapProp)) {
  646. cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
  647. mappedConfigs);
  648. return std::find(mappedConfigs.begin(), mappedConfigs.end(),
  649. cmSystemTools::UpperCase(parameters.front())) !=
  650. mappedConfigs.end()
  651. ? "1"
  652. : "0";
  653. }
  654. }
  655. }
  656. return "0";
  657. }
  658. } configurationTestNode;
  659. static const struct JoinNode : public cmGeneratorExpressionNode
  660. {
  661. JoinNode() {}
  662. int NumExpectedParameters() const CM_OVERRIDE { return 2; }
  663. bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
  664. std::string Evaluate(const std::vector<std::string>& parameters,
  665. cmGeneratorExpressionContext* /*context*/,
  666. const GeneratorExpressionContent* /*content*/,
  667. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  668. CM_OVERRIDE
  669. {
  670. std::vector<std::string> list;
  671. cmSystemTools::ExpandListArgument(parameters.front(), list);
  672. return cmJoin(list, parameters[1]);
  673. }
  674. } joinNode;
  675. static const struct CompileLanguageNode : public cmGeneratorExpressionNode
  676. {
  677. CompileLanguageNode() {}
  678. int NumExpectedParameters() const CM_OVERRIDE { return OneOrZeroParameters; }
  679. std::string Evaluate(const std::vector<std::string>& parameters,
  680. cmGeneratorExpressionContext* context,
  681. const GeneratorExpressionContent* content,
  682. cmGeneratorExpressionDAGChecker* dagChecker) const
  683. CM_OVERRIDE
  684. {
  685. if (context->Language.empty()) {
  686. reportError(
  687. context, content->GetOriginalExpression(),
  688. "$<COMPILE_LANGUAGE:...> may only be used to specify include "
  689. "directories compile definitions, compile options and to evaluate "
  690. "components of the file(GENERATE) command.");
  691. return std::string();
  692. }
  693. std::vector<std::string> enabledLanguages;
  694. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  695. gg->GetEnabledLanguages(enabledLanguages);
  696. if (!parameters.empty() &&
  697. std::find(enabledLanguages.begin(), enabledLanguages.end(),
  698. parameters.front()) == enabledLanguages.end()) {
  699. reportError(context, content->GetOriginalExpression(),
  700. "$<COMPILE_LANGUAGE:...> Unknown language.");
  701. return std::string();
  702. }
  703. std::string genName = gg->GetName();
  704. if (genName.find("Visual Studio") != std::string::npos) {
  705. reportError(context, content->GetOriginalExpression(),
  706. "$<COMPILE_LANGUAGE:...> may not be used with Visual Studio "
  707. "generators.");
  708. return std::string();
  709. }
  710. if (genName.find("Xcode") != std::string::npos) {
  711. if (dagChecker && (dagChecker->EvaluatingCompileDefinitions() ||
  712. dagChecker->EvaluatingIncludeDirectories())) {
  713. reportError(
  714. context, content->GetOriginalExpression(),
  715. "$<COMPILE_LANGUAGE:...> may only be used with COMPILE_OPTIONS "
  716. "with the Xcode generator.");
  717. return std::string();
  718. }
  719. } else {
  720. if (genName.find("Makefiles") == std::string::npos &&
  721. genName.find("Ninja") == std::string::npos &&
  722. genName.find("Watcom WMake") == std::string::npos) {
  723. reportError(
  724. context, content->GetOriginalExpression(),
  725. "$<COMPILE_LANGUAGE:...> not supported for this generator.");
  726. return std::string();
  727. }
  728. }
  729. if (parameters.empty()) {
  730. return context->Language;
  731. }
  732. return context->Language == parameters.front() ? "1" : "0";
  733. }
  734. } languageNode;
  735. #define TRANSITIVE_PROPERTY_NAME(PROPERTY) , "INTERFACE_" #PROPERTY
  736. static const char* targetPropertyTransitiveWhitelist[] = {
  737. CM_NULLPTR CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(TRANSITIVE_PROPERTY_NAME)
  738. };
  739. #undef TRANSITIVE_PROPERTY_NAME
  740. template <typename T>
  741. std::string getLinkedTargetsContent(
  742. std::vector<T> const& libraries, cmGeneratorTarget const* target,
  743. cmGeneratorTarget const* headTarget, cmGeneratorExpressionContext* context,
  744. cmGeneratorExpressionDAGChecker* dagChecker,
  745. const std::string& interfacePropertyName)
  746. {
  747. std::string linkedTargetsContent;
  748. std::string sep;
  749. std::string depString;
  750. for (typename std::vector<T>::const_iterator it = libraries.begin();
  751. it != libraries.end(); ++it) {
  752. // Broken code can have a target in its own link interface.
  753. // Don't follow such link interface entries so as not to create a
  754. // self-referencing loop.
  755. if (it->Target && it->Target != target) {
  756. depString += sep + "$<TARGET_PROPERTY:" + it->Target->GetName() + "," +
  757. interfacePropertyName + ">";
  758. sep = ";";
  759. }
  760. }
  761. if (!depString.empty()) {
  762. linkedTargetsContent =
  763. cmGeneratorExpressionNode::EvaluateDependentExpression(
  764. depString, target->GetLocalGenerator(), context, headTarget, target,
  765. dagChecker);
  766. }
  767. linkedTargetsContent =
  768. cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);
  769. return linkedTargetsContent;
  770. }
  771. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  772. {
  773. TargetPropertyNode() {}
  774. // This node handles errors on parameter count itself.
  775. int NumExpectedParameters() const CM_OVERRIDE { return OneOrMoreParameters; }
  776. std::string Evaluate(const std::vector<std::string>& parameters,
  777. cmGeneratorExpressionContext* context,
  778. const GeneratorExpressionContent* content,
  779. cmGeneratorExpressionDAGChecker* dagCheckerParent) const
  780. CM_OVERRIDE
  781. {
  782. if (parameters.size() != 1 && parameters.size() != 2) {
  783. reportError(
  784. context, content->GetOriginalExpression(),
  785. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  786. return std::string();
  787. }
  788. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  789. cmGeneratorTarget const* target = context->HeadTarget;
  790. std::string propertyName = *parameters.begin();
  791. if (parameters.size() == 1) {
  792. context->HadHeadSensitiveCondition = true;
  793. }
  794. if (!target && parameters.size() == 1) {
  795. reportError(
  796. context, content->GetOriginalExpression(),
  797. "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
  798. "It may not be used with add_custom_command or add_custom_target. "
  799. "Specify the target to read a property from using the "
  800. "$<TARGET_PROPERTY:tgt,prop> signature instead.");
  801. return std::string();
  802. }
  803. if (parameters.size() == 2) {
  804. if (parameters.begin()->empty() && parameters[1].empty()) {
  805. reportError(
  806. context, content->GetOriginalExpression(),
  807. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  808. "target name and property name.");
  809. return std::string();
  810. }
  811. if (parameters.begin()->empty()) {
  812. reportError(
  813. context, content->GetOriginalExpression(),
  814. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  815. "target name.");
  816. return std::string();
  817. }
  818. std::string targetName = parameters.front();
  819. propertyName = parameters[1];
  820. if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
  821. if (!propertyNameValidator.find(propertyName.c_str())) {
  822. ::reportError(context, content->GetOriginalExpression(),
  823. "Target name and property name not supported.");
  824. return std::string();
  825. }
  826. ::reportError(context, content->GetOriginalExpression(),
  827. "Target name not supported.");
  828. return std::string();
  829. }
  830. if (propertyName == "ALIASED_TARGET") {
  831. if (context->LG->GetMakefile()->IsAlias(targetName)) {
  832. if (cmGeneratorTarget* tgt =
  833. context->LG->FindGeneratorTargetToUse(targetName)) {
  834. return tgt->GetName();
  835. }
  836. }
  837. return "";
  838. }
  839. target = context->LG->FindGeneratorTargetToUse(targetName);
  840. if (!target) {
  841. std::ostringstream e;
  842. e << "Target \"" << targetName << "\" not found.";
  843. reportError(context, content->GetOriginalExpression(), e.str());
  844. return std::string();
  845. }
  846. context->AllTargets.insert(target);
  847. }
  848. if (target == context->HeadTarget) {
  849. // Keep track of the properties seen while processing.
  850. // The evaluation of the LINK_LIBRARIES generator expressions
  851. // will check this to ensure that properties have one consistent
  852. // value for all evaluations.
  853. context->SeenTargetProperties.insert(propertyName);
  854. }
  855. if (propertyName == "SOURCES") {
  856. context->SourceSensitiveTargets.insert(target);
  857. }
  858. if (propertyName.empty()) {
  859. reportError(
  860. context, content->GetOriginalExpression(),
  861. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  862. "name.");
  863. return std::string();
  864. }
  865. if (!propertyNameValidator.find(propertyName)) {
  866. ::reportError(context, content->GetOriginalExpression(),
  867. "Property name not supported.");
  868. return std::string();
  869. }
  870. assert(target);
  871. if (propertyName == "LINKER_LANGUAGE") {
  872. if (target->LinkLanguagePropagatesToDependents() && dagCheckerParent &&
  873. (dagCheckerParent->EvaluatingLinkLibraries() ||
  874. dagCheckerParent->EvaluatingSources())) {
  875. reportError(
  876. context, content->GetOriginalExpression(),
  877. "LINKER_LANGUAGE target property can not be used while evaluating "
  878. "link libraries for a static library");
  879. return std::string();
  880. }
  881. return target->GetLinkerLanguage(context->Config);
  882. }
  883. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
  884. target->GetName(), propertyName,
  885. content, dagCheckerParent);
  886. switch (dagChecker.Check()) {
  887. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  888. dagChecker.ReportError(context, content->GetOriginalExpression());
  889. return std::string();
  890. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  891. // No error. We just skip cyclic references.
  892. return std::string();
  893. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  894. for (size_t i = 1; i < cmArraySize(targetPropertyTransitiveWhitelist);
  895. ++i) {
  896. if (targetPropertyTransitiveWhitelist[i] == propertyName) {
  897. // No error. We're not going to find anything new here.
  898. return std::string();
  899. }
  900. }
  901. case cmGeneratorExpressionDAGChecker::DAG:
  902. break;
  903. }
  904. const char* prop = target->GetProperty(propertyName);
  905. if (dagCheckerParent) {
  906. if (dagCheckerParent->EvaluatingLinkLibraries()) {
  907. #define TRANSITIVE_PROPERTY_COMPARE(PROPERTY) \
  908. (#PROPERTY == propertyName || "INTERFACE_" #PROPERTY == propertyName) ||
  909. if (CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(
  910. TRANSITIVE_PROPERTY_COMPARE) false) {
  911. reportError(
  912. context, content->GetOriginalExpression(),
  913. "$<TARGET_PROPERTY:...> expression in link libraries "
  914. "evaluation depends on target property which is transitive "
  915. "over the link libraries, creating a recursion.");
  916. return std::string();
  917. }
  918. #undef TRANSITIVE_PROPERTY_COMPARE
  919. if (!prop) {
  920. return std::string();
  921. }
  922. } else {
  923. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
  924. assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  925. ASSERT_TRANSITIVE_PROPERTY_METHOD) false);
  926. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  927. }
  928. }
  929. std::string linkedTargetsContent;
  930. std::string interfacePropertyName;
  931. bool isInterfaceProperty = false;
  932. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  933. if (propertyName == #prop) { \
  934. interfacePropertyName = "INTERFACE_" #prop; \
  935. } else if (propertyName == "INTERFACE_" #prop) { \
  936. interfacePropertyName = "INTERFACE_" #prop; \
  937. isInterfaceProperty = true; \
  938. } else
  939. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  940. // Note that the above macro terminates with an else
  941. /* else */ if (cmHasLiteralPrefix(propertyName.c_str(),
  942. "COMPILE_DEFINITIONS_")) {
  943. cmPolicies::PolicyStatus polSt =
  944. context->LG->GetPolicyStatus(cmPolicies::CMP0043);
  945. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  946. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  947. }
  948. }
  949. #undef POPULATE_INTERFACE_PROPERTY_NAME
  950. cmGeneratorTarget const* headTarget =
  951. context->HeadTarget && isInterfaceProperty ? context->HeadTarget
  952. : target;
  953. if (isInterfaceProperty) {
  954. if (cmLinkInterfaceLibraries const* iface =
  955. target->GetLinkInterfaceLibraries(context->Config, headTarget,
  956. true)) {
  957. linkedTargetsContent =
  958. getLinkedTargetsContent(iface->Libraries, target, headTarget,
  959. context, &dagChecker, interfacePropertyName);
  960. }
  961. } else if (!interfacePropertyName.empty()) {
  962. if (cmLinkImplementationLibraries const* impl =
  963. target->GetLinkImplementationLibraries(context->Config)) {
  964. linkedTargetsContent =
  965. getLinkedTargetsContent(impl->Libraries, target, target, context,
  966. &dagChecker, interfacePropertyName);
  967. }
  968. }
  969. if (!prop) {
  970. if (target->IsImported() ||
  971. target->GetType() == cmState::INTERFACE_LIBRARY) {
  972. return linkedTargetsContent;
  973. }
  974. if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
  975. context->Config)) {
  976. context->HadContextSensitiveCondition = true;
  977. return target->GetLinkInterfaceDependentBoolProperty(propertyName,
  978. context->Config)
  979. ? "1"
  980. : "0";
  981. }
  982. if (target->IsLinkInterfaceDependentStringProperty(propertyName,
  983. context->Config)) {
  984. context->HadContextSensitiveCondition = true;
  985. const char* propContent =
  986. target->GetLinkInterfaceDependentStringProperty(propertyName,
  987. context->Config);
  988. return propContent ? propContent : "";
  989. }
  990. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  991. context->Config)) {
  992. context->HadContextSensitiveCondition = true;
  993. const char* propContent =
  994. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  995. context->Config);
  996. return propContent ? propContent : "";
  997. }
  998. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  999. context->Config)) {
  1000. context->HadContextSensitiveCondition = true;
  1001. const char* propContent =
  1002. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1003. context->Config);
  1004. return propContent ? propContent : "";
  1005. }
  1006. return linkedTargetsContent;
  1007. }
  1008. if (!target->IsImported() && dagCheckerParent &&
  1009. !dagCheckerParent->EvaluatingLinkLibraries()) {
  1010. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1011. context->Config)) {
  1012. context->HadContextSensitiveCondition = true;
  1013. const char* propContent =
  1014. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1015. context->Config);
  1016. return propContent ? propContent : "";
  1017. }
  1018. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1019. context->Config)) {
  1020. context->HadContextSensitiveCondition = true;
  1021. const char* propContent =
  1022. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1023. context->Config);
  1024. return propContent ? propContent : "";
  1025. }
  1026. }
  1027. if (!interfacePropertyName.empty()) {
  1028. std::string result = this->EvaluateDependentExpression(
  1029. prop, context->LG, context, headTarget, target, &dagChecker);
  1030. if (!linkedTargetsContent.empty()) {
  1031. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1032. }
  1033. return result;
  1034. }
  1035. return prop;
  1036. }
  1037. } targetPropertyNode;
  1038. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1039. {
  1040. TargetNameNode() {}
  1041. bool GeneratesContent() const CM_OVERRIDE { return true; }
  1042. bool AcceptsArbitraryContentParameter() const CM_OVERRIDE { return true; }
  1043. bool RequiresLiteralInput() const CM_OVERRIDE { return true; }
  1044. std::string Evaluate(const std::vector<std::string>& parameters,
  1045. cmGeneratorExpressionContext* /*context*/,
  1046. const GeneratorExpressionContent* /*content*/,
  1047. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  1048. CM_OVERRIDE
  1049. {
  1050. return parameters.front();
  1051. }
  1052. int NumExpectedParameters() const CM_OVERRIDE { return 1; }
  1053. } targetNameNode;
  1054. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1055. {
  1056. TargetObjectsNode() {}
  1057. std::string Evaluate(const std::vector<std::string>& parameters,
  1058. cmGeneratorExpressionContext* context,
  1059. const GeneratorExpressionContent* content,
  1060. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  1061. CM_OVERRIDE
  1062. {
  1063. if (!context->EvaluateForBuildsystem) {
  1064. std::ostringstream e;
  1065. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1066. "is only suitable for consumption by CMake. It is not suitable "
  1067. "for writing out elsewhere.";
  1068. reportError(context, content->GetOriginalExpression(), e.str());
  1069. return std::string();
  1070. }
  1071. std::string tgtName = parameters.front();
  1072. cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
  1073. if (!gt) {
  1074. std::ostringstream e;
  1075. e << "Objects of target \"" << tgtName
  1076. << "\" referenced but no such target exists.";
  1077. reportError(context, content->GetOriginalExpression(), e.str());
  1078. return std::string();
  1079. }
  1080. if (gt->GetType() != cmState::OBJECT_LIBRARY) {
  1081. std::ostringstream e;
  1082. e << "Objects of target \"" << tgtName
  1083. << "\" referenced but is not an OBJECT library.";
  1084. reportError(context, content->GetOriginalExpression(), e.str());
  1085. return std::string();
  1086. }
  1087. std::vector<cmSourceFile const*> objectSources;
  1088. gt->GetObjectSources(objectSources, context->Config);
  1089. std::map<cmSourceFile const*, std::string> mapping;
  1090. for (std::vector<cmSourceFile const*>::const_iterator it =
  1091. objectSources.begin();
  1092. it != objectSources.end(); ++it) {
  1093. mapping[*it];
  1094. }
  1095. gt->LocalGenerator->ComputeObjectFilenames(mapping, gt);
  1096. std::string obj_dir = gt->ObjectDirectory;
  1097. std::string result;
  1098. const char* sep = "";
  1099. for (std::vector<cmSourceFile const*>::const_iterator it =
  1100. objectSources.begin();
  1101. it != objectSources.end(); ++it) {
  1102. // Find the object file name corresponding to this source file.
  1103. std::map<cmSourceFile const*, std::string>::const_iterator map_it =
  1104. mapping.find(*it);
  1105. // It must exist because we populated the mapping just above.
  1106. assert(!map_it->second.empty());
  1107. result += sep;
  1108. std::string objFile = obj_dir + map_it->second;
  1109. cmSourceFile* sf =
  1110. context->LG->GetMakefile()->GetOrCreateSource(objFile, true);
  1111. sf->SetObjectLibrary(tgtName);
  1112. sf->SetProperty("EXTERNAL_OBJECT", "1");
  1113. result += objFile;
  1114. sep = ";";
  1115. }
  1116. return result;
  1117. }
  1118. } targetObjectsNode;
  1119. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1120. {
  1121. CompileFeaturesNode() {}
  1122. int NumExpectedParameters() const CM_OVERRIDE { return OneOrMoreParameters; }
  1123. std::string Evaluate(const std::vector<std::string>& parameters,
  1124. cmGeneratorExpressionContext* context,
  1125. const GeneratorExpressionContent* content,
  1126. cmGeneratorExpressionDAGChecker* dagChecker) const
  1127. CM_OVERRIDE
  1128. {
  1129. cmGeneratorTarget const* target = context->HeadTarget;
  1130. if (!target) {
  1131. reportError(
  1132. context, content->GetOriginalExpression(),
  1133. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1134. "not be used with add_custom_command or add_custom_target.");
  1135. return std::string();
  1136. }
  1137. context->HadHeadSensitiveCondition = true;
  1138. typedef std::map<std::string, std::vector<std::string> > LangMap;
  1139. static LangMap availableFeatures;
  1140. LangMap testedFeatures;
  1141. for (std::vector<std::string>::const_iterator it = parameters.begin();
  1142. it != parameters.end(); ++it) {
  1143. std::string error;
  1144. std::string lang;
  1145. if (!context->LG->GetMakefile()->CompileFeatureKnown(
  1146. context->HeadTarget->Target, *it, lang, &error)) {
  1147. reportError(context, content->GetOriginalExpression(), error);
  1148. return std::string();
  1149. }
  1150. testedFeatures[lang].push_back(*it);
  1151. if (availableFeatures.find(lang) == availableFeatures.end()) {
  1152. const char* featuresKnown =
  1153. context->LG->GetMakefile()->CompileFeaturesAvailable(lang, &error);
  1154. if (!featuresKnown) {
  1155. reportError(context, content->GetOriginalExpression(), error);
  1156. return std::string();
  1157. }
  1158. cmSystemTools::ExpandListArgument(featuresKnown,
  1159. availableFeatures[lang]);
  1160. }
  1161. }
  1162. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1163. for (LangMap::const_iterator lit = testedFeatures.begin();
  1164. lit != testedFeatures.end(); ++lit) {
  1165. std::vector<std::string> const& langAvailable =
  1166. availableFeatures[lit->first];
  1167. const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
  1168. "CMAKE_" + lit->first + "_STANDARD_DEFAULT");
  1169. for (std::vector<std::string>::const_iterator it = lit->second.begin();
  1170. it != lit->second.end(); ++it) {
  1171. if (std::find(langAvailable.begin(), langAvailable.end(), *it) ==
  1172. langAvailable.end()) {
  1173. return "0";
  1174. }
  1175. if (standardDefault && !*standardDefault) {
  1176. // This compiler has no notion of language standard levels.
  1177. // All features known for the language are always available.
  1178. continue;
  1179. }
  1180. if (!context->LG->GetMakefile()->HaveStandardAvailable(
  1181. target->Target, lit->first, *it)) {
  1182. if (evalLL) {
  1183. const char* l = target->GetProperty(lit->first + "_STANDARD");
  1184. if (!l) {
  1185. l = standardDefault;
  1186. }
  1187. assert(l);
  1188. context->MaxLanguageStandard[target][lit->first] = l;
  1189. } else {
  1190. return "0";
  1191. }
  1192. }
  1193. }
  1194. }
  1195. return "1";
  1196. }
  1197. } compileFeaturesNode;
  1198. static const char* targetPolicyWhitelist[] = {
  1199. CM_NULLPTR
  1200. #define TARGET_POLICY_STRING(POLICY) , #POLICY
  1201. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1202. #undef TARGET_POLICY_STRING
  1203. };
  1204. cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
  1205. const char* policy)
  1206. {
  1207. #define RETURN_POLICY(POLICY) \
  1208. if (strcmp(policy, #POLICY) == 0) { \
  1209. return tgt->GetPolicyStatus##POLICY(); \
  1210. }
  1211. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1212. #undef RETURN_POLICY
  1213. assert(0 && "Unreachable code. Not a valid policy");
  1214. return cmPolicies::WARN;
  1215. }
  1216. cmPolicies::PolicyID policyForString(const char* policy_id)
  1217. {
  1218. #define RETURN_POLICY_ID(POLICY_ID) \
  1219. if (strcmp(policy_id, #POLICY_ID) == 0) { \
  1220. return cmPolicies::POLICY_ID; \
  1221. }
  1222. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1223. #undef RETURN_POLICY_ID
  1224. assert(0 && "Unreachable code. Not a valid policy");
  1225. return cmPolicies::CMP0002;
  1226. }
  1227. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1228. {
  1229. TargetPolicyNode() {}
  1230. int NumExpectedParameters() const CM_OVERRIDE { return 1; }
  1231. std::string Evaluate(const std::vector<std::string>& parameters,
  1232. cmGeneratorExpressionContext* context,
  1233. const GeneratorExpressionContent* content,
  1234. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  1235. CM_OVERRIDE
  1236. {
  1237. if (!context->HeadTarget) {
  1238. reportError(
  1239. context, content->GetOriginalExpression(),
  1240. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1241. "may not be used with add_custom_command or add_custom_target.");
  1242. return std::string();
  1243. }
  1244. context->HadContextSensitiveCondition = true;
  1245. context->HadHeadSensitiveCondition = true;
  1246. for (size_t i = 1; i < cmArraySize(targetPolicyWhitelist); ++i) {
  1247. const char* policy = targetPolicyWhitelist[i];
  1248. if (parameters.front() == policy) {
  1249. cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
  1250. switch (statusForTarget(context->HeadTarget, policy)) {
  1251. case cmPolicies::WARN:
  1252. lg->IssueMessage(
  1253. cmake::AUTHOR_WARNING,
  1254. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1255. case cmPolicies::REQUIRED_IF_USED:
  1256. case cmPolicies::REQUIRED_ALWAYS:
  1257. case cmPolicies::OLD:
  1258. return "0";
  1259. case cmPolicies::NEW:
  1260. return "1";
  1261. }
  1262. }
  1263. }
  1264. reportError(
  1265. context, content->GetOriginalExpression(),
  1266. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1267. "policies. Currently it may be used with the following policies:\n"
  1268. #define STRINGIFY_HELPER(X) #X
  1269. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1270. #define TARGET_POLICY_LIST_ITEM(POLICY) " * " STRINGIFY(POLICY) "\n"
  1271. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1272. #undef TARGET_POLICY_LIST_ITEM
  1273. );
  1274. return std::string();
  1275. }
  1276. } targetPolicyNode;
  1277. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1278. {
  1279. InstallPrefixNode() {}
  1280. bool GeneratesContent() const CM_OVERRIDE { return true; }
  1281. int NumExpectedParameters() const CM_OVERRIDE { return 0; }
  1282. std::string Evaluate(const std::vector<std::string>& /*parameters*/,
  1283. cmGeneratorExpressionContext* context,
  1284. const GeneratorExpressionContent* content,
  1285. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  1286. CM_OVERRIDE
  1287. {
  1288. reportError(context, content->GetOriginalExpression(),
  1289. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1290. "should never be evaluated.");
  1291. return std::string();
  1292. }
  1293. } installPrefixNode;
  1294. class ArtifactDirTag;
  1295. class ArtifactLinkerTag;
  1296. class ArtifactNameTag;
  1297. class ArtifactPathTag;
  1298. class ArtifactPdbTag;
  1299. class ArtifactSonameTag;
  1300. template <typename ArtifactT>
  1301. struct TargetFilesystemArtifactResultCreator
  1302. {
  1303. static std::string Create(cmGeneratorTarget* target,
  1304. cmGeneratorExpressionContext* context,
  1305. const GeneratorExpressionContent* content);
  1306. };
  1307. template <>
  1308. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1309. {
  1310. static std::string Create(cmGeneratorTarget* target,
  1311. cmGeneratorExpressionContext* context,
  1312. const GeneratorExpressionContent* content)
  1313. {
  1314. // The target soname file (.so.1).
  1315. if (target->IsDLLPlatform()) {
  1316. ::reportError(context, content->GetOriginalExpression(),
  1317. "TARGET_SONAME_FILE is not allowed "
  1318. "for DLL target platforms.");
  1319. return std::string();
  1320. }
  1321. if (target->GetType() != cmState::SHARED_LIBRARY) {
  1322. ::reportError(context, content->GetOriginalExpression(),
  1323. "TARGET_SONAME_FILE is allowed only for "
  1324. "SHARED libraries.");
  1325. return std::string();
  1326. }
  1327. std::string result = target->GetDirectory(context->Config);
  1328. result += "/";
  1329. result += target->GetSOName(context->Config);
  1330. return result;
  1331. }
  1332. };
  1333. template <>
  1334. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1335. {
  1336. static std::string Create(cmGeneratorTarget* target,
  1337. cmGeneratorExpressionContext* context,
  1338. const GeneratorExpressionContent* content)
  1339. {
  1340. if (target->IsImported()) {
  1341. ::reportError(context, content->GetOriginalExpression(),
  1342. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1343. return std::string();
  1344. }
  1345. std::string language = target->GetLinkerLanguage(context->Config);
  1346. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1347. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1348. ::reportError(context, content->GetOriginalExpression(),
  1349. "TARGET_PDB_FILE is not supported by the target linker.");
  1350. return std::string();
  1351. }
  1352. cmState::TargetType targetType = target->GetType();
  1353. if (targetType != cmState::SHARED_LIBRARY &&
  1354. targetType != cmState::MODULE_LIBRARY &&
  1355. targetType != cmState::EXECUTABLE) {
  1356. ::reportError(context, content->GetOriginalExpression(),
  1357. "TARGET_PDB_FILE is allowed only for "
  1358. "targets with linker created artifacts.");
  1359. return std::string();
  1360. }
  1361. std::string result = target->GetPDBDirectory(context->Config);
  1362. result += "/";
  1363. result += target->GetPDBName(context->Config);
  1364. return result;
  1365. }
  1366. };
  1367. template <>
  1368. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1369. {
  1370. static std::string Create(cmGeneratorTarget* target,
  1371. cmGeneratorExpressionContext* context,
  1372. const GeneratorExpressionContent* content)
  1373. {
  1374. // The file used to link to the target (.so, .lib, .a).
  1375. if (!target->IsLinkable()) {
  1376. ::reportError(context, content->GetOriginalExpression(),
  1377. "TARGET_LINKER_FILE is allowed only for libraries and "
  1378. "executables with ENABLE_EXPORTS.");
  1379. return std::string();
  1380. }
  1381. return target->GetFullPath(context->Config, target->HasImportLibrary());
  1382. }
  1383. };
  1384. template <>
  1385. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1386. {
  1387. static std::string Create(cmGeneratorTarget* target,
  1388. cmGeneratorExpressionContext* context,
  1389. const GeneratorExpressionContent* /*unused*/)
  1390. {
  1391. return target->GetFullPath(context->Config, false, true);
  1392. }
  1393. };
  1394. template <typename ArtifactT>
  1395. struct TargetFilesystemArtifactResultGetter
  1396. {
  1397. static std::string Get(const std::string& result);
  1398. };
  1399. template <>
  1400. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1401. {
  1402. static std::string Get(const std::string& result)
  1403. {
  1404. return cmSystemTools::GetFilenameName(result);
  1405. }
  1406. };
  1407. template <>
  1408. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1409. {
  1410. static std::string Get(const std::string& result)
  1411. {
  1412. return cmSystemTools::GetFilenamePath(result);
  1413. }
  1414. };
  1415. template <>
  1416. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1417. {
  1418. static std::string Get(const std::string& result) { return result; }
  1419. };
  1420. template <typename ArtifactT, typename ComponentT>
  1421. struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
  1422. {
  1423. TargetFilesystemArtifact() {}
  1424. int NumExpectedParameters() const CM_OVERRIDE { return 1; }
  1425. std::string Evaluate(const std::vector<std::string>& parameters,
  1426. cmGeneratorExpressionContext* context,
  1427. const GeneratorExpressionContent* content,
  1428. cmGeneratorExpressionDAGChecker* dagChecker) const
  1429. CM_OVERRIDE
  1430. {
  1431. // Lookup the referenced target.
  1432. std::string name = *parameters.begin();
  1433. if (!cmGeneratorExpression::IsValidTargetName(name)) {
  1434. ::reportError(context, content->GetOriginalExpression(),
  1435. "Expression syntax not recognized.");
  1436. return std::string();
  1437. }
  1438. cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
  1439. if (!target) {
  1440. ::reportError(context, content->GetOriginalExpression(),
  1441. "No target \"" + name + "\"");
  1442. return std::string();
  1443. }
  1444. if (target->GetType() >= cmState::OBJECT_LIBRARY &&
  1445. target->GetType() != cmState::UNKNOWN_LIBRARY) {
  1446. ::reportError(context, content->GetOriginalExpression(), "Target \"" +
  1447. name + "\" is not an executable or library.");
  1448. return std::string();
  1449. }
  1450. if (dagChecker && (dagChecker->EvaluatingLinkLibraries(name.c_str()) ||
  1451. (dagChecker->EvaluatingSources() &&
  1452. name == dagChecker->TopTarget()))) {
  1453. ::reportError(context, content->GetOriginalExpression(),
  1454. "Expressions which require the linker language may not "
  1455. "be used while evaluating link libraries");
  1456. return std::string();
  1457. }
  1458. context->DependTargets.insert(target);
  1459. context->AllTargets.insert(target);
  1460. std::string result =
  1461. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(target, context,
  1462. content);
  1463. if (context->HadError) {
  1464. return std::string();
  1465. }
  1466. return TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1467. }
  1468. };
  1469. template <typename ArtifactT>
  1470. struct TargetFilesystemArtifactNodeGroup
  1471. {
  1472. TargetFilesystemArtifactNodeGroup() {}
  1473. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1474. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1475. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1476. };
  1477. static const TargetFilesystemArtifactNodeGroup<ArtifactNameTag>
  1478. targetNodeGroup;
  1479. static const TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag>
  1480. targetLinkerNodeGroup;
  1481. static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
  1482. targetSoNameNodeGroup;
  1483. static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
  1484. targetPdbNodeGroup;
  1485. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1486. {
  1487. ShellPathNode() {}
  1488. std::string Evaluate(const std::vector<std::string>& parameters,
  1489. cmGeneratorExpressionContext* context,
  1490. const GeneratorExpressionContent* content,
  1491. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const
  1492. CM_OVERRIDE
  1493. {
  1494. if (!cmSystemTools::FileIsFullPath(parameters.front())) {
  1495. reportError(context, content->GetOriginalExpression(),
  1496. "\"" + parameters.front() + "\" is not an absolute path.");
  1497. return std::string();
  1498. }
  1499. cmOutputConverter converter(context->LG->GetStateSnapshot());
  1500. return converter.ConvertDirectorySeparatorsForShell(parameters.front());
  1501. }
  1502. } shellPathNode;
  1503. const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
  1504. const std::string& identifier)
  1505. {
  1506. typedef std::map<std::string, const cmGeneratorExpressionNode*> NodeMap;
  1507. static NodeMap nodeMap;
  1508. if (nodeMap.empty()) {
  1509. nodeMap["0"] = &zeroNode;
  1510. nodeMap["1"] = &oneNode;
  1511. nodeMap["AND"] = &andNode;
  1512. nodeMap["OR"] = &orNode;
  1513. nodeMap["NOT"] = &notNode;
  1514. nodeMap["C_COMPILER_ID"] = &cCompilerIdNode;
  1515. nodeMap["CXX_COMPILER_ID"] = &cxxCompilerIdNode;
  1516. nodeMap["VERSION_GREATER"] = &versionGreaterNode;
  1517. nodeMap["VERSION_GREATER_EQUAL"] = &versionGreaterEqNode;
  1518. nodeMap["VERSION_LESS"] = &versionLessNode;
  1519. nodeMap["VERSION_LESS_EQUAL"] = &versionLessEqNode;
  1520. nodeMap["VERSION_EQUAL"] = &versionEqualNode;
  1521. nodeMap["C_COMPILER_VERSION"] = &cCompilerVersionNode;
  1522. nodeMap["CXX_COMPILER_VERSION"] = &cxxCompilerVersionNode;
  1523. nodeMap["PLATFORM_ID"] = &platformIdNode;
  1524. nodeMap["COMPILE_FEATURES"] = &compileFeaturesNode;
  1525. nodeMap["CONFIGURATION"] = &configurationNode;
  1526. nodeMap["CONFIG"] = &configurationTestNode;
  1527. nodeMap["TARGET_FILE"] = &targetNodeGroup.File;
  1528. nodeMap["TARGET_LINKER_FILE"] = &targetLinkerNodeGroup.File;
  1529. nodeMap["TARGET_SONAME_FILE"] = &targetSoNameNodeGroup.File;
  1530. nodeMap["TARGET_PDB_FILE"] = &targetPdbNodeGroup.File;
  1531. nodeMap["TARGET_FILE_NAME"] = &targetNodeGroup.FileName;
  1532. nodeMap["TARGET_LINKER_FILE_NAME"] = &targetLinkerNodeGroup.FileName;
  1533. nodeMap["TARGET_SONAME_FILE_NAME"] = &targetSoNameNodeGroup.FileName;
  1534. nodeMap["TARGET_PDB_FILE_NAME"] = &targetPdbNodeGroup.FileName;
  1535. nodeMap["TARGET_FILE_DIR"] = &targetNodeGroup.FileDir;
  1536. nodeMap["TARGET_LINKER_FILE_DIR"] = &targetLinkerNodeGroup.FileDir;
  1537. nodeMap["TARGET_SONAME_FILE_DIR"] = &targetSoNameNodeGroup.FileDir;
  1538. nodeMap["TARGET_PDB_FILE_DIR"] = &targetPdbNodeGroup.FileDir;
  1539. nodeMap["STREQUAL"] = &strEqualNode;
  1540. nodeMap["EQUAL"] = &equalNode;
  1541. nodeMap["LOWER_CASE"] = &lowerCaseNode;
  1542. nodeMap["UPPER_CASE"] = &upperCaseNode;
  1543. nodeMap["MAKE_C_IDENTIFIER"] = &makeCIdentifierNode;
  1544. nodeMap["BOOL"] = &boolNode;
  1545. nodeMap["ANGLE-R"] = &angle_rNode;
  1546. nodeMap["COMMA"] = &commaNode;
  1547. nodeMap["SEMICOLON"] = &semicolonNode;
  1548. nodeMap["TARGET_PROPERTY"] = &targetPropertyNode;
  1549. nodeMap["TARGET_NAME"] = &targetNameNode;
  1550. nodeMap["TARGET_OBJECTS"] = &targetObjectsNode;
  1551. nodeMap["TARGET_POLICY"] = &targetPolicyNode;
  1552. nodeMap["BUILD_INTERFACE"] = &buildInterfaceNode;
  1553. nodeMap["INSTALL_INTERFACE"] = &installInterfaceNode;
  1554. nodeMap["INSTALL_PREFIX"] = &installPrefixNode;
  1555. nodeMap["JOIN"] = &joinNode;
  1556. nodeMap["LINK_ONLY"] = &linkOnlyNode;
  1557. nodeMap["COMPILE_LANGUAGE"] = &languageNode;
  1558. nodeMap["SHELL_PATH"] = &shellPathNode;
  1559. }
  1560. NodeMap::const_iterator i = nodeMap.find(identifier);
  1561. if (i == nodeMap.end()) {
  1562. return CM_NULLPTR;
  1563. }
  1564. return i->second;
  1565. }
  1566. void reportError(cmGeneratorExpressionContext* context,
  1567. const std::string& expr, const std::string& result)
  1568. {
  1569. context->HadError = true;
  1570. if (context->Quiet) {
  1571. return;
  1572. }
  1573. std::ostringstream e;
  1574. /* clang-format off */
  1575. e << "Error evaluating generator expression:\n"
  1576. << " " << expr << "\n"
  1577. << result;
  1578. /* clang-format on */
  1579. context->LG->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1580. context->Backtrace);
  1581. }