1
0

cmGeneratorExpressionNode.cxx 82 KB

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