cmGeneratorExpressionNode.cxx 68 KB

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