cmGeneratorExpressionNode.cxx 81 KB

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