cmGeneratorExpressionNode.cxx 100 KB

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