cmGeneratorExpressionNode.cxx 81 KB

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