cmGeneratorExpressionNode.cxx 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357
  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 "cmMessageType.h"
  15. #include "cmOutputConverter.h"
  16. #include "cmPolicies.h"
  17. #include "cmRange.h"
  18. #include "cmState.h"
  19. #include "cmStateSnapshot.h"
  20. #include "cmStateTypes.h"
  21. #include "cmSystemTools.h"
  22. #include "cmTarget.h"
  23. #include "cm_static_string_view.hxx"
  24. #include "cm_string_view.hxx"
  25. #include "cmake.h"
  26. #include "cmsys/RegularExpression.hxx"
  27. #include "cmsys/String.h"
  28. #include <algorithm>
  29. #include <assert.h>
  30. #include <errno.h>
  31. #include <iterator>
  32. #include <map>
  33. #include <memory>
  34. #include <set>
  35. #include <sstream>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <utility>
  39. std::string cmGeneratorExpressionNode::EvaluateDependentExpression(
  40. std::string const& prop, cmLocalGenerator* lg,
  41. cmGeneratorExpressionContext* context, cmGeneratorTarget const* headTarget,
  42. cmGeneratorTarget const* currentTarget,
  43. cmGeneratorExpressionDAGChecker* dagChecker)
  44. {
  45. cmGeneratorExpression ge(context->Backtrace);
  46. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  47. cge->SetEvaluateForBuildsystem(context->EvaluateForBuildsystem);
  48. std::string result =
  49. cge->Evaluate(lg, context->Config, context->Quiet, headTarget,
  50. currentTarget, dagChecker, context->Language);
  51. if (cge->GetHadContextSensitiveCondition()) {
  52. context->HadContextSensitiveCondition = true;
  53. }
  54. if (cge->GetHadHeadSensitiveCondition()) {
  55. context->HadHeadSensitiveCondition = true;
  56. }
  57. return result;
  58. }
  59. static const struct ZeroNode : public cmGeneratorExpressionNode
  60. {
  61. ZeroNode() {} // NOLINT(modernize-use-equals-default)
  62. bool GeneratesContent() const override { return false; }
  63. bool AcceptsArbitraryContentParameter() const override { return true; }
  64. std::string Evaluate(
  65. const std::vector<std::string>& /*parameters*/,
  66. cmGeneratorExpressionContext* /*context*/,
  67. const GeneratorExpressionContent* /*content*/,
  68. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  69. {
  70. return std::string();
  71. }
  72. } zeroNode;
  73. static const struct OneNode : public cmGeneratorExpressionNode
  74. {
  75. OneNode() {} // NOLINT(modernize-use-equals-default)
  76. bool AcceptsArbitraryContentParameter() const override { return true; }
  77. std::string Evaluate(
  78. const std::vector<std::string>& parameters,
  79. cmGeneratorExpressionContext* /*context*/,
  80. const GeneratorExpressionContent* /*content*/,
  81. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  82. {
  83. return parameters.front();
  84. }
  85. } oneNode;
  86. static const struct OneNode buildInterfaceNode;
  87. static const struct ZeroNode installInterfaceNode;
  88. struct BooleanOpNode : public cmGeneratorExpressionNode
  89. {
  90. BooleanOpNode(const char* op_, const char* successVal_,
  91. const char* failureVal_)
  92. : op(op_)
  93. , successVal(successVal_)
  94. , failureVal(failureVal_)
  95. {
  96. }
  97. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  98. std::string Evaluate(const std::vector<std::string>& parameters,
  99. cmGeneratorExpressionContext* context,
  100. const GeneratorExpressionContent* content,
  101. cmGeneratorExpressionDAGChecker*) const override
  102. {
  103. for (std::string const& param : parameters) {
  104. if (param == this->failureVal) {
  105. return this->failureVal;
  106. }
  107. if (param != this->successVal) {
  108. std::ostringstream e;
  109. e << "Parameters to $<" << this->op;
  110. e << "> must resolve to either '0' or '1'.";
  111. reportError(context, content->GetOriginalExpression(), e.str());
  112. return std::string();
  113. }
  114. }
  115. return this->successVal;
  116. }
  117. const char *const op, *const successVal, *const failureVal;
  118. };
  119. static const BooleanOpNode andNode("AND", "1", "0"), orNode("OR", "0", "1");
  120. static const struct NotNode : public cmGeneratorExpressionNode
  121. {
  122. NotNode() {} // NOLINT(modernize-use-equals-default)
  123. std::string Evaluate(
  124. const std::vector<std::string>& parameters,
  125. cmGeneratorExpressionContext* context,
  126. const GeneratorExpressionContent* content,
  127. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  128. {
  129. if (parameters.front() != "0" && parameters.front() != "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.front() == "0" ? "1" : "0";
  136. }
  137. } notNode;
  138. static const struct BoolNode : public cmGeneratorExpressionNode
  139. {
  140. BoolNode() {} // NOLINT(modernize-use-equals-default)
  141. int NumExpectedParameters() const override { return 1; }
  142. std::string Evaluate(
  143. const std::vector<std::string>& parameters,
  144. cmGeneratorExpressionContext* /*context*/,
  145. const GeneratorExpressionContent* /*content*/,
  146. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  147. {
  148. return !cmSystemTools::IsOff(parameters.front()) ? "1" : "0";
  149. }
  150. } boolNode;
  151. static const struct IfNode : public cmGeneratorExpressionNode
  152. {
  153. IfNode() {} // NOLINT(modernize-use-equals-default)
  154. int NumExpectedParameters() const override { return 3; }
  155. std::string Evaluate(const std::vector<std::string>& parameters,
  156. cmGeneratorExpressionContext* context,
  157. const GeneratorExpressionContent* content,
  158. cmGeneratorExpressionDAGChecker*) const override
  159. {
  160. if (parameters[0] != "1" && parameters[0] != "0") {
  161. reportError(context, content->GetOriginalExpression(),
  162. "First parameter to $<IF> must resolve to exactly one '0' "
  163. "or '1' value.");
  164. return std::string();
  165. }
  166. return parameters[0] == "1" ? parameters[1] : parameters[2];
  167. }
  168. } ifNode;
  169. static const struct StrEqualNode : public cmGeneratorExpressionNode
  170. {
  171. StrEqualNode() {} // NOLINT(modernize-use-equals-default)
  172. int NumExpectedParameters() const override { return 2; }
  173. std::string Evaluate(
  174. const std::vector<std::string>& parameters,
  175. cmGeneratorExpressionContext* /*context*/,
  176. const GeneratorExpressionContent* /*content*/,
  177. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  178. {
  179. return parameters.front() == parameters[1] ? "1" : "0";
  180. }
  181. } strEqualNode;
  182. static const struct EqualNode : public cmGeneratorExpressionNode
  183. {
  184. EqualNode() {} // NOLINT(modernize-use-equals-default)
  185. int NumExpectedParameters() const override { return 2; }
  186. std::string Evaluate(
  187. const std::vector<std::string>& parameters,
  188. cmGeneratorExpressionContext* context,
  189. const GeneratorExpressionContent* content,
  190. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  191. {
  192. long numbers[2];
  193. for (int i = 0; i < 2; ++i) {
  194. if (!ParameterToLong(parameters[i].c_str(), &numbers[i])) {
  195. reportError(context, content->GetOriginalExpression(),
  196. "$<EQUAL> parameter " + parameters[i] +
  197. " is not a valid integer.");
  198. return {};
  199. }
  200. }
  201. return numbers[0] == numbers[1] ? "1" : "0";
  202. }
  203. static bool ParameterToLong(const char* param, long* outResult)
  204. {
  205. const char isNegative = param[0] == '-';
  206. int base = 0;
  207. if (cmHasLiteralPrefix(param, "0b") || cmHasLiteralPrefix(param, "0B")) {
  208. base = 2;
  209. param += 2;
  210. } else if (cmHasLiteralPrefix(param, "-0b") ||
  211. cmHasLiteralPrefix(param, "-0B") ||
  212. cmHasLiteralPrefix(param, "+0b") ||
  213. cmHasLiteralPrefix(param, "+0B")) {
  214. base = 2;
  215. param += 3;
  216. }
  217. char* pEnd;
  218. long result = strtol(param, &pEnd, base);
  219. if (pEnd == param || *pEnd != '\0' || errno == ERANGE) {
  220. return false;
  221. }
  222. if (isNegative && result > 0) {
  223. result *= -1;
  224. }
  225. *outResult = result;
  226. return true;
  227. }
  228. } equalNode;
  229. static const struct InListNode : public cmGeneratorExpressionNode
  230. {
  231. InListNode() {} // NOLINT(modernize-use-equals-default)
  232. int NumExpectedParameters() const override { return 2; }
  233. std::string Evaluate(
  234. const std::vector<std::string>& parameters,
  235. cmGeneratorExpressionContext* context,
  236. const GeneratorExpressionContent* /*content*/,
  237. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  238. {
  239. std::vector<std::string> values, checkValues;
  240. bool check = false;
  241. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0085)) {
  242. case cmPolicies::WARN:
  243. if (parameters.front().empty()) {
  244. check = true;
  245. cmSystemTools::ExpandListArgument(parameters[1], checkValues, true);
  246. }
  247. CM_FALLTHROUGH;
  248. case cmPolicies::OLD:
  249. cmSystemTools::ExpandListArgument(parameters[1], values);
  250. if (check && values != checkValues) {
  251. std::ostringstream e;
  252. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0085)
  253. << "\nSearch Item:\n \"" << parameters.front()
  254. << "\"\nList:\n \"" << parameters[1] << "\"\n";
  255. context->LG->GetCMakeInstance()->IssueMessage(
  256. MessageType ::AUTHOR_WARNING, e.str(), context->Backtrace);
  257. return "0";
  258. }
  259. if (values.empty()) {
  260. return "0";
  261. }
  262. break;
  263. case cmPolicies::REQUIRED_IF_USED:
  264. case cmPolicies::REQUIRED_ALWAYS:
  265. case cmPolicies::NEW:
  266. cmSystemTools::ExpandListArgument(parameters[1], values, true);
  267. break;
  268. }
  269. return std::find(values.cbegin(), values.cend(), parameters.front()) ==
  270. values.cend()
  271. ? "0"
  272. : "1";
  273. }
  274. } inListNode;
  275. static const struct FilterNode : public cmGeneratorExpressionNode
  276. {
  277. FilterNode() {} // NOLINT(modernize-use-equals-default)
  278. int NumExpectedParameters() const override { return 3; }
  279. std::string Evaluate(
  280. const std::vector<std::string>& parameters,
  281. cmGeneratorExpressionContext* context,
  282. const GeneratorExpressionContent* content,
  283. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  284. {
  285. if (parameters.size() != 3) {
  286. reportError(context, content->GetOriginalExpression(),
  287. "$<FILTER:...> expression requires three parameters");
  288. return {};
  289. }
  290. if (parameters[1] != "INCLUDE" && parameters[1] != "EXCLUDE") {
  291. reportError(
  292. context, content->GetOriginalExpression(),
  293. "$<FILTER:...> second parameter must be either INCLUDE or EXCLUDE");
  294. return {};
  295. }
  296. const bool exclude = parameters[1] == "EXCLUDE";
  297. cmsys::RegularExpression re;
  298. if (!re.compile(parameters[2])) {
  299. reportError(context, content->GetOriginalExpression(),
  300. "$<FILTER:...> failed to compile regex");
  301. return {};
  302. }
  303. std::vector<std::string> values, result;
  304. cmSystemTools::ExpandListArgument(parameters.front(), values, true);
  305. std::copy_if(values.cbegin(), values.cend(), std::back_inserter(result),
  306. [&re, exclude](std::string const& input) {
  307. return exclude ^ re.find(input);
  308. });
  309. return cmJoin(cmMakeRange(result.cbegin(), result.cend()), ";");
  310. }
  311. } filterNode;
  312. static const struct RemoveDuplicatesNode : public cmGeneratorExpressionNode
  313. {
  314. RemoveDuplicatesNode() {} // NOLINT(modernize-use-equals-default)
  315. int NumExpectedParameters() const override { return 1; }
  316. std::string Evaluate(
  317. const std::vector<std::string>& parameters,
  318. cmGeneratorExpressionContext* context,
  319. const GeneratorExpressionContent* content,
  320. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  321. {
  322. if (parameters.size() != 1) {
  323. reportError(
  324. context, content->GetOriginalExpression(),
  325. "$<REMOVE_DUPLICATES:...> expression requires one parameter");
  326. }
  327. std::vector<std::string> values;
  328. cmSystemTools::ExpandListArgument(parameters.front(), values, true);
  329. auto valuesEnd = cmRemoveDuplicates(values);
  330. auto valuesBegin = values.cbegin();
  331. return cmJoin(cmMakeRange(valuesBegin, valuesEnd), ";");
  332. }
  333. } removeDuplicatesNode;
  334. static const struct TargetExistsNode : public cmGeneratorExpressionNode
  335. {
  336. TargetExistsNode() {} // NOLINT(modernize-use-equals-default)
  337. int NumExpectedParameters() const override { return 1; }
  338. std::string Evaluate(
  339. const std::vector<std::string>& parameters,
  340. cmGeneratorExpressionContext* context,
  341. const GeneratorExpressionContent* content,
  342. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  343. {
  344. if (parameters.size() != 1) {
  345. reportError(context, content->GetOriginalExpression(),
  346. "$<TARGET_EXISTS:...> expression requires one parameter");
  347. return std::string();
  348. }
  349. std::string targetName = parameters.front();
  350. if (targetName.empty() ||
  351. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  352. reportError(context, content->GetOriginalExpression(),
  353. "$<TARGET_EXISTS:tgt> expression requires a non-empty "
  354. "valid target name.");
  355. return std::string();
  356. }
  357. return context->LG->GetMakefile()->FindTargetToUse(targetName) ? "1" : "0";
  358. }
  359. } targetExistsNode;
  360. static const struct TargetNameIfExistsNode : public cmGeneratorExpressionNode
  361. {
  362. TargetNameIfExistsNode() {} // NOLINT(modernize-use-equals-default)
  363. int NumExpectedParameters() const override { return 1; }
  364. std::string Evaluate(
  365. const std::vector<std::string>& parameters,
  366. cmGeneratorExpressionContext* context,
  367. const GeneratorExpressionContent* content,
  368. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  369. {
  370. if (parameters.size() != 1) {
  371. reportError(context, content->GetOriginalExpression(),
  372. "$<TARGET_NAME_IF_EXISTS:...> expression requires one "
  373. "parameter");
  374. return std::string();
  375. }
  376. std::string targetName = parameters.front();
  377. if (targetName.empty() ||
  378. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  379. reportError(context, content->GetOriginalExpression(),
  380. "$<TARGET_NAME_IF_EXISTS:tgt> expression requires a "
  381. "non-empty valid target name.");
  382. return std::string();
  383. }
  384. return context->LG->GetMakefile()->FindTargetToUse(targetName)
  385. ? targetName
  386. : std::string();
  387. }
  388. } targetNameIfExistsNode;
  389. struct GenexEvaluator : public cmGeneratorExpressionNode
  390. {
  391. GenexEvaluator() {} // NOLINT(modernize-use-equals-default)
  392. protected:
  393. std::string EvaluateExpression(
  394. const std::string& genexOperator, const std::string& expression,
  395. cmGeneratorExpressionContext* context,
  396. const GeneratorExpressionContent* content,
  397. cmGeneratorExpressionDAGChecker* dagCheckerParent) const
  398. {
  399. if (context->HeadTarget) {
  400. cmGeneratorExpressionDAGChecker dagChecker(
  401. context->Backtrace, context->HeadTarget,
  402. genexOperator + ":" + expression, content, dagCheckerParent);
  403. switch (dagChecker.Check()) {
  404. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  405. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE: {
  406. dagChecker.ReportError(context, content->GetOriginalExpression());
  407. return std::string();
  408. }
  409. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  410. case cmGeneratorExpressionDAGChecker::DAG:
  411. break;
  412. }
  413. return this->EvaluateDependentExpression(
  414. expression, context->LG, context, context->HeadTarget,
  415. context->CurrentTarget, &dagChecker);
  416. }
  417. return this->EvaluateDependentExpression(
  418. expression, context->LG, context, context->HeadTarget,
  419. context->CurrentTarget, dagCheckerParent);
  420. }
  421. };
  422. static const struct TargetGenexEvalNode : public GenexEvaluator
  423. {
  424. TargetGenexEvalNode() {} // NOLINT(modernize-use-equals-default)
  425. int NumExpectedParameters() const override { return 2; }
  426. bool AcceptsArbitraryContentParameter() const override { return true; }
  427. std::string Evaluate(
  428. const std::vector<std::string>& parameters,
  429. cmGeneratorExpressionContext* context,
  430. const GeneratorExpressionContent* content,
  431. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  432. {
  433. const std::string& targetName = parameters.front();
  434. if (targetName.empty() ||
  435. !cmGeneratorExpression::IsValidTargetName(targetName)) {
  436. reportError(context, content->GetOriginalExpression(),
  437. "$<TARGET_GENEX_EVAL:tgt, ...> expression requires a "
  438. "non-empty valid target name.");
  439. return std::string();
  440. }
  441. const auto* target = context->LG->FindGeneratorTargetToUse(targetName);
  442. if (!target) {
  443. std::ostringstream e;
  444. e << "$<TARGET_GENEX_EVAL:tgt, ...> target \"" << targetName
  445. << "\" not found.";
  446. reportError(context, content->GetOriginalExpression(), e.str());
  447. return std::string();
  448. }
  449. const std::string& expression = parameters[1];
  450. if (expression.empty()) {
  451. return expression;
  452. }
  453. cmGeneratorExpressionContext targetContext(
  454. context->LG, context->Config, context->Quiet, target, target,
  455. context->EvaluateForBuildsystem, context->Backtrace, context->Language);
  456. return this->EvaluateExpression("TARGET_GENEX_EVAL", expression,
  457. &targetContext, content, dagCheckerParent);
  458. }
  459. } targetGenexEvalNode;
  460. static const struct GenexEvalNode : public GenexEvaluator
  461. {
  462. GenexEvalNode() {} // NOLINT(modernize-use-equals-default)
  463. int NumExpectedParameters() const override { return 1; }
  464. bool AcceptsArbitraryContentParameter() const override { return true; }
  465. std::string Evaluate(
  466. const std::vector<std::string>& parameters,
  467. cmGeneratorExpressionContext* context,
  468. const GeneratorExpressionContent* content,
  469. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  470. {
  471. const std::string& expression = parameters[0];
  472. if (expression.empty()) {
  473. return expression;
  474. }
  475. return this->EvaluateExpression("GENEX_EVAL", expression, context, content,
  476. dagCheckerParent);
  477. }
  478. } genexEvalNode;
  479. static const struct LowerCaseNode : public cmGeneratorExpressionNode
  480. {
  481. LowerCaseNode() {} // NOLINT(modernize-use-equals-default)
  482. bool AcceptsArbitraryContentParameter() const override { return true; }
  483. std::string Evaluate(
  484. const std::vector<std::string>& parameters,
  485. cmGeneratorExpressionContext* /*context*/,
  486. const GeneratorExpressionContent* /*content*/,
  487. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  488. {
  489. return cmSystemTools::LowerCase(parameters.front());
  490. }
  491. } lowerCaseNode;
  492. static const struct UpperCaseNode : public cmGeneratorExpressionNode
  493. {
  494. UpperCaseNode() {} // NOLINT(modernize-use-equals-default)
  495. bool AcceptsArbitraryContentParameter() const override { return true; }
  496. std::string Evaluate(
  497. const std::vector<std::string>& parameters,
  498. cmGeneratorExpressionContext* /*context*/,
  499. const GeneratorExpressionContent* /*content*/,
  500. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  501. {
  502. return cmSystemTools::UpperCase(parameters.front());
  503. }
  504. } upperCaseNode;
  505. static const struct MakeCIdentifierNode : public cmGeneratorExpressionNode
  506. {
  507. MakeCIdentifierNode() {} // NOLINT(modernize-use-equals-default)
  508. bool AcceptsArbitraryContentParameter() const override { return true; }
  509. std::string Evaluate(
  510. const std::vector<std::string>& parameters,
  511. cmGeneratorExpressionContext* /*context*/,
  512. const GeneratorExpressionContent* /*content*/,
  513. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  514. {
  515. return cmSystemTools::MakeCidentifier(parameters.front());
  516. }
  517. } makeCIdentifierNode;
  518. template <char C>
  519. struct CharacterNode : public cmGeneratorExpressionNode
  520. {
  521. CharacterNode() {} // NOLINT(modernize-use-equals-default)
  522. int NumExpectedParameters() const override { return 0; }
  523. std::string Evaluate(
  524. const std::vector<std::string>& /*parameters*/,
  525. cmGeneratorExpressionContext* /*context*/,
  526. const GeneratorExpressionContent* /*content*/,
  527. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  528. {
  529. return { C };
  530. }
  531. };
  532. static const CharacterNode<'>'> angle_rNode;
  533. static const CharacterNode<','> commaNode;
  534. static const CharacterNode<';'> semicolonNode;
  535. struct CompilerIdNode : public cmGeneratorExpressionNode
  536. {
  537. CompilerIdNode(const char* compilerLang)
  538. : CompilerLanguage(compilerLang)
  539. {
  540. }
  541. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  542. std::string Evaluate(
  543. const std::vector<std::string>& parameters,
  544. cmGeneratorExpressionContext* context,
  545. const GeneratorExpressionContent* content,
  546. cmGeneratorExpressionDAGChecker* dagChecker) const override
  547. {
  548. if (!context->HeadTarget) {
  549. std::ostringstream e;
  550. e << "$<" << this->CompilerLanguage
  551. << "_COMPILER_ID> may only be used with binary targets. It may "
  552. "not be used with add_custom_command or add_custom_target.";
  553. reportError(context, content->GetOriginalExpression(), e.str());
  554. return {};
  555. }
  556. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  557. this->CompilerLanguage);
  558. }
  559. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  560. cmGeneratorExpressionContext* context,
  561. const GeneratorExpressionContent* content,
  562. cmGeneratorExpressionDAGChecker* /*unused*/,
  563. const std::string& lang) const
  564. {
  565. std::string const& compilerId =
  566. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
  567. "_COMPILER_ID");
  568. if (parameters.empty()) {
  569. return compilerId;
  570. }
  571. if (compilerId.empty()) {
  572. return parameters.front().empty() ? "1" : "0";
  573. }
  574. static cmsys::RegularExpression compilerIdValidator("^[A-Za-z0-9_]*$");
  575. for (auto& param : parameters) {
  576. if (!compilerIdValidator.find(param)) {
  577. reportError(context, content->GetOriginalExpression(),
  578. "Expression syntax not recognized.");
  579. return std::string();
  580. }
  581. if (strcmp(param.c_str(), compilerId.c_str()) == 0) {
  582. return "1";
  583. }
  584. if (cmsysString_strcasecmp(param.c_str(), compilerId.c_str()) == 0) {
  585. switch (context->LG->GetPolicyStatus(cmPolicies::CMP0044)) {
  586. case cmPolicies::WARN: {
  587. std::ostringstream e;
  588. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0044);
  589. context->LG->GetCMakeInstance()->IssueMessage(
  590. MessageType::AUTHOR_WARNING, e.str(), context->Backtrace);
  591. CM_FALLTHROUGH;
  592. }
  593. case cmPolicies::OLD:
  594. return "1";
  595. case cmPolicies::NEW:
  596. case cmPolicies::REQUIRED_ALWAYS:
  597. case cmPolicies::REQUIRED_IF_USED:
  598. break;
  599. }
  600. }
  601. }
  602. return "0";
  603. }
  604. const char* const CompilerLanguage;
  605. };
  606. static const CompilerIdNode cCompilerIdNode("C"), cxxCompilerIdNode("CXX"),
  607. cudaCompilerIdNode("CUDA"), fortranCompilerIdNode("Fortran");
  608. struct CompilerVersionNode : public cmGeneratorExpressionNode
  609. {
  610. CompilerVersionNode(const char* compilerLang)
  611. : CompilerLanguage(compilerLang)
  612. {
  613. }
  614. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  615. std::string Evaluate(
  616. const std::vector<std::string>& parameters,
  617. cmGeneratorExpressionContext* context,
  618. const GeneratorExpressionContent* content,
  619. cmGeneratorExpressionDAGChecker* dagChecker) const override
  620. {
  621. if (!context->HeadTarget) {
  622. std::ostringstream e;
  623. e << "$<" << this->CompilerLanguage
  624. << "_COMPILER_VERSION> may only be used with binary targets. It "
  625. "may not be used with add_custom_command or add_custom_target.";
  626. reportError(context, content->GetOriginalExpression(), e.str());
  627. return {};
  628. }
  629. return this->EvaluateWithLanguage(parameters, context, content, dagChecker,
  630. this->CompilerLanguage);
  631. }
  632. std::string EvaluateWithLanguage(const std::vector<std::string>& parameters,
  633. cmGeneratorExpressionContext* context,
  634. const GeneratorExpressionContent* content,
  635. cmGeneratorExpressionDAGChecker* /*unused*/,
  636. const std::string& lang) const
  637. {
  638. std::string const& compilerVersion =
  639. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_" + lang +
  640. "_COMPILER_VERSION");
  641. if (parameters.empty()) {
  642. return compilerVersion;
  643. }
  644. static cmsys::RegularExpression compilerIdValidator("^[0-9\\.]*$");
  645. if (!compilerIdValidator.find(parameters.front())) {
  646. reportError(context, content->GetOriginalExpression(),
  647. "Expression syntax not recognized.");
  648. return {};
  649. }
  650. if (compilerVersion.empty()) {
  651. return parameters.front().empty() ? "1" : "0";
  652. }
  653. return cmSystemTools::VersionCompare(cmSystemTools::OP_EQUAL,
  654. parameters.front().c_str(),
  655. compilerVersion.c_str())
  656. ? "1"
  657. : "0";
  658. }
  659. const char* const CompilerLanguage;
  660. };
  661. static const CompilerVersionNode cCompilerVersionNode("C"),
  662. cxxCompilerVersionNode("CXX"), cudaCompilerVersionNode("CUDA"),
  663. fortranCompilerVersionNode("Fortran");
  664. struct PlatformIdNode : public cmGeneratorExpressionNode
  665. {
  666. PlatformIdNode() {} // NOLINT(modernize-use-equals-default)
  667. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  668. std::string Evaluate(
  669. const std::vector<std::string>& parameters,
  670. cmGeneratorExpressionContext* context,
  671. const GeneratorExpressionContent* /*content*/,
  672. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  673. {
  674. std::string const& platformId =
  675. context->LG->GetMakefile()->GetSafeDefinition("CMAKE_SYSTEM_NAME");
  676. if (parameters.empty()) {
  677. return platformId;
  678. }
  679. if (platformId.empty()) {
  680. return parameters.front().empty() ? "1" : "0";
  681. }
  682. for (auto& param : parameters) {
  683. if (param == platformId) {
  684. return "1";
  685. }
  686. }
  687. return "0";
  688. }
  689. } platformIdNode;
  690. template <cmSystemTools::CompareOp Op>
  691. struct VersionNode : public cmGeneratorExpressionNode
  692. {
  693. VersionNode() {} // NOLINT(modernize-use-equals-default)
  694. int NumExpectedParameters() const override { return 2; }
  695. std::string Evaluate(
  696. const std::vector<std::string>& parameters,
  697. cmGeneratorExpressionContext* /*context*/,
  698. const GeneratorExpressionContent* /*content*/,
  699. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  700. {
  701. return cmSystemTools::VersionCompare(Op, parameters.front().c_str(),
  702. parameters[1].c_str())
  703. ? "1"
  704. : "0";
  705. }
  706. };
  707. static const VersionNode<cmSystemTools::OP_GREATER> versionGreaterNode;
  708. static const VersionNode<cmSystemTools::OP_GREATER_EQUAL> versionGreaterEqNode;
  709. static const VersionNode<cmSystemTools::OP_LESS> versionLessNode;
  710. static const VersionNode<cmSystemTools::OP_LESS_EQUAL> versionLessEqNode;
  711. static const VersionNode<cmSystemTools::OP_EQUAL> versionEqualNode;
  712. static const struct LinkOnlyNode : public cmGeneratorExpressionNode
  713. {
  714. LinkOnlyNode() {} // NOLINT(modernize-use-equals-default)
  715. std::string Evaluate(
  716. const std::vector<std::string>& parameters,
  717. cmGeneratorExpressionContext* context,
  718. const GeneratorExpressionContent* content,
  719. cmGeneratorExpressionDAGChecker* dagChecker) const override
  720. {
  721. if (!dagChecker) {
  722. reportError(context, content->GetOriginalExpression(),
  723. "$<LINK_ONLY:...> may only be used for linking");
  724. return std::string();
  725. }
  726. if (!dagChecker->GetTransitivePropertiesOnly()) {
  727. return parameters.front();
  728. }
  729. return std::string();
  730. }
  731. } linkOnlyNode;
  732. static const struct ConfigurationNode : public cmGeneratorExpressionNode
  733. {
  734. ConfigurationNode() {} // NOLINT(modernize-use-equals-default)
  735. int NumExpectedParameters() const override { return 0; }
  736. std::string Evaluate(
  737. const std::vector<std::string>& /*parameters*/,
  738. cmGeneratorExpressionContext* context,
  739. const GeneratorExpressionContent* /*content*/,
  740. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  741. {
  742. context->HadContextSensitiveCondition = true;
  743. return context->Config;
  744. }
  745. } configurationNode;
  746. static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
  747. {
  748. ConfigurationTestNode() {} // NOLINT(modernize-use-equals-default)
  749. int NumExpectedParameters() const override { return OneOrZeroParameters; }
  750. std::string Evaluate(
  751. const std::vector<std::string>& parameters,
  752. cmGeneratorExpressionContext* context,
  753. const GeneratorExpressionContent* content,
  754. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  755. {
  756. if (parameters.empty()) {
  757. return configurationNode.Evaluate(parameters, context, content, nullptr);
  758. }
  759. static cmsys::RegularExpression configValidator("^[A-Za-z0-9_]*$");
  760. if (!configValidator.find(parameters.front())) {
  761. reportError(context, content->GetOriginalExpression(),
  762. "Expression syntax not recognized.");
  763. return std::string();
  764. }
  765. context->HadContextSensitiveCondition = true;
  766. if (context->Config.empty()) {
  767. return parameters.front().empty() ? "1" : "0";
  768. }
  769. if (cmsysString_strcasecmp(parameters.front().c_str(),
  770. context->Config.c_str()) == 0) {
  771. return "1";
  772. }
  773. if (context->CurrentTarget && context->CurrentTarget->IsImported()) {
  774. const char* loc = nullptr;
  775. const char* imp = nullptr;
  776. std::string suffix;
  777. if (context->CurrentTarget->Target->GetMappedConfig(
  778. context->Config, &loc, &imp, suffix)) {
  779. // This imported target has an appropriate location
  780. // for this (possibly mapped) config.
  781. // Check if there is a proper config mapping for the tested config.
  782. std::vector<std::string> mappedConfigs;
  783. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  784. mapProp += cmSystemTools::UpperCase(context->Config);
  785. if (const char* mapValue =
  786. context->CurrentTarget->GetProperty(mapProp)) {
  787. cmSystemTools::ExpandListArgument(cmSystemTools::UpperCase(mapValue),
  788. mappedConfigs);
  789. return std::find(mappedConfigs.begin(), mappedConfigs.end(),
  790. cmSystemTools::UpperCase(parameters.front())) !=
  791. mappedConfigs.end()
  792. ? "1"
  793. : "0";
  794. }
  795. }
  796. }
  797. return "0";
  798. }
  799. } configurationTestNode;
  800. static const struct JoinNode : public cmGeneratorExpressionNode
  801. {
  802. JoinNode() {} // NOLINT(modernize-use-equals-default)
  803. int NumExpectedParameters() const override { return 2; }
  804. bool AcceptsArbitraryContentParameter() const override { return true; }
  805. std::string Evaluate(
  806. const std::vector<std::string>& parameters,
  807. cmGeneratorExpressionContext* /*context*/,
  808. const GeneratorExpressionContent* /*content*/,
  809. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  810. {
  811. std::vector<std::string> list;
  812. cmSystemTools::ExpandListArgument(parameters.front(), list);
  813. return cmJoin(list, parameters[1]);
  814. }
  815. } joinNode;
  816. static const struct CompileLanguageNode : public cmGeneratorExpressionNode
  817. {
  818. CompileLanguageNode() {} // NOLINT(modernize-use-equals-default)
  819. int NumExpectedParameters() const override { return ZeroOrMoreParameters; }
  820. std::string Evaluate(
  821. const std::vector<std::string>& parameters,
  822. cmGeneratorExpressionContext* context,
  823. const GeneratorExpressionContent* content,
  824. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  825. {
  826. if (context->Language.empty()) {
  827. reportError(
  828. context, content->GetOriginalExpression(),
  829. "$<COMPILE_LANGUAGE:...> may only be used to specify include "
  830. "directories, compile definitions, compile options, and to evaluate "
  831. "components of the file(GENERATE) command.");
  832. return std::string();
  833. }
  834. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  835. std::string genName = gg->GetName();
  836. if (genName.find("Makefiles") == std::string::npos &&
  837. genName.find("Ninja") == std::string::npos &&
  838. genName.find("Visual Studio") == std::string::npos &&
  839. genName.find("Xcode") == std::string::npos &&
  840. genName.find("Watcom WMake") == std::string::npos) {
  841. reportError(context, content->GetOriginalExpression(),
  842. "$<COMPILE_LANGUAGE:...> not supported for this generator.");
  843. return std::string();
  844. }
  845. if (parameters.empty()) {
  846. return context->Language;
  847. }
  848. for (auto& param : parameters) {
  849. if (context->Language == param) {
  850. return "1";
  851. }
  852. }
  853. return "0";
  854. }
  855. } languageNode;
  856. static const struct CompileLanguageAndIdNode : public cmGeneratorExpressionNode
  857. {
  858. CompileLanguageAndIdNode() {} // NOLINT(modernize-use-equals-default)
  859. int NumExpectedParameters() const override { return TwoOrMoreParameters; }
  860. std::string Evaluate(
  861. const std::vector<std::string>& parameters,
  862. cmGeneratorExpressionContext* context,
  863. const GeneratorExpressionContent* content,
  864. cmGeneratorExpressionDAGChecker* dagChecker) const override
  865. {
  866. if (!context->HeadTarget || context->Language.empty()) {
  867. // reportError(context, content->GetOriginalExpression(), "");
  868. reportError(
  869. context, content->GetOriginalExpression(),
  870. "$<COMPILE_LANG_AND_ID:lang,id> may only be used with binary targets "
  871. "to specify include directories, compile definitions, and compile "
  872. "options. It may not be used with the add_custom_command, "
  873. "add_custom_target, or file(GENERATE) commands.");
  874. return std::string();
  875. }
  876. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  877. std::string genName = gg->GetName();
  878. if (genName.find("Makefiles") == std::string::npos &&
  879. genName.find("Ninja") == std::string::npos &&
  880. genName.find("Visual Studio") == std::string::npos &&
  881. genName.find("Xcode") == std::string::npos &&
  882. genName.find("Watcom WMake") == std::string::npos) {
  883. reportError(
  884. context, content->GetOriginalExpression(),
  885. "$<COMPILE_LANG_AND_ID:lang,id> not supported for this generator.");
  886. return std::string();
  887. }
  888. const std::string& lang = context->Language;
  889. if (lang == parameters.front()) {
  890. std::vector<std::string> idParameter((parameters.cbegin() + 1),
  891. parameters.cend());
  892. return CompilerIdNode{ lang.c_str() }.EvaluateWithLanguage(
  893. idParameter, context, content, dagChecker, lang);
  894. }
  895. return "0";
  896. }
  897. } languageAndIdNode;
  898. template <typename T>
  899. std::string getLinkedTargetsContent(
  900. std::vector<T> const& libraries, cmGeneratorTarget const* target,
  901. cmGeneratorTarget const* headTarget, cmGeneratorExpressionContext* context,
  902. cmGeneratorExpressionDAGChecker* dagChecker,
  903. const std::string& interfacePropertyName)
  904. {
  905. std::string linkedTargetsContent;
  906. std::string sep;
  907. std::string depString;
  908. for (T const& l : libraries) {
  909. // Broken code can have a target in its own link interface.
  910. // Don't follow such link interface entries so as not to create a
  911. // self-referencing loop.
  912. if (l.Target && l.Target != target) {
  913. std::string uniqueName =
  914. target->GetGlobalGenerator()->IndexGeneratorTargetUniquely(l.Target);
  915. depString += sep + "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," +
  916. interfacePropertyName + ">";
  917. sep = ";";
  918. }
  919. }
  920. if (!depString.empty()) {
  921. linkedTargetsContent =
  922. cmGeneratorExpressionNode::EvaluateDependentExpression(
  923. depString, target->GetLocalGenerator(), context, headTarget, target,
  924. dagChecker);
  925. }
  926. linkedTargetsContent =
  927. cmGeneratorExpression::StripEmptyListElements(linkedTargetsContent);
  928. return linkedTargetsContent;
  929. }
  930. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  931. {
  932. TargetPropertyNode() {} // NOLINT(modernize-use-equals-default)
  933. // This node handles errors on parameter count itself.
  934. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  935. static const char* GetErrorText(std::string const& targetName,
  936. std::string const& propertyName)
  937. {
  938. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  939. if (targetName.empty() && propertyName.empty()) {
  940. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  941. "target name and property name.";
  942. }
  943. if (targetName.empty()) {
  944. return "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  945. "target name.";
  946. }
  947. if (!cmGeneratorExpression::IsValidTargetName(targetName)) {
  948. if (!propertyNameValidator.find(propertyName)) {
  949. return "Target name and property name not supported.";
  950. }
  951. return "Target name not supported.";
  952. }
  953. return nullptr;
  954. }
  955. std::string Evaluate(
  956. const std::vector<std::string>& parameters,
  957. cmGeneratorExpressionContext* context,
  958. const GeneratorExpressionContent* content,
  959. cmGeneratorExpressionDAGChecker* dagCheckerParent) const override
  960. {
  961. static cmsys::RegularExpression propertyNameValidator("^[A-Za-z0-9_]+$");
  962. cmGeneratorTarget const* target = nullptr;
  963. std::string targetName, propertyName;
  964. if (parameters.size() == 2) {
  965. targetName = parameters[0];
  966. propertyName = parameters[1];
  967. if (const char* e = GetErrorText(targetName, propertyName)) {
  968. reportError(context, content->GetOriginalExpression(), e);
  969. return std::string();
  970. }
  971. if (propertyName == "ALIASED_TARGET"_s) {
  972. if (context->LG->GetMakefile()->IsAlias(targetName)) {
  973. if (cmGeneratorTarget* tgt =
  974. context->LG->FindGeneratorTargetToUse(targetName)) {
  975. return tgt->GetName();
  976. }
  977. }
  978. return std::string();
  979. }
  980. target = context->LG->FindGeneratorTargetToUse(targetName);
  981. if (!target) {
  982. std::ostringstream e;
  983. e << "Target \"" << targetName << "\" not found.";
  984. reportError(context, content->GetOriginalExpression(), e.str());
  985. return std::string();
  986. }
  987. context->AllTargets.insert(target);
  988. } else if (parameters.size() == 1) {
  989. target = context->HeadTarget;
  990. propertyName = parameters[0];
  991. // Keep track of the properties seen while processing.
  992. // The evaluation of the LINK_LIBRARIES generator expressions
  993. // will check this to ensure that properties have one consistent
  994. // value for all evaluations.
  995. context->SeenTargetProperties.insert(propertyName);
  996. context->HadHeadSensitiveCondition = true;
  997. if (!target) {
  998. reportError(
  999. context, content->GetOriginalExpression(),
  1000. "$<TARGET_PROPERTY:prop> may only be used with binary targets. "
  1001. "It may not be used with add_custom_command or add_custom_target. "
  1002. "Specify the target to read a property from using the "
  1003. "$<TARGET_PROPERTY:tgt,prop> signature instead.");
  1004. return std::string();
  1005. }
  1006. } else {
  1007. reportError(
  1008. context, content->GetOriginalExpression(),
  1009. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  1010. return std::string();
  1011. }
  1012. if (propertyName == "SOURCES") {
  1013. context->SourceSensitiveTargets.insert(target);
  1014. }
  1015. if (propertyName.empty()) {
  1016. reportError(
  1017. context, content->GetOriginalExpression(),
  1018. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  1019. "name.");
  1020. return std::string();
  1021. }
  1022. if (!propertyNameValidator.find(propertyName)) {
  1023. ::reportError(context, content->GetOriginalExpression(),
  1024. "Property name not supported.");
  1025. return std::string();
  1026. }
  1027. assert(target);
  1028. if (propertyName == "LINKER_LANGUAGE") {
  1029. if (target->LinkLanguagePropagatesToDependents() && dagCheckerParent &&
  1030. (dagCheckerParent->EvaluatingLinkLibraries() ||
  1031. dagCheckerParent->EvaluatingSources())) {
  1032. reportError(
  1033. context, content->GetOriginalExpression(),
  1034. "LINKER_LANGUAGE target property can not be used while evaluating "
  1035. "link libraries for a static library");
  1036. return std::string();
  1037. }
  1038. return target->GetLinkerLanguage(context->Config);
  1039. }
  1040. std::string interfacePropertyName;
  1041. bool isInterfaceProperty = false;
  1042. #define POPULATE_INTERFACE_PROPERTY_NAME(prop) \
  1043. if (propertyName == #prop) { \
  1044. interfacePropertyName = "INTERFACE_" #prop; \
  1045. } else if (propertyName == "INTERFACE_" #prop) { \
  1046. interfacePropertyName = "INTERFACE_" #prop; \
  1047. isInterfaceProperty = true; \
  1048. } else
  1049. CM_FOR_EACH_TRANSITIVE_PROPERTY_NAME(POPULATE_INTERFACE_PROPERTY_NAME)
  1050. // Note that the above macro terminates with an else
  1051. /* else */ if (cmHasLiteralPrefix(propertyName, "COMPILE_DEFINITIONS_")) {
  1052. cmPolicies::PolicyStatus polSt =
  1053. context->LG->GetPolicyStatus(cmPolicies::CMP0043);
  1054. if (polSt == cmPolicies::WARN || polSt == cmPolicies::OLD) {
  1055. interfacePropertyName = "INTERFACE_COMPILE_DEFINITIONS";
  1056. }
  1057. }
  1058. #undef POPULATE_INTERFACE_PROPERTY_NAME
  1059. cmGeneratorExpressionDAGChecker dagChecker(
  1060. context->Backtrace, target, propertyName, content, dagCheckerParent);
  1061. switch (dagChecker.Check()) {
  1062. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1063. dagChecker.ReportError(context, content->GetOriginalExpression());
  1064. return std::string();
  1065. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1066. // No error. We just skip cyclic references.
  1067. return std::string();
  1068. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1069. if (isInterfaceProperty) {
  1070. // No error. We're not going to find anything new here.
  1071. return std::string();
  1072. }
  1073. case cmGeneratorExpressionDAGChecker::DAG:
  1074. break;
  1075. }
  1076. std::string result;
  1077. bool haveProp = false;
  1078. if (const char* p = target->GetProperty(propertyName)) {
  1079. result = p;
  1080. haveProp = true;
  1081. }
  1082. if (dagCheckerParent) {
  1083. if (dagCheckerParent->EvaluatingGenexExpression() ||
  1084. dagCheckerParent->EvaluatingPICExpression()) {
  1085. // No check required.
  1086. } else if (dagCheckerParent->EvaluatingLinkLibraries()) {
  1087. if (!interfacePropertyName.empty()) {
  1088. reportError(
  1089. context, content->GetOriginalExpression(),
  1090. "$<TARGET_PROPERTY:...> expression in link libraries "
  1091. "evaluation depends on target property which is transitive "
  1092. "over the link libraries, creating a recursion.");
  1093. return std::string();
  1094. }
  1095. if (!haveProp) {
  1096. return std::string();
  1097. }
  1098. } else {
  1099. #define ASSERT_TRANSITIVE_PROPERTY_METHOD(METHOD) dagCheckerParent->METHOD() ||
  1100. assert(CM_FOR_EACH_TRANSITIVE_PROPERTY_METHOD(
  1101. ASSERT_TRANSITIVE_PROPERTY_METHOD) false); // NOLINT(clang-tidy)
  1102. #undef ASSERT_TRANSITIVE_PROPERTY_METHOD
  1103. }
  1104. }
  1105. if (!haveProp && !target->IsImported() &&
  1106. target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1107. if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
  1108. context->Config)) {
  1109. context->HadContextSensitiveCondition = true;
  1110. return target->GetLinkInterfaceDependentBoolProperty(propertyName,
  1111. context->Config)
  1112. ? "1"
  1113. : "0";
  1114. }
  1115. if (target->IsLinkInterfaceDependentStringProperty(propertyName,
  1116. context->Config)) {
  1117. context->HadContextSensitiveCondition = true;
  1118. const char* propContent =
  1119. target->GetLinkInterfaceDependentStringProperty(propertyName,
  1120. context->Config);
  1121. return propContent ? propContent : "";
  1122. }
  1123. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1124. context->Config)) {
  1125. context->HadContextSensitiveCondition = true;
  1126. const char* propContent =
  1127. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1128. context->Config);
  1129. return propContent ? propContent : "";
  1130. }
  1131. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1132. context->Config)) {
  1133. context->HadContextSensitiveCondition = true;
  1134. const char* propContent =
  1135. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1136. context->Config);
  1137. return propContent ? propContent : "";
  1138. }
  1139. }
  1140. if (!target->IsImported() && dagCheckerParent &&
  1141. !dagCheckerParent->EvaluatingLinkLibraries()) {
  1142. if (target->IsLinkInterfaceDependentNumberMinProperty(propertyName,
  1143. context->Config)) {
  1144. context->HadContextSensitiveCondition = true;
  1145. const char* propContent =
  1146. target->GetLinkInterfaceDependentNumberMinProperty(propertyName,
  1147. context->Config);
  1148. return propContent ? propContent : "";
  1149. }
  1150. if (target->IsLinkInterfaceDependentNumberMaxProperty(propertyName,
  1151. context->Config)) {
  1152. context->HadContextSensitiveCondition = true;
  1153. const char* propContent =
  1154. target->GetLinkInterfaceDependentNumberMaxProperty(propertyName,
  1155. context->Config);
  1156. return propContent ? propContent : "";
  1157. }
  1158. }
  1159. if (!interfacePropertyName.empty()) {
  1160. cmGeneratorTarget const* headTarget =
  1161. context->HeadTarget && isInterfaceProperty ? context->HeadTarget
  1162. : target;
  1163. result = this->EvaluateDependentExpression(
  1164. result, context->LG, context, headTarget, target, &dagChecker);
  1165. std::string linkedTargetsContent;
  1166. if (isInterfaceProperty) {
  1167. if (cmLinkInterfaceLibraries const* iface =
  1168. target->GetLinkInterfaceLibraries(context->Config, headTarget,
  1169. true)) {
  1170. linkedTargetsContent = getLinkedTargetsContent(
  1171. iface->Libraries, target, headTarget, context, &dagChecker,
  1172. interfacePropertyName);
  1173. }
  1174. } else {
  1175. if (cmLinkImplementationLibraries const* impl =
  1176. target->GetLinkImplementationLibraries(context->Config)) {
  1177. linkedTargetsContent =
  1178. getLinkedTargetsContent(impl->Libraries, target, target, context,
  1179. &dagChecker, interfacePropertyName);
  1180. }
  1181. }
  1182. if (!linkedTargetsContent.empty()) {
  1183. result += (result.empty() ? "" : ";") + linkedTargetsContent;
  1184. }
  1185. }
  1186. return result;
  1187. }
  1188. } targetPropertyNode;
  1189. static const struct TargetNameNode : public cmGeneratorExpressionNode
  1190. {
  1191. TargetNameNode() {} // NOLINT(modernize-use-equals-default)
  1192. bool GeneratesContent() const override { return true; }
  1193. bool AcceptsArbitraryContentParameter() const override { return true; }
  1194. bool RequiresLiteralInput() const override { return true; }
  1195. std::string Evaluate(
  1196. const std::vector<std::string>& parameters,
  1197. cmGeneratorExpressionContext* /*context*/,
  1198. const GeneratorExpressionContent* /*content*/,
  1199. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1200. {
  1201. return parameters.front();
  1202. }
  1203. int NumExpectedParameters() const override { return 1; }
  1204. } targetNameNode;
  1205. static const struct TargetObjectsNode : public cmGeneratorExpressionNode
  1206. {
  1207. TargetObjectsNode() {} // NOLINT(modernize-use-equals-default)
  1208. std::string Evaluate(
  1209. const std::vector<std::string>& parameters,
  1210. cmGeneratorExpressionContext* context,
  1211. const GeneratorExpressionContent* content,
  1212. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1213. {
  1214. std::string tgtName = parameters.front();
  1215. cmGeneratorTarget* gt = context->LG->FindGeneratorTargetToUse(tgtName);
  1216. if (!gt) {
  1217. std::ostringstream e;
  1218. e << "Objects of target \"" << tgtName
  1219. << "\" referenced but no such target exists.";
  1220. reportError(context, content->GetOriginalExpression(), e.str());
  1221. return std::string();
  1222. }
  1223. cmStateEnums::TargetType type = gt->GetType();
  1224. if (type != cmStateEnums::EXECUTABLE &&
  1225. type != cmStateEnums::STATIC_LIBRARY &&
  1226. type != cmStateEnums::SHARED_LIBRARY &&
  1227. type != cmStateEnums::MODULE_LIBRARY &&
  1228. type != cmStateEnums::OBJECT_LIBRARY) {
  1229. std::ostringstream e;
  1230. e << "Objects of target \"" << tgtName
  1231. << "\" referenced but is not an allowed library types (EXECUTABLE, "
  1232. << "STATIC, SHARED, MODULE, OBJECT).";
  1233. reportError(context, content->GetOriginalExpression(), e.str());
  1234. return std::string();
  1235. }
  1236. if (!context->EvaluateForBuildsystem) {
  1237. cmGlobalGenerator* gg = context->LG->GetGlobalGenerator();
  1238. std::string reason;
  1239. if (!gg->HasKnownObjectFileLocation(&reason)) {
  1240. std::ostringstream e;
  1241. e << "The evaluation of the TARGET_OBJECTS generator expression "
  1242. "is only suitable for consumption by CMake (limited"
  1243. << reason
  1244. << "). "
  1245. "It is not suitable for writing out elsewhere.";
  1246. reportError(context, content->GetOriginalExpression(), e.str());
  1247. return std::string();
  1248. }
  1249. }
  1250. std::vector<std::string> objects;
  1251. if (gt->IsImported()) {
  1252. const char* loc = nullptr;
  1253. const char* imp = nullptr;
  1254. std::string suffix;
  1255. if (gt->Target->GetMappedConfig(context->Config, &loc, &imp, suffix)) {
  1256. cmSystemTools::ExpandListArgument(loc, objects);
  1257. }
  1258. context->HadContextSensitiveCondition = true;
  1259. } else {
  1260. gt->GetTargetObjectNames(context->Config, objects);
  1261. std::string obj_dir;
  1262. if (context->EvaluateForBuildsystem) {
  1263. // Use object file directory with buildsystem placeholder.
  1264. obj_dir = gt->ObjectDirectory;
  1265. // Here we assume that the set of object files produced
  1266. // by an object library does not vary with configuration
  1267. // and do not set HadContextSensitiveCondition to true.
  1268. } else {
  1269. // Use object file directory with per-config location.
  1270. obj_dir = gt->GetObjectDirectory(context->Config);
  1271. context->HadContextSensitiveCondition = true;
  1272. }
  1273. for (std::string& o : objects) {
  1274. o = obj_dir + o;
  1275. }
  1276. }
  1277. // Create the cmSourceFile instances in the referencing directory.
  1278. cmMakefile* mf = context->LG->GetMakefile();
  1279. for (std::string& o : objects) {
  1280. mf->AddTargetObject(tgtName, o);
  1281. }
  1282. return cmJoin(objects, ";");
  1283. }
  1284. } targetObjectsNode;
  1285. static const struct CompileFeaturesNode : public cmGeneratorExpressionNode
  1286. {
  1287. CompileFeaturesNode() {} // NOLINT(modernize-use-equals-default)
  1288. int NumExpectedParameters() const override { return OneOrMoreParameters; }
  1289. std::string Evaluate(
  1290. const std::vector<std::string>& parameters,
  1291. cmGeneratorExpressionContext* context,
  1292. const GeneratorExpressionContent* content,
  1293. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1294. {
  1295. cmGeneratorTarget const* target = context->HeadTarget;
  1296. if (!target) {
  1297. reportError(
  1298. context, content->GetOriginalExpression(),
  1299. "$<COMPILE_FEATURE> may only be used with binary targets. It may "
  1300. "not be used with add_custom_command or add_custom_target.");
  1301. return std::string();
  1302. }
  1303. context->HadHeadSensitiveCondition = true;
  1304. typedef std::map<std::string, std::vector<std::string>> LangMap;
  1305. static LangMap availableFeatures;
  1306. LangMap testedFeatures;
  1307. for (std::string const& p : parameters) {
  1308. std::string error;
  1309. std::string lang;
  1310. if (!context->LG->GetMakefile()->CompileFeatureKnown(
  1311. context->HeadTarget->Target, p, lang, &error)) {
  1312. reportError(context, content->GetOriginalExpression(), error);
  1313. return std::string();
  1314. }
  1315. testedFeatures[lang].push_back(p);
  1316. if (availableFeatures.find(lang) == availableFeatures.end()) {
  1317. const char* featuresKnown =
  1318. context->LG->GetMakefile()->CompileFeaturesAvailable(lang, &error);
  1319. if (!featuresKnown) {
  1320. reportError(context, content->GetOriginalExpression(), error);
  1321. return std::string();
  1322. }
  1323. cmSystemTools::ExpandListArgument(featuresKnown,
  1324. availableFeatures[lang]);
  1325. }
  1326. }
  1327. bool evalLL = dagChecker && dagChecker->EvaluatingLinkLibraries();
  1328. for (auto const& lit : testedFeatures) {
  1329. std::vector<std::string> const& langAvailable =
  1330. availableFeatures[lit.first];
  1331. const char* standardDefault = context->LG->GetMakefile()->GetDefinition(
  1332. "CMAKE_" + lit.first + "_STANDARD_DEFAULT");
  1333. for (std::string const& it : lit.second) {
  1334. if (std::find(langAvailable.begin(), langAvailable.end(), it) ==
  1335. langAvailable.end()) {
  1336. return "0";
  1337. }
  1338. if (standardDefault && !*standardDefault) {
  1339. // This compiler has no notion of language standard levels.
  1340. // All features known for the language are always available.
  1341. continue;
  1342. }
  1343. if (!context->LG->GetMakefile()->HaveStandardAvailable(
  1344. target->Target, lit.first, it)) {
  1345. if (evalLL) {
  1346. const char* l = target->GetProperty(lit.first + "_STANDARD");
  1347. if (!l) {
  1348. l = standardDefault;
  1349. }
  1350. assert(l);
  1351. context->MaxLanguageStandard[target][lit.first] = l;
  1352. } else {
  1353. return "0";
  1354. }
  1355. }
  1356. }
  1357. }
  1358. return "1";
  1359. }
  1360. } compileFeaturesNode;
  1361. static const char* targetPolicyWhitelist[] = {
  1362. nullptr
  1363. #define TARGET_POLICY_STRING(POLICY) , #POLICY
  1364. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_STRING)
  1365. #undef TARGET_POLICY_STRING
  1366. };
  1367. cmPolicies::PolicyStatus statusForTarget(cmGeneratorTarget const* tgt,
  1368. const char* policy)
  1369. {
  1370. #define RETURN_POLICY(POLICY) \
  1371. if (strcmp(policy, #POLICY) == 0) { \
  1372. return tgt->GetPolicyStatus##POLICY(); \
  1373. }
  1374. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY)
  1375. #undef RETURN_POLICY
  1376. assert(false && "Unreachable code. Not a valid policy");
  1377. return cmPolicies::WARN;
  1378. }
  1379. cmPolicies::PolicyID policyForString(const char* policy_id)
  1380. {
  1381. #define RETURN_POLICY_ID(POLICY_ID) \
  1382. if (strcmp(policy_id, #POLICY_ID) == 0) { \
  1383. return cmPolicies::POLICY_ID; \
  1384. }
  1385. CM_FOR_EACH_TARGET_POLICY(RETURN_POLICY_ID)
  1386. #undef RETURN_POLICY_ID
  1387. assert(false && "Unreachable code. Not a valid policy");
  1388. return cmPolicies::CMP0002;
  1389. }
  1390. static const struct TargetPolicyNode : public cmGeneratorExpressionNode
  1391. {
  1392. TargetPolicyNode() {} // NOLINT(modernize-use-equals-default)
  1393. int NumExpectedParameters() const override { return 1; }
  1394. std::string Evaluate(
  1395. const std::vector<std::string>& parameters,
  1396. cmGeneratorExpressionContext* context,
  1397. const GeneratorExpressionContent* content,
  1398. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1399. {
  1400. if (!context->HeadTarget) {
  1401. reportError(
  1402. context, content->GetOriginalExpression(),
  1403. "$<TARGET_POLICY:prop> may only be used with binary targets. It "
  1404. "may not be used with add_custom_command or add_custom_target.");
  1405. return std::string();
  1406. }
  1407. context->HadContextSensitiveCondition = true;
  1408. context->HadHeadSensitiveCondition = true;
  1409. for (size_t i = 1; i < cm::size(targetPolicyWhitelist); ++i) {
  1410. const char* policy = targetPolicyWhitelist[i];
  1411. if (parameters.front() == policy) {
  1412. cmLocalGenerator* lg = context->HeadTarget->GetLocalGenerator();
  1413. switch (statusForTarget(context->HeadTarget, policy)) {
  1414. case cmPolicies::WARN:
  1415. lg->IssueMessage(
  1416. MessageType::AUTHOR_WARNING,
  1417. cmPolicies::GetPolicyWarning(policyForString(policy)));
  1418. CM_FALLTHROUGH;
  1419. case cmPolicies::REQUIRED_IF_USED:
  1420. case cmPolicies::REQUIRED_ALWAYS:
  1421. case cmPolicies::OLD:
  1422. return "0";
  1423. case cmPolicies::NEW:
  1424. return "1";
  1425. }
  1426. }
  1427. }
  1428. reportError(
  1429. context, content->GetOriginalExpression(),
  1430. "$<TARGET_POLICY:prop> may only be used with a limited number of "
  1431. "policies. Currently it may be used with the following policies:\n"
  1432. #define STRINGIFY_HELPER(X) #X
  1433. #define STRINGIFY(X) STRINGIFY_HELPER(X)
  1434. #define TARGET_POLICY_LIST_ITEM(POLICY) " * " STRINGIFY(POLICY) "\n"
  1435. CM_FOR_EACH_TARGET_POLICY(TARGET_POLICY_LIST_ITEM)
  1436. #undef TARGET_POLICY_LIST_ITEM
  1437. );
  1438. return std::string();
  1439. }
  1440. } targetPolicyNode;
  1441. static const struct InstallPrefixNode : public cmGeneratorExpressionNode
  1442. {
  1443. InstallPrefixNode() {} // NOLINT(modernize-use-equals-default)
  1444. bool GeneratesContent() const override { return true; }
  1445. int NumExpectedParameters() const override { return 0; }
  1446. std::string Evaluate(
  1447. const std::vector<std::string>& /*parameters*/,
  1448. cmGeneratorExpressionContext* context,
  1449. const GeneratorExpressionContent* content,
  1450. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1451. {
  1452. reportError(context, content->GetOriginalExpression(),
  1453. "INSTALL_PREFIX is a marker for install(EXPORT) only. It "
  1454. "should never be evaluated.");
  1455. return std::string();
  1456. }
  1457. } installPrefixNode;
  1458. class ArtifactDirTag;
  1459. class ArtifactLinkerTag;
  1460. class ArtifactNameTag;
  1461. class ArtifactPathTag;
  1462. class ArtifactPdbTag;
  1463. class ArtifactSonameTag;
  1464. class ArtifactBundleDirTag;
  1465. class ArtifactBundleContentDirTag;
  1466. template <typename ArtifactT>
  1467. struct TargetFilesystemArtifactResultCreator
  1468. {
  1469. static std::string Create(cmGeneratorTarget* target,
  1470. cmGeneratorExpressionContext* context,
  1471. const GeneratorExpressionContent* content);
  1472. };
  1473. template <>
  1474. struct TargetFilesystemArtifactResultCreator<ArtifactSonameTag>
  1475. {
  1476. static std::string Create(cmGeneratorTarget* target,
  1477. cmGeneratorExpressionContext* context,
  1478. const GeneratorExpressionContent* content)
  1479. {
  1480. // The target soname file (.so.1).
  1481. if (target->IsDLLPlatform()) {
  1482. ::reportError(context, content->GetOriginalExpression(),
  1483. "TARGET_SONAME_FILE is not allowed "
  1484. "for DLL target platforms.");
  1485. return std::string();
  1486. }
  1487. if (target->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1488. ::reportError(context, content->GetOriginalExpression(),
  1489. "TARGET_SONAME_FILE is allowed only for "
  1490. "SHARED libraries.");
  1491. return std::string();
  1492. }
  1493. std::string result = target->GetDirectory(context->Config);
  1494. result += "/";
  1495. result += target->GetSOName(context->Config);
  1496. return result;
  1497. }
  1498. };
  1499. template <>
  1500. struct TargetFilesystemArtifactResultCreator<ArtifactPdbTag>
  1501. {
  1502. static std::string Create(cmGeneratorTarget* target,
  1503. cmGeneratorExpressionContext* context,
  1504. const GeneratorExpressionContent* content)
  1505. {
  1506. if (target->IsImported()) {
  1507. ::reportError(context, content->GetOriginalExpression(),
  1508. "TARGET_PDB_FILE not allowed for IMPORTED targets.");
  1509. return std::string();
  1510. }
  1511. std::string language = target->GetLinkerLanguage(context->Config);
  1512. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1513. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1514. ::reportError(context, content->GetOriginalExpression(),
  1515. "TARGET_PDB_FILE is not supported by the target linker.");
  1516. return std::string();
  1517. }
  1518. cmStateEnums::TargetType targetType = target->GetType();
  1519. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1520. targetType != cmStateEnums::MODULE_LIBRARY &&
  1521. targetType != cmStateEnums::EXECUTABLE) {
  1522. ::reportError(context, content->GetOriginalExpression(),
  1523. "TARGET_PDB_FILE is allowed only for "
  1524. "targets with linker created artifacts.");
  1525. return std::string();
  1526. }
  1527. std::string result = target->GetPDBDirectory(context->Config);
  1528. result += "/";
  1529. result += target->GetPDBName(context->Config);
  1530. return result;
  1531. }
  1532. };
  1533. template <>
  1534. struct TargetFilesystemArtifactResultCreator<ArtifactLinkerTag>
  1535. {
  1536. static std::string Create(cmGeneratorTarget* target,
  1537. cmGeneratorExpressionContext* context,
  1538. const GeneratorExpressionContent* content)
  1539. {
  1540. // The file used to link to the target (.so, .lib, .a).
  1541. if (!target->IsLinkable()) {
  1542. ::reportError(context, content->GetOriginalExpression(),
  1543. "TARGET_LINKER_FILE is allowed only for libraries and "
  1544. "executables with ENABLE_EXPORTS.");
  1545. return std::string();
  1546. }
  1547. cmStateEnums::ArtifactType artifact =
  1548. target->HasImportLibrary(context->Config)
  1549. ? cmStateEnums::ImportLibraryArtifact
  1550. : cmStateEnums::RuntimeBinaryArtifact;
  1551. return target->GetFullPath(context->Config, artifact);
  1552. }
  1553. };
  1554. template <>
  1555. struct TargetFilesystemArtifactResultCreator<ArtifactBundleDirTag>
  1556. {
  1557. static std::string Create(cmGeneratorTarget* target,
  1558. cmGeneratorExpressionContext* context,
  1559. const GeneratorExpressionContent* content)
  1560. {
  1561. if (target->IsImported()) {
  1562. ::reportError(context, content->GetOriginalExpression(),
  1563. "TARGET_BUNDLE_DIR not allowed for IMPORTED targets.");
  1564. return std::string();
  1565. }
  1566. if (!target->IsBundleOnApple()) {
  1567. ::reportError(context, content->GetOriginalExpression(),
  1568. "TARGET_BUNDLE_DIR is allowed only for Bundle targets.");
  1569. return std::string();
  1570. }
  1571. std::string outpath = target->GetDirectory(context->Config) + '/';
  1572. return target->BuildBundleDirectory(outpath, context->Config,
  1573. cmGeneratorTarget::BundleDirLevel);
  1574. }
  1575. };
  1576. template <>
  1577. struct TargetFilesystemArtifactResultCreator<ArtifactBundleContentDirTag>
  1578. {
  1579. static std::string Create(cmGeneratorTarget* target,
  1580. cmGeneratorExpressionContext* context,
  1581. const GeneratorExpressionContent* content)
  1582. {
  1583. if (target->IsImported()) {
  1584. ::reportError(
  1585. context, content->GetOriginalExpression(),
  1586. "TARGET_BUNDLE_CONTENT_DIR not allowed for IMPORTED targets.");
  1587. return std::string();
  1588. }
  1589. if (!target->IsBundleOnApple()) {
  1590. ::reportError(
  1591. context, content->GetOriginalExpression(),
  1592. "TARGET_BUNDLE_CONTENT_DIR is allowed only for Bundle targets.");
  1593. return std::string();
  1594. }
  1595. std::string outpath = target->GetDirectory(context->Config) + '/';
  1596. return target->BuildBundleDirectory(outpath, context->Config,
  1597. cmGeneratorTarget::ContentLevel);
  1598. }
  1599. };
  1600. template <>
  1601. struct TargetFilesystemArtifactResultCreator<ArtifactNameTag>
  1602. {
  1603. static std::string Create(cmGeneratorTarget* target,
  1604. cmGeneratorExpressionContext* context,
  1605. const GeneratorExpressionContent* /*unused*/)
  1606. {
  1607. return target->GetFullPath(context->Config,
  1608. cmStateEnums::RuntimeBinaryArtifact, true);
  1609. }
  1610. };
  1611. template <typename ArtifactT>
  1612. struct TargetFilesystemArtifactResultGetter
  1613. {
  1614. static std::string Get(const std::string& result);
  1615. };
  1616. template <>
  1617. struct TargetFilesystemArtifactResultGetter<ArtifactNameTag>
  1618. {
  1619. static std::string Get(const std::string& result)
  1620. {
  1621. return cmSystemTools::GetFilenameName(result);
  1622. }
  1623. };
  1624. template <>
  1625. struct TargetFilesystemArtifactResultGetter<ArtifactDirTag>
  1626. {
  1627. static std::string Get(const std::string& result)
  1628. {
  1629. return cmSystemTools::GetFilenamePath(result);
  1630. }
  1631. };
  1632. template <>
  1633. struct TargetFilesystemArtifactResultGetter<ArtifactPathTag>
  1634. {
  1635. static std::string Get(const std::string& result) { return result; }
  1636. };
  1637. struct TargetArtifactBase : public cmGeneratorExpressionNode
  1638. {
  1639. TargetArtifactBase() {} // NOLINT(modernize-use-equals-default)
  1640. protected:
  1641. cmGeneratorTarget* GetTarget(
  1642. const std::vector<std::string>& parameters,
  1643. cmGeneratorExpressionContext* context,
  1644. const GeneratorExpressionContent* content,
  1645. cmGeneratorExpressionDAGChecker* dagChecker) const
  1646. {
  1647. // Lookup the referenced target.
  1648. std::string name = parameters.front();
  1649. if (!cmGeneratorExpression::IsValidTargetName(name)) {
  1650. ::reportError(context, content->GetOriginalExpression(),
  1651. "Expression syntax not recognized.");
  1652. return nullptr;
  1653. }
  1654. cmGeneratorTarget* target = context->LG->FindGeneratorTargetToUse(name);
  1655. if (!target) {
  1656. ::reportError(context, content->GetOriginalExpression(),
  1657. "No target \"" + name + "\"");
  1658. return nullptr;
  1659. }
  1660. if (target->GetType() >= cmStateEnums::OBJECT_LIBRARY &&
  1661. target->GetType() != cmStateEnums::UNKNOWN_LIBRARY) {
  1662. ::reportError(context, content->GetOriginalExpression(),
  1663. "Target \"" + name +
  1664. "\" is not an executable or library.");
  1665. return nullptr;
  1666. }
  1667. if (dagChecker &&
  1668. (dagChecker->EvaluatingLinkLibraries(target) ||
  1669. (dagChecker->EvaluatingSources() &&
  1670. target == dagChecker->TopTarget()))) {
  1671. ::reportError(context, content->GetOriginalExpression(),
  1672. "Expressions which require the linker language may not "
  1673. "be used while evaluating link libraries");
  1674. return nullptr;
  1675. }
  1676. return target;
  1677. }
  1678. };
  1679. template <typename ArtifactT, typename ComponentT>
  1680. struct TargetFilesystemArtifact : public TargetArtifactBase
  1681. {
  1682. TargetFilesystemArtifact() {} // NOLINT(modernize-use-equals-default)
  1683. int NumExpectedParameters() const override { return 1; }
  1684. std::string Evaluate(
  1685. const std::vector<std::string>& parameters,
  1686. cmGeneratorExpressionContext* context,
  1687. const GeneratorExpressionContent* content,
  1688. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1689. {
  1690. cmGeneratorTarget* target =
  1691. this->GetTarget(parameters, context, content, dagChecker);
  1692. if (!target) {
  1693. return std::string();
  1694. }
  1695. context->DependTargets.insert(target);
  1696. context->AllTargets.insert(target);
  1697. std::string result =
  1698. TargetFilesystemArtifactResultCreator<ArtifactT>::Create(target, context,
  1699. content);
  1700. if (context->HadError) {
  1701. return std::string();
  1702. }
  1703. return TargetFilesystemArtifactResultGetter<ComponentT>::Get(result);
  1704. }
  1705. };
  1706. template <typename ArtifactT>
  1707. struct TargetFilesystemArtifactNodeGroup
  1708. {
  1709. TargetFilesystemArtifactNodeGroup() // NOLINT(modernize-use-equals-default)
  1710. {
  1711. }
  1712. TargetFilesystemArtifact<ArtifactT, ArtifactPathTag> File;
  1713. TargetFilesystemArtifact<ArtifactT, ArtifactNameTag> FileName;
  1714. TargetFilesystemArtifact<ArtifactT, ArtifactDirTag> FileDir;
  1715. };
  1716. static const TargetFilesystemArtifactNodeGroup<ArtifactNameTag>
  1717. targetNodeGroup;
  1718. static const TargetFilesystemArtifactNodeGroup<ArtifactLinkerTag>
  1719. targetLinkerNodeGroup;
  1720. static const TargetFilesystemArtifactNodeGroup<ArtifactSonameTag>
  1721. targetSoNameNodeGroup;
  1722. static const TargetFilesystemArtifactNodeGroup<ArtifactPdbTag>
  1723. targetPdbNodeGroup;
  1724. static const TargetFilesystemArtifact<ArtifactBundleDirTag, ArtifactPathTag>
  1725. targetBundleDirNode;
  1726. static const TargetFilesystemArtifact<ArtifactBundleContentDirTag,
  1727. ArtifactPathTag>
  1728. targetBundleContentDirNode;
  1729. //
  1730. // To retrieve base name for various artifacts
  1731. //
  1732. template <typename ArtifactT>
  1733. struct TargetOutputNameArtifactResultGetter
  1734. {
  1735. static std::string Get(cmGeneratorTarget* target,
  1736. cmGeneratorExpressionContext* context,
  1737. const GeneratorExpressionContent* content);
  1738. };
  1739. template <>
  1740. struct TargetOutputNameArtifactResultGetter<ArtifactNameTag>
  1741. {
  1742. static std::string Get(cmGeneratorTarget* target,
  1743. cmGeneratorExpressionContext* context,
  1744. const GeneratorExpressionContent* /*unused*/)
  1745. {
  1746. return target->GetOutputName(context->Config,
  1747. cmStateEnums::RuntimeBinaryArtifact) +
  1748. target->GetFilePostfix(context->Config);
  1749. }
  1750. };
  1751. template <>
  1752. struct TargetOutputNameArtifactResultGetter<ArtifactLinkerTag>
  1753. {
  1754. static std::string Get(cmGeneratorTarget* target,
  1755. cmGeneratorExpressionContext* context,
  1756. const GeneratorExpressionContent* content)
  1757. {
  1758. // The file used to link to the target (.so, .lib, .a).
  1759. if (!target->IsLinkable()) {
  1760. ::reportError(context, content->GetOriginalExpression(),
  1761. "TARGET_LINKER_FILE_BASE_NAME is allowed only for "
  1762. "libraries and executables with ENABLE_EXPORTS.");
  1763. return std::string();
  1764. }
  1765. cmStateEnums::ArtifactType artifact =
  1766. target->HasImportLibrary(context->Config)
  1767. ? cmStateEnums::ImportLibraryArtifact
  1768. : cmStateEnums::RuntimeBinaryArtifact;
  1769. return target->GetOutputName(context->Config, artifact) +
  1770. target->GetFilePostfix(context->Config);
  1771. }
  1772. };
  1773. template <>
  1774. struct TargetOutputNameArtifactResultGetter<ArtifactPdbTag>
  1775. {
  1776. static std::string Get(cmGeneratorTarget* target,
  1777. cmGeneratorExpressionContext* context,
  1778. const GeneratorExpressionContent* content)
  1779. {
  1780. if (target->IsImported()) {
  1781. ::reportError(
  1782. context, content->GetOriginalExpression(),
  1783. "TARGET_PDB_FILE_BASE_NAME not allowed for IMPORTED targets.");
  1784. return std::string();
  1785. }
  1786. std::string language = target->GetLinkerLanguage(context->Config);
  1787. std::string pdbSupportVar = "CMAKE_" + language + "_LINKER_SUPPORTS_PDB";
  1788. if (!context->LG->GetMakefile()->IsOn(pdbSupportVar)) {
  1789. ::reportError(
  1790. context, content->GetOriginalExpression(),
  1791. "TARGET_PDB_FILE_BASE_NAME is not supported by the target linker.");
  1792. return std::string();
  1793. }
  1794. cmStateEnums::TargetType targetType = target->GetType();
  1795. if (targetType != cmStateEnums::SHARED_LIBRARY &&
  1796. targetType != cmStateEnums::MODULE_LIBRARY &&
  1797. targetType != cmStateEnums::EXECUTABLE) {
  1798. ::reportError(context, content->GetOriginalExpression(),
  1799. "TARGET_PDB_FILE_BASE_NAME is allowed only for "
  1800. "targets with linker created artifacts.");
  1801. return std::string();
  1802. }
  1803. return target->GetPDBOutputName(context->Config) +
  1804. target->GetFilePostfix(context->Config);
  1805. }
  1806. };
  1807. template <typename ArtifactT>
  1808. struct TargetFileBaseNameArtifact : public TargetArtifactBase
  1809. {
  1810. TargetFileBaseNameArtifact() {} // NOLINT(modernize-use-equals-default)
  1811. int NumExpectedParameters() const override { return 1; }
  1812. std::string Evaluate(
  1813. const std::vector<std::string>& parameters,
  1814. cmGeneratorExpressionContext* context,
  1815. const GeneratorExpressionContent* content,
  1816. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1817. {
  1818. cmGeneratorTarget* target =
  1819. this->GetTarget(parameters, context, content, dagChecker);
  1820. if (!target) {
  1821. return std::string();
  1822. }
  1823. std::string result = TargetOutputNameArtifactResultGetter<ArtifactT>::Get(
  1824. target, context, content);
  1825. if (context->HadError) {
  1826. return std::string();
  1827. }
  1828. return result;
  1829. }
  1830. };
  1831. static const TargetFileBaseNameArtifact<ArtifactNameTag>
  1832. targetFileBaseNameNode;
  1833. static const TargetFileBaseNameArtifact<ArtifactLinkerTag>
  1834. targetLinkerFileBaseNameNode;
  1835. static const TargetFileBaseNameArtifact<ArtifactPdbTag>
  1836. targetPdbFileBaseNameNode;
  1837. class ArtifactFilePrefixTag;
  1838. class ArtifactLinkerFilePrefixTag;
  1839. class ArtifactFileSuffixTag;
  1840. class ArtifactLinkerFileSuffixTag;
  1841. template <typename ArtifactT>
  1842. struct TargetFileArtifactResultGetter
  1843. {
  1844. static std::string Get(cmGeneratorTarget* target,
  1845. cmGeneratorExpressionContext* context,
  1846. const GeneratorExpressionContent* content);
  1847. };
  1848. template <>
  1849. struct TargetFileArtifactResultGetter<ArtifactFilePrefixTag>
  1850. {
  1851. static std::string Get(cmGeneratorTarget* target,
  1852. cmGeneratorExpressionContext* context,
  1853. const GeneratorExpressionContent*)
  1854. {
  1855. return target->GetFilePrefix(context->Config);
  1856. }
  1857. };
  1858. template <>
  1859. struct TargetFileArtifactResultGetter<ArtifactLinkerFilePrefixTag>
  1860. {
  1861. static std::string Get(cmGeneratorTarget* target,
  1862. cmGeneratorExpressionContext* context,
  1863. const GeneratorExpressionContent* content)
  1864. {
  1865. if (!target->IsLinkable()) {
  1866. ::reportError(context, content->GetOriginalExpression(),
  1867. "TARGET_LINKER_PREFIX is allowed only for libraries and "
  1868. "executables with ENABLE_EXPORTS.");
  1869. return std::string();
  1870. }
  1871. cmStateEnums::ArtifactType artifact =
  1872. target->HasImportLibrary(context->Config)
  1873. ? cmStateEnums::ImportLibraryArtifact
  1874. : cmStateEnums::RuntimeBinaryArtifact;
  1875. return target->GetFilePrefix(context->Config, artifact);
  1876. }
  1877. };
  1878. template <>
  1879. struct TargetFileArtifactResultGetter<ArtifactFileSuffixTag>
  1880. {
  1881. static std::string Get(cmGeneratorTarget* target,
  1882. cmGeneratorExpressionContext* context,
  1883. const GeneratorExpressionContent*)
  1884. {
  1885. return target->GetFileSuffix(context->Config);
  1886. }
  1887. };
  1888. template <>
  1889. struct TargetFileArtifactResultGetter<ArtifactLinkerFileSuffixTag>
  1890. {
  1891. static std::string Get(cmGeneratorTarget* target,
  1892. cmGeneratorExpressionContext* context,
  1893. const GeneratorExpressionContent* content)
  1894. {
  1895. if (!target->IsLinkable()) {
  1896. ::reportError(context, content->GetOriginalExpression(),
  1897. "TARGET_LINKER_SUFFIX is allowed only for libraries and "
  1898. "executables with ENABLE_EXPORTS.");
  1899. return std::string();
  1900. }
  1901. cmStateEnums::ArtifactType artifact =
  1902. target->HasImportLibrary(context->Config)
  1903. ? cmStateEnums::ImportLibraryArtifact
  1904. : cmStateEnums::RuntimeBinaryArtifact;
  1905. return target->GetFileSuffix(context->Config, artifact);
  1906. }
  1907. };
  1908. template <typename ArtifactT>
  1909. struct TargetFileArtifact : public TargetArtifactBase
  1910. {
  1911. TargetFileArtifact() {} // NOLINT(modernize-use-equals-default)
  1912. int NumExpectedParameters() const override { return 1; }
  1913. std::string Evaluate(
  1914. const std::vector<std::string>& parameters,
  1915. cmGeneratorExpressionContext* context,
  1916. const GeneratorExpressionContent* content,
  1917. cmGeneratorExpressionDAGChecker* dagChecker) const override
  1918. {
  1919. cmGeneratorTarget* target =
  1920. this->GetTarget(parameters, context, content, dagChecker);
  1921. if (!target) {
  1922. return std::string();
  1923. }
  1924. std::string result =
  1925. TargetFileArtifactResultGetter<ArtifactT>::Get(target, context, content);
  1926. if (context->HadError) {
  1927. return std::string();
  1928. }
  1929. return result;
  1930. }
  1931. };
  1932. static const TargetFileArtifact<ArtifactFilePrefixTag> targetFilePrefixNode;
  1933. static const TargetFileArtifact<ArtifactLinkerFilePrefixTag>
  1934. targetLinkerFilePrefixNode;
  1935. static const TargetFileArtifact<ArtifactFileSuffixTag> targetFileSuffixNode;
  1936. static const TargetFileArtifact<ArtifactLinkerFileSuffixTag>
  1937. targetLinkerFileSuffixNode;
  1938. static const struct ShellPathNode : public cmGeneratorExpressionNode
  1939. {
  1940. ShellPathNode() {} // NOLINT(modernize-use-equals-default)
  1941. std::string Evaluate(
  1942. const std::vector<std::string>& parameters,
  1943. cmGeneratorExpressionContext* context,
  1944. const GeneratorExpressionContent* content,
  1945. cmGeneratorExpressionDAGChecker* /*dagChecker*/) const override
  1946. {
  1947. std::vector<std::string> listIn;
  1948. cmSystemTools::ExpandListArgument(parameters.front(), listIn);
  1949. if (listIn.empty()) {
  1950. reportError(context, content->GetOriginalExpression(),
  1951. "\"\" is not an absolute path.");
  1952. return std::string();
  1953. }
  1954. cmStateSnapshot snapshot = context->LG->GetStateSnapshot();
  1955. cmOutputConverter converter(snapshot);
  1956. const char* separator = snapshot.GetState()->UseWindowsShell() ? ";" : ":";
  1957. std::vector<std::string> listOut;
  1958. listOut.reserve(listIn.size());
  1959. for (auto const& in : listIn) {
  1960. if (!cmSystemTools::FileIsFullPath(in)) {
  1961. reportError(context, content->GetOriginalExpression(),
  1962. "\"" + in + "\" is not an absolute path.");
  1963. return std::string();
  1964. }
  1965. listOut.emplace_back(converter.ConvertDirectorySeparatorsForShell(in));
  1966. }
  1967. return cmJoin(listOut, separator);
  1968. }
  1969. } shellPathNode;
  1970. const cmGeneratorExpressionNode* cmGeneratorExpressionNode::GetNode(
  1971. const std::string& identifier)
  1972. {
  1973. static std::map<std::string, cmGeneratorExpressionNode const*> const nodeMap{
  1974. { "0", &zeroNode },
  1975. { "1", &oneNode },
  1976. { "AND", &andNode },
  1977. { "OR", &orNode },
  1978. { "NOT", &notNode },
  1979. { "C_COMPILER_ID", &cCompilerIdNode },
  1980. { "CXX_COMPILER_ID", &cxxCompilerIdNode },
  1981. { "CUDA_COMPILER_ID", &cudaCompilerIdNode },
  1982. { "Fortran_COMPILER_ID", &fortranCompilerIdNode },
  1983. { "VERSION_GREATER", &versionGreaterNode },
  1984. { "VERSION_GREATER_EQUAL", &versionGreaterEqNode },
  1985. { "VERSION_LESS", &versionLessNode },
  1986. { "VERSION_LESS_EQUAL", &versionLessEqNode },
  1987. { "VERSION_EQUAL", &versionEqualNode },
  1988. { "C_COMPILER_VERSION", &cCompilerVersionNode },
  1989. { "CXX_COMPILER_VERSION", &cxxCompilerVersionNode },
  1990. { "CUDA_COMPILER_VERSION", &cudaCompilerVersionNode },
  1991. { "Fortran_COMPILER_VERSION", &fortranCompilerVersionNode },
  1992. { "PLATFORM_ID", &platformIdNode },
  1993. { "COMPILE_FEATURES", &compileFeaturesNode },
  1994. { "CONFIGURATION", &configurationNode },
  1995. { "CONFIG", &configurationTestNode },
  1996. { "TARGET_FILE", &targetNodeGroup.File },
  1997. { "TARGET_LINKER_FILE", &targetLinkerNodeGroup.File },
  1998. { "TARGET_SONAME_FILE", &targetSoNameNodeGroup.File },
  1999. { "TARGET_PDB_FILE", &targetPdbNodeGroup.File },
  2000. { "TARGET_FILE_BASE_NAME", &targetFileBaseNameNode },
  2001. { "TARGET_LINKER_FILE_BASE_NAME", &targetLinkerFileBaseNameNode },
  2002. { "TARGET_PDB_FILE_BASE_NAME", &targetPdbFileBaseNameNode },
  2003. { "TARGET_FILE_PREFIX", &targetFilePrefixNode },
  2004. { "TARGET_LINKER_FILE_PREFIX", &targetLinkerFilePrefixNode },
  2005. { "TARGET_FILE_SUFFIX", &targetFileSuffixNode },
  2006. { "TARGET_LINKER_FILE_SUFFIX", &targetLinkerFileSuffixNode },
  2007. { "TARGET_FILE_NAME", &targetNodeGroup.FileName },
  2008. { "TARGET_LINKER_FILE_NAME", &targetLinkerNodeGroup.FileName },
  2009. { "TARGET_SONAME_FILE_NAME", &targetSoNameNodeGroup.FileName },
  2010. { "TARGET_PDB_FILE_NAME", &targetPdbNodeGroup.FileName },
  2011. { "TARGET_FILE_DIR", &targetNodeGroup.FileDir },
  2012. { "TARGET_LINKER_FILE_DIR", &targetLinkerNodeGroup.FileDir },
  2013. { "TARGET_SONAME_FILE_DIR", &targetSoNameNodeGroup.FileDir },
  2014. { "TARGET_PDB_FILE_DIR", &targetPdbNodeGroup.FileDir },
  2015. { "TARGET_BUNDLE_DIR", &targetBundleDirNode },
  2016. { "TARGET_BUNDLE_CONTENT_DIR", &targetBundleContentDirNode },
  2017. { "STREQUAL", &strEqualNode },
  2018. { "EQUAL", &equalNode },
  2019. { "IN_LIST", &inListNode },
  2020. { "FILTER", &filterNode },
  2021. { "REMOVE_DUPLICATES", &removeDuplicatesNode },
  2022. { "LOWER_CASE", &lowerCaseNode },
  2023. { "UPPER_CASE", &upperCaseNode },
  2024. { "MAKE_C_IDENTIFIER", &makeCIdentifierNode },
  2025. { "BOOL", &boolNode },
  2026. { "IF", &ifNode },
  2027. { "ANGLE-R", &angle_rNode },
  2028. { "COMMA", &commaNode },
  2029. { "SEMICOLON", &semicolonNode },
  2030. { "TARGET_PROPERTY", &targetPropertyNode },
  2031. { "TARGET_NAME", &targetNameNode },
  2032. { "TARGET_OBJECTS", &targetObjectsNode },
  2033. { "TARGET_POLICY", &targetPolicyNode },
  2034. { "TARGET_EXISTS", &targetExistsNode },
  2035. { "TARGET_NAME_IF_EXISTS", &targetNameIfExistsNode },
  2036. { "TARGET_GENEX_EVAL", &targetGenexEvalNode },
  2037. { "GENEX_EVAL", &genexEvalNode },
  2038. { "BUILD_INTERFACE", &buildInterfaceNode },
  2039. { "INSTALL_INTERFACE", &installInterfaceNode },
  2040. { "INSTALL_PREFIX", &installPrefixNode },
  2041. { "JOIN", &joinNode },
  2042. { "LINK_ONLY", &linkOnlyNode },
  2043. { "COMPILE_LANG_AND_ID", &languageAndIdNode },
  2044. { "COMPILE_LANGUAGE", &languageNode },
  2045. { "SHELL_PATH", &shellPathNode }
  2046. };
  2047. {
  2048. auto itr = nodeMap.find(identifier);
  2049. if (itr != nodeMap.end()) {
  2050. return itr->second;
  2051. }
  2052. }
  2053. return nullptr;
  2054. }
  2055. void reportError(cmGeneratorExpressionContext* context,
  2056. const std::string& expr, const std::string& result)
  2057. {
  2058. context->HadError = true;
  2059. if (context->Quiet) {
  2060. return;
  2061. }
  2062. std::ostringstream e;
  2063. /* clang-format off */
  2064. e << "Error evaluating generator expression:\n"
  2065. << " " << expr << "\n"
  2066. << result;
  2067. /* clang-format on */
  2068. context->LG->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
  2069. e.str(), context->Backtrace);
  2070. }