cmGeneratorExpressionNode.cxx 80 KB

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