cmGeneratorTarget.cxx 208 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246
  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 "cmGeneratorTarget.h"
  4. #include "cmsys/RegularExpression.hxx"
  5. #include <algorithm>
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <iterator>
  9. #include <memory> // IWYU pragma: keep
  10. #include <queue>
  11. #include <sstream>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <unordered_set>
  16. #include <utility>
  17. #include "cmAlgorithms.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommand.h"
  20. #include "cmCustomCommandGenerator.h"
  21. #include "cmCustomCommandLines.h"
  22. #include "cmGeneratorExpression.h"
  23. #include "cmGeneratorExpressionDAGChecker.h"
  24. #include "cmGlobalGenerator.h"
  25. #include "cmLocalGenerator.h"
  26. #include "cmMakefile.h"
  27. #include "cmMessageType.h"
  28. #include "cmPropertyMap.h"
  29. #include "cmSourceFile.h"
  30. #include "cmSourceFileLocation.h"
  31. #include "cmState.h"
  32. #include "cmSystemTools.h"
  33. #include "cmTarget.h"
  34. #include "cmTargetLinkLibraryType.h"
  35. #include "cmTargetPropertyComputer.h"
  36. #include "cmake.h"
  37. class cmMessenger;
  38. template <>
  39. const char* cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  40. cmGeneratorTarget const* tgt, cmMessenger* /* messenger */,
  41. cmListFileBacktrace const& /* context */)
  42. {
  43. return tgt->GetSourcesProperty();
  44. }
  45. template <>
  46. const char*
  47. cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
  48. cmGeneratorTarget const* tgt)
  49. {
  50. return tgt->GetLocation("");
  51. }
  52. template <>
  53. const char* cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  54. cmGeneratorTarget const* tgt, const std::string& config)
  55. {
  56. return tgt->GetLocation(config);
  57. }
  58. class cmGeneratorTarget::TargetPropertyEntry
  59. {
  60. static cmLinkImplItem NoLinkImplItem;
  61. public:
  62. TargetPropertyEntry(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  63. cmLinkImplItem const& item = NoLinkImplItem)
  64. : ge(std::move(cge))
  65. , LinkImplItem(item)
  66. {
  67. }
  68. const std::unique_ptr<cmCompiledGeneratorExpression> ge;
  69. cmLinkImplItem const& LinkImplItem;
  70. };
  71. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  72. void CreatePropertyGeneratorExpressions(
  73. cmStringRange entries, cmBacktraceRange backtraces,
  74. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  75. bool evaluateForBuildsystem = false)
  76. {
  77. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  78. for (std::vector<std::string>::const_iterator it = entries.begin();
  79. it != entries.end(); ++it, ++btIt) {
  80. cmGeneratorExpression ge(*btIt);
  81. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  82. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  83. items.push_back(
  84. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  85. }
  86. }
  87. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  88. : Target(t)
  89. , FortranModuleDirectoryCreated(false)
  90. , SourceFileFlagsConstructed(false)
  91. , PolicyWarnedCMP0022(false)
  92. , PolicyReportedCMP0069(false)
  93. , DebugIncludesDone(false)
  94. , DebugCompileOptionsDone(false)
  95. , DebugCompileFeaturesDone(false)
  96. , DebugCompileDefinitionsDone(false)
  97. , DebugLinkOptionsDone(false)
  98. , DebugLinkDirectoriesDone(false)
  99. , DebugSourcesDone(false)
  100. , LinkImplementationLanguageIsContextDependent(true)
  101. , UtilityItemsDone(false)
  102. {
  103. this->Makefile = this->Target->GetMakefile();
  104. this->LocalGenerator = lg;
  105. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  106. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  107. CreatePropertyGeneratorExpressions(t->GetIncludeDirectoriesEntries(),
  108. t->GetIncludeDirectoriesBacktraces(),
  109. this->IncludeDirectoriesEntries);
  110. CreatePropertyGeneratorExpressions(t->GetCompileOptionsEntries(),
  111. t->GetCompileOptionsBacktraces(),
  112. this->CompileOptionsEntries);
  113. CreatePropertyGeneratorExpressions(t->GetCompileFeaturesEntries(),
  114. t->GetCompileFeaturesBacktraces(),
  115. this->CompileFeaturesEntries);
  116. CreatePropertyGeneratorExpressions(t->GetCompileDefinitionsEntries(),
  117. t->GetCompileDefinitionsBacktraces(),
  118. this->CompileDefinitionsEntries);
  119. CreatePropertyGeneratorExpressions(t->GetLinkOptionsEntries(),
  120. t->GetLinkOptionsBacktraces(),
  121. this->LinkOptionsEntries);
  122. CreatePropertyGeneratorExpressions(t->GetLinkDirectoriesEntries(),
  123. t->GetLinkDirectoriesBacktraces(),
  124. this->LinkDirectoriesEntries);
  125. CreatePropertyGeneratorExpressions(t->GetSourceEntries(),
  126. t->GetSourceBacktraces(),
  127. this->SourceEntries, true);
  128. this->DLLPlatform =
  129. !this->Makefile->GetSafeDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX").empty();
  130. this->PolicyMap = t->PolicyMap;
  131. }
  132. cmGeneratorTarget::~cmGeneratorTarget()
  133. {
  134. cmDeleteAll(this->IncludeDirectoriesEntries);
  135. cmDeleteAll(this->CompileOptionsEntries);
  136. cmDeleteAll(this->CompileFeaturesEntries);
  137. cmDeleteAll(this->CompileDefinitionsEntries);
  138. cmDeleteAll(this->LinkOptionsEntries);
  139. cmDeleteAll(this->LinkDirectoriesEntries);
  140. cmDeleteAll(this->SourceEntries);
  141. cmDeleteAll(this->LinkInformation);
  142. }
  143. const char* cmGeneratorTarget::GetSourcesProperty() const
  144. {
  145. std::vector<std::string> values;
  146. for (TargetPropertyEntry* se : this->SourceEntries) {
  147. values.push_back(se->ge->GetInput());
  148. }
  149. static std::string value;
  150. value.clear();
  151. value = cmJoin(values, ";");
  152. return value.c_str();
  153. }
  154. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  155. {
  156. return this->GetLocalGenerator()->GetGlobalGenerator();
  157. }
  158. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  159. {
  160. return this->LocalGenerator;
  161. }
  162. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  163. {
  164. return this->Target->GetType();
  165. }
  166. const std::string& cmGeneratorTarget::GetName() const
  167. {
  168. return this->Target->GetName();
  169. }
  170. std::string cmGeneratorTarget::GetExportName() const
  171. {
  172. const char* exportName = this->GetProperty("EXPORT_NAME");
  173. if (exportName && *exportName) {
  174. if (!cmGeneratorExpression::IsValidTargetName(exportName)) {
  175. std::ostringstream e;
  176. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  177. << this->GetName() << "\": is not valid.";
  178. cmSystemTools::Error(e.str());
  179. return "";
  180. }
  181. return exportName;
  182. }
  183. return this->GetName();
  184. }
  185. const char* cmGeneratorTarget::GetProperty(const std::string& prop) const
  186. {
  187. if (!cmTargetPropertyComputer::PassesWhitelist(
  188. this->GetType(), prop, this->Makefile->GetMessenger(),
  189. this->GetBacktrace())) {
  190. return nullptr;
  191. }
  192. if (const char* result = cmTargetPropertyComputer::GetProperty(
  193. this, prop, this->Makefile->GetMessenger(), this->GetBacktrace())) {
  194. return result;
  195. }
  196. if (cmSystemTools::GetFatalErrorOccured()) {
  197. return nullptr;
  198. }
  199. return this->Target->GetProperty(prop);
  200. }
  201. const char* cmGeneratorTarget::GetSafeProperty(const std::string& prop) const
  202. {
  203. const char* ret = this->GetProperty(prop);
  204. if (!ret) {
  205. return "";
  206. }
  207. return ret;
  208. }
  209. const char* cmGeneratorTarget::GetOutputTargetType(
  210. cmStateEnums::ArtifactType artifact) const
  211. {
  212. switch (this->GetType()) {
  213. case cmStateEnums::SHARED_LIBRARY:
  214. if (this->IsDLLPlatform()) {
  215. switch (artifact) {
  216. case cmStateEnums::RuntimeBinaryArtifact:
  217. // A DLL shared library is treated as a runtime target.
  218. return "RUNTIME";
  219. case cmStateEnums::ImportLibraryArtifact:
  220. // A DLL import library is treated as an archive target.
  221. return "ARCHIVE";
  222. }
  223. } else {
  224. // For non-DLL platforms shared libraries are treated as
  225. // library targets.
  226. return "LIBRARY";
  227. }
  228. break;
  229. case cmStateEnums::STATIC_LIBRARY:
  230. // Static libraries are always treated as archive targets.
  231. return "ARCHIVE";
  232. case cmStateEnums::MODULE_LIBRARY:
  233. switch (artifact) {
  234. case cmStateEnums::RuntimeBinaryArtifact:
  235. // Module libraries are always treated as library targets.
  236. return "LIBRARY";
  237. case cmStateEnums::ImportLibraryArtifact:
  238. // Module import libraries are treated as archive targets.
  239. return "ARCHIVE";
  240. }
  241. break;
  242. case cmStateEnums::OBJECT_LIBRARY:
  243. // Object libraries are always treated as object targets.
  244. return "OBJECT";
  245. case cmStateEnums::EXECUTABLE:
  246. switch (artifact) {
  247. case cmStateEnums::RuntimeBinaryArtifact:
  248. // Executables are always treated as runtime targets.
  249. return "RUNTIME";
  250. case cmStateEnums::ImportLibraryArtifact:
  251. // Executable import libraries are treated as archive targets.
  252. return "ARCHIVE";
  253. }
  254. break;
  255. default:
  256. break;
  257. }
  258. return "";
  259. }
  260. std::string cmGeneratorTarget::GetOutputName(
  261. const std::string& config, cmStateEnums::ArtifactType artifact) const
  262. {
  263. // Lookup/compute/cache the output name for this configuration.
  264. OutputNameKey key(config, artifact);
  265. cmGeneratorTarget::OutputNameMapType::iterator i =
  266. this->OutputNameMap.find(key);
  267. if (i == this->OutputNameMap.end()) {
  268. // Add empty name in map to detect potential recursion.
  269. OutputNameMapType::value_type entry(key, "");
  270. i = this->OutputNameMap.insert(entry).first;
  271. // Compute output name.
  272. std::vector<std::string> props;
  273. std::string type = this->GetOutputTargetType(artifact);
  274. std::string configUpper = cmSystemTools::UpperCase(config);
  275. if (!type.empty() && !configUpper.empty()) {
  276. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  277. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  278. }
  279. if (!type.empty()) {
  280. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  281. props.push_back(type + "_OUTPUT_NAME");
  282. }
  283. if (!configUpper.empty()) {
  284. // OUTPUT_NAME_<CONFIG>
  285. props.push_back("OUTPUT_NAME_" + configUpper);
  286. // <CONFIG>_OUTPUT_NAME
  287. props.push_back(configUpper + "_OUTPUT_NAME");
  288. }
  289. // OUTPUT_NAME
  290. props.emplace_back("OUTPUT_NAME");
  291. std::string outName;
  292. for (std::string const& p : props) {
  293. if (const char* outNameProp = this->GetProperty(p)) {
  294. outName = outNameProp;
  295. break;
  296. }
  297. }
  298. if (outName.empty()) {
  299. outName = this->GetName();
  300. }
  301. // Now evaluate genex and update the previously-prepared map entry.
  302. cmGeneratorExpression ge;
  303. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  304. i->second = cge->Evaluate(this->LocalGenerator, config);
  305. } else if (i->second.empty()) {
  306. // An empty map entry indicates we have been called recursively
  307. // from the above block.
  308. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  309. MessageType::FATAL_ERROR,
  310. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  311. this->GetBacktrace());
  312. }
  313. return i->second;
  314. }
  315. void cmGeneratorTarget::ClearSourcesCache()
  316. {
  317. this->KindedSourcesMap.clear();
  318. this->LinkImplementationLanguageIsContextDependent = true;
  319. this->Objects.clear();
  320. }
  321. void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
  322. {
  323. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  324. cmGeneratorExpression ge(lfbt);
  325. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  326. cge->SetEvaluateForBuildsystem(true);
  327. this->SourceEntries.insert(before ? this->SourceEntries.begin()
  328. : this->SourceEntries.end(),
  329. new TargetPropertyEntry(std::move(cge)));
  330. this->ClearSourcesCache();
  331. }
  332. void cmGeneratorTarget::AddSource(const std::string& src, bool before)
  333. {
  334. this->Target->AddSource(src, before);
  335. this->AddSourceCommon(src, before);
  336. }
  337. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  338. {
  339. this->Target->AddTracedSources(srcs);
  340. if (!srcs.empty()) {
  341. this->AddSourceCommon(cmJoin(srcs, ";"));
  342. }
  343. }
  344. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  345. bool before)
  346. {
  347. this->Target->InsertInclude(src, this->Makefile->GetBacktrace(), before);
  348. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  349. cmGeneratorExpression ge(lfbt);
  350. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  351. cge->SetEvaluateForBuildsystem(true);
  352. this->IncludeDirectoriesEntries.insert(
  353. before ? this->IncludeDirectoriesEntries.begin()
  354. : this->IncludeDirectoriesEntries.end(),
  355. new TargetPropertyEntry(std::move(cge)));
  356. }
  357. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  358. cmSourceFile const* sf) const
  359. {
  360. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  361. if (i != this->SourceDepends.end()) {
  362. return &i->second.Depends;
  363. }
  364. return nullptr;
  365. }
  366. static void handleSystemIncludesDep(
  367. cmLocalGenerator* lg, cmGeneratorTarget const* depTgt,
  368. const std::string& config, cmGeneratorTarget const* headTarget,
  369. cmGeneratorExpressionDAGChecker* dagChecker,
  370. std::vector<std::string>& result, bool excludeImported,
  371. std::string const& language)
  372. {
  373. if (const char* dirs =
  374. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  375. cmGeneratorExpression ge;
  376. cmSystemTools::ExpandListArgument(
  377. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  378. dagChecker, language),
  379. result);
  380. }
  381. if (!depTgt->IsImported() || excludeImported) {
  382. return;
  383. }
  384. if (const char* dirs =
  385. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  386. cmGeneratorExpression ge;
  387. cmSystemTools::ExpandListArgument(
  388. ge.Parse(dirs)->Evaluate(lg, config, false, headTarget, depTgt,
  389. dagChecker, language),
  390. result);
  391. }
  392. }
  393. /* clang-format off */
  394. #define IMPLEMENT_VISIT(KIND) \
  395. do { \
  396. KindedSources const& kinded = this->GetKindedSources(config); \
  397. for (SourceAndKind const& s : kinded.Sources) { \
  398. if (s.Kind == KIND) { \
  399. data.push_back(s.Source.Value); \
  400. } \
  401. } \
  402. } while (false)
  403. /* clang-format on */
  404. void cmGeneratorTarget::GetObjectSources(
  405. std::vector<cmSourceFile const*>& data, const std::string& config) const
  406. {
  407. IMPLEMENT_VISIT(SourceKindObjectSource);
  408. if (!this->Objects.empty()) {
  409. return;
  410. }
  411. for (cmSourceFile const* it : data) {
  412. this->Objects[it];
  413. }
  414. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  415. }
  416. void cmGeneratorTarget::ComputeObjectMapping()
  417. {
  418. if (!this->Objects.empty()) {
  419. return;
  420. }
  421. std::vector<std::string> configs;
  422. this->Makefile->GetConfigurations(configs);
  423. if (configs.empty()) {
  424. configs.emplace_back();
  425. }
  426. for (std::string const& c : configs) {
  427. std::vector<cmSourceFile const*> sourceFiles;
  428. this->GetObjectSources(sourceFiles, c);
  429. }
  430. }
  431. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  432. const std::string& config) const
  433. {
  434. if (!config.empty()) {
  435. std::string featureConfig = feature;
  436. featureConfig += "_";
  437. featureConfig += cmSystemTools::UpperCase(config);
  438. if (const char* value = this->GetProperty(featureConfig)) {
  439. return value;
  440. }
  441. }
  442. if (const char* value = this->GetProperty(feature)) {
  443. return value;
  444. }
  445. return this->LocalGenerator->GetFeature(feature, config);
  446. }
  447. const char* cmGeneratorTarget::GetLinkPIEProperty(
  448. const std::string& config) const
  449. {
  450. static std::string PICValue;
  451. PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
  452. "POSITION_INDEPENDENT_CODE", config);
  453. if (PICValue == "(unset)") {
  454. // POSITION_INDEPENDENT_CODE is not set
  455. return nullptr;
  456. }
  457. switch (this->GetPolicyStatusCMP0083()) {
  458. case cmPolicies::WARN: {
  459. std::ostringstream e;
  460. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0083);
  461. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, e.str());
  462. CM_FALLTHROUGH;
  463. }
  464. case cmPolicies::OLD:
  465. return nullptr;
  466. default:
  467. // nothing to do
  468. break;
  469. }
  470. return PICValue.c_str();
  471. }
  472. bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
  473. std::string const& config) const
  474. {
  475. const char* feature = "INTERPROCEDURAL_OPTIMIZATION";
  476. const bool result = cmSystemTools::IsOn(this->GetFeature(feature, config));
  477. if (!result) {
  478. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  479. return false;
  480. }
  481. if (lang != "C" && lang != "CXX" && lang != "Fortran") {
  482. // We do not define IPO behavior for other languages.
  483. return false;
  484. }
  485. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  486. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  487. if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) {
  488. return true;
  489. }
  490. if (this->PolicyReportedCMP0069) {
  491. // problem is already reported, no need to issue a message
  492. return false;
  493. }
  494. const bool in_try_compile =
  495. this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile();
  496. if (cmp0069 == cmPolicies::WARN && !in_try_compile) {
  497. std::ostringstream w;
  498. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  499. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  500. << "'" << this->GetName() << "'.";
  501. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  502. MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  503. this->PolicyReportedCMP0069 = true;
  504. }
  505. return false;
  506. }
  507. // Note: check consistency with messages from CheckIPOSupported
  508. const char* message = nullptr;
  509. if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
  510. message = "CMake doesn't support IPO for current compiler";
  511. } else if (!this->Makefile->IsOn("_CMAKE_" + lang +
  512. "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  513. message = "Compiler doesn't support IPO";
  514. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  515. message = "CMake doesn't support IPO for current generator";
  516. }
  517. if (!message) {
  518. // No error/warning messages
  519. return true;
  520. }
  521. if (this->PolicyReportedCMP0069) {
  522. // problem is already reported, no need to issue a message
  523. return false;
  524. }
  525. this->PolicyReportedCMP0069 = true;
  526. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  527. MessageType::FATAL_ERROR, message, this->GetBacktrace());
  528. return false;
  529. }
  530. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  531. {
  532. this->ComputeObjectMapping();
  533. return this->Objects[file];
  534. }
  535. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  536. {
  537. static std::string extension;
  538. const bool has_ptx_extension =
  539. this->GetPropertyAsBool("CUDA_PTX_COMPILATION");
  540. if (has_ptx_extension) {
  541. extension = ".ptx";
  542. return extension.c_str();
  543. }
  544. return nullptr;
  545. }
  546. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  547. {
  548. this->ExplicitObjectName.insert(sf);
  549. }
  550. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  551. {
  552. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  553. std::set<cmSourceFile const*>::const_iterator it =
  554. this->ExplicitObjectName.find(file);
  555. return it != this->ExplicitObjectName.end();
  556. }
  557. void cmGeneratorTarget::GetModuleDefinitionSources(
  558. std::vector<cmSourceFile const*>& data, const std::string& config) const
  559. {
  560. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  561. }
  562. void cmGeneratorTarget::GetHeaderSources(
  563. std::vector<cmSourceFile const*>& data, const std::string& config) const
  564. {
  565. IMPLEMENT_VISIT(SourceKindHeader);
  566. }
  567. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  568. const std::string& config) const
  569. {
  570. IMPLEMENT_VISIT(SourceKindExtra);
  571. }
  572. void cmGeneratorTarget::GetCustomCommands(
  573. std::vector<cmSourceFile const*>& data, const std::string& config) const
  574. {
  575. IMPLEMENT_VISIT(SourceKindCustomCommand);
  576. }
  577. void cmGeneratorTarget::GetExternalObjects(
  578. std::vector<cmSourceFile const*>& data, const std::string& config) const
  579. {
  580. IMPLEMENT_VISIT(SourceKindExternalObject);
  581. }
  582. void cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& headers,
  583. const std::string& config) const
  584. {
  585. KindedSources const& kinded = this->GetKindedSources(config);
  586. headers = kinded.ExpectedResxHeaders;
  587. }
  588. void cmGeneratorTarget::GetResxSources(std::vector<cmSourceFile const*>& data,
  589. const std::string& config) const
  590. {
  591. IMPLEMENT_VISIT(SourceKindResx);
  592. }
  593. void cmGeneratorTarget::GetAppManifest(std::vector<cmSourceFile const*>& data,
  594. const std::string& config) const
  595. {
  596. IMPLEMENT_VISIT(SourceKindAppManifest);
  597. }
  598. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  599. const std::string& config) const
  600. {
  601. IMPLEMENT_VISIT(SourceKindManifest);
  602. }
  603. void cmGeneratorTarget::GetCertificates(std::vector<cmSourceFile const*>& data,
  604. const std::string& config) const
  605. {
  606. IMPLEMENT_VISIT(SourceKindCertificate);
  607. }
  608. void cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  609. const std::string& config) const
  610. {
  611. KindedSources const& kinded = this->GetKindedSources(config);
  612. headers = kinded.ExpectedXamlHeaders;
  613. }
  614. void cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  615. const std::string& config) const
  616. {
  617. KindedSources const& kinded = this->GetKindedSources(config);
  618. srcs = kinded.ExpectedXamlSources;
  619. }
  620. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  621. {
  622. if (!this->UtilityItemsDone) {
  623. this->UtilityItemsDone = true;
  624. std::set<BT<std::string>> const& utilities = this->GetUtilities();
  625. for (BT<std::string> const& i : utilities) {
  626. if (cmGeneratorTarget* gt =
  627. this->LocalGenerator->FindGeneratorTargetToUse(i.Value)) {
  628. this->UtilityItems.insert(cmLinkItem(gt, i.Backtrace));
  629. } else {
  630. this->UtilityItems.insert(cmLinkItem(i.Value, i.Backtrace));
  631. }
  632. }
  633. }
  634. return this->UtilityItems;
  635. }
  636. void cmGeneratorTarget::GetXamlSources(std::vector<cmSourceFile const*>& data,
  637. const std::string& config) const
  638. {
  639. IMPLEMENT_VISIT(SourceKindXaml);
  640. }
  641. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  642. {
  643. static std::string location;
  644. if (this->IsImported()) {
  645. location = this->Target->ImportedGetFullPath(
  646. config, cmStateEnums::RuntimeBinaryArtifact);
  647. } else {
  648. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  649. }
  650. return location.c_str();
  651. }
  652. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  653. const
  654. {
  655. return this->Target->GetPreBuildCommands();
  656. }
  657. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  658. const
  659. {
  660. return this->Target->GetPreLinkCommands();
  661. }
  662. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  663. const
  664. {
  665. return this->Target->GetPostBuildCommands();
  666. }
  667. bool cmGeneratorTarget::IsImported() const
  668. {
  669. return this->Target->IsImported();
  670. }
  671. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  672. {
  673. return this->Target->IsImportedGloballyVisible();
  674. }
  675. const char* cmGeneratorTarget::GetLocationForBuild() const
  676. {
  677. static std::string location;
  678. if (this->IsImported()) {
  679. location = this->Target->ImportedGetFullPath(
  680. "", cmStateEnums::RuntimeBinaryArtifact);
  681. return location.c_str();
  682. }
  683. // Now handle the deprecated build-time configuration location.
  684. location = this->GetDirectory();
  685. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  686. if (cfgid && strcmp(cfgid, ".") != 0) {
  687. location += "/";
  688. location += cfgid;
  689. }
  690. if (this->IsAppBundleOnApple()) {
  691. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  692. if (!macdir.empty()) {
  693. location += "/";
  694. location += macdir;
  695. }
  696. }
  697. location += "/";
  698. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  699. return location.c_str();
  700. }
  701. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  702. const std::string& dir, const std::string& config,
  703. const std::string& language) const
  704. {
  705. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  706. std::string config_upper;
  707. if (!config.empty()) {
  708. config_upper = cmSystemTools::UpperCase(config);
  709. }
  710. typedef std::map<std::string, std::vector<std::string>> IncludeCacheType;
  711. IncludeCacheType::const_iterator iter =
  712. this->SystemIncludesCache.find(config_upper);
  713. if (iter == this->SystemIncludesCache.end()) {
  714. cmGeneratorExpressionDAGChecker dagChecker(
  715. this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
  716. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  717. std::vector<std::string> result;
  718. for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
  719. cmGeneratorExpression ge;
  720. cmSystemTools::ExpandListArgument(
  721. ge.Parse(it)->Evaluate(this->LocalGenerator, config, false, this,
  722. &dagChecker, language),
  723. result);
  724. }
  725. std::vector<cmGeneratorTarget const*> const& deps =
  726. this->GetLinkImplementationClosure(config);
  727. for (cmGeneratorTarget const* dep : deps) {
  728. handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
  729. &dagChecker, result, excludeImported, language);
  730. }
  731. std::for_each(result.begin(), result.end(),
  732. cmSystemTools::ConvertToUnixSlashes);
  733. std::sort(result.begin(), result.end());
  734. result.erase(std::unique(result.begin(), result.end()), result.end());
  735. IncludeCacheType::value_type entry(config_upper, result);
  736. iter = this->SystemIncludesCache.insert(entry).first;
  737. }
  738. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  739. }
  740. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  741. {
  742. return this->Target->GetPropertyAsBool(prop);
  743. }
  744. static void AddInterfaceEntries(
  745. cmGeneratorTarget const* thisTarget, std::string const& config,
  746. std::string const& prop,
  747. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  748. {
  749. if (cmLinkImplementationLibraries const* impl =
  750. thisTarget->GetLinkImplementationLibraries(config)) {
  751. for (cmLinkImplItem const& lib : impl->Libraries) {
  752. if (lib.Target) {
  753. std::string uniqueName =
  754. thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  755. lib.Target);
  756. std::string genex =
  757. "$<TARGET_PROPERTY:" + std::move(uniqueName) + "," + prop + ">";
  758. cmGeneratorExpression ge(lib.Backtrace);
  759. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  760. cge->SetEvaluateForBuildsystem(true);
  761. entries.push_back(
  762. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib));
  763. }
  764. }
  765. }
  766. }
  767. static void AddObjectEntries(
  768. cmGeneratorTarget const* thisTarget, std::string const& config,
  769. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  770. {
  771. if (cmLinkImplementationLibraries const* impl =
  772. thisTarget->GetLinkImplementationLibraries(config)) {
  773. for (cmLinkImplItem const& lib : impl->Libraries) {
  774. if (lib.Target &&
  775. lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  776. std::string uniqueName =
  777. thisTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  778. lib.Target);
  779. std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
  780. cmGeneratorExpression ge(lib.Backtrace);
  781. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  782. cge->SetEvaluateForBuildsystem(true);
  783. entries.push_back(
  784. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge), lib));
  785. }
  786. }
  787. }
  788. }
  789. static bool processSources(
  790. cmGeneratorTarget const* tgt,
  791. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  792. std::vector<BT<std::string>>& srcs,
  793. std::unordered_set<std::string>& uniqueSrcs,
  794. cmGeneratorExpressionDAGChecker* dagChecker, std::string const& config,
  795. bool debugSources)
  796. {
  797. cmMakefile* mf = tgt->Target->GetMakefile();
  798. bool contextDependent = false;
  799. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  800. cmLinkImplItem const& item = entry->LinkImplItem;
  801. std::string const& targetName = item.AsStr();
  802. std::vector<std::string> entrySources;
  803. cmSystemTools::ExpandListArgument(
  804. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt, tgt,
  805. dagChecker),
  806. entrySources);
  807. if (entry->ge->GetHadContextSensitiveCondition()) {
  808. contextDependent = true;
  809. }
  810. for (std::string& src : entrySources) {
  811. cmSourceFile* sf = mf->GetOrCreateSource(src);
  812. std::string e;
  813. std::string fullPath = sf->GetFullPath(&e);
  814. if (fullPath.empty()) {
  815. if (!e.empty()) {
  816. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  817. cm->IssueMessage(MessageType::FATAL_ERROR, e, tgt->GetBacktrace());
  818. }
  819. return contextDependent;
  820. }
  821. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
  822. std::ostringstream err;
  823. if (!targetName.empty()) {
  824. err << "Target \"" << targetName
  825. << "\" contains relative path in its INTERFACE_SOURCES:\n \""
  826. << src << "\"";
  827. } else {
  828. err << "Found relative path while evaluating sources of \""
  829. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  830. }
  831. tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  832. err.str());
  833. return contextDependent;
  834. }
  835. src = fullPath;
  836. }
  837. std::string usedSources;
  838. for (std::string const& src : entrySources) {
  839. if (uniqueSrcs.insert(src).second) {
  840. srcs.emplace_back(src, entry->ge->GetBacktrace());
  841. if (debugSources) {
  842. usedSources += " * " + src + "\n";
  843. }
  844. }
  845. }
  846. if (!usedSources.empty()) {
  847. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  848. MessageType::LOG,
  849. std::string("Used sources for target ") + tgt->GetName() + ":\n" +
  850. usedSources,
  851. entry->ge->GetBacktrace());
  852. }
  853. }
  854. return contextDependent;
  855. }
  856. std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
  857. std::string const& config) const
  858. {
  859. std::vector<BT<std::string>> files;
  860. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  861. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  862. // At configure-time, this method can be called as part of getting the
  863. // LOCATION property or to export() a file to be include()d. However
  864. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  865. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  866. // behavior of CMP0024 and CMP0026 only.
  867. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  868. for (std::string const& entry : sourceEntries) {
  869. std::vector<std::string> items;
  870. cmSystemTools::ExpandListArgument(entry, items);
  871. for (std::string const& item : items) {
  872. if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
  873. item.back() == '>') {
  874. continue;
  875. }
  876. files.emplace_back(item);
  877. }
  878. }
  879. return files;
  880. }
  881. std::vector<std::string> debugProperties;
  882. const char* debugProp =
  883. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  884. if (debugProp) {
  885. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  886. }
  887. bool debugSources = !this->DebugSourcesDone &&
  888. std::find(debugProperties.begin(), debugProperties.end(), "SOURCES") !=
  889. debugProperties.end();
  890. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  891. this->DebugSourcesDone = true;
  892. }
  893. cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
  894. nullptr);
  895. std::unordered_set<std::string> uniqueSrcs;
  896. bool contextDependentDirectSources =
  897. processSources(this, this->SourceEntries, files, uniqueSrcs, &dagChecker,
  898. config, debugSources);
  899. // Collect INTERFACE_SOURCES of all direct link-dependencies.
  900. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  901. linkInterfaceSourcesEntries;
  902. AddInterfaceEntries(this, config, "INTERFACE_SOURCES",
  903. linkInterfaceSourcesEntries);
  904. std::vector<std::string>::size_type numFilesBefore = files.size();
  905. bool contextDependentInterfaceSources =
  906. processSources(this, linkInterfaceSourcesEntries, files, uniqueSrcs,
  907. &dagChecker, config, debugSources);
  908. // Collect TARGET_OBJECTS of direct object link-dependencies.
  909. std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkObjectsEntries;
  910. AddObjectEntries(this, config, linkObjectsEntries);
  911. std::vector<std::string>::size_type numFilesBefore2 = files.size();
  912. bool contextDependentObjects =
  913. processSources(this, linkObjectsEntries, files, uniqueSrcs, &dagChecker,
  914. config, debugSources);
  915. if (!contextDependentDirectSources &&
  916. !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
  917. !(contextDependentObjects && numFilesBefore2 < files.size())) {
  918. this->LinkImplementationLanguageIsContextDependent = false;
  919. }
  920. cmDeleteAll(linkInterfaceSourcesEntries);
  921. cmDeleteAll(linkObjectsEntries);
  922. return files;
  923. }
  924. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  925. const std::string& config) const
  926. {
  927. std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
  928. files.reserve(tmp.size());
  929. for (BT<cmSourceFile*>& v : tmp) {
  930. files.push_back(v.Value);
  931. }
  932. }
  933. std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
  934. std::string const& config) const
  935. {
  936. std::vector<BT<cmSourceFile*>> files;
  937. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  938. // Since we are still configuring not all sources may exist yet,
  939. // so we need to avoid full source classification because that
  940. // requires the absolute paths to all sources to be determined.
  941. // Since this is only for compatibility with old policies that
  942. // projects should not depend on anymore, just compute the files
  943. // without memoizing them.
  944. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  945. std::set<cmSourceFile*> emitted;
  946. for (BT<std::string> const& s : srcs) {
  947. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  948. if (emitted.insert(sf).second) {
  949. files.emplace_back(sf, s.Backtrace);
  950. }
  951. }
  952. return files;
  953. }
  954. KindedSources const& kinded = this->GetKindedSources(config);
  955. files.reserve(kinded.Sources.size());
  956. for (SourceAndKind const& si : kinded.Sources) {
  957. files.push_back(si.Source);
  958. }
  959. return files;
  960. }
  961. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  962. std::vector<cmSourceFile*>& files, const std::string& config) const
  963. {
  964. std::vector<BT<cmSourceFile*>> tmp =
  965. this->GetSourceFilesWithoutObjectLibraries(config);
  966. files.reserve(tmp.size());
  967. for (BT<cmSourceFile*>& v : tmp) {
  968. files.push_back(v.Value);
  969. }
  970. }
  971. std::vector<BT<cmSourceFile*>>
  972. cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  973. std::string const& config) const
  974. {
  975. std::vector<BT<cmSourceFile*>> files;
  976. KindedSources const& kinded = this->GetKindedSources(config);
  977. files.reserve(kinded.Sources.size());
  978. for (SourceAndKind const& si : kinded.Sources) {
  979. if (si.Source.Value->GetObjectLibrary().empty()) {
  980. files.push_back(si.Source);
  981. }
  982. }
  983. return files;
  984. }
  985. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  986. std::string const& config) const
  987. {
  988. // If we already processed one configuration and found no dependenc
  989. // on configuration then always use the one result.
  990. if (!this->LinkImplementationLanguageIsContextDependent) {
  991. return this->KindedSourcesMap.begin()->second;
  992. }
  993. // Lookup any existing link implementation for this configuration.
  994. std::string const key = cmSystemTools::UpperCase(config);
  995. KindedSourcesMapType::iterator it = this->KindedSourcesMap.find(key);
  996. if (it != this->KindedSourcesMap.end()) {
  997. if (!it->second.Initialized) {
  998. std::ostringstream e;
  999. e << "The SOURCES of \"" << this->GetName()
  1000. << "\" use a generator expression that depends on the "
  1001. "SOURCES themselves.";
  1002. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1003. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1004. static KindedSources empty;
  1005. return empty;
  1006. }
  1007. return it->second;
  1008. }
  1009. // Add an entry to the map for this configuration.
  1010. KindedSources& files = this->KindedSourcesMap[key];
  1011. this->ComputeKindedSources(files, config);
  1012. files.Initialized = true;
  1013. return files;
  1014. }
  1015. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  1016. std::string const& config) const
  1017. {
  1018. // Get the source file paths by string.
  1019. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1020. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  1021. std::vector<cmSourceFile*> badObjLib;
  1022. std::set<cmSourceFile*> emitted;
  1023. for (BT<std::string> const& s : srcs) {
  1024. // Create each source at most once.
  1025. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1026. if (!emitted.insert(sf).second) {
  1027. continue;
  1028. }
  1029. // Compute the kind (classification) of this source file.
  1030. SourceKind kind;
  1031. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1032. if (sf->GetCustomCommand()) {
  1033. kind = SourceKindCustomCommand;
  1034. } else if (this->Target->GetType() == cmStateEnums::UTILITY) {
  1035. kind = SourceKindExtra;
  1036. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  1037. kind = SourceKindHeader;
  1038. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  1039. kind = SourceKindExternalObject;
  1040. } else if (!sf->GetLanguage().empty()) {
  1041. kind = SourceKindObjectSource;
  1042. } else if (ext == "def") {
  1043. kind = SourceKindModuleDefinition;
  1044. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1045. badObjLib.push_back(sf);
  1046. }
  1047. } else if (ext == "idl") {
  1048. kind = SourceKindIDL;
  1049. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1050. badObjLib.push_back(sf);
  1051. }
  1052. } else if (ext == "resx") {
  1053. kind = SourceKindResx;
  1054. // Build and save the name of the corresponding .h file
  1055. // This relationship will be used later when building the project files.
  1056. // Both names would have been auto generated from Visual Studio
  1057. // where the user supplied the file name and Visual Studio
  1058. // appended the suffix.
  1059. std::string resx = sf->GetFullPath();
  1060. std::string hFileName = resx.substr(0, resx.find_last_of('.')) + ".h";
  1061. files.ExpectedResxHeaders.insert(hFileName);
  1062. } else if (ext == "appxmanifest") {
  1063. kind = SourceKindAppManifest;
  1064. } else if (ext == "manifest") {
  1065. kind = SourceKindManifest;
  1066. } else if (ext == "pfx") {
  1067. kind = SourceKindCertificate;
  1068. } else if (ext == "xaml") {
  1069. kind = SourceKindXaml;
  1070. // Build and save the name of the corresponding .h and .cpp file
  1071. // This relationship will be used later when building the project files.
  1072. // Both names would have been auto generated from Visual Studio
  1073. // where the user supplied the file name and Visual Studio
  1074. // appended the suffix.
  1075. std::string xaml = sf->GetFullPath();
  1076. std::string hFileName = xaml + ".h";
  1077. std::string cppFileName = xaml + ".cpp";
  1078. files.ExpectedXamlHeaders.insert(hFileName);
  1079. files.ExpectedXamlSources.insert(cppFileName);
  1080. } else if (header_regex.find(sf->GetFullPath())) {
  1081. kind = SourceKindHeader;
  1082. } else {
  1083. kind = SourceKindExtra;
  1084. }
  1085. // Save this classified source file in the result vector.
  1086. files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
  1087. }
  1088. if (!badObjLib.empty()) {
  1089. std::ostringstream e;
  1090. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  1091. for (cmSourceFile* i : badObjLib) {
  1092. e << " " << i->GetLocation().GetName() << "\n";
  1093. }
  1094. e << "but may contain only sources that compile, header files, and "
  1095. "other files that would not affect linking of a normal library.";
  1096. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1097. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1098. }
  1099. }
  1100. std::vector<cmGeneratorTarget::AllConfigSource> const&
  1101. cmGeneratorTarget::GetAllConfigSources() const
  1102. {
  1103. if (this->AllConfigSources.empty()) {
  1104. this->ComputeAllConfigSources();
  1105. }
  1106. return this->AllConfigSources;
  1107. }
  1108. void cmGeneratorTarget::ComputeAllConfigSources() const
  1109. {
  1110. std::vector<std::string> configs;
  1111. this->Makefile->GetConfigurations(configs);
  1112. std::map<cmSourceFile const*, size_t> index;
  1113. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1114. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1115. for (SourceAndKind const& src : sources.Sources) {
  1116. std::map<cmSourceFile const*, size_t>::iterator mi =
  1117. index.find(src.Source.Value);
  1118. if (mi == index.end()) {
  1119. AllConfigSource acs;
  1120. acs.Source = src.Source.Value;
  1121. acs.Kind = src.Kind;
  1122. this->AllConfigSources.push_back(std::move(acs));
  1123. std::map<cmSourceFile const*, size_t>::value_type entry(
  1124. src.Source.Value, this->AllConfigSources.size() - 1);
  1125. mi = index.insert(entry).first;
  1126. }
  1127. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1128. }
  1129. }
  1130. }
  1131. std::string cmGeneratorTarget::GetCompilePDBName(
  1132. const std::string& config) const
  1133. {
  1134. std::string prefix;
  1135. std::string base;
  1136. std::string suffix;
  1137. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  1138. prefix, base, suffix);
  1139. // Check for a per-configuration output directory target property.
  1140. std::string configUpper = cmSystemTools::UpperCase(config);
  1141. std::string configProp = "COMPILE_PDB_NAME_";
  1142. configProp += configUpper;
  1143. const char* config_name = this->GetProperty(configProp);
  1144. if (config_name && *config_name) {
  1145. return prefix + config_name + ".pdb";
  1146. }
  1147. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  1148. if (name && *name) {
  1149. return prefix + name + ".pdb";
  1150. }
  1151. return "";
  1152. }
  1153. std::string cmGeneratorTarget::GetCompilePDBPath(
  1154. const std::string& config) const
  1155. {
  1156. std::string dir = this->GetCompilePDBDirectory(config);
  1157. std::string name = this->GetCompilePDBName(config);
  1158. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1159. dir = this->GetPDBDirectory(config);
  1160. }
  1161. if (!dir.empty()) {
  1162. dir += "/";
  1163. }
  1164. return dir + name;
  1165. }
  1166. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1167. {
  1168. // soname is supported only for shared libraries and modules,
  1169. // and then only when the platform supports an soname flag.
  1170. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1171. !this->GetPropertyAsBool("NO_SONAME") &&
  1172. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1173. }
  1174. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1175. const std::string& config) const
  1176. {
  1177. // Only executables and shared libraries can have an rpath and may
  1178. // need relinking.
  1179. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1180. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1181. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1182. return false;
  1183. }
  1184. // If there is no install location this target will not be installed
  1185. // and therefore does not need relinking.
  1186. if (!this->Target->GetHaveInstallRule()) {
  1187. return false;
  1188. }
  1189. // If skipping all rpaths completely then no relinking is needed.
  1190. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1191. return false;
  1192. }
  1193. // If building with the install-tree rpath no relinking is needed.
  1194. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1195. return false;
  1196. }
  1197. // If chrpath is going to be used no relinking is needed.
  1198. if (this->IsChrpathUsed(config)) {
  1199. return false;
  1200. }
  1201. // Check for rpath support on this platform.
  1202. std::string ll = this->GetLinkerLanguage(config);
  1203. if (!ll.empty()) {
  1204. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1205. flagVar += ll;
  1206. flagVar += "_FLAG";
  1207. if (!this->Makefile->IsSet(flagVar)) {
  1208. // There is no rpath support on this platform so nothing needs
  1209. // relinking.
  1210. return false;
  1211. }
  1212. } else {
  1213. // No linker language is known. This error will be reported by
  1214. // other code.
  1215. return false;
  1216. }
  1217. // If either a build or install tree rpath is set then the rpath
  1218. // will likely change between the build tree and install tree and
  1219. // this target must be relinked.
  1220. bool have_rpath =
  1221. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  1222. bool is_ninja =
  1223. this->LocalGenerator->GetGlobalGenerator()->GetName() == "Ninja";
  1224. if (have_rpath && is_ninja) {
  1225. std::ostringstream w;
  1226. /* clang-format off */
  1227. w <<
  1228. "The install of the " << this->GetName() << " target requires "
  1229. "changing an RPATH from the build tree, but this is not supported "
  1230. "with the Ninja generator unless on an ELF-based platform. The "
  1231. "CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1232. "relinking step."
  1233. ;
  1234. /* clang-format on */
  1235. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1236. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1237. }
  1238. return have_rpath;
  1239. }
  1240. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1241. {
  1242. // Only certain target types have an rpath.
  1243. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1244. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1245. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1246. return false;
  1247. }
  1248. // If the target will not be installed we do not need to change its
  1249. // rpath.
  1250. if (!this->Target->GetHaveInstallRule()) {
  1251. return false;
  1252. }
  1253. // Skip chrpath if skipping rpath altogether.
  1254. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1255. return false;
  1256. }
  1257. // Skip chrpath if it does not need to be changed at install time.
  1258. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1259. return false;
  1260. }
  1261. // Allow the user to disable builtin chrpath explicitly.
  1262. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1263. return false;
  1264. }
  1265. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1266. return true;
  1267. }
  1268. #if defined(CMAKE_USE_ELF_PARSER)
  1269. // Enable if the rpath flag uses a separator and the target uses ELF
  1270. // binaries.
  1271. std::string ll = this->GetLinkerLanguage(config);
  1272. if (!ll.empty()) {
  1273. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1274. sepVar += ll;
  1275. sepVar += "_FLAG_SEP";
  1276. const char* sep = this->Makefile->GetDefinition(sepVar);
  1277. if (sep && *sep) {
  1278. // TODO: Add ELF check to ABI detection and get rid of
  1279. // CMAKE_EXECUTABLE_FORMAT.
  1280. if (const char* fmt =
  1281. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  1282. return strcmp(fmt, "ELF") == 0;
  1283. }
  1284. }
  1285. }
  1286. #endif
  1287. static_cast<void>(config);
  1288. return false;
  1289. }
  1290. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  1291. const std::string& config) const
  1292. {
  1293. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  1294. if (cmGeneratorTarget::ImportInfo const* info =
  1295. this->GetImportInfo(config)) {
  1296. return info->NoSOName;
  1297. }
  1298. }
  1299. return false;
  1300. }
  1301. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  1302. const std::string& config) const
  1303. {
  1304. bool install_name_is_rpath = false;
  1305. bool macosx_rpath = false;
  1306. if (!this->IsImported()) {
  1307. if (this->GetType() != cmStateEnums::SHARED_LIBRARY) {
  1308. return false;
  1309. }
  1310. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  1311. bool use_install_name = this->MacOSXUseInstallNameDir();
  1312. if (install_name && use_install_name &&
  1313. std::string(install_name) == "@rpath") {
  1314. install_name_is_rpath = true;
  1315. } else if (install_name && use_install_name) {
  1316. return false;
  1317. }
  1318. if (!install_name_is_rpath) {
  1319. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  1320. }
  1321. } else {
  1322. // Lookup the imported soname.
  1323. if (cmGeneratorTarget::ImportInfo const* info =
  1324. this->GetImportInfo(config)) {
  1325. if (!info->NoSOName && !info->SOName.empty()) {
  1326. if (info->SOName.find("@rpath/") == 0) {
  1327. install_name_is_rpath = true;
  1328. }
  1329. } else {
  1330. std::string install_name;
  1331. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  1332. if (install_name.find("@rpath") != std::string::npos) {
  1333. install_name_is_rpath = true;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. if (!install_name_is_rpath && !macosx_rpath) {
  1339. return false;
  1340. }
  1341. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1342. std::ostringstream w;
  1343. w << "Attempting to use ";
  1344. if (macosx_rpath) {
  1345. w << "MACOSX_RPATH";
  1346. } else {
  1347. w << "@rpath";
  1348. }
  1349. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  1350. w << " This could be because you are using a Mac OS X version";
  1351. w << " less than 10.5 or because CMake's platform configuration is";
  1352. w << " corrupt.";
  1353. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1354. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1355. }
  1356. return true;
  1357. }
  1358. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  1359. {
  1360. // we can't do rpaths when unsupported
  1361. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  1362. return false;
  1363. }
  1364. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  1365. if (macosx_rpath_str) {
  1366. return this->GetPropertyAsBool("MACOSX_RPATH");
  1367. }
  1368. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  1369. if (cmp0042 == cmPolicies::WARN) {
  1370. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  1371. this->GetName());
  1372. }
  1373. return cmp0042 == cmPolicies::NEW;
  1374. }
  1375. bool cmGeneratorTarget::MacOSXUseInstallNameDir() const
  1376. {
  1377. const char* build_with_install_name =
  1378. this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR");
  1379. if (build_with_install_name) {
  1380. return cmSystemTools::IsOn(build_with_install_name);
  1381. }
  1382. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1383. if (cmp0068 == cmPolicies::NEW) {
  1384. return false;
  1385. }
  1386. bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  1387. if (use_install_name && cmp0068 == cmPolicies::WARN) {
  1388. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1389. this->GetName());
  1390. }
  1391. return use_install_name;
  1392. }
  1393. bool cmGeneratorTarget::CanGenerateInstallNameDir(
  1394. InstallNameType name_type) const
  1395. {
  1396. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  1397. if (cmp0068 == cmPolicies::NEW) {
  1398. return true;
  1399. }
  1400. bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH");
  1401. if (name_type == INSTALL_NAME_FOR_INSTALL) {
  1402. skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  1403. } else {
  1404. skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH");
  1405. }
  1406. if (skip && cmp0068 == cmPolicies::WARN) {
  1407. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  1408. this->GetName());
  1409. }
  1410. return !skip;
  1411. }
  1412. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1413. {
  1414. if (this->IsImported()) {
  1415. // Lookup the imported soname.
  1416. if (cmGeneratorTarget::ImportInfo const* info =
  1417. this->GetImportInfo(config)) {
  1418. if (info->NoSOName) {
  1419. // The imported library has no builtin soname so the name
  1420. // searched at runtime will be just the filename.
  1421. return cmSystemTools::GetFilenameName(info->Location);
  1422. }
  1423. // Use the soname given if any.
  1424. if (info->SOName.find("@rpath/") == 0) {
  1425. return info->SOName.substr(6);
  1426. }
  1427. return info->SOName;
  1428. }
  1429. return "";
  1430. }
  1431. // Compute the soname that will be built.
  1432. std::string name;
  1433. std::string soName;
  1434. std::string realName;
  1435. std::string impName;
  1436. std::string pdbName;
  1437. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  1438. return soName;
  1439. }
  1440. static bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  1441. {
  1442. return level == cmGeneratorTarget::FullLevel;
  1443. }
  1444. static bool shouldAddContentLevel(
  1445. cmGeneratorTarget::BundleDirectoryLevel level)
  1446. {
  1447. return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
  1448. }
  1449. std::string cmGeneratorTarget::GetAppBundleDirectory(
  1450. const std::string& config, BundleDirectoryLevel level) const
  1451. {
  1452. std::string fpath =
  1453. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  1454. fpath += ".";
  1455. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1456. if (!ext) {
  1457. ext = "app";
  1458. }
  1459. fpath += ext;
  1460. if (shouldAddContentLevel(level) &&
  1461. !this->Makefile->PlatformIsAppleEmbedded()) {
  1462. fpath += "/Contents";
  1463. if (shouldAddFullLevel(level)) {
  1464. fpath += "/MacOS";
  1465. }
  1466. }
  1467. return fpath;
  1468. }
  1469. bool cmGeneratorTarget::IsBundleOnApple() const
  1470. {
  1471. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  1472. this->IsCFBundleOnApple();
  1473. }
  1474. std::string cmGeneratorTarget::GetCFBundleDirectory(
  1475. const std::string& config, BundleDirectoryLevel level) const
  1476. {
  1477. std::string fpath;
  1478. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1479. fpath += ".";
  1480. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1481. if (!ext) {
  1482. if (this->IsXCTestOnApple()) {
  1483. ext = "xctest";
  1484. } else {
  1485. ext = "bundle";
  1486. }
  1487. }
  1488. fpath += ext;
  1489. if (shouldAddContentLevel(level) &&
  1490. !this->Makefile->PlatformIsAppleEmbedded()) {
  1491. fpath += "/Contents";
  1492. if (shouldAddFullLevel(level)) {
  1493. fpath += "/MacOS";
  1494. }
  1495. }
  1496. return fpath;
  1497. }
  1498. std::string cmGeneratorTarget::GetFrameworkDirectory(
  1499. const std::string& config, BundleDirectoryLevel level) const
  1500. {
  1501. std::string fpath;
  1502. fpath += this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  1503. fpath += ".";
  1504. const char* ext = this->GetProperty("BUNDLE_EXTENSION");
  1505. if (!ext) {
  1506. ext = "framework";
  1507. }
  1508. fpath += ext;
  1509. if (shouldAddFullLevel(level) &&
  1510. !this->Makefile->PlatformIsAppleEmbedded()) {
  1511. fpath += "/Versions/";
  1512. fpath += this->GetFrameworkVersion();
  1513. }
  1514. return fpath;
  1515. }
  1516. std::string cmGeneratorTarget::GetFullName(
  1517. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1518. {
  1519. if (this->IsImported()) {
  1520. return this->GetFullNameImported(config, artifact);
  1521. }
  1522. return this->GetFullNameInternal(config, artifact);
  1523. }
  1524. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1525. const std::string& config) const
  1526. {
  1527. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1528. // If building directly for installation then the build tree install_name
  1529. // is the same as the install tree.
  1530. if (this->MacOSXUseInstallNameDir()) {
  1531. return this->GetInstallNameDirForInstallTree();
  1532. }
  1533. // Use the build tree directory for the target.
  1534. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) {
  1535. std::string dir;
  1536. if (this->MacOSXRpathInstallNameDirDefault()) {
  1537. dir = "@rpath";
  1538. } else {
  1539. dir = this->GetDirectory(config);
  1540. }
  1541. dir += "/";
  1542. return dir;
  1543. }
  1544. }
  1545. return "";
  1546. }
  1547. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1548. {
  1549. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1550. std::string dir;
  1551. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1552. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) {
  1553. if (install_name_dir && *install_name_dir) {
  1554. dir = install_name_dir;
  1555. dir += "/";
  1556. }
  1557. }
  1558. if (!install_name_dir) {
  1559. if (this->MacOSXRpathInstallNameDirDefault()) {
  1560. dir = "@rpath/";
  1561. }
  1562. }
  1563. return dir;
  1564. }
  1565. return "";
  1566. }
  1567. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  1568. {
  1569. return this->Target->GetBacktrace();
  1570. }
  1571. const std::set<BT<std::string>>& cmGeneratorTarget::GetUtilities() const
  1572. {
  1573. return this->Target->GetUtilities();
  1574. }
  1575. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  1576. {
  1577. return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  1578. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1579. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1580. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  1581. this->GetType() == cmStateEnums::EXECUTABLE;
  1582. }
  1583. const std::string* cmGeneratorTarget::GetExportMacro() const
  1584. {
  1585. // Define the symbol for targets that export symbols.
  1586. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1587. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1588. this->IsExecutableWithExports()) {
  1589. if (const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  1590. this->ExportMacro = custom_export_name;
  1591. } else {
  1592. std::string in = this->GetName();
  1593. in += "_EXPORTS";
  1594. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  1595. }
  1596. return &this->ExportMacro;
  1597. }
  1598. return nullptr;
  1599. }
  1600. class cmTargetCollectLinkLanguages
  1601. {
  1602. public:
  1603. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1604. std::string config,
  1605. std::unordered_set<std::string>& languages,
  1606. cmGeneratorTarget const* head)
  1607. : Config(std::move(config))
  1608. , Languages(languages)
  1609. , HeadTarget(head)
  1610. , Target(target)
  1611. {
  1612. this->Visited.insert(target);
  1613. }
  1614. void Visit(cmLinkItem const& item)
  1615. {
  1616. if (!item.Target) {
  1617. if (item.AsStr().find("::") != std::string::npos) {
  1618. bool noMessage = false;
  1619. MessageType messageType = MessageType::FATAL_ERROR;
  1620. std::ostringstream e;
  1621. switch (this->Target->GetLocalGenerator()->GetPolicyStatus(
  1622. cmPolicies::CMP0028)) {
  1623. case cmPolicies::WARN: {
  1624. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1625. messageType = MessageType::AUTHOR_WARNING;
  1626. } break;
  1627. case cmPolicies::OLD:
  1628. noMessage = true;
  1629. case cmPolicies::REQUIRED_IF_USED:
  1630. case cmPolicies::REQUIRED_ALWAYS:
  1631. case cmPolicies::NEW:
  1632. // Issue the fatal message.
  1633. break;
  1634. }
  1635. if (!noMessage) {
  1636. e << "Target \"" << this->Target->GetName()
  1637. << "\" links to target \"" << item.AsStr()
  1638. << "\" but the target was not found. Perhaps a find_package() "
  1639. "call is missing for an IMPORTED target, or an ALIAS target is "
  1640. "missing?";
  1641. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1642. messageType, e.str(), this->Target->GetBacktrace());
  1643. }
  1644. }
  1645. return;
  1646. }
  1647. if (!this->Visited.insert(item.Target).second) {
  1648. return;
  1649. }
  1650. cmLinkInterface const* iface =
  1651. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  1652. if (!iface) {
  1653. return;
  1654. }
  1655. for (std::string const& language : iface->Languages) {
  1656. this->Languages.insert(language);
  1657. }
  1658. for (cmLinkItem const& lib : iface->Libraries) {
  1659. this->Visit(lib);
  1660. }
  1661. }
  1662. private:
  1663. std::string Config;
  1664. std::unordered_set<std::string>& Languages;
  1665. cmGeneratorTarget const* HeadTarget;
  1666. const cmGeneratorTarget* Target;
  1667. std::set<cmGeneratorTarget const*> Visited;
  1668. };
  1669. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  1670. const std::string& config) const
  1671. {
  1672. std::string key(cmSystemTools::UpperCase(config));
  1673. LinkClosureMapType::iterator i = this->LinkClosureMap.find(key);
  1674. if (i == this->LinkClosureMap.end()) {
  1675. LinkClosure lc;
  1676. this->ComputeLinkClosure(config, lc);
  1677. LinkClosureMapType::value_type entry(key, lc);
  1678. i = this->LinkClosureMap.insert(entry).first;
  1679. }
  1680. return &i->second;
  1681. }
  1682. class cmTargetSelectLinker
  1683. {
  1684. int Preference;
  1685. cmGeneratorTarget const* Target;
  1686. cmGlobalGenerator* GG;
  1687. std::set<std::string> Preferred;
  1688. public:
  1689. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1690. : Preference(0)
  1691. , Target(target)
  1692. {
  1693. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1694. }
  1695. void Consider(const char* lang)
  1696. {
  1697. int preference = this->GG->GetLinkerPreference(lang);
  1698. if (preference > this->Preference) {
  1699. this->Preference = preference;
  1700. this->Preferred.clear();
  1701. }
  1702. if (preference == this->Preference) {
  1703. this->Preferred.insert(lang);
  1704. }
  1705. }
  1706. std::string Choose()
  1707. {
  1708. if (this->Preferred.empty()) {
  1709. return "";
  1710. }
  1711. if (this->Preferred.size() > 1) {
  1712. std::ostringstream e;
  1713. e << "Target " << this->Target->GetName()
  1714. << " contains multiple languages with the highest linker preference"
  1715. << " (" << this->Preference << "):\n";
  1716. for (std::string const& li : this->Preferred) {
  1717. e << " " << li << "\n";
  1718. }
  1719. e << "Set the LINKER_LANGUAGE property for this target.";
  1720. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  1721. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  1722. this->Target->GetBacktrace());
  1723. }
  1724. return *this->Preferred.begin();
  1725. }
  1726. };
  1727. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1728. LinkClosure& lc) const
  1729. {
  1730. // Get languages built in this target.
  1731. std::unordered_set<std::string> languages;
  1732. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  1733. assert(impl);
  1734. for (std::string const& li : impl->Languages) {
  1735. languages.insert(li);
  1736. }
  1737. // Add interface languages from linked targets.
  1738. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  1739. for (cmLinkImplItem const& lib : impl->Libraries) {
  1740. cll.Visit(lib);
  1741. }
  1742. // Store the transitive closure of languages.
  1743. for (std::string const& lang : languages) {
  1744. lc.Languages.push_back(lang);
  1745. }
  1746. // Choose the language whose linker should be used.
  1747. if (this->GetProperty("HAS_CXX")) {
  1748. lc.LinkerLanguage = "CXX";
  1749. } else if (const char* linkerLang = this->GetProperty("LINKER_LANGUAGE")) {
  1750. lc.LinkerLanguage = linkerLang;
  1751. } else {
  1752. // Find the language with the highest preference value.
  1753. cmTargetSelectLinker tsl(this);
  1754. // First select from the languages compiled directly in this target.
  1755. for (std::string const& l : impl->Languages) {
  1756. tsl.Consider(l.c_str());
  1757. }
  1758. // Now consider languages that propagate from linked targets.
  1759. for (std::string const& lang : languages) {
  1760. std::string propagates =
  1761. "CMAKE_" + lang + "_LINKER_PREFERENCE_PROPAGATES";
  1762. if (this->Makefile->IsOn(propagates)) {
  1763. tsl.Consider(lang.c_str());
  1764. }
  1765. }
  1766. lc.LinkerLanguage = tsl.Choose();
  1767. }
  1768. }
  1769. void cmGeneratorTarget::GetFullNameComponents(
  1770. std::string& prefix, std::string& base, std::string& suffix,
  1771. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1772. {
  1773. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  1774. }
  1775. std::string cmGeneratorTarget::BuildBundleDirectory(
  1776. const std::string& base, const std::string& config,
  1777. BundleDirectoryLevel level) const
  1778. {
  1779. std::string fpath = base;
  1780. if (this->IsAppBundleOnApple()) {
  1781. fpath += this->GetAppBundleDirectory(config, level);
  1782. }
  1783. if (this->IsFrameworkOnApple()) {
  1784. fpath += this->GetFrameworkDirectory(config, level);
  1785. }
  1786. if (this->IsCFBundleOnApple()) {
  1787. fpath += this->GetCFBundleDirectory(config, level);
  1788. }
  1789. return fpath;
  1790. }
  1791. std::string cmGeneratorTarget::GetMacContentDirectory(
  1792. const std::string& config, cmStateEnums::ArtifactType artifact) const
  1793. {
  1794. // Start with the output directory for the target.
  1795. std::string fpath = this->GetDirectory(config, artifact);
  1796. fpath += "/";
  1797. BundleDirectoryLevel level = ContentLevel;
  1798. if (this->IsFrameworkOnApple()) {
  1799. // additional files with a framework go into the version specific
  1800. // directory
  1801. level = FullLevel;
  1802. }
  1803. fpath = this->BuildBundleDirectory(fpath, config, level);
  1804. return fpath;
  1805. }
  1806. std::string cmGeneratorTarget::GetEffectiveFolderName() const
  1807. {
  1808. std::string effectiveFolder;
  1809. if (!this->GlobalGenerator->UseFolderProperty()) {
  1810. return effectiveFolder;
  1811. }
  1812. const char* targetFolder = this->GetProperty("FOLDER");
  1813. if (targetFolder) {
  1814. effectiveFolder += targetFolder;
  1815. }
  1816. return effectiveFolder;
  1817. }
  1818. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1819. const std::string& config) const
  1820. {
  1821. // There is no compile information for imported targets.
  1822. if (this->IsImported()) {
  1823. return nullptr;
  1824. }
  1825. if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  1826. std::string msg = "cmTarget::GetCompileInfo called for ";
  1827. msg += this->GetName();
  1828. msg += " which has type ";
  1829. msg += cmState::GetTargetTypeName(this->GetType());
  1830. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  1831. return nullptr;
  1832. }
  1833. // Lookup/compute/cache the compile information for this configuration.
  1834. std::string config_upper;
  1835. if (!config.empty()) {
  1836. config_upper = cmSystemTools::UpperCase(config);
  1837. }
  1838. CompileInfoMapType::const_iterator i =
  1839. this->CompileInfoMap.find(config_upper);
  1840. if (i == this->CompileInfoMap.end()) {
  1841. CompileInfo info;
  1842. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1843. CompileInfoMapType::value_type entry(config_upper, info);
  1844. i = this->CompileInfoMap.insert(entry).first;
  1845. }
  1846. return &i->second;
  1847. }
  1848. cmGeneratorTarget::ModuleDefinitionInfo const*
  1849. cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
  1850. {
  1851. // A module definition file only makes sense on certain target types.
  1852. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1853. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  1854. !this->IsExecutableWithExports()) {
  1855. return nullptr;
  1856. }
  1857. // Lookup/compute/cache the compile information for this configuration.
  1858. std::string config_upper;
  1859. if (!config.empty()) {
  1860. config_upper = cmSystemTools::UpperCase(config);
  1861. }
  1862. ModuleDefinitionInfoMapType::const_iterator i =
  1863. this->ModuleDefinitionInfoMap.find(config_upper);
  1864. if (i == this->ModuleDefinitionInfoMap.end()) {
  1865. ModuleDefinitionInfo info;
  1866. this->ComputeModuleDefinitionInfo(config, info);
  1867. ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
  1868. i = this->ModuleDefinitionInfoMap.insert(entry).first;
  1869. }
  1870. return &i->second;
  1871. }
  1872. void cmGeneratorTarget::ComputeModuleDefinitionInfo(
  1873. std::string const& config, ModuleDefinitionInfo& info) const
  1874. {
  1875. this->GetModuleDefinitionSources(info.Sources, config);
  1876. info.WindowsExportAllSymbols =
  1877. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
  1878. this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
  1879. #if defined(_WIN32) && defined(CMAKE_BUILD_WITH_CMAKE)
  1880. info.DefFileGenerated =
  1881. info.WindowsExportAllSymbols || info.Sources.size() > 1;
  1882. #else
  1883. // Our __create_def helper is only available on Windows.
  1884. info.DefFileGenerated = false;
  1885. #endif
  1886. if (info.DefFileGenerated) {
  1887. info.DefFile = this->ObjectDirectory /* has slash */ + "exports.def";
  1888. } else if (!info.Sources.empty()) {
  1889. info.DefFile = info.Sources.front()->GetFullPath();
  1890. }
  1891. }
  1892. bool cmGeneratorTarget::IsDLLPlatform() const
  1893. {
  1894. return this->DLLPlatform;
  1895. }
  1896. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  1897. const std::string& config) const
  1898. {
  1899. const char* prop =
  1900. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  1901. if (!prop) {
  1902. return;
  1903. }
  1904. cmGeneratorExpression ge;
  1905. cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr,
  1906. nullptr);
  1907. cmSystemTools::ExpandListArgument(
  1908. ge.Parse(prop)->Evaluate(this->LocalGenerator, config, false, this,
  1909. &dagChecker),
  1910. result);
  1911. }
  1912. void processILibs(const std::string& config,
  1913. cmGeneratorTarget const* headTarget, cmLinkItem const& item,
  1914. cmGlobalGenerator* gg,
  1915. std::vector<cmGeneratorTarget const*>& tgts,
  1916. std::set<cmGeneratorTarget const*>& emitted)
  1917. {
  1918. if (item.Target && emitted.insert(item.Target).second) {
  1919. tgts.push_back(item.Target);
  1920. if (cmLinkInterfaceLibraries const* iface =
  1921. item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) {
  1922. for (cmLinkItem const& lib : iface->Libraries) {
  1923. processILibs(config, headTarget, lib, gg, tgts, emitted);
  1924. }
  1925. }
  1926. }
  1927. }
  1928. const std::vector<const cmGeneratorTarget*>&
  1929. cmGeneratorTarget::GetLinkImplementationClosure(
  1930. const std::string& config) const
  1931. {
  1932. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  1933. if (!tgts.Done) {
  1934. tgts.Done = true;
  1935. std::set<cmGeneratorTarget const*> emitted;
  1936. cmLinkImplementationLibraries const* impl =
  1937. this->GetLinkImplementationLibraries(config);
  1938. for (cmLinkImplItem const& lib : impl->Libraries) {
  1939. processILibs(config, this, lib,
  1940. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  1941. }
  1942. }
  1943. return tgts;
  1944. }
  1945. class cmTargetTraceDependencies
  1946. {
  1947. public:
  1948. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1949. void Trace();
  1950. private:
  1951. cmGeneratorTarget* GeneratorTarget;
  1952. cmMakefile* Makefile;
  1953. cmLocalGenerator* LocalGenerator;
  1954. cmGlobalGenerator const* GlobalGenerator;
  1955. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1956. SourceEntry* CurrentEntry;
  1957. std::queue<cmSourceFile*> SourceQueue;
  1958. std::set<cmSourceFile*> SourcesQueued;
  1959. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1960. NameMapType NameMap;
  1961. std::vector<std::string> NewSources;
  1962. void QueueSource(cmSourceFile* sf);
  1963. void FollowName(std::string const& name);
  1964. void FollowNames(std::vector<std::string> const& names);
  1965. bool IsUtility(std::string const& dep);
  1966. void CheckCustomCommand(cmCustomCommand const& cc);
  1967. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1968. void FollowCommandDepends(cmCustomCommand const& cc,
  1969. const std::string& config,
  1970. std::set<std::string>& emitted);
  1971. };
  1972. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  1973. : GeneratorTarget(target)
  1974. {
  1975. // Convenience.
  1976. this->Makefile = target->Target->GetMakefile();
  1977. this->LocalGenerator = target->GetLocalGenerator();
  1978. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  1979. this->CurrentEntry = nullptr;
  1980. // Queue all the source files already specified for the target.
  1981. if (target->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  1982. std::vector<std::string> configs;
  1983. this->Makefile->GetConfigurations(configs);
  1984. if (configs.empty()) {
  1985. configs.emplace_back();
  1986. }
  1987. std::set<cmSourceFile*> emitted;
  1988. for (std::string const& c : configs) {
  1989. std::vector<cmSourceFile*> sources;
  1990. this->GeneratorTarget->GetSourceFiles(sources, c);
  1991. for (cmSourceFile* sf : sources) {
  1992. const std::set<cmGeneratorTarget const*> tgts =
  1993. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1994. if (tgts.find(this->GeneratorTarget) != tgts.end()) {
  1995. std::ostringstream e;
  1996. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1997. << "\"\ndepends on the sources of a target it is used in. This "
  1998. "is a dependency loop and is not allowed.";
  1999. this->GeneratorTarget->LocalGenerator->IssueMessage(
  2000. MessageType::FATAL_ERROR, e.str());
  2001. return;
  2002. }
  2003. if (emitted.insert(sf).second &&
  2004. this->SourcesQueued.insert(sf).second) {
  2005. this->SourceQueue.push(sf);
  2006. }
  2007. }
  2008. }
  2009. }
  2010. // Queue pre-build, pre-link, and post-build rule dependencies.
  2011. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  2012. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  2013. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  2014. }
  2015. void cmTargetTraceDependencies::Trace()
  2016. {
  2017. // Process one dependency at a time until the queue is empty.
  2018. while (!this->SourceQueue.empty()) {
  2019. // Get the next source from the queue.
  2020. cmSourceFile* sf = this->SourceQueue.front();
  2021. this->SourceQueue.pop();
  2022. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  2023. // Queue dependencies added explicitly by the user.
  2024. if (const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  2025. std::vector<std::string> objDeps;
  2026. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  2027. for (std::string& objDep : objDeps) {
  2028. if (cmSystemTools::FileIsFullPath(objDep)) {
  2029. objDep = cmSystemTools::CollapseFullPath(objDep);
  2030. }
  2031. }
  2032. this->FollowNames(objDeps);
  2033. }
  2034. // Queue the source needed to generate this file, if any.
  2035. this->FollowName(sf->GetFullPath());
  2036. // Queue dependencies added programmatically by commands.
  2037. this->FollowNames(sf->GetDepends());
  2038. // Queue custom command dependencies.
  2039. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  2040. this->CheckCustomCommand(*cc);
  2041. }
  2042. }
  2043. this->CurrentEntry = nullptr;
  2044. this->GeneratorTarget->AddTracedSources(this->NewSources);
  2045. }
  2046. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  2047. {
  2048. if (this->SourcesQueued.insert(sf).second) {
  2049. this->SourceQueue.push(sf);
  2050. // Make sure this file is in the target at the end.
  2051. this->NewSources.push_back(sf->GetFullPath());
  2052. }
  2053. }
  2054. void cmTargetTraceDependencies::FollowName(std::string const& name)
  2055. {
  2056. NameMapType::iterator i = this->NameMap.find(name);
  2057. if (i == this->NameMap.end()) {
  2058. // Check if we know how to generate this file.
  2059. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  2060. NameMapType::value_type entry(name, sf);
  2061. i = this->NameMap.insert(entry).first;
  2062. }
  2063. if (cmSourceFile* sf = i->second) {
  2064. // Record the dependency we just followed.
  2065. if (this->CurrentEntry) {
  2066. this->CurrentEntry->Depends.push_back(sf);
  2067. }
  2068. this->QueueSource(sf);
  2069. }
  2070. }
  2071. void cmTargetTraceDependencies::FollowNames(
  2072. std::vector<std::string> const& names)
  2073. {
  2074. for (std::string const& name : names) {
  2075. this->FollowName(name);
  2076. }
  2077. }
  2078. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  2079. {
  2080. // Dependencies on targets (utilities) are supposed to be named by
  2081. // just the target name. However for compatibility we support
  2082. // naming the output file generated by the target (assuming there is
  2083. // no output-name property which old code would not have set). In
  2084. // that case the target name will be the file basename of the
  2085. // dependency.
  2086. std::string util = cmSystemTools::GetFilenameName(dep);
  2087. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  2088. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2089. }
  2090. // Check for a target with this name.
  2091. if (cmGeneratorTarget* t =
  2092. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  2093. util)) {
  2094. // If we find the target and the dep was given as a full path,
  2095. // then make sure it was not a full path to something else, and
  2096. // the fact that the name matched a target was just a coincidence.
  2097. if (cmSystemTools::FileIsFullPath(dep)) {
  2098. if (t->GetType() >= cmStateEnums::EXECUTABLE &&
  2099. t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  2100. // This is really only for compatibility so we do not need to
  2101. // worry about configuration names and output names.
  2102. std::string tLocation = t->GetLocationForBuild();
  2103. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2104. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2105. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2106. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2107. if (depLocation == tLocation) {
  2108. this->GeneratorTarget->Target->AddUtility(util);
  2109. return true;
  2110. }
  2111. }
  2112. } else {
  2113. // The original name of the dependency was not a full path. It
  2114. // must name a target, so add the target-level dependency.
  2115. this->GeneratorTarget->Target->AddUtility(util);
  2116. return true;
  2117. }
  2118. }
  2119. // The dependency does not name a target built in this project.
  2120. return false;
  2121. }
  2122. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  2123. {
  2124. // Transform command names that reference targets built in this
  2125. // project to corresponding target-level dependencies.
  2126. cmGeneratorExpression ge(cc.GetBacktrace());
  2127. // Add target-level dependencies referenced by generator expressions.
  2128. std::set<cmGeneratorTarget*> targets;
  2129. for (cmCustomCommandLine const& cCmdLine : cc.GetCommandLines()) {
  2130. std::string const& command = *cCmdLine.begin();
  2131. // Check for a target with this name.
  2132. if (cmGeneratorTarget* t =
  2133. this->LocalGenerator->FindGeneratorTargetToUse(command)) {
  2134. if (t->GetType() == cmStateEnums::EXECUTABLE) {
  2135. // The command refers to an executable target built in
  2136. // this project. Add the target-level dependency to make
  2137. // sure the executable is up to date before this custom
  2138. // command possibly runs.
  2139. this->GeneratorTarget->Target->AddUtility(command);
  2140. }
  2141. }
  2142. // Check for target references in generator expressions.
  2143. for (std::string const& cl : cCmdLine) {
  2144. const std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cl);
  2145. cge->Evaluate(this->GeneratorTarget->GetLocalGenerator(), "", true);
  2146. std::set<cmGeneratorTarget*> geTargets = cge->GetTargets();
  2147. targets.insert(geTargets.begin(), geTargets.end());
  2148. }
  2149. }
  2150. for (cmGeneratorTarget* target : targets) {
  2151. this->GeneratorTarget->Target->AddUtility(target->GetName());
  2152. }
  2153. // Queue the custom command dependencies.
  2154. std::vector<std::string> configs;
  2155. std::set<std::string> emitted;
  2156. this->Makefile->GetConfigurations(configs);
  2157. if (configs.empty()) {
  2158. configs.emplace_back();
  2159. }
  2160. for (std::string const& conf : configs) {
  2161. this->FollowCommandDepends(cc, conf, emitted);
  2162. }
  2163. }
  2164. void cmTargetTraceDependencies::FollowCommandDepends(
  2165. cmCustomCommand const& cc, const std::string& config,
  2166. std::set<std::string>& emitted)
  2167. {
  2168. cmCustomCommandGenerator ccg(cc, config,
  2169. this->GeneratorTarget->LocalGenerator);
  2170. const std::vector<std::string>& depends = ccg.GetDepends();
  2171. for (std::string const& dep : depends) {
  2172. if (emitted.insert(dep).second) {
  2173. if (!this->IsUtility(dep)) {
  2174. // The dependency does not name a target and may be a file we
  2175. // know how to generate. Queue it.
  2176. this->FollowName(dep);
  2177. }
  2178. }
  2179. }
  2180. }
  2181. void cmTargetTraceDependencies::CheckCustomCommands(
  2182. const std::vector<cmCustomCommand>& commands)
  2183. {
  2184. for (cmCustomCommand const& command : commands) {
  2185. this->CheckCustomCommand(command);
  2186. }
  2187. }
  2188. void cmGeneratorTarget::TraceDependencies()
  2189. {
  2190. // CMake-generated targets have no dependencies to trace. Normally tracing
  2191. // would find nothing anyway, but when building CMake itself the "install"
  2192. // target command ends up referencing the "cmake" target but we do not
  2193. // really want the dependency because "install" depend on "all" anyway.
  2194. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2195. return;
  2196. }
  2197. // Use a helper object to trace the dependencies.
  2198. cmTargetTraceDependencies tracer(this);
  2199. tracer.Trace();
  2200. }
  2201. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  2202. const std::string& config) const
  2203. {
  2204. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  2205. return info->CompilePdbDir;
  2206. }
  2207. return "";
  2208. }
  2209. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2210. std::vector<std::string>& archVec) const
  2211. {
  2212. const char* archs = nullptr;
  2213. if (!config.empty()) {
  2214. std::string defVarName = "OSX_ARCHITECTURES_";
  2215. defVarName += cmSystemTools::UpperCase(config);
  2216. archs = this->GetProperty(defVarName);
  2217. }
  2218. if (!archs) {
  2219. archs = this->GetProperty("OSX_ARCHITECTURES");
  2220. }
  2221. if (archs) {
  2222. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  2223. }
  2224. }
  2225. //----------------------------------------------------------------------------
  2226. std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
  2227. std::string const& var, std::string const& lang,
  2228. std::string const& config) const
  2229. {
  2230. if (this->IsIPOEnabled(lang, config)) {
  2231. std::string varIPO = var + "_IPO";
  2232. if (this->Makefile->IsDefinitionSet(varIPO)) {
  2233. return varIPO;
  2234. }
  2235. }
  2236. return var;
  2237. }
  2238. //----------------------------------------------------------------------------
  2239. std::string cmGeneratorTarget::GetCreateRuleVariable(
  2240. std::string const& lang, std::string const& config) const
  2241. {
  2242. switch (this->GetType()) {
  2243. case cmStateEnums::STATIC_LIBRARY: {
  2244. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  2245. return this->GetFeatureSpecificLinkRuleVariable(var, lang, config);
  2246. }
  2247. case cmStateEnums::SHARED_LIBRARY:
  2248. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  2249. case cmStateEnums::MODULE_LIBRARY:
  2250. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  2251. case cmStateEnums::EXECUTABLE:
  2252. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2253. default:
  2254. break;
  2255. }
  2256. return "";
  2257. }
  2258. static void processIncludeDirectories(
  2259. cmGeneratorTarget const* tgt,
  2260. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2261. std::vector<BT<std::string>>& includes,
  2262. std::unordered_set<std::string>& uniqueIncludes,
  2263. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2264. bool debugIncludes, const std::string& language)
  2265. {
  2266. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2267. cmLinkImplItem const& item = entry->LinkImplItem;
  2268. std::string const& targetName = item.AsStr();
  2269. bool const fromImported = item.Target && item.Target->IsImported();
  2270. bool const checkCMP0027 = item.FromGenex;
  2271. std::vector<std::string> entryIncludes;
  2272. cmSystemTools::ExpandListArgument(
  2273. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2274. dagChecker, language),
  2275. entryIncludes);
  2276. std::string usedIncludes;
  2277. for (std::string& entryInclude : entryIncludes) {
  2278. if (fromImported && !cmSystemTools::FileExists(entryInclude)) {
  2279. std::ostringstream e;
  2280. MessageType messageType = MessageType::FATAL_ERROR;
  2281. if (checkCMP0027) {
  2282. switch (tgt->GetPolicyStatusCMP0027()) {
  2283. case cmPolicies::WARN:
  2284. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2285. CM_FALLTHROUGH;
  2286. case cmPolicies::OLD:
  2287. messageType = MessageType::AUTHOR_WARNING;
  2288. break;
  2289. case cmPolicies::REQUIRED_ALWAYS:
  2290. case cmPolicies::REQUIRED_IF_USED:
  2291. case cmPolicies::NEW:
  2292. break;
  2293. }
  2294. }
  2295. /* clang-format off */
  2296. e << "Imported target \"" << targetName << "\" includes "
  2297. "non-existent path\n \"" << entryInclude << "\"\nin its "
  2298. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2299. "* The path was deleted, renamed, or moved to another "
  2300. "location.\n"
  2301. "* An install or uninstall procedure did not complete "
  2302. "successfully.\n"
  2303. "* The installation package was faulty and references files it "
  2304. "does not provide.\n";
  2305. /* clang-format on */
  2306. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2307. return;
  2308. }
  2309. if (!cmSystemTools::FileIsFullPath(entryInclude)) {
  2310. std::ostringstream e;
  2311. bool noMessage = false;
  2312. MessageType messageType = MessageType::FATAL_ERROR;
  2313. if (!targetName.empty()) {
  2314. /* clang-format off */
  2315. e << "Target \"" << targetName << "\" contains relative "
  2316. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2317. " \"" << entryInclude << "\"";
  2318. /* clang-format on */
  2319. } else {
  2320. switch (tgt->GetPolicyStatusCMP0021()) {
  2321. case cmPolicies::WARN: {
  2322. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2323. messageType = MessageType::AUTHOR_WARNING;
  2324. } break;
  2325. case cmPolicies::OLD:
  2326. noMessage = true;
  2327. case cmPolicies::REQUIRED_IF_USED:
  2328. case cmPolicies::REQUIRED_ALWAYS:
  2329. case cmPolicies::NEW:
  2330. // Issue the fatal message.
  2331. break;
  2332. }
  2333. e << "Found relative path while evaluating include directories of "
  2334. "\""
  2335. << tgt->GetName() << "\":\n \"" << entryInclude << "\"\n";
  2336. }
  2337. if (!noMessage) {
  2338. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2339. if (messageType == MessageType::FATAL_ERROR) {
  2340. return;
  2341. }
  2342. }
  2343. }
  2344. if (!cmSystemTools::IsOff(entryInclude)) {
  2345. cmSystemTools::ConvertToUnixSlashes(entryInclude);
  2346. }
  2347. std::string inc = entryInclude;
  2348. if (uniqueIncludes.insert(inc).second) {
  2349. includes.emplace_back(inc, entry->ge->GetBacktrace());
  2350. if (debugIncludes) {
  2351. usedIncludes += " * " + inc + "\n";
  2352. }
  2353. }
  2354. }
  2355. if (!usedIncludes.empty()) {
  2356. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2357. MessageType::LOG,
  2358. std::string("Used includes for target ") + tgt->GetName() + ":\n" +
  2359. usedIncludes,
  2360. entry->ge->GetBacktrace());
  2361. }
  2362. }
  2363. }
  2364. std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
  2365. const std::string& config, const std::string& lang) const
  2366. {
  2367. std::vector<BT<std::string>> includes;
  2368. std::unordered_set<std::string> uniqueIncludes;
  2369. cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES",
  2370. nullptr, nullptr);
  2371. std::vector<std::string> debugProperties;
  2372. const char* debugProp =
  2373. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2374. if (debugProp) {
  2375. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2376. }
  2377. bool debugIncludes = !this->DebugIncludesDone &&
  2378. std::find(debugProperties.begin(), debugProperties.end(),
  2379. "INCLUDE_DIRECTORIES") != debugProperties.end();
  2380. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2381. this->DebugIncludesDone = true;
  2382. }
  2383. processIncludeDirectories(this, this->IncludeDirectoriesEntries, includes,
  2384. uniqueIncludes, &dagChecker, config, debugIncludes,
  2385. lang);
  2386. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2387. linkInterfaceIncludeDirectoriesEntries;
  2388. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2389. linkInterfaceIncludeDirectoriesEntries);
  2390. if (this->Makefile->IsOn("APPLE")) {
  2391. cmLinkImplementationLibraries const* impl =
  2392. this->GetLinkImplementationLibraries(config);
  2393. for (cmLinkImplItem const& lib : impl->Libraries) {
  2394. std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr());
  2395. static cmsys::RegularExpression frameworkCheck(
  2396. "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2397. if (!frameworkCheck.find(libDir)) {
  2398. continue;
  2399. }
  2400. libDir = frameworkCheck.match(1);
  2401. cmGeneratorExpression ge;
  2402. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2403. ge.Parse(libDir.c_str());
  2404. linkInterfaceIncludeDirectoriesEntries.push_back(
  2405. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2406. }
  2407. }
  2408. processIncludeDirectories(this, linkInterfaceIncludeDirectoriesEntries,
  2409. includes, uniqueIncludes, &dagChecker, config,
  2410. debugIncludes, lang);
  2411. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2412. return includes;
  2413. }
  2414. enum class OptionsParse
  2415. {
  2416. None,
  2417. Shell
  2418. };
  2419. static void processOptionsInternal(
  2420. cmGeneratorTarget const* tgt,
  2421. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2422. std::vector<BT<std::string>>& options,
  2423. std::unordered_set<std::string>& uniqueOptions,
  2424. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2425. bool debugOptions, const char* logName, std::string const& language,
  2426. OptionsParse parse)
  2427. {
  2428. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2429. std::vector<std::string> entryOptions;
  2430. cmSystemTools::ExpandListArgument(
  2431. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2432. dagChecker, language),
  2433. entryOptions);
  2434. std::string usedOptions;
  2435. for (std::string const& opt : entryOptions) {
  2436. if (uniqueOptions.insert(opt).second) {
  2437. if (parse == OptionsParse::Shell &&
  2438. cmHasLiteralPrefix(opt, "SHELL:")) {
  2439. std::vector<std::string> tmp;
  2440. cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
  2441. for (std::string& o : tmp) {
  2442. options.emplace_back(std::move(o), entry->ge->GetBacktrace());
  2443. }
  2444. } else {
  2445. options.emplace_back(opt, entry->ge->GetBacktrace());
  2446. }
  2447. if (debugOptions) {
  2448. usedOptions += " * " + opt + "\n";
  2449. }
  2450. }
  2451. }
  2452. if (!usedOptions.empty()) {
  2453. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2454. MessageType::LOG,
  2455. std::string("Used ") + logName + std::string(" for target ") +
  2456. tgt->GetName() + ":\n" + usedOptions,
  2457. entry->ge->GetBacktrace());
  2458. }
  2459. }
  2460. }
  2461. static void processCompileOptions(
  2462. cmGeneratorTarget const* tgt,
  2463. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2464. std::vector<BT<std::string>>& options,
  2465. std::unordered_set<std::string>& uniqueOptions,
  2466. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2467. bool debugOptions, std::string const& language)
  2468. {
  2469. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2470. config, debugOptions, "compile options", language,
  2471. OptionsParse::Shell);
  2472. }
  2473. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  2474. const std::string& config,
  2475. const std::string& language) const
  2476. {
  2477. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  2478. result.reserve(tmp.size());
  2479. for (BT<std::string>& v : tmp) {
  2480. result.emplace_back(std::move(v.Value));
  2481. }
  2482. }
  2483. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  2484. std::string const& config, std::string const& language) const
  2485. {
  2486. std::vector<BT<std::string>> result;
  2487. std::unordered_set<std::string> uniqueOptions;
  2488. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
  2489. nullptr);
  2490. std::vector<std::string> debugProperties;
  2491. const char* debugProp =
  2492. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2493. if (debugProp) {
  2494. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2495. }
  2496. bool debugOptions = !this->DebugCompileOptionsDone &&
  2497. std::find(debugProperties.begin(), debugProperties.end(),
  2498. "COMPILE_OPTIONS") != debugProperties.end();
  2499. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2500. this->DebugCompileOptionsDone = true;
  2501. }
  2502. processCompileOptions(this, this->CompileOptionsEntries, result,
  2503. uniqueOptions, &dagChecker, config, debugOptions,
  2504. language);
  2505. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2506. linkInterfaceCompileOptionsEntries;
  2507. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS",
  2508. linkInterfaceCompileOptionsEntries);
  2509. processCompileOptions(this, linkInterfaceCompileOptionsEntries, result,
  2510. uniqueOptions, &dagChecker, config, debugOptions,
  2511. language);
  2512. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2513. return result;
  2514. }
  2515. static void processCompileFeatures(
  2516. cmGeneratorTarget const* tgt,
  2517. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2518. std::vector<BT<std::string>>& options,
  2519. std::unordered_set<std::string>& uniqueOptions,
  2520. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2521. bool debugOptions)
  2522. {
  2523. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2524. config, debugOptions, "compile features",
  2525. std::string(), OptionsParse::None);
  2526. }
  2527. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  2528. const std::string& config) const
  2529. {
  2530. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  2531. result.reserve(tmp.size());
  2532. for (BT<std::string>& v : tmp) {
  2533. result.emplace_back(std::move(v.Value));
  2534. }
  2535. }
  2536. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  2537. std::string const& config) const
  2538. {
  2539. std::vector<BT<std::string>> result;
  2540. std::unordered_set<std::string> uniqueFeatures;
  2541. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
  2542. nullptr);
  2543. std::vector<std::string> debugProperties;
  2544. const char* debugProp =
  2545. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2546. if (debugProp) {
  2547. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2548. }
  2549. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  2550. std::find(debugProperties.begin(), debugProperties.end(),
  2551. "COMPILE_FEATURES") != debugProperties.end();
  2552. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2553. this->DebugCompileFeaturesDone = true;
  2554. }
  2555. processCompileFeatures(this, this->CompileFeaturesEntries, result,
  2556. uniqueFeatures, &dagChecker, config, debugFeatures);
  2557. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2558. linkInterfaceCompileFeaturesEntries;
  2559. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  2560. linkInterfaceCompileFeaturesEntries);
  2561. processCompileFeatures(this, linkInterfaceCompileFeaturesEntries, result,
  2562. uniqueFeatures, &dagChecker, config, debugFeatures);
  2563. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2564. return result;
  2565. }
  2566. static void processCompileDefinitions(
  2567. cmGeneratorTarget const* tgt,
  2568. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2569. std::vector<BT<std::string>>& options,
  2570. std::unordered_set<std::string>& uniqueOptions,
  2571. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2572. bool debugOptions, std::string const& language)
  2573. {
  2574. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2575. config, debugOptions, "compile definitions", language,
  2576. OptionsParse::None);
  2577. }
  2578. void cmGeneratorTarget::GetCompileDefinitions(
  2579. std::vector<std::string>& result, const std::string& config,
  2580. const std::string& language) const
  2581. {
  2582. std::vector<BT<std::string>> tmp =
  2583. this->GetCompileDefinitions(config, language);
  2584. result.reserve(tmp.size());
  2585. for (BT<std::string>& v : tmp) {
  2586. result.emplace_back(std::move(v.Value));
  2587. }
  2588. }
  2589. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  2590. std::string const& config, std::string const& language) const
  2591. {
  2592. std::vector<BT<std::string>> list;
  2593. std::unordered_set<std::string> uniqueOptions;
  2594. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS",
  2595. nullptr, nullptr);
  2596. std::vector<std::string> debugProperties;
  2597. const char* debugProp =
  2598. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2599. if (debugProp) {
  2600. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2601. }
  2602. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  2603. std::find(debugProperties.begin(), debugProperties.end(),
  2604. "COMPILE_DEFINITIONS") != debugProperties.end();
  2605. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2606. this->DebugCompileDefinitionsDone = true;
  2607. }
  2608. processCompileDefinitions(this, this->CompileDefinitionsEntries, list,
  2609. uniqueOptions, &dagChecker, config, debugDefines,
  2610. language);
  2611. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2612. linkInterfaceCompileDefinitionsEntries;
  2613. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2614. linkInterfaceCompileDefinitionsEntries);
  2615. if (!config.empty()) {
  2616. std::string configPropName =
  2617. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  2618. const char* configProp = this->GetProperty(configPropName);
  2619. if (configProp) {
  2620. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  2621. case cmPolicies::WARN: {
  2622. std::ostringstream e;
  2623. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2624. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  2625. e.str());
  2626. CM_FALLTHROUGH;
  2627. }
  2628. case cmPolicies::OLD: {
  2629. cmGeneratorExpression ge;
  2630. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  2631. ge.Parse(configProp);
  2632. linkInterfaceCompileDefinitionsEntries.push_back(
  2633. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2634. } break;
  2635. case cmPolicies::NEW:
  2636. case cmPolicies::REQUIRED_ALWAYS:
  2637. case cmPolicies::REQUIRED_IF_USED:
  2638. break;
  2639. }
  2640. }
  2641. }
  2642. processCompileDefinitions(this, linkInterfaceCompileDefinitionsEntries, list,
  2643. uniqueOptions, &dagChecker, config, debugDefines,
  2644. language);
  2645. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2646. return list;
  2647. }
  2648. namespace {
  2649. void processLinkOptions(
  2650. cmGeneratorTarget const* tgt,
  2651. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2652. std::vector<BT<std::string>>& options,
  2653. std::unordered_set<std::string>& uniqueOptions,
  2654. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2655. bool debugOptions, std::string const& language)
  2656. {
  2657. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2658. config, debugOptions, "link options", language,
  2659. OptionsParse::Shell);
  2660. }
  2661. }
  2662. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  2663. const std::string& config,
  2664. const std::string& language) const
  2665. {
  2666. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  2667. result.reserve(tmp.size());
  2668. for (BT<std::string>& v : tmp) {
  2669. result.emplace_back(std::move(v.Value));
  2670. }
  2671. }
  2672. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  2673. std::string const& config, std::string const& language) const
  2674. {
  2675. std::vector<BT<std::string>> result;
  2676. std::unordered_set<std::string> uniqueOptions;
  2677. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
  2678. nullptr);
  2679. std::vector<std::string> debugProperties;
  2680. const char* debugProp =
  2681. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2682. if (debugProp) {
  2683. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2684. }
  2685. bool debugOptions = !this->DebugLinkOptionsDone &&
  2686. std::find(debugProperties.begin(), debugProperties.end(),
  2687. "LINK_OPTIONS") != debugProperties.end();
  2688. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2689. this->DebugLinkOptionsDone = true;
  2690. }
  2691. processLinkOptions(this, this->LinkOptionsEntries, result, uniqueOptions,
  2692. &dagChecker, config, debugOptions, language);
  2693. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2694. linkInterfaceLinkOptionsEntries;
  2695. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS",
  2696. linkInterfaceLinkOptionsEntries);
  2697. processLinkOptions(this, linkInterfaceLinkOptionsEntries, result,
  2698. uniqueOptions, &dagChecker, config, debugOptions,
  2699. language);
  2700. cmDeleteAll(linkInterfaceLinkOptionsEntries);
  2701. // Last step: replace "LINKER:" prefixed elements by
  2702. // actual linker wrapper
  2703. const std::string wrapper(this->Makefile->GetSafeDefinition(
  2704. "CMAKE_" + language + "_LINKER_WRAPPER_FLAG"));
  2705. std::vector<std::string> wrapperFlag;
  2706. cmSystemTools::ExpandListArgument(wrapper, wrapperFlag);
  2707. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  2708. "CMAKE_" + language + "_LINKER_WRAPPER_FLAG_SEP"));
  2709. bool concatFlagAndArgs = true;
  2710. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  2711. concatFlagAndArgs = false;
  2712. wrapperFlag.pop_back();
  2713. }
  2714. const std::string LINKER{ "LINKER:" };
  2715. const std::string SHELL{ "SHELL:" };
  2716. const std::string LINKER_SHELL = LINKER + SHELL;
  2717. std::vector<BT<std::string>>::iterator entry;
  2718. while ((entry = std::find_if(result.begin(), result.end(),
  2719. [&LINKER](BT<std::string> const& item) -> bool {
  2720. return item.Value.compare(0, LINKER.length(),
  2721. LINKER) == 0;
  2722. })) != result.end()) {
  2723. std::string value = std::move(entry->Value);
  2724. cmListFileBacktrace bt = std::move(entry->Backtrace);
  2725. entry = result.erase(entry);
  2726. std::vector<std::string> linkerOptions;
  2727. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  2728. cmSystemTools::ParseUnixCommandLine(
  2729. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  2730. } else {
  2731. linkerOptions =
  2732. cmSystemTools::tokenize(value.substr(LINKER.length()), ",");
  2733. }
  2734. if (linkerOptions.empty() ||
  2735. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  2736. continue;
  2737. }
  2738. // for now, raise an error if prefix SHELL: is part of arguments
  2739. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  2740. [&SHELL](const std::string& item) -> bool {
  2741. return item.find(SHELL) != std::string::npos;
  2742. }) != linkerOptions.end()) {
  2743. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  2744. MessageType::FATAL_ERROR,
  2745. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  2746. this->GetBacktrace());
  2747. return result;
  2748. }
  2749. std::vector<BT<std::string>> options;
  2750. if (wrapperFlag.empty()) {
  2751. // nothing specified, insert elements as is
  2752. options.reserve(linkerOptions.size());
  2753. for (std::string& o : linkerOptions) {
  2754. options.emplace_back(std::move(o), bt);
  2755. }
  2756. } else {
  2757. if (!wrapperSep.empty()) {
  2758. if (concatFlagAndArgs) {
  2759. // insert flag elements except last one
  2760. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  2761. options.emplace_back(*i, bt);
  2762. }
  2763. // concatenate last flag element and all LINKER list values
  2764. // in one option
  2765. options.emplace_back(
  2766. wrapperFlag.back() + cmJoin(linkerOptions, wrapperSep), bt);
  2767. } else {
  2768. for (std::string const& i : wrapperFlag) {
  2769. options.emplace_back(i, bt);
  2770. }
  2771. // concatenate all LINKER list values in one option
  2772. options.emplace_back(cmJoin(linkerOptions, wrapperSep), bt);
  2773. }
  2774. } else {
  2775. // prefix each element of LINKER list with wrapper
  2776. if (concatFlagAndArgs) {
  2777. std::transform(linkerOptions.begin(), linkerOptions.end(),
  2778. linkerOptions.begin(),
  2779. [&wrapperFlag](std::string const& o) -> std::string {
  2780. return wrapperFlag.back() + o;
  2781. });
  2782. }
  2783. for (std::string& o : linkerOptions) {
  2784. for (auto i = wrapperFlag.begin(),
  2785. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  2786. : wrapperFlag.end();
  2787. i != e; ++i) {
  2788. options.emplace_back(*i, bt);
  2789. }
  2790. options.emplace_back(std::move(o), bt);
  2791. }
  2792. }
  2793. }
  2794. result.insert(entry, options.begin(), options.end());
  2795. }
  2796. return result;
  2797. }
  2798. namespace {
  2799. void processStaticLibraryLinkOptions(
  2800. cmGeneratorTarget const* tgt,
  2801. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2802. std::vector<BT<std::string>>& options,
  2803. std::unordered_set<std::string>& uniqueOptions,
  2804. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2805. std::string const& language)
  2806. {
  2807. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2808. config, false, "static library link options",
  2809. language, OptionsParse::Shell);
  2810. }
  2811. }
  2812. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  2813. std::vector<std::string>& result, const std::string& config,
  2814. const std::string& language) const
  2815. {
  2816. std::vector<BT<std::string>> tmp =
  2817. this->GetStaticLibraryLinkOptions(config, language);
  2818. result.reserve(tmp.size());
  2819. for (BT<std::string>& v : tmp) {
  2820. result.emplace_back(std::move(v.Value));
  2821. }
  2822. }
  2823. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  2824. std::string const& config, std::string const& language) const
  2825. {
  2826. std::vector<BT<std::string>> result;
  2827. std::vector<cmGeneratorTarget::TargetPropertyEntry*> entries;
  2828. std::unordered_set<std::string> uniqueOptions;
  2829. cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
  2830. nullptr, nullptr);
  2831. if (const char* linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  2832. std::vector<std::string> options;
  2833. cmGeneratorExpression ge;
  2834. cmSystemTools::ExpandListArgument(linkOptions, options);
  2835. for (const auto& option : options) {
  2836. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(option);
  2837. entries.push_back(
  2838. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  2839. }
  2840. }
  2841. processStaticLibraryLinkOptions(this, entries, result, uniqueOptions,
  2842. &dagChecker, config, language);
  2843. cmDeleteAll(entries);
  2844. return result;
  2845. }
  2846. namespace {
  2847. void processLinkDirectories(
  2848. cmGeneratorTarget const* tgt,
  2849. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2850. std::vector<BT<std::string>>& directories,
  2851. std::unordered_set<std::string>& uniqueDirectories,
  2852. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2853. bool debugDirectories, std::string const& language)
  2854. {
  2855. for (cmGeneratorTarget::TargetPropertyEntry* entry : entries) {
  2856. cmLinkImplItem const& item = entry->LinkImplItem;
  2857. std::string const& targetName = item.AsStr();
  2858. std::vector<std::string> entryDirectories;
  2859. cmSystemTools::ExpandListArgument(
  2860. entry->ge->Evaluate(tgt->GetLocalGenerator(), config, false, tgt,
  2861. dagChecker, language),
  2862. entryDirectories);
  2863. std::string usedDirectories;
  2864. for (std::string& entryDirectory : entryDirectories) {
  2865. if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
  2866. std::ostringstream e;
  2867. bool noMessage = false;
  2868. MessageType messageType = MessageType::FATAL_ERROR;
  2869. if (!targetName.empty()) {
  2870. /* clang-format off */
  2871. e << "Target \"" << targetName << "\" contains relative "
  2872. "path in its INTERFACE_LINK_DIRECTORIES:\n"
  2873. " \"" << entryDirectory << "\"";
  2874. /* clang-format on */
  2875. } else {
  2876. switch (tgt->GetPolicyStatusCMP0081()) {
  2877. case cmPolicies::WARN: {
  2878. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
  2879. messageType = MessageType::AUTHOR_WARNING;
  2880. } break;
  2881. case cmPolicies::OLD:
  2882. noMessage = true;
  2883. break;
  2884. case cmPolicies::REQUIRED_IF_USED:
  2885. case cmPolicies::REQUIRED_ALWAYS:
  2886. case cmPolicies::NEW:
  2887. // Issue the fatal message.
  2888. break;
  2889. }
  2890. e << "Found relative path while evaluating link directories of "
  2891. "\""
  2892. << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
  2893. }
  2894. if (!noMessage) {
  2895. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2896. if (messageType == MessageType::FATAL_ERROR) {
  2897. return;
  2898. }
  2899. }
  2900. }
  2901. // Sanitize the path the same way the link_directories command does
  2902. // in case projects set the LINK_DIRECTORIES property directly.
  2903. cmSystemTools::ConvertToUnixSlashes(entryDirectory);
  2904. if (uniqueDirectories.insert(entryDirectory).second) {
  2905. directories.emplace_back(entryDirectory);
  2906. if (debugDirectories) {
  2907. usedDirectories += " * " + entryDirectory + "\n";
  2908. }
  2909. }
  2910. }
  2911. if (!usedDirectories.empty()) {
  2912. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  2913. MessageType::LOG,
  2914. std::string("Used link directories for target ") + tgt->GetName() +
  2915. ":\n" + usedDirectories,
  2916. entry->ge->GetBacktrace());
  2917. }
  2918. }
  2919. }
  2920. }
  2921. void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
  2922. const std::string& config,
  2923. const std::string& language) const
  2924. {
  2925. std::vector<BT<std::string>> tmp =
  2926. this->GetLinkDirectories(config, language);
  2927. result.reserve(tmp.size());
  2928. for (BT<std::string>& v : tmp) {
  2929. result.emplace_back(std::move(v.Value));
  2930. }
  2931. }
  2932. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
  2933. std::string const& config, std::string const& language) const
  2934. {
  2935. std::vector<BT<std::string>> result;
  2936. std::unordered_set<std::string> uniqueDirectories;
  2937. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
  2938. nullptr);
  2939. std::vector<std::string> debugProperties;
  2940. const char* debugProp =
  2941. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2942. if (debugProp) {
  2943. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2944. }
  2945. bool debugDirectories = !this->DebugLinkDirectoriesDone &&
  2946. std::find(debugProperties.begin(), debugProperties.end(),
  2947. "LINK_DIRECTORIES") != debugProperties.end();
  2948. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  2949. this->DebugLinkDirectoriesDone = true;
  2950. }
  2951. processLinkDirectories(this, this->LinkDirectoriesEntries, result,
  2952. uniqueDirectories, &dagChecker, config,
  2953. debugDirectories, language);
  2954. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2955. linkInterfaceLinkDirectoriesEntries;
  2956. AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES",
  2957. linkInterfaceLinkDirectoriesEntries);
  2958. processLinkDirectories(this, linkInterfaceLinkDirectoriesEntries, result,
  2959. uniqueDirectories, &dagChecker, config,
  2960. debugDirectories, language);
  2961. cmDeleteAll(linkInterfaceLinkDirectoriesEntries);
  2962. return result;
  2963. }
  2964. namespace {
  2965. void processLinkDepends(
  2966. cmGeneratorTarget const* tgt,
  2967. const std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries,
  2968. std::vector<BT<std::string>>& options,
  2969. std::unordered_set<std::string>& uniqueOptions,
  2970. cmGeneratorExpressionDAGChecker* dagChecker, const std::string& config,
  2971. std::string const& language)
  2972. {
  2973. processOptionsInternal(tgt, entries, options, uniqueOptions, dagChecker,
  2974. config, false, "link depends", language,
  2975. OptionsParse::None);
  2976. }
  2977. }
  2978. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  2979. const std::string& config,
  2980. const std::string& language) const
  2981. {
  2982. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  2983. result.reserve(tmp.size());
  2984. for (BT<std::string>& v : tmp) {
  2985. result.emplace_back(std::move(v.Value));
  2986. }
  2987. }
  2988. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  2989. std::string const& config, std::string const& language) const
  2990. {
  2991. std::vector<BT<std::string>> result;
  2992. std::vector<cmGeneratorTarget::TargetPropertyEntry*> linkDependsEntries;
  2993. std::unordered_set<std::string> uniqueOptions;
  2994. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
  2995. nullptr);
  2996. if (const char* linkDepends = this->GetProperty("LINK_DEPENDS")) {
  2997. std::vector<std::string> depends;
  2998. cmGeneratorExpression ge;
  2999. cmSystemTools::ExpandListArgument(linkDepends, depends);
  3000. for (const auto& depend : depends) {
  3001. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(depend);
  3002. linkDependsEntries.push_back(
  3003. new cmGeneratorTarget::TargetPropertyEntry(std::move(cge)));
  3004. }
  3005. }
  3006. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS",
  3007. linkDependsEntries);
  3008. processLinkDepends(this, linkDependsEntries, result, uniqueOptions,
  3009. &dagChecker, config, language);
  3010. cmDeleteAll(linkDependsEntries);
  3011. return result;
  3012. }
  3013. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  3014. {
  3015. if (this->IsImported()) {
  3016. return;
  3017. }
  3018. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  3019. // Get the names.
  3020. std::string name;
  3021. std::string soName;
  3022. std::string realName;
  3023. std::string impName;
  3024. std::string pdbName;
  3025. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  3026. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3027. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  3028. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3029. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3030. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3031. } else {
  3032. return;
  3033. }
  3034. // Get the directory.
  3035. std::string dir =
  3036. this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact);
  3037. // Add each name.
  3038. std::string f;
  3039. if (!name.empty()) {
  3040. f = dir;
  3041. f += "/";
  3042. f += name;
  3043. gg->AddToManifest(f);
  3044. }
  3045. if (!soName.empty()) {
  3046. f = dir;
  3047. f += "/";
  3048. f += soName;
  3049. gg->AddToManifest(f);
  3050. }
  3051. if (!realName.empty()) {
  3052. f = dir;
  3053. f += "/";
  3054. f += realName;
  3055. gg->AddToManifest(f);
  3056. }
  3057. if (!pdbName.empty()) {
  3058. f = dir;
  3059. f += "/";
  3060. f += pdbName;
  3061. gg->AddToManifest(f);
  3062. }
  3063. if (!impName.empty()) {
  3064. f = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
  3065. f += "/";
  3066. f += impName;
  3067. gg->AddToManifest(f);
  3068. }
  3069. }
  3070. bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config) const
  3071. {
  3072. std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
  3073. for (BT<std::string> const& f : features) {
  3074. if (!this->Makefile->AddRequiredTargetFeature(this->Target, f.Value)) {
  3075. return false;
  3076. }
  3077. }
  3078. return true;
  3079. }
  3080. std::string cmGeneratorTarget::GetImportedLibName(
  3081. std::string const& config) const
  3082. {
  3083. if (cmGeneratorTarget::ImportInfo const* info =
  3084. this->GetImportInfo(config)) {
  3085. return info->LibName;
  3086. }
  3087. return std::string();
  3088. }
  3089. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  3090. cmStateEnums::ArtifactType artifact,
  3091. bool realname) const
  3092. {
  3093. if (this->IsImported()) {
  3094. return this->Target->ImportedGetFullPath(config, artifact);
  3095. }
  3096. return this->NormalGetFullPath(config, artifact, realname);
  3097. }
  3098. std::string cmGeneratorTarget::NormalGetFullPath(
  3099. const std::string& config, cmStateEnums::ArtifactType artifact,
  3100. bool realname) const
  3101. {
  3102. std::string fpath = this->GetDirectory(config, artifact);
  3103. fpath += "/";
  3104. if (this->IsAppBundleOnApple()) {
  3105. fpath = this->BuildBundleDirectory(fpath, config, FullLevel);
  3106. fpath += "/";
  3107. }
  3108. // Add the full name of the target.
  3109. switch (artifact) {
  3110. case cmStateEnums::RuntimeBinaryArtifact:
  3111. if (realname) {
  3112. fpath += this->NormalGetRealName(config);
  3113. } else {
  3114. fpath +=
  3115. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  3116. }
  3117. break;
  3118. case cmStateEnums::ImportLibraryArtifact:
  3119. fpath += this->GetFullName(config, cmStateEnums::ImportLibraryArtifact);
  3120. break;
  3121. }
  3122. return fpath;
  3123. }
  3124. std::string cmGeneratorTarget::NormalGetRealName(
  3125. const std::string& config) const
  3126. {
  3127. // This should not be called for imported targets.
  3128. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3129. // enforcement of the limited imported target API.
  3130. if (this->IsImported()) {
  3131. std::string msg = "NormalGetRealName called on imported target: ";
  3132. msg += this->GetName();
  3133. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3134. }
  3135. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  3136. // Compute the real name that will be built.
  3137. std::string name;
  3138. std::string realName;
  3139. std::string impName;
  3140. std::string pdbName;
  3141. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3142. return realName;
  3143. }
  3144. // Compute the real name that will be built.
  3145. std::string name;
  3146. std::string soName;
  3147. std::string realName;
  3148. std::string impName;
  3149. std::string pdbName;
  3150. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3151. return realName;
  3152. }
  3153. void cmGeneratorTarget::GetLibraryNames(std::string& name, std::string& soName,
  3154. std::string& realName,
  3155. std::string& impName,
  3156. std::string& pdbName,
  3157. const std::string& config) const
  3158. {
  3159. // This should not be called for imported targets.
  3160. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3161. // enforcement of the limited imported target API.
  3162. if (this->IsImported()) {
  3163. std::string msg = "GetLibraryNames called on imported target: ";
  3164. msg += this->GetName();
  3165. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3166. return;
  3167. }
  3168. // Check for library version properties.
  3169. const char* version = this->GetProperty("VERSION");
  3170. const char* soversion = this->GetProperty("SOVERSION");
  3171. if (!this->HasSOName(config) ||
  3172. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  3173. this->IsFrameworkOnApple()) {
  3174. // Versioning is supported only for shared libraries and modules,
  3175. // and then only when the platform supports an soname flag.
  3176. version = nullptr;
  3177. soversion = nullptr;
  3178. }
  3179. if (version && !soversion) {
  3180. // The soversion must be set if the library version is set. Use
  3181. // the library version as the soversion.
  3182. soversion = version;
  3183. }
  3184. if (!version && soversion) {
  3185. // Use the soversion as the library version.
  3186. version = soversion;
  3187. }
  3188. // Get the components of the library name.
  3189. std::string prefix;
  3190. std::string base;
  3191. std::string suffix;
  3192. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3193. prefix, base, suffix);
  3194. // The library name.
  3195. name = prefix + base + suffix;
  3196. if (this->IsFrameworkOnApple()) {
  3197. realName = prefix;
  3198. if (!this->Makefile->PlatformIsAppleEmbedded()) {
  3199. realName += "Versions/";
  3200. realName += this->GetFrameworkVersion();
  3201. realName += "/";
  3202. }
  3203. realName += base;
  3204. soName = realName;
  3205. } else {
  3206. // The library's soname.
  3207. this->ComputeVersionedName(soName, prefix, base, suffix, name, soversion);
  3208. // The library's real name on disk.
  3209. this->ComputeVersionedName(realName, prefix, base, suffix, name, version);
  3210. }
  3211. // The import library name.
  3212. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  3213. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  3214. impName =
  3215. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  3216. } else {
  3217. impName.clear();
  3218. }
  3219. // The program database file name.
  3220. pdbName = this->GetPDBName(config);
  3221. }
  3222. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  3223. std::string& realName,
  3224. std::string& impName,
  3225. std::string& pdbName,
  3226. const std::string& config) const
  3227. {
  3228. // This should not be called for imported targets.
  3229. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3230. // enforcement of the limited imported target API.
  3231. if (this->IsImported()) {
  3232. std::string msg = "GetExecutableNames called on imported target: ";
  3233. msg += this->GetName();
  3234. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  3235. }
  3236. // This versioning is supported only for executables and then only
  3237. // when the platform supports symbolic links.
  3238. #if defined(_WIN32) && !defined(__CYGWIN__)
  3239. const char* version = 0;
  3240. #else
  3241. // Check for executable version properties.
  3242. const char* version = this->GetProperty("VERSION");
  3243. if (this->GetType() != cmStateEnums::EXECUTABLE ||
  3244. this->Makefile->IsOn("XCODE")) {
  3245. version = nullptr;
  3246. }
  3247. #endif
  3248. // Get the components of the executable name.
  3249. std::string prefix;
  3250. std::string base;
  3251. std::string suffix;
  3252. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3253. prefix, base, suffix);
  3254. // The executable name.
  3255. name = prefix + base + suffix;
  3256. // The executable's real name on disk.
  3257. #if defined(__CYGWIN__)
  3258. realName = prefix + base;
  3259. #else
  3260. realName = name;
  3261. #endif
  3262. if (version) {
  3263. realName += "-";
  3264. realName += version;
  3265. }
  3266. #if defined(__CYGWIN__)
  3267. realName += suffix;
  3268. #endif
  3269. // The import library name.
  3270. impName =
  3271. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  3272. // The program database file name.
  3273. pdbName = this->GetPDBName(config);
  3274. }
  3275. std::string cmGeneratorTarget::GetFullNameInternal(
  3276. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3277. {
  3278. std::string prefix;
  3279. std::string base;
  3280. std::string suffix;
  3281. this->GetFullNameInternal(config, artifact, prefix, base, suffix);
  3282. return prefix + base + suffix;
  3283. }
  3284. std::string cmGeneratorTarget::ImportedGetLocation(
  3285. const std::string& config) const
  3286. {
  3287. assert(this->IsImported());
  3288. return this->Target->ImportedGetFullPath(
  3289. config, cmStateEnums::RuntimeBinaryArtifact);
  3290. }
  3291. std::string cmGeneratorTarget::GetFullNameImported(
  3292. const std::string& config, cmStateEnums::ArtifactType artifact) const
  3293. {
  3294. return cmSystemTools::GetFilenameName(
  3295. this->Target->ImportedGetFullPath(config, artifact));
  3296. }
  3297. void cmGeneratorTarget::GetFullNameInternal(
  3298. const std::string& config, cmStateEnums::ArtifactType artifact,
  3299. std::string& outPrefix, std::string& outBase, std::string& outSuffix) const
  3300. {
  3301. // Use just the target name for non-main target types.
  3302. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  3303. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  3304. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  3305. this->GetType() != cmStateEnums::EXECUTABLE) {
  3306. outPrefix.clear();
  3307. outBase = this->GetName();
  3308. outSuffix.clear();
  3309. return;
  3310. }
  3311. const bool isImportedLibraryArtifact =
  3312. (artifact == cmStateEnums::ImportLibraryArtifact);
  3313. // Return an empty name for the import library if this platform
  3314. // does not support import libraries.
  3315. if (isImportedLibraryArtifact &&
  3316. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX")) {
  3317. outPrefix.clear();
  3318. outBase.clear();
  3319. outSuffix.clear();
  3320. return;
  3321. }
  3322. // The implib option is only allowed for shared libraries, module
  3323. // libraries, and executables.
  3324. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  3325. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  3326. this->GetType() != cmStateEnums::EXECUTABLE) {
  3327. artifact = cmStateEnums::RuntimeBinaryArtifact;
  3328. }
  3329. // Compute the full name for main target types.
  3330. const char* targetPrefix =
  3331. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  3332. : this->GetProperty("PREFIX"));
  3333. const char* targetSuffix =
  3334. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  3335. : this->GetProperty("SUFFIX"));
  3336. const char* configPostfix = nullptr;
  3337. if (!config.empty()) {
  3338. std::string configProp = cmSystemTools::UpperCase(config);
  3339. configProp += "_POSTFIX";
  3340. configPostfix = this->GetProperty(configProp);
  3341. // Mac application bundles and frameworks have no postfix.
  3342. if (configPostfix &&
  3343. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  3344. configPostfix = nullptr;
  3345. }
  3346. }
  3347. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  3348. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  3349. // Check for language-specific default prefix and suffix.
  3350. std::string ll = this->GetLinkerLanguage(config);
  3351. if (!ll.empty()) {
  3352. if (!targetSuffix && suffixVar && *suffixVar) {
  3353. std::string langSuff = suffixVar + std::string("_") + ll;
  3354. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3355. }
  3356. if (!targetPrefix && prefixVar && *prefixVar) {
  3357. std::string langPrefix = prefixVar + std::string("_") + ll;
  3358. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3359. }
  3360. }
  3361. // if there is no prefix on the target use the cmake definition
  3362. if (!targetPrefix && prefixVar) {
  3363. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar).c_str();
  3364. }
  3365. // if there is no suffix on the target use the cmake definition
  3366. if (!targetSuffix && suffixVar) {
  3367. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar).c_str();
  3368. }
  3369. // frameworks have directory prefix but no suffix
  3370. std::string fw_prefix;
  3371. if (this->IsFrameworkOnApple()) {
  3372. fw_prefix = this->GetFrameworkDirectory(config, ContentLevel);
  3373. fw_prefix += "/";
  3374. targetPrefix = fw_prefix.c_str();
  3375. targetSuffix = nullptr;
  3376. }
  3377. if (this->IsCFBundleOnApple()) {
  3378. fw_prefix = this->GetCFBundleDirectory(config, FullLevel);
  3379. fw_prefix += "/";
  3380. targetPrefix = fw_prefix.c_str();
  3381. targetSuffix = nullptr;
  3382. }
  3383. // Begin the final name with the prefix.
  3384. outPrefix = targetPrefix ? targetPrefix : "";
  3385. // Append the target name or property-specified name.
  3386. outBase += this->GetOutputName(config, artifact);
  3387. // Append the per-configuration postfix.
  3388. outBase += configPostfix ? configPostfix : "";
  3389. // Name shared libraries with their version number on some platforms.
  3390. if (const char* soversion = this->GetProperty("SOVERSION")) {
  3391. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  3392. !isImportedLibraryArtifact &&
  3393. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")) {
  3394. outBase += "-";
  3395. outBase += soversion;
  3396. }
  3397. }
  3398. // Append the suffix.
  3399. outSuffix = targetSuffix ? targetSuffix : "";
  3400. }
  3401. std::string cmGeneratorTarget::GetLinkerLanguage(
  3402. const std::string& config) const
  3403. {
  3404. return this->GetLinkClosure(config)->LinkerLanguage;
  3405. }
  3406. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  3407. {
  3408. std::string prefix;
  3409. std::string base;
  3410. std::string suffix;
  3411. this->GetFullNameInternal(config, cmStateEnums::RuntimeBinaryArtifact,
  3412. prefix, base, suffix);
  3413. std::vector<std::string> props;
  3414. std::string configUpper = cmSystemTools::UpperCase(config);
  3415. if (!configUpper.empty()) {
  3416. // PDB_NAME_<CONFIG>
  3417. props.push_back("PDB_NAME_" + configUpper);
  3418. }
  3419. // PDB_NAME
  3420. props.emplace_back("PDB_NAME");
  3421. for (std::string const& p : props) {
  3422. if (const char* outName = this->GetProperty(p)) {
  3423. base = outName;
  3424. break;
  3425. }
  3426. }
  3427. return prefix + base + ".pdb";
  3428. }
  3429. std::string cmGeneratorTarget::GetObjectDirectory(
  3430. std::string const& config) const
  3431. {
  3432. std::string obj_dir =
  3433. this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config);
  3434. #if defined(__APPLE__)
  3435. // find and replace $(PROJECT_NAME) xcode placeholder
  3436. const std::string projectName = this->LocalGenerator->GetProjectName();
  3437. cmSystemTools::ReplaceString(obj_dir, "$(PROJECT_NAME)", projectName);
  3438. // Replace Xcode's placeholder for the object file directory since
  3439. // installation and export scripts need to know the real directory.
  3440. // Xcode has build-time settings (e.g. for sanitizers) that affect this,
  3441. // but we use the default here. Users that want to enable sanitizers
  3442. // will do so at the cost of object library installation and export.
  3443. cmSystemTools::ReplaceString(obj_dir, "$(OBJECT_FILE_DIR_normal:base)",
  3444. "Objects-normal");
  3445. #endif
  3446. return obj_dir;
  3447. }
  3448. void cmGeneratorTarget::GetTargetObjectNames(
  3449. std::string const& config, std::vector<std::string>& objects) const
  3450. {
  3451. std::vector<cmSourceFile const*> objectSources;
  3452. this->GetObjectSources(objectSources, config);
  3453. std::map<cmSourceFile const*, std::string> mapping;
  3454. for (cmSourceFile const* sf : objectSources) {
  3455. mapping[sf];
  3456. }
  3457. this->LocalGenerator->ComputeObjectFilenames(mapping, this);
  3458. for (cmSourceFile const* src : objectSources) {
  3459. // Find the object file name corresponding to this source file.
  3460. std::map<cmSourceFile const*, std::string>::const_iterator map_it =
  3461. mapping.find(src);
  3462. // It must exist because we populated the mapping just above.
  3463. assert(!map_it->second.empty());
  3464. objects.push_back(map_it->second);
  3465. }
  3466. }
  3467. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  3468. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  3469. {
  3470. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  3471. if (nameResult == 0) {
  3472. return strcmp(
  3473. t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(),
  3474. t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0;
  3475. }
  3476. return nameResult < 0;
  3477. }
  3478. struct cmGeneratorTarget::SourceFileFlags
  3479. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  3480. {
  3481. struct SourceFileFlags flags;
  3482. this->ConstructSourceFileFlags();
  3483. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  3484. this->SourceFlagsMap.find(sf);
  3485. if (si != this->SourceFlagsMap.end()) {
  3486. flags = si->second;
  3487. } else {
  3488. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  3489. // were not listed in one of the other lists.
  3490. if (const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  3491. flags.MacFolder = location;
  3492. const bool stripResources =
  3493. this->GlobalGenerator->ShouldStripResourcePath(this->Makefile);
  3494. if (strcmp(location, "Resources") == 0) {
  3495. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3496. if (stripResources) {
  3497. flags.MacFolder = "";
  3498. }
  3499. } else if (cmSystemTools::StringStartsWith(location, "Resources/")) {
  3500. flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource;
  3501. if (stripResources) {
  3502. flags.MacFolder += strlen("Resources/");
  3503. }
  3504. } else {
  3505. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  3506. }
  3507. }
  3508. }
  3509. return flags;
  3510. }
  3511. void cmGeneratorTarget::ConstructSourceFileFlags() const
  3512. {
  3513. if (this->SourceFileFlagsConstructed) {
  3514. return;
  3515. }
  3516. this->SourceFileFlagsConstructed = true;
  3517. // Process public headers to mark the source files.
  3518. if (const char* files = this->GetProperty("PUBLIC_HEADER")) {
  3519. std::vector<std::string> relFiles;
  3520. cmSystemTools::ExpandListArgument(files, relFiles);
  3521. for (std::string const& relFile : relFiles) {
  3522. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3523. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3524. flags.MacFolder = "Headers";
  3525. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  3526. }
  3527. }
  3528. }
  3529. // Process private headers after public headers so that they take
  3530. // precedence if a file is listed in both.
  3531. if (const char* files = this->GetProperty("PRIVATE_HEADER")) {
  3532. std::vector<std::string> relFiles;
  3533. cmSystemTools::ExpandListArgument(files, relFiles);
  3534. for (std::string const& relFile : relFiles) {
  3535. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3536. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3537. flags.MacFolder = "PrivateHeaders";
  3538. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  3539. }
  3540. }
  3541. }
  3542. // Mark sources listed as resources.
  3543. if (const char* files = this->GetProperty("RESOURCE")) {
  3544. std::vector<std::string> relFiles;
  3545. cmSystemTools::ExpandListArgument(files, relFiles);
  3546. for (std::string const& relFile : relFiles) {
  3547. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  3548. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3549. flags.MacFolder = "";
  3550. if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
  3551. flags.MacFolder = "Resources";
  3552. }
  3553. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3554. }
  3555. }
  3556. }
  3557. }
  3558. const cmGeneratorTarget::CompatibleInterfacesBase&
  3559. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  3560. {
  3561. cmGeneratorTarget::CompatibleInterfaces& compat =
  3562. this->CompatibleInterfacesMap[config];
  3563. if (!compat.Done) {
  3564. compat.Done = true;
  3565. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  3566. compat.PropsString.insert("AUTOUIC_OPTIONS");
  3567. std::vector<cmGeneratorTarget const*> const& deps =
  3568. this->GetLinkImplementationClosure(config);
  3569. for (cmGeneratorTarget const* li : deps) {
  3570. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  3571. if (const char* prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  3572. std::vector<std::string> props; \
  3573. cmSystemTools::ExpandListArgument(prop, props); \
  3574. compat.Props##x.insert(props.begin(), props.end()); \
  3575. }
  3576. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  3577. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  3578. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  3579. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  3580. #undef CM_READ_COMPATIBLE_INTERFACE
  3581. }
  3582. }
  3583. return compat;
  3584. }
  3585. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  3586. const std::string& p, const std::string& config) const
  3587. {
  3588. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3589. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3590. return false;
  3591. }
  3592. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  3593. }
  3594. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  3595. const std::string& p, const std::string& config) const
  3596. {
  3597. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3598. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3599. return false;
  3600. }
  3601. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  3602. }
  3603. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  3604. const std::string& p, const std::string& config) const
  3605. {
  3606. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3607. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3608. return false;
  3609. }
  3610. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  3611. }
  3612. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  3613. const std::string& p, const std::string& config) const
  3614. {
  3615. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  3616. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  3617. return false;
  3618. }
  3619. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  3620. }
  3621. enum CompatibleType
  3622. {
  3623. BoolType,
  3624. StringType,
  3625. NumberMinType,
  3626. NumberMaxType
  3627. };
  3628. template <typename PropertyType>
  3629. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3630. const std::string& prop,
  3631. const std::string& config,
  3632. CompatibleType, PropertyType*);
  3633. template <>
  3634. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3635. const std::string& prop,
  3636. const std::string& config,
  3637. CompatibleType /*unused*/,
  3638. bool* /*unused*/)
  3639. {
  3640. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  3641. }
  3642. template <>
  3643. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3644. const std::string& prop,
  3645. const std::string& config,
  3646. CompatibleType t,
  3647. const char** /*unused*/)
  3648. {
  3649. switch (t) {
  3650. case BoolType:
  3651. assert(false &&
  3652. "String compatibility check function called for boolean");
  3653. return nullptr;
  3654. case StringType:
  3655. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  3656. case NumberMinType:
  3657. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  3658. case NumberMaxType:
  3659. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  3660. }
  3661. assert(false && "Unreachable!");
  3662. return nullptr;
  3663. }
  3664. template <typename PropertyType>
  3665. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3666. cmGeneratorTarget const* dependee,
  3667. const std::string& propName,
  3668. std::set<std::string>& emitted,
  3669. const std::string& config, CompatibleType t,
  3670. PropertyType* /*unused*/)
  3671. {
  3672. const char* prop = dependee->GetProperty(propName);
  3673. if (!prop) {
  3674. return;
  3675. }
  3676. std::vector<std::string> props;
  3677. cmSystemTools::ExpandListArgument(prop, props);
  3678. std::string pdir = cmSystemTools::GetCMakeRoot();
  3679. pdir += "/Help/prop_tgt/";
  3680. for (std::string const& p : props) {
  3681. std::string pname = cmSystemTools::HelpFileName(p);
  3682. std::string pfile = pdir + pname + ".rst";
  3683. if (cmSystemTools::FileExists(pfile, true)) {
  3684. std::ostringstream e;
  3685. e << "Target \"" << dependee->GetName() << "\" has property \"" << p
  3686. << "\" listed in its " << propName
  3687. << " property. "
  3688. "This is not allowed. Only user-defined properties may appear "
  3689. "listed in the "
  3690. << propName << " property.";
  3691. depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  3692. e.str());
  3693. return;
  3694. }
  3695. if (emitted.insert(p).second) {
  3696. getLinkInterfaceDependentProperty<PropertyType>(depender, p, config, t,
  3697. nullptr);
  3698. if (cmSystemTools::GetErrorOccuredFlag()) {
  3699. return;
  3700. }
  3701. }
  3702. }
  3703. }
  3704. static std::string intersect(const std::set<std::string>& s1,
  3705. const std::set<std::string>& s2)
  3706. {
  3707. std::set<std::string> intersect;
  3708. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  3709. std::inserter(intersect, intersect.begin()));
  3710. if (!intersect.empty()) {
  3711. return *intersect.begin();
  3712. }
  3713. return "";
  3714. }
  3715. static std::string intersect(const std::set<std::string>& s1,
  3716. const std::set<std::string>& s2,
  3717. const std::set<std::string>& s3)
  3718. {
  3719. std::string result;
  3720. result = intersect(s1, s2);
  3721. if (!result.empty()) {
  3722. return result;
  3723. }
  3724. result = intersect(s1, s3);
  3725. if (!result.empty()) {
  3726. return result;
  3727. }
  3728. return intersect(s2, s3);
  3729. }
  3730. static std::string intersect(const std::set<std::string>& s1,
  3731. const std::set<std::string>& s2,
  3732. const std::set<std::string>& s3,
  3733. const std::set<std::string>& s4)
  3734. {
  3735. std::string result;
  3736. result = intersect(s1, s2);
  3737. if (!result.empty()) {
  3738. return result;
  3739. }
  3740. result = intersect(s1, s3);
  3741. if (!result.empty()) {
  3742. return result;
  3743. }
  3744. result = intersect(s1, s4);
  3745. if (!result.empty()) {
  3746. return result;
  3747. }
  3748. return intersect(s2, s3, s4);
  3749. }
  3750. void cmGeneratorTarget::CheckPropertyCompatibility(
  3751. cmComputeLinkInformation* info, const std::string& config) const
  3752. {
  3753. const cmComputeLinkInformation::ItemVector& deps = info->GetItems();
  3754. std::set<std::string> emittedBools;
  3755. static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3756. std::set<std::string> emittedStrings;
  3757. static const std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3758. std::set<std::string> emittedMinNumbers;
  3759. static const std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3760. std::set<std::string> emittedMaxNumbers;
  3761. static const std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3762. for (auto const& dep : deps) {
  3763. if (!dep.Target) {
  3764. continue;
  3765. }
  3766. checkPropertyConsistency<bool>(this, dep.Target, strBool, emittedBools,
  3767. config, BoolType, nullptr);
  3768. if (cmSystemTools::GetErrorOccuredFlag()) {
  3769. return;
  3770. }
  3771. checkPropertyConsistency<const char*>(this, dep.Target, strString,
  3772. emittedStrings, config, StringType,
  3773. nullptr);
  3774. if (cmSystemTools::GetErrorOccuredFlag()) {
  3775. return;
  3776. }
  3777. checkPropertyConsistency<const char*>(this, dep.Target, strNumMin,
  3778. emittedMinNumbers, config,
  3779. NumberMinType, nullptr);
  3780. if (cmSystemTools::GetErrorOccuredFlag()) {
  3781. return;
  3782. }
  3783. checkPropertyConsistency<const char*>(this, dep.Target, strNumMax,
  3784. emittedMaxNumbers, config,
  3785. NumberMaxType, nullptr);
  3786. if (cmSystemTools::GetErrorOccuredFlag()) {
  3787. return;
  3788. }
  3789. }
  3790. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  3791. emittedMaxNumbers);
  3792. if (!prop.empty()) {
  3793. // Use a sorted std::vector to keep the error message sorted.
  3794. std::vector<std::string> props;
  3795. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3796. if (i != emittedBools.end()) {
  3797. props.push_back(strBool);
  3798. }
  3799. i = emittedStrings.find(prop);
  3800. if (i != emittedStrings.end()) {
  3801. props.push_back(strString);
  3802. }
  3803. i = emittedMinNumbers.find(prop);
  3804. if (i != emittedMinNumbers.end()) {
  3805. props.push_back(strNumMin);
  3806. }
  3807. i = emittedMaxNumbers.find(prop);
  3808. if (i != emittedMaxNumbers.end()) {
  3809. props.push_back(strNumMax);
  3810. }
  3811. std::sort(props.begin(), props.end());
  3812. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3813. propsString += " and the " + props.back();
  3814. std::ostringstream e;
  3815. e << "Property \"" << prop << "\" appears in both the " << propsString
  3816. << " property in the dependencies of target \"" << this->GetName()
  3817. << "\". This is not allowed. A property may only require compatibility "
  3818. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  3819. "or a "
  3820. "string interpretation, but not a mixture.";
  3821. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  3822. }
  3823. }
  3824. template <typename PropertyType>
  3825. std::string valueAsString(PropertyType);
  3826. template <>
  3827. std::string valueAsString<bool>(bool value)
  3828. {
  3829. return value ? "TRUE" : "FALSE";
  3830. }
  3831. template <>
  3832. std::string valueAsString<const char*>(const char* value)
  3833. {
  3834. return value ? value : "(unset)";
  3835. }
  3836. template <>
  3837. std::string valueAsString<std::string>(std::string value)
  3838. {
  3839. return value;
  3840. }
  3841. template <>
  3842. std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/)
  3843. {
  3844. return "(unset)";
  3845. }
  3846. std::string compatibilityType(CompatibleType t)
  3847. {
  3848. switch (t) {
  3849. case BoolType:
  3850. return "Boolean compatibility";
  3851. case StringType:
  3852. return "String compatibility";
  3853. case NumberMaxType:
  3854. return "Numeric maximum compatibility";
  3855. case NumberMinType:
  3856. return "Numeric minimum compatibility";
  3857. }
  3858. assert(false && "Unreachable!");
  3859. return "";
  3860. }
  3861. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3862. {
  3863. switch (t) {
  3864. case BoolType:
  3865. case StringType:
  3866. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3867. case NumberMaxType:
  3868. case NumberMinType:
  3869. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3870. }
  3871. assert(false && "Unreachable!");
  3872. return "";
  3873. }
  3874. template <typename PropertyType>
  3875. PropertyType getTypedProperty(
  3876. cmGeneratorTarget const* tgt, const std::string& prop,
  3877. cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
  3878. template <>
  3879. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  3880. const std::string& prop,
  3881. cmGeneratorExpressionInterpreter* genexInterpreter)
  3882. {
  3883. if (genexInterpreter == nullptr) {
  3884. return tgt->GetPropertyAsBool(prop);
  3885. }
  3886. const char* value = tgt->GetProperty(prop);
  3887. return cmSystemTools::IsOn(genexInterpreter->Evaluate(value, prop));
  3888. }
  3889. template <>
  3890. const char* getTypedProperty<const char*>(
  3891. cmGeneratorTarget const* tgt, const std::string& prop,
  3892. cmGeneratorExpressionInterpreter* genexInterpreter)
  3893. {
  3894. const char* value = tgt->GetProperty(prop);
  3895. if (genexInterpreter == nullptr) {
  3896. return value;
  3897. }
  3898. return genexInterpreter->Evaluate(value, prop).c_str();
  3899. }
  3900. template <>
  3901. std::string getTypedProperty<std::string>(
  3902. cmGeneratorTarget const* tgt, const std::string& prop,
  3903. cmGeneratorExpressionInterpreter* genexInterpreter)
  3904. {
  3905. const char* value = tgt->GetProperty(prop);
  3906. if (genexInterpreter == nullptr) {
  3907. return valueAsString(value);
  3908. }
  3909. return genexInterpreter->Evaluate(value, prop);
  3910. }
  3911. template <typename PropertyType>
  3912. PropertyType impliedValue(PropertyType);
  3913. template <>
  3914. bool impliedValue<bool>(bool /*unused*/)
  3915. {
  3916. return false;
  3917. }
  3918. template <>
  3919. const char* impliedValue<const char*>(const char* /*unused*/)
  3920. {
  3921. return "";
  3922. }
  3923. template <>
  3924. std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
  3925. {
  3926. return std::string();
  3927. }
  3928. template <typename PropertyType>
  3929. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3930. PropertyType rhs,
  3931. CompatibleType t);
  3932. template <>
  3933. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3934. CompatibleType /*unused*/)
  3935. {
  3936. return std::make_pair(lhs == rhs, lhs);
  3937. }
  3938. std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  3939. const char* rhs)
  3940. {
  3941. const bool b = strcmp(lhs, rhs) == 0;
  3942. return std::make_pair(b, b ? lhs : nullptr);
  3943. }
  3944. std::pair<bool, std::string> consistentStringProperty(const std::string& lhs,
  3945. const std::string& rhs)
  3946. {
  3947. const bool b = lhs == rhs;
  3948. return std::make_pair(b, b ? lhs : valueAsString(nullptr));
  3949. }
  3950. std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  3951. const char* rhs,
  3952. CompatibleType t)
  3953. {
  3954. char* pEnd;
  3955. const char* const null_ptr = nullptr;
  3956. long lnum = strtol(lhs, &pEnd, 0);
  3957. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  3958. return std::pair<bool, const char*>(false, null_ptr);
  3959. }
  3960. long rnum = strtol(rhs, &pEnd, 0);
  3961. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  3962. return std::pair<bool, const char*>(false, null_ptr);
  3963. }
  3964. if (t == NumberMaxType) {
  3965. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3966. }
  3967. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3968. }
  3969. template <>
  3970. std::pair<bool, const char*> consistentProperty(const char* lhs,
  3971. const char* rhs,
  3972. CompatibleType t)
  3973. {
  3974. if (!lhs && !rhs) {
  3975. return std::make_pair(true, lhs);
  3976. }
  3977. if (!lhs) {
  3978. return std::make_pair(true, rhs);
  3979. }
  3980. if (!rhs) {
  3981. return std::make_pair(true, lhs);
  3982. }
  3983. const char* const null_ptr = nullptr;
  3984. switch (t) {
  3985. case BoolType: {
  3986. bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
  3987. return std::make_pair(same, same ? lhs : nullptr);
  3988. }
  3989. case StringType:
  3990. return consistentStringProperty(lhs, rhs);
  3991. case NumberMinType:
  3992. case NumberMaxType:
  3993. return consistentNumberProperty(lhs, rhs, t);
  3994. }
  3995. assert(false && "Unreachable!");
  3996. return std::pair<bool, const char*>(false, null_ptr);
  3997. }
  3998. std::pair<bool, std::string> consistentProperty(const std::string& lhs,
  3999. const std::string& rhs,
  4000. CompatibleType t)
  4001. {
  4002. const std::string null_ptr = valueAsString(nullptr);
  4003. if (lhs == null_ptr && rhs == null_ptr) {
  4004. return std::make_pair(true, lhs);
  4005. }
  4006. if (lhs == null_ptr) {
  4007. return std::make_pair(true, rhs);
  4008. }
  4009. if (rhs == null_ptr) {
  4010. return std::make_pair(true, lhs);
  4011. }
  4012. switch (t) {
  4013. case BoolType: {
  4014. bool same = cmSystemTools::IsOn(lhs) == cmSystemTools::IsOn(rhs);
  4015. return std::make_pair(same, same ? lhs : null_ptr);
  4016. }
  4017. case StringType:
  4018. return consistentStringProperty(lhs, rhs);
  4019. case NumberMinType:
  4020. case NumberMaxType: {
  4021. auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
  4022. return std::make_pair(
  4023. value.first, value.first ? std::string(value.second) : null_ptr);
  4024. }
  4025. }
  4026. assert(false && "Unreachable!");
  4027. return std::pair<bool, std::string>(false, null_ptr);
  4028. }
  4029. template <typename PropertyType>
  4030. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  4031. const std::string& p,
  4032. const std::string& config,
  4033. const char* defaultValue,
  4034. CompatibleType t,
  4035. PropertyType* /*unused*/)
  4036. {
  4037. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  4038. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  4039. const bool explicitlySet =
  4040. std::find(headPropKeys.begin(), headPropKeys.end(), p) !=
  4041. headPropKeys.end();
  4042. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  4043. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  4044. std::vector<cmGeneratorTarget const*> const& deps =
  4045. tgt->GetLinkImplementationClosure(config);
  4046. if (deps.empty()) {
  4047. return propContent;
  4048. }
  4049. bool propInitialized = explicitlySet;
  4050. std::string report = " * Target \"";
  4051. report += tgt->GetName();
  4052. if (explicitlySet) {
  4053. report += "\" has property content \"";
  4054. report += valueAsString<PropertyType>(propContent);
  4055. report += "\"\n";
  4056. } else if (impliedByUse) {
  4057. report += "\" property is implied by use.\n";
  4058. } else {
  4059. report += "\" property not set.\n";
  4060. }
  4061. std::string interfaceProperty = "INTERFACE_" + p;
  4062. std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter(
  4063. p == "POSITION_INDEPENDENT_CODE" ? new cmGeneratorExpressionInterpreter(
  4064. tgt->GetLocalGenerator(), config, tgt)
  4065. : nullptr);
  4066. for (cmGeneratorTarget const* theTarget : deps) {
  4067. // An error should be reported if one dependency
  4068. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4069. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4070. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4071. // with a dependency.
  4072. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  4073. const bool ifaceIsSet = std::find(propKeys.begin(), propKeys.end(),
  4074. interfaceProperty) != propKeys.end();
  4075. PropertyType ifacePropContent = getTypedProperty<PropertyType>(
  4076. theTarget, interfaceProperty, genexInterpreter.get());
  4077. std::string reportEntry;
  4078. if (ifaceIsSet) {
  4079. reportEntry += " * Target \"";
  4080. reportEntry += theTarget->GetName();
  4081. reportEntry += "\" property value \"";
  4082. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4083. reportEntry += "\" ";
  4084. }
  4085. if (explicitlySet) {
  4086. if (ifaceIsSet) {
  4087. std::pair<bool, PropertyType> consistent =
  4088. consistentProperty(propContent, ifacePropContent, t);
  4089. report += reportEntry;
  4090. report += compatibilityAgree(t, propContent != consistent.second);
  4091. if (!consistent.first) {
  4092. std::ostringstream e;
  4093. e << "Property " << p << " on target \"" << tgt->GetName()
  4094. << "\" does\nnot match the "
  4095. "INTERFACE_"
  4096. << p
  4097. << " property requirement\nof "
  4098. "dependency \""
  4099. << theTarget->GetName() << "\".\n";
  4100. cmSystemTools::Error(e.str());
  4101. break;
  4102. }
  4103. propContent = consistent.second;
  4104. continue;
  4105. }
  4106. // Explicitly set on target and not set in iface. Can't disagree.
  4107. continue;
  4108. }
  4109. if (impliedByUse) {
  4110. propContent = impliedValue<PropertyType>(propContent);
  4111. if (ifaceIsSet) {
  4112. std::pair<bool, PropertyType> consistent =
  4113. consistentProperty(propContent, ifacePropContent, t);
  4114. report += reportEntry;
  4115. report += compatibilityAgree(t, propContent != consistent.second);
  4116. if (!consistent.first) {
  4117. std::ostringstream e;
  4118. e << "Property " << p << " on target \"" << tgt->GetName()
  4119. << "\" is\nimplied to be " << defaultValue
  4120. << " because it was used to determine the link libraries\n"
  4121. "already. The INTERFACE_"
  4122. << p << " property on\ndependency \"" << theTarget->GetName()
  4123. << "\" is in conflict.\n";
  4124. cmSystemTools::Error(e.str());
  4125. break;
  4126. }
  4127. propContent = consistent.second;
  4128. continue;
  4129. }
  4130. // Implicitly set on target and not set in iface. Can't disagree.
  4131. continue;
  4132. }
  4133. if (ifaceIsSet) {
  4134. if (propInitialized) {
  4135. std::pair<bool, PropertyType> consistent =
  4136. consistentProperty(propContent, ifacePropContent, t);
  4137. report += reportEntry;
  4138. report += compatibilityAgree(t, propContent != consistent.second);
  4139. if (!consistent.first) {
  4140. std::ostringstream e;
  4141. e << "The INTERFACE_" << p << " property of \""
  4142. << theTarget->GetName() << "\" does\nnot agree with the value of "
  4143. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  4144. cmSystemTools::Error(e.str());
  4145. break;
  4146. }
  4147. propContent = consistent.second;
  4148. continue;
  4149. }
  4150. report += reportEntry + "(Interface set)\n";
  4151. propContent = ifacePropContent;
  4152. propInitialized = true;
  4153. } else {
  4154. // Not set. Nothing to agree on.
  4155. continue;
  4156. }
  4157. }
  4158. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4159. report, compatibilityType(t));
  4160. return propContent;
  4161. }
  4162. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  4163. const std::string& p, const std::string& config) const
  4164. {
  4165. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4166. BoolType, nullptr);
  4167. }
  4168. std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
  4169. const std::string& p, const std::string& config) const
  4170. {
  4171. return checkInterfacePropertyCompatibility<std::string>(
  4172. this, p, config, "FALSE", BoolType, nullptr);
  4173. }
  4174. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  4175. const std::string& p, const std::string& config) const
  4176. {
  4177. return checkInterfacePropertyCompatibility<const char*>(
  4178. this, p, config, "empty", StringType, nullptr);
  4179. }
  4180. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  4181. const std::string& p, const std::string& config) const
  4182. {
  4183. return checkInterfacePropertyCompatibility<const char*>(
  4184. this, p, config, "empty", NumberMinType, nullptr);
  4185. }
  4186. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4187. const std::string& p, const std::string& config) const
  4188. {
  4189. return checkInterfacePropertyCompatibility<const char*>(
  4190. this, p, config, "empty", NumberMaxType, nullptr);
  4191. }
  4192. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  4193. const std::string& config) const
  4194. {
  4195. // Lookup any existing information for this configuration.
  4196. std::string key(cmSystemTools::UpperCase(config));
  4197. cmTargetLinkInformationMap::iterator i = this->LinkInformation.find(key);
  4198. if (i == this->LinkInformation.end()) {
  4199. // Compute information for this configuration.
  4200. cmComputeLinkInformation* info =
  4201. new cmComputeLinkInformation(this, config);
  4202. if (!info || !info->Compute()) {
  4203. delete info;
  4204. info = nullptr;
  4205. }
  4206. // Store the information for this configuration.
  4207. cmTargetLinkInformationMap::value_type entry(key, info);
  4208. i = this->LinkInformation.insert(entry).first;
  4209. if (info) {
  4210. this->CheckPropertyCompatibility(info, config);
  4211. }
  4212. }
  4213. return i->second;
  4214. }
  4215. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  4216. {
  4217. int patch;
  4218. this->GetTargetVersion(false, major, minor, patch);
  4219. }
  4220. void cmGeneratorTarget::GetTargetVersion(bool soversion, int& major,
  4221. int& minor, int& patch) const
  4222. {
  4223. // Set the default values.
  4224. major = 0;
  4225. minor = 0;
  4226. patch = 0;
  4227. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  4228. // Look for a VERSION or SOVERSION property.
  4229. const char* prop = soversion ? "SOVERSION" : "VERSION";
  4230. if (const char* version = this->GetProperty(prop)) {
  4231. // Try to parse the version number and store the results that were
  4232. // successfully parsed.
  4233. int parsed_major;
  4234. int parsed_minor;
  4235. int parsed_patch;
  4236. switch (sscanf(version, "%d.%d.%d", &parsed_major, &parsed_minor,
  4237. &parsed_patch)) {
  4238. case 3:
  4239. patch = parsed_patch;
  4240. CM_FALLTHROUGH;
  4241. case 2:
  4242. minor = parsed_minor;
  4243. CM_FALLTHROUGH;
  4244. case 1:
  4245. major = parsed_major;
  4246. CM_FALLTHROUGH;
  4247. default:
  4248. break;
  4249. }
  4250. }
  4251. }
  4252. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  4253. std::string const& working_dir) const
  4254. {
  4255. if (!this->FortranModuleDirectoryCreated) {
  4256. this->FortranModuleDirectory =
  4257. this->CreateFortranModuleDirectory(working_dir);
  4258. this->FortranModuleDirectoryCreated = true;
  4259. }
  4260. return this->FortranModuleDirectory;
  4261. }
  4262. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  4263. std::string const& working_dir) const
  4264. {
  4265. std::string mod_dir;
  4266. std::string target_mod_dir;
  4267. if (const char* prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  4268. target_mod_dir = prop;
  4269. } else {
  4270. std::string const& default_mod_dir =
  4271. this->LocalGenerator->GetCurrentBinaryDirectory();
  4272. if (default_mod_dir != working_dir) {
  4273. target_mod_dir = default_mod_dir;
  4274. }
  4275. }
  4276. const char* moddir_flag =
  4277. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  4278. if (!target_mod_dir.empty() && moddir_flag) {
  4279. // Compute the full path to the module directory.
  4280. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  4281. // Already a full path.
  4282. mod_dir = target_mod_dir;
  4283. } else {
  4284. // Interpret relative to the current output directory.
  4285. mod_dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  4286. mod_dir += "/";
  4287. mod_dir += target_mod_dir;
  4288. }
  4289. // Make sure the module output directory exists.
  4290. cmSystemTools::MakeDirectory(mod_dir);
  4291. }
  4292. return mod_dir;
  4293. }
  4294. std::string cmGeneratorTarget::GetFrameworkVersion() const
  4295. {
  4296. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  4297. if (const char* fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  4298. return fversion;
  4299. }
  4300. if (const char* tversion = this->GetProperty("VERSION")) {
  4301. return tversion;
  4302. }
  4303. return "A";
  4304. }
  4305. void cmGeneratorTarget::ComputeVersionedName(std::string& vName,
  4306. std::string const& prefix,
  4307. std::string const& base,
  4308. std::string const& suffix,
  4309. std::string const& name,
  4310. const char* version) const
  4311. {
  4312. vName = this->Makefile->IsOn("APPLE") ? (prefix + base) : name;
  4313. if (version) {
  4314. vName += ".";
  4315. vName += version;
  4316. }
  4317. vName += this->Makefile->IsOn("APPLE") ? suffix : std::string();
  4318. }
  4319. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  4320. {
  4321. cmPropertyMap const& propsObject = this->Target->GetProperties();
  4322. std::vector<std::string> props;
  4323. props.reserve(propsObject.size());
  4324. for (auto const& it : propsObject) {
  4325. props.push_back(it.first);
  4326. }
  4327. return props;
  4328. }
  4329. void cmGeneratorTarget::ReportPropertyOrigin(
  4330. const std::string& p, const std::string& result, const std::string& report,
  4331. const std::string& compatibilityType) const
  4332. {
  4333. std::vector<std::string> debugProperties;
  4334. const char* debugProp = this->Target->GetMakefile()->GetDefinition(
  4335. "CMAKE_DEBUG_TARGET_PROPERTIES");
  4336. if (debugProp) {
  4337. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4338. }
  4339. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  4340. std::find(debugProperties.begin(), debugProperties.end(), p) !=
  4341. debugProperties.end();
  4342. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4343. this->DebugCompatiblePropertiesDone[p] = true;
  4344. }
  4345. if (!debugOrigin) {
  4346. return;
  4347. }
  4348. std::string areport = compatibilityType;
  4349. areport += std::string(" of property \"") + p + "\" for target \"";
  4350. areport += std::string(this->GetName());
  4351. areport += "\" (result: \"";
  4352. areport += result;
  4353. areport += "\"):\n" + report;
  4354. this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
  4355. areport);
  4356. }
  4357. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  4358. cmListFileBacktrace const& bt,
  4359. std::vector<cmLinkItem>& items) const
  4360. {
  4361. for (std::string const& n : names) {
  4362. std::string name = this->CheckCMP0004(n);
  4363. if (name == this->GetName() || name.empty()) {
  4364. continue;
  4365. }
  4366. items.push_back(this->ResolveLinkItem(name, bt));
  4367. }
  4368. }
  4369. void cmGeneratorTarget::ExpandLinkItems(
  4370. std::string const& prop, std::string const& value, std::string const& config,
  4371. cmGeneratorTarget const* headTarget, bool usage_requirements_only,
  4372. std::vector<cmLinkItem>& items, bool& hadHeadSensitiveCondition) const
  4373. {
  4374. cmGeneratorExpression ge;
  4375. cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
  4376. // The $<LINK_ONLY> expression may be in a link interface to specify private
  4377. // link dependencies that are otherwise excluded from usage requirements.
  4378. if (usage_requirements_only) {
  4379. dagChecker.SetTransitivePropertiesOnly();
  4380. }
  4381. std::vector<std::string> libs;
  4382. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  4383. cmSystemTools::ExpandListArgument(cge->Evaluate(this->LocalGenerator, config,
  4384. false, headTarget, this,
  4385. &dagChecker),
  4386. libs);
  4387. this->LookupLinkItems(libs, cge->GetBacktrace(), items);
  4388. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  4389. }
  4390. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  4391. const std::string& config, cmGeneratorTarget const* head) const
  4392. {
  4393. // Imported targets have their own link interface.
  4394. if (this->IsImported()) {
  4395. return this->GetImportLinkInterface(config, head, false);
  4396. }
  4397. // Link interfaces are not supported for executables that do not
  4398. // export symbols.
  4399. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  4400. !this->IsExecutableWithExports()) {
  4401. return nullptr;
  4402. }
  4403. // Lookup any existing link interface for this configuration.
  4404. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  4405. // If the link interface does not depend on the head target
  4406. // then return the one we computed first.
  4407. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4408. return &hm.begin()->second;
  4409. }
  4410. cmOptionalLinkInterface& iface = hm[head];
  4411. if (!iface.LibrariesDone) {
  4412. iface.LibrariesDone = true;
  4413. this->ComputeLinkInterfaceLibraries(config, iface, head, false);
  4414. }
  4415. if (!iface.AllDone) {
  4416. iface.AllDone = true;
  4417. if (iface.Exists) {
  4418. this->ComputeLinkInterface(config, iface, head);
  4419. }
  4420. }
  4421. return iface.Exists ? &iface : nullptr;
  4422. }
  4423. void cmGeneratorTarget::ComputeLinkInterface(
  4424. const std::string& config, cmOptionalLinkInterface& iface,
  4425. cmGeneratorTarget const* headTarget) const
  4426. {
  4427. if (iface.ExplicitLibraries) {
  4428. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4429. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4430. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4431. // Shared libraries may have runtime implementation dependencies
  4432. // on other shared libraries that are not in the interface.
  4433. std::set<cmLinkItem> emitted;
  4434. for (cmLinkItem const& lib : iface.Libraries) {
  4435. emitted.insert(lib);
  4436. }
  4437. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4438. cmLinkImplementation const* impl = this->GetLinkImplementation(config);
  4439. for (cmLinkImplItem const& lib : impl->Libraries) {
  4440. if (emitted.insert(lib).second) {
  4441. if (lib.Target) {
  4442. // This is a runtime dependency on another shared library.
  4443. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4444. iface.SharedDeps.push_back(lib);
  4445. }
  4446. } else {
  4447. // TODO: Recognize shared library file names. Perhaps this
  4448. // should be moved to cmComputeLinkInformation, but that creates
  4449. // a chicken-and-egg problem since this list is needed for its
  4450. // construction.
  4451. }
  4452. }
  4453. }
  4454. }
  4455. }
  4456. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  4457. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  4458. // The link implementation is the default link interface.
  4459. cmLinkImplementationLibraries const* impl =
  4460. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4461. iface.ImplementationIsInterface = true;
  4462. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4463. }
  4464. if (this->LinkLanguagePropagatesToDependents()) {
  4465. // Targets using this archive need its language runtime libraries.
  4466. if (cmLinkImplementation const* impl =
  4467. this->GetLinkImplementation(config)) {
  4468. iface.Languages = impl->Languages;
  4469. }
  4470. }
  4471. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  4472. // Construct the property name suffix for this configuration.
  4473. std::string suffix = "_";
  4474. if (!config.empty()) {
  4475. suffix += cmSystemTools::UpperCase(config);
  4476. } else {
  4477. suffix += "NOCONFIG";
  4478. }
  4479. // How many repetitions are needed if this library has cyclic
  4480. // dependencies?
  4481. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4482. propName += suffix;
  4483. if (const char* config_reps = this->GetProperty(propName)) {
  4484. sscanf(config_reps, "%u", &iface.Multiplicity);
  4485. } else if (const char* reps =
  4486. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  4487. sscanf(reps, "%u", &iface.Multiplicity);
  4488. }
  4489. }
  4490. }
  4491. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  4492. const std::string& config, cmGeneratorTarget const* head,
  4493. bool usage_requirements_only) const
  4494. {
  4495. // Imported targets have their own link interface.
  4496. if (this->IsImported()) {
  4497. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  4498. }
  4499. // Link interfaces are not supported for executables that do not
  4500. // export symbols.
  4501. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  4502. !this->IsExecutableWithExports()) {
  4503. return nullptr;
  4504. }
  4505. // Lookup any existing link interface for this configuration.
  4506. std::string CONFIG = cmSystemTools::UpperCase(config);
  4507. cmHeadToLinkInterfaceMap& hm =
  4508. (usage_requirements_only
  4509. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4510. : this->GetHeadToLinkInterfaceMap(config));
  4511. // If the link interface does not depend on the head target
  4512. // then return the one we computed first.
  4513. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4514. return &hm.begin()->second;
  4515. }
  4516. cmOptionalLinkInterface& iface = hm[head];
  4517. if (!iface.LibrariesDone) {
  4518. iface.LibrariesDone = true;
  4519. this->ComputeLinkInterfaceLibraries(config, iface, head,
  4520. usage_requirements_only);
  4521. }
  4522. return iface.Exists ? &iface : nullptr;
  4523. }
  4524. std::string cmGeneratorTarget::GetDirectory(
  4525. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4526. {
  4527. if (this->IsImported()) {
  4528. // Return the directory from which the target is imported.
  4529. return cmSystemTools::GetFilenamePath(
  4530. this->Target->ImportedGetFullPath(config, artifact));
  4531. }
  4532. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  4533. // Return the directory in which the target will be built.
  4534. switch (artifact) {
  4535. case cmStateEnums::RuntimeBinaryArtifact:
  4536. return info->OutDir;
  4537. case cmStateEnums::ImportLibraryArtifact:
  4538. return info->ImpDir;
  4539. }
  4540. }
  4541. return "";
  4542. }
  4543. bool cmGeneratorTarget::UsesDefaultOutputDir(
  4544. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4545. {
  4546. std::string dir;
  4547. return this->ComputeOutputDir(config, artifact, dir);
  4548. }
  4549. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  4550. const std::string& config) const
  4551. {
  4552. // There is no output information for imported targets.
  4553. if (this->IsImported()) {
  4554. return nullptr;
  4555. }
  4556. // Only libraries and executables have well-defined output files.
  4557. if (!this->HaveWellDefinedOutputFiles()) {
  4558. std::string msg = "cmGeneratorTarget::GetOutputInfo called for ";
  4559. msg += this->GetName();
  4560. msg += " which has type ";
  4561. msg += cmState::GetTargetTypeName(this->GetType());
  4562. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4563. return nullptr;
  4564. }
  4565. // Lookup/compute/cache the output information for this configuration.
  4566. std::string config_upper;
  4567. if (!config.empty()) {
  4568. config_upper = cmSystemTools::UpperCase(config);
  4569. }
  4570. OutputInfoMapType::iterator i = this->OutputInfoMap.find(config_upper);
  4571. if (i == this->OutputInfoMap.end()) {
  4572. // Add empty info in map to detect potential recursion.
  4573. OutputInfo info;
  4574. OutputInfoMapType::value_type entry(config_upper, info);
  4575. i = this->OutputInfoMap.insert(entry).first;
  4576. // Compute output directories.
  4577. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  4578. info.OutDir);
  4579. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  4580. info.ImpDir);
  4581. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  4582. info.PdbDir = info.OutDir;
  4583. }
  4584. // Now update the previously-prepared map entry.
  4585. i->second = info;
  4586. } else if (i->second.empty()) {
  4587. // An empty map entry indicates we have been called recursively
  4588. // from the above block.
  4589. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4590. MessageType::FATAL_ERROR,
  4591. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  4592. this->GetBacktrace());
  4593. return nullptr;
  4594. }
  4595. return &i->second;
  4596. }
  4597. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  4598. cmStateEnums::ArtifactType artifact,
  4599. std::string& out) const
  4600. {
  4601. bool usesDefaultOutputDir = false;
  4602. std::string conf = config;
  4603. // Look for a target property defining the target output directory
  4604. // based on the target type.
  4605. std::string targetTypeName = this->GetOutputTargetType(artifact);
  4606. const char* propertyName = nullptr;
  4607. std::string propertyNameStr = targetTypeName;
  4608. if (!propertyNameStr.empty()) {
  4609. propertyNameStr += "_OUTPUT_DIRECTORY";
  4610. propertyName = propertyNameStr.c_str();
  4611. }
  4612. // Check for a per-configuration output directory target property.
  4613. std::string configUpper = cmSystemTools::UpperCase(conf);
  4614. const char* configProp = nullptr;
  4615. std::string configPropStr = targetTypeName;
  4616. if (!configPropStr.empty()) {
  4617. configPropStr += "_OUTPUT_DIRECTORY_";
  4618. configPropStr += configUpper;
  4619. configProp = configPropStr.c_str();
  4620. }
  4621. // Select an output directory.
  4622. if (const char* config_outdir = this->GetProperty(configProp)) {
  4623. // Use the user-specified per-configuration output directory.
  4624. cmGeneratorExpression ge;
  4625. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  4626. ge.Parse(config_outdir);
  4627. out = cge->Evaluate(this->LocalGenerator, config);
  4628. // Skip per-configuration subdirectory.
  4629. conf.clear();
  4630. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4631. // Use the user-specified output directory.
  4632. cmGeneratorExpression ge;
  4633. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  4634. out = cge->Evaluate(this->LocalGenerator, config);
  4635. // Skip per-configuration subdirectory if the value contained a
  4636. // generator expression.
  4637. if (out != outdir) {
  4638. conf.clear();
  4639. }
  4640. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4641. // Lookup the output path for executables.
  4642. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4643. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4644. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4645. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4646. // Lookup the output path for libraries.
  4647. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4648. }
  4649. if (out.empty()) {
  4650. // Default to the current output directory.
  4651. usesDefaultOutputDir = true;
  4652. out = ".";
  4653. }
  4654. // Convert the output path to a full path in case it is
  4655. // specified as a relative path. Treat a relative path as
  4656. // relative to the current output directory for this makefile.
  4657. out = (cmSystemTools::CollapseFullPath(
  4658. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4659. // The generator may add the configuration's subdirectory.
  4660. if (!conf.empty()) {
  4661. bool useEPN =
  4662. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  4663. std::string suffix =
  4664. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  4665. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4666. "/", conf, suffix, out);
  4667. }
  4668. return usesDefaultOutputDir;
  4669. }
  4670. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  4671. const std::string& config,
  4672. std::string& out) const
  4673. {
  4674. // Look for a target property defining the target output directory
  4675. // based on the target type.
  4676. const char* propertyName = nullptr;
  4677. std::string propertyNameStr = kind;
  4678. if (!propertyNameStr.empty()) {
  4679. propertyNameStr += "_OUTPUT_DIRECTORY";
  4680. propertyName = propertyNameStr.c_str();
  4681. }
  4682. std::string conf = config;
  4683. // Check for a per-configuration output directory target property.
  4684. std::string configUpper = cmSystemTools::UpperCase(conf);
  4685. const char* configProp = nullptr;
  4686. std::string configPropStr = kind;
  4687. if (!configPropStr.empty()) {
  4688. configPropStr += "_OUTPUT_DIRECTORY_";
  4689. configPropStr += configUpper;
  4690. configProp = configPropStr.c_str();
  4691. }
  4692. // Select an output directory.
  4693. if (const char* config_outdir = this->GetProperty(configProp)) {
  4694. // Use the user-specified per-configuration output directory.
  4695. cmGeneratorExpression ge;
  4696. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  4697. ge.Parse(config_outdir);
  4698. out = cge->Evaluate(this->LocalGenerator, config);
  4699. // Skip per-configuration subdirectory.
  4700. conf.clear();
  4701. } else if (const char* outdir = this->GetProperty(propertyName)) {
  4702. // Use the user-specified output directory.
  4703. cmGeneratorExpression ge;
  4704. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outdir);
  4705. out = cge->Evaluate(this->LocalGenerator, config);
  4706. // Skip per-configuration subdirectory if the value contained a
  4707. // generator expression.
  4708. if (out != outdir) {
  4709. conf.clear();
  4710. }
  4711. }
  4712. if (out.empty()) {
  4713. return false;
  4714. }
  4715. // Convert the output path to a full path in case it is
  4716. // specified as a relative path. Treat a relative path as
  4717. // relative to the current output directory for this makefile.
  4718. out = (cmSystemTools::CollapseFullPath(
  4719. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  4720. // The generator may add the configuration's subdirectory.
  4721. if (!conf.empty()) {
  4722. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  4723. "/", conf, "", out);
  4724. }
  4725. return true;
  4726. }
  4727. bool cmGeneratorTarget::HaveInstallTreeRPATH() const
  4728. {
  4729. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  4730. return (install_rpath && *install_rpath) &&
  4731. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  4732. }
  4733. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  4734. const std::string& config, cmOptionalLinkInterface& iface,
  4735. cmGeneratorTarget const* headTarget, bool usage_requirements_only) const
  4736. {
  4737. // Construct the property name suffix for this configuration.
  4738. std::string suffix = "_";
  4739. if (!config.empty()) {
  4740. suffix += cmSystemTools::UpperCase(config);
  4741. } else {
  4742. suffix += "NOCONFIG";
  4743. }
  4744. // An explicit list of interface libraries may be set for shared
  4745. // libraries and executables that export symbols.
  4746. const char* explicitLibraries = nullptr;
  4747. std::string linkIfaceProp;
  4748. if (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4749. this->GetPolicyStatusCMP0022() != cmPolicies::WARN) {
  4750. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4751. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4752. explicitLibraries = this->GetProperty(linkIfaceProp);
  4753. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4754. this->IsExecutableWithExports()) {
  4755. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4756. // shared lib or executable.
  4757. // Lookup the per-configuration property.
  4758. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4759. linkIfaceProp += suffix;
  4760. explicitLibraries = this->GetProperty(linkIfaceProp);
  4761. // If not set, try the generic property.
  4762. if (!explicitLibraries) {
  4763. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4764. explicitLibraries = this->GetProperty(linkIfaceProp);
  4765. }
  4766. }
  4767. if (explicitLibraries &&
  4768. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4769. !this->PolicyWarnedCMP0022) {
  4770. // Compare the explicitly set old link interface properties to the
  4771. // preferred new link interface property one and warn if different.
  4772. const char* newExplicitLibraries =
  4773. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  4774. if (newExplicitLibraries &&
  4775. strcmp(newExplicitLibraries, explicitLibraries) != 0) {
  4776. std::ostringstream w;
  4777. /* clang-format off */
  4778. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4779. "Target \"" << this->GetName() << "\" has an "
  4780. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4781. linkIfaceProp << " properties."
  4782. "\n"
  4783. "INTERFACE_LINK_LIBRARIES:\n"
  4784. " " << newExplicitLibraries << "\n" <<
  4785. linkIfaceProp << ":\n"
  4786. " " << explicitLibraries << "\n";
  4787. /* clang-format on */
  4788. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
  4789. this->PolicyWarnedCMP0022 = true;
  4790. }
  4791. }
  4792. // There is no implicit link interface for executables or modules
  4793. // so if none was explicitly set then there is no link interface.
  4794. if (!explicitLibraries &&
  4795. (this->GetType() == cmStateEnums::EXECUTABLE ||
  4796. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  4797. return;
  4798. }
  4799. iface.Exists = true;
  4800. iface.ExplicitLibraries = explicitLibraries;
  4801. if (explicitLibraries) {
  4802. // The interface libraries have been explicitly set.
  4803. this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget,
  4804. usage_requirements_only, iface.Libraries,
  4805. iface.HadHeadSensitiveCondition);
  4806. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  4807. this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4808. // If CMP0022 is NEW then the plain tll signature sets the
  4809. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4810. // cleared the property explicitly and we should not fall back
  4811. // to the link implementation.
  4812. {
  4813. // The link implementation is the default link interface.
  4814. cmLinkImplementationLibraries const* impl =
  4815. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4816. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  4817. impl->Libraries.end());
  4818. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4819. !this->PolicyWarnedCMP0022 && !usage_requirements_only) {
  4820. // Compare the link implementation fallback link interface to the
  4821. // preferred new link interface property and warn if different.
  4822. std::vector<cmLinkItem> ifaceLibs;
  4823. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4824. if (const char* newExplicitLibraries = this->GetProperty(newProp)) {
  4825. bool hadHeadSensitiveConditionDummy = false;
  4826. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4827. headTarget, usage_requirements_only, ifaceLibs,
  4828. hadHeadSensitiveConditionDummy);
  4829. }
  4830. if (ifaceLibs != iface.Libraries) {
  4831. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4832. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4833. if (oldLibraries.empty()) {
  4834. oldLibraries = "(empty)";
  4835. }
  4836. if (newLibraries.empty()) {
  4837. newLibraries = "(empty)";
  4838. }
  4839. std::ostringstream w;
  4840. /* clang-format off */
  4841. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4842. "Target \"" << this->GetName() << "\" has an "
  4843. "INTERFACE_LINK_LIBRARIES property. "
  4844. "This should be preferred as the source of the link interface "
  4845. "for this library but because CMP0022 is not set CMake is "
  4846. "ignoring the property and using the link implementation "
  4847. "as the link interface instead."
  4848. "\n"
  4849. "INTERFACE_LINK_LIBRARIES:\n"
  4850. " " << newLibraries << "\n"
  4851. "Link implementation:\n"
  4852. " " << oldLibraries << "\n";
  4853. /* clang-format on */
  4854. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  4855. w.str());
  4856. this->PolicyWarnedCMP0022 = true;
  4857. }
  4858. }
  4859. }
  4860. }
  4861. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  4862. const std::string& config, cmGeneratorTarget const* headTarget,
  4863. bool usage_requirements_only) const
  4864. {
  4865. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  4866. if (!info) {
  4867. return nullptr;
  4868. }
  4869. std::string CONFIG = cmSystemTools::UpperCase(config);
  4870. cmHeadToLinkInterfaceMap& hm =
  4871. (usage_requirements_only
  4872. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  4873. : this->GetHeadToLinkInterfaceMap(config));
  4874. // If the link interface does not depend on the head target
  4875. // then return the one we computed first.
  4876. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  4877. return &hm.begin()->second;
  4878. }
  4879. cmOptionalLinkInterface& iface = hm[headTarget];
  4880. if (!iface.AllDone) {
  4881. iface.AllDone = true;
  4882. iface.Multiplicity = info->Multiplicity;
  4883. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4884. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  4885. headTarget, usage_requirements_only, iface.Libraries,
  4886. iface.HadHeadSensitiveCondition);
  4887. std::vector<std::string> deps;
  4888. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4889. this->LookupLinkItems(deps, cmListFileBacktrace(), iface.SharedDeps);
  4890. }
  4891. return &iface;
  4892. }
  4893. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  4894. const std::string& config) const
  4895. {
  4896. // There is no imported information for non-imported targets.
  4897. if (!this->IsImported()) {
  4898. return nullptr;
  4899. }
  4900. // Lookup/compute/cache the import information for this
  4901. // configuration.
  4902. std::string config_upper;
  4903. if (!config.empty()) {
  4904. config_upper = cmSystemTools::UpperCase(config);
  4905. } else {
  4906. config_upper = "NOCONFIG";
  4907. }
  4908. ImportInfoMapType::const_iterator i = this->ImportInfoMap.find(config_upper);
  4909. if (i == this->ImportInfoMap.end()) {
  4910. ImportInfo info;
  4911. this->ComputeImportInfo(config_upper, info);
  4912. ImportInfoMapType::value_type entry(config_upper, info);
  4913. i = this->ImportInfoMap.insert(entry).first;
  4914. }
  4915. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4916. return &i->second;
  4917. }
  4918. // If the location is empty then the target is not available for
  4919. // this configuration.
  4920. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  4921. return nullptr;
  4922. }
  4923. // Return the import information.
  4924. return &i->second;
  4925. }
  4926. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  4927. ImportInfo& info) const
  4928. {
  4929. // This method finds information about an imported target from its
  4930. // properties. The "IMPORTED_" namespace is reserved for properties
  4931. // defined by the project exporting the target.
  4932. // Initialize members.
  4933. info.NoSOName = false;
  4934. const char* loc = nullptr;
  4935. const char* imp = nullptr;
  4936. std::string suffix;
  4937. if (!this->Target->GetMappedConfig(desired_config, &loc, &imp, suffix)) {
  4938. return;
  4939. }
  4940. // Get the link interface.
  4941. {
  4942. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4943. const char* propertyLibs = this->GetProperty(linkProp);
  4944. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  4945. if (!propertyLibs) {
  4946. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4947. linkProp += suffix;
  4948. propertyLibs = this->GetProperty(linkProp);
  4949. }
  4950. if (!propertyLibs) {
  4951. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4952. propertyLibs = this->GetProperty(linkProp);
  4953. }
  4954. }
  4955. if (propertyLibs) {
  4956. info.LibrariesProp = linkProp;
  4957. info.Libraries = propertyLibs;
  4958. }
  4959. }
  4960. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  4961. if (loc) {
  4962. info.LibName = loc;
  4963. }
  4964. return;
  4965. }
  4966. // A provided configuration has been chosen. Load the
  4967. // configuration's properties.
  4968. // Get the location.
  4969. if (loc) {
  4970. info.Location = loc;
  4971. } else {
  4972. std::string impProp = "IMPORTED_LOCATION";
  4973. impProp += suffix;
  4974. if (const char* config_location = this->GetProperty(impProp)) {
  4975. info.Location = config_location;
  4976. } else if (const char* location = this->GetProperty("IMPORTED_LOCATION")) {
  4977. info.Location = location;
  4978. }
  4979. }
  4980. // Get the soname.
  4981. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4982. std::string soProp = "IMPORTED_SONAME";
  4983. soProp += suffix;
  4984. if (const char* config_soname = this->GetProperty(soProp)) {
  4985. info.SOName = config_soname;
  4986. } else if (const char* soname = this->GetProperty("IMPORTED_SONAME")) {
  4987. info.SOName = soname;
  4988. }
  4989. }
  4990. // Get the "no-soname" mark.
  4991. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  4992. std::string soProp = "IMPORTED_NO_SONAME";
  4993. soProp += suffix;
  4994. if (const char* config_no_soname = this->GetProperty(soProp)) {
  4995. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4996. } else if (const char* no_soname =
  4997. this->GetProperty("IMPORTED_NO_SONAME")) {
  4998. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4999. }
  5000. }
  5001. // Get the import library.
  5002. if (imp) {
  5003. info.ImportLibrary = imp;
  5004. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5005. this->IsExecutableWithExports()) {
  5006. std::string impProp = "IMPORTED_IMPLIB";
  5007. impProp += suffix;
  5008. if (const char* config_implib = this->GetProperty(impProp)) {
  5009. info.ImportLibrary = config_implib;
  5010. } else if (const char* implib = this->GetProperty("IMPORTED_IMPLIB")) {
  5011. info.ImportLibrary = implib;
  5012. }
  5013. }
  5014. // Get the link dependencies.
  5015. {
  5016. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5017. linkProp += suffix;
  5018. if (const char* config_libs = this->GetProperty(linkProp)) {
  5019. info.SharedDeps = config_libs;
  5020. } else if (const char* libs =
  5021. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  5022. info.SharedDeps = libs;
  5023. }
  5024. }
  5025. // Get the link languages.
  5026. if (this->LinkLanguagePropagatesToDependents()) {
  5027. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5028. linkProp += suffix;
  5029. if (const char* config_libs = this->GetProperty(linkProp)) {
  5030. info.Languages = config_libs;
  5031. } else if (const char* libs =
  5032. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  5033. info.Languages = libs;
  5034. }
  5035. }
  5036. // Get information if target is managed assembly.
  5037. {
  5038. std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  5039. if (auto pc = this->GetProperty(linkProp + suffix)) {
  5040. info.Managed = this->CheckManagedType(pc);
  5041. } else if (auto p = this->GetProperty(linkProp)) {
  5042. info.Managed = this->CheckManagedType(p);
  5043. }
  5044. }
  5045. // Get the cyclic repetition count.
  5046. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5047. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5048. linkProp += suffix;
  5049. if (const char* config_reps = this->GetProperty(linkProp)) {
  5050. sscanf(config_reps, "%u", &info.Multiplicity);
  5051. } else if (const char* reps =
  5052. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  5053. sscanf(reps, "%u", &info.Multiplicity);
  5054. }
  5055. }
  5056. }
  5057. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  5058. const std::string& config) const
  5059. {
  5060. std::string CONFIG = cmSystemTools::UpperCase(config);
  5061. return this->LinkInterfaceMap[CONFIG];
  5062. }
  5063. cmHeadToLinkInterfaceMap&
  5064. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  5065. const std::string& config) const
  5066. {
  5067. std::string CONFIG = cmSystemTools::UpperCase(config);
  5068. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  5069. }
  5070. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  5071. const std::string& config) const
  5072. {
  5073. // There is no link implementation for imported targets.
  5074. if (this->IsImported()) {
  5075. return nullptr;
  5076. }
  5077. std::string CONFIG = cmSystemTools::UpperCase(config);
  5078. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this];
  5079. if (!impl.LibrariesDone) {
  5080. impl.LibrariesDone = true;
  5081. this->ComputeLinkImplementationLibraries(config, impl, this);
  5082. }
  5083. if (!impl.LanguagesDone) {
  5084. impl.LanguagesDone = true;
  5085. this->ComputeLinkImplementationLanguages(config, impl);
  5086. }
  5087. return &impl;
  5088. }
  5089. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  5090. std::vector<cmSourceFile*>& files) const
  5091. {
  5092. std::vector<std::string> configs;
  5093. this->Makefile->GetConfigurations(configs);
  5094. if (configs.empty()) {
  5095. configs.emplace_back();
  5096. }
  5097. std::vector<std::string>::const_iterator it = configs.begin();
  5098. const std::string& firstConfig = *it;
  5099. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  5100. for (; it != configs.end(); ++it) {
  5101. std::vector<cmSourceFile*> configFiles;
  5102. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  5103. if (configFiles != files) {
  5104. std::string firstConfigFiles;
  5105. const char* sep = "";
  5106. for (cmSourceFile* f : files) {
  5107. firstConfigFiles += sep;
  5108. firstConfigFiles += f->GetFullPath();
  5109. sep = "\n ";
  5110. }
  5111. std::string thisConfigFiles;
  5112. sep = "";
  5113. for (cmSourceFile* f : configFiles) {
  5114. thisConfigFiles += sep;
  5115. thisConfigFiles += f->GetFullPath();
  5116. sep = "\n ";
  5117. }
  5118. std::ostringstream e;
  5119. /* clang-format off */
  5120. e << "Target \"" << this->GetName()
  5121. << "\" has source files which vary by "
  5122. "configuration. This is not supported by the \""
  5123. << this->GlobalGenerator->GetName()
  5124. << "\" generator.\n"
  5125. "Config \"" << firstConfig << "\":\n"
  5126. " " << firstConfigFiles << "\n"
  5127. "Config \"" << *it << "\":\n"
  5128. " " << thisConfigFiles << "\n";
  5129. /* clang-format on */
  5130. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  5131. return false;
  5132. }
  5133. }
  5134. return true;
  5135. }
  5136. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  5137. std::vector<cmGeneratorTarget*>& objlibs) const
  5138. {
  5139. // At configure-time, this method can be called as part of getting the
  5140. // LOCATION property or to export() a file to be include()d. However
  5141. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  5142. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  5143. // behavior of CMP0024 and CMP0026 only.
  5144. cmStringRange rng = this->Target->GetSourceEntries();
  5145. for (std::string const& entry : rng) {
  5146. std::vector<std::string> files;
  5147. cmSystemTools::ExpandListArgument(entry, files);
  5148. for (std::string const& li : files) {
  5149. if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
  5150. std::string objLibName = li.substr(17, li.size() - 18);
  5151. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  5152. continue;
  5153. }
  5154. cmGeneratorTarget* objLib =
  5155. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  5156. if (objLib) {
  5157. objlibs.push_back(objLib);
  5158. }
  5159. }
  5160. }
  5161. }
  5162. }
  5163. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  5164. {
  5165. // Strip whitespace off the library names because we used to do this
  5166. // in case variables were expanded at generate time. We no longer
  5167. // do the expansion but users link to libraries like " ${VAR} ".
  5168. std::string lib = item;
  5169. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5170. if (pos != std::string::npos) {
  5171. lib = lib.substr(pos);
  5172. }
  5173. pos = lib.find_last_not_of(" \t\r\n");
  5174. if (pos != std::string::npos) {
  5175. lib = lib.substr(0, pos + 1);
  5176. }
  5177. if (lib != item) {
  5178. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  5179. switch (this->GetPolicyStatusCMP0004()) {
  5180. case cmPolicies::WARN: {
  5181. std::ostringstream w;
  5182. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  5183. << "Target \"" << this->GetName() << "\" links to item \"" << item
  5184. << "\" which has leading or trailing whitespace.";
  5185. cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
  5186. this->GetBacktrace());
  5187. }
  5188. case cmPolicies::OLD:
  5189. break;
  5190. case cmPolicies::NEW: {
  5191. std::ostringstream e;
  5192. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  5193. << "\" which has leading or trailing whitespace. "
  5194. << "This is now an error according to policy CMP0004.";
  5195. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  5196. this->GetBacktrace());
  5197. } break;
  5198. case cmPolicies::REQUIRED_IF_USED:
  5199. case cmPolicies::REQUIRED_ALWAYS: {
  5200. std::ostringstream e;
  5201. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  5202. << "Target \"" << this->GetName() << "\" links to item \"" << item
  5203. << "\" which has leading or trailing whitespace.";
  5204. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  5205. this->GetBacktrace());
  5206. } break;
  5207. }
  5208. }
  5209. return lib;
  5210. }
  5211. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  5212. const std::string& config) const
  5213. {
  5214. std::vector<cmSourceFile*> sourceFiles;
  5215. this->GetSourceFiles(sourceFiles, config);
  5216. for (cmSourceFile* src : sourceFiles) {
  5217. const std::string& lang = src->GetLanguage();
  5218. if (!lang.empty()) {
  5219. languages.insert(lang);
  5220. }
  5221. }
  5222. std::vector<cmGeneratorTarget*> objectLibraries;
  5223. std::vector<cmSourceFile const*> externalObjects;
  5224. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  5225. std::vector<cmGeneratorTarget*> objectTargets;
  5226. this->GetObjectLibrariesCMP0026(objectTargets);
  5227. objectLibraries.reserve(objectTargets.size());
  5228. for (cmGeneratorTarget* gt : objectTargets) {
  5229. objectLibraries.push_back(gt);
  5230. }
  5231. } else {
  5232. this->GetExternalObjects(externalObjects, config);
  5233. for (cmSourceFile const* extObj : externalObjects) {
  5234. std::string objLib = extObj->GetObjectLibrary();
  5235. if (cmGeneratorTarget* tgt =
  5236. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  5237. auto const objLibIt =
  5238. std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
  5239. [tgt](cmGeneratorTarget* t) { return t == tgt; });
  5240. if (objectLibraries.cend() == objLibIt) {
  5241. objectLibraries.push_back(tgt);
  5242. }
  5243. }
  5244. }
  5245. }
  5246. for (cmGeneratorTarget* objLib : objectLibraries) {
  5247. objLib->GetLanguages(languages, config);
  5248. }
  5249. }
  5250. bool cmGeneratorTarget::IsCSharpOnly() const
  5251. {
  5252. // Only certain target types may compile CSharp.
  5253. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  5254. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  5255. this->GetType() != cmStateEnums::EXECUTABLE) {
  5256. return false;
  5257. }
  5258. std::set<std::string> languages;
  5259. this->GetLanguages(languages, "");
  5260. // Consider an explicit linker language property, but *not* the
  5261. // computed linker language that may depend on linked targets.
  5262. const char* linkLang = this->GetProperty("LINKER_LANGUAGE");
  5263. if (linkLang && *linkLang) {
  5264. languages.insert(linkLang);
  5265. }
  5266. return languages.size() == 1 && languages.count("CSharp") > 0;
  5267. }
  5268. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  5269. const std::string& config, cmOptionalLinkImplementation& impl) const
  5270. {
  5271. // This target needs runtime libraries for its source languages.
  5272. std::set<std::string> languages;
  5273. // Get languages used in our source files.
  5274. this->GetLanguages(languages, config);
  5275. // Copy the set of languages to the link implementation.
  5276. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  5277. languages.end());
  5278. }
  5279. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  5280. {
  5281. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  5282. return false;
  5283. }
  5284. if (this->GetProperty("BUILD_RPATH")) {
  5285. return true;
  5286. }
  5287. if (cmLinkImplementationLibraries const* impl =
  5288. this->GetLinkImplementationLibraries(config)) {
  5289. return !impl->Libraries.empty();
  5290. }
  5291. return false;
  5292. }
  5293. cmLinkImplementationLibraries const*
  5294. cmGeneratorTarget::GetLinkImplementationLibraries(
  5295. const std::string& config) const
  5296. {
  5297. return this->GetLinkImplementationLibrariesInternal(config, this);
  5298. }
  5299. cmLinkImplementationLibraries const*
  5300. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  5301. const std::string& config, cmGeneratorTarget const* head) const
  5302. {
  5303. // There is no link implementation for imported targets.
  5304. if (this->IsImported()) {
  5305. return nullptr;
  5306. }
  5307. // Populate the link implementation libraries for this configuration.
  5308. std::string CONFIG = cmSystemTools::UpperCase(config);
  5309. HeadToLinkImplementationMap& hm = this->LinkImplMap[CONFIG];
  5310. // If the link implementation does not depend on the head target
  5311. // then return the one we computed first.
  5312. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  5313. return &hm.begin()->second;
  5314. }
  5315. cmOptionalLinkImplementation& impl = hm[head];
  5316. if (!impl.LibrariesDone) {
  5317. impl.LibrariesDone = true;
  5318. this->ComputeLinkImplementationLibraries(config, impl, head);
  5319. }
  5320. return &impl;
  5321. }
  5322. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  5323. const std::string& p) const
  5324. {
  5325. return this->LinkImplicitNullProperties.find(p) !=
  5326. this->LinkImplicitNullProperties.end();
  5327. }
  5328. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  5329. const std::string& config, cmOptionalLinkImplementation& impl,
  5330. cmGeneratorTarget const* head) const
  5331. {
  5332. cmStringRange entryRange = this->Target->GetLinkImplementationEntries();
  5333. cmBacktraceRange btRange = this->Target->GetLinkImplementationBacktraces();
  5334. cmBacktraceRange::const_iterator btIt = btRange.begin();
  5335. // Collect libraries directly linked in this configuration.
  5336. for (cmStringRange::const_iterator le = entryRange.begin(),
  5337. end = entryRange.end();
  5338. le != end; ++le, ++btIt) {
  5339. std::vector<std::string> llibs;
  5340. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
  5341. nullptr);
  5342. cmGeneratorExpression ge(*btIt);
  5343. std::unique_ptr<cmCompiledGeneratorExpression> const cge = ge.Parse(*le);
  5344. std::string const& evaluated =
  5345. cge->Evaluate(this->LocalGenerator, config, false, head, &dagChecker);
  5346. cmSystemTools::ExpandListArgument(evaluated, llibs);
  5347. if (cge->GetHadHeadSensitiveCondition()) {
  5348. impl.HadHeadSensitiveCondition = true;
  5349. }
  5350. for (std::string const& lib : llibs) {
  5351. // Skip entries that resolve to the target itself or are empty.
  5352. std::string name = this->CheckCMP0004(lib);
  5353. if (name == this->GetName() || name.empty()) {
  5354. if (name == this->GetName()) {
  5355. bool noMessage = false;
  5356. MessageType messageType = MessageType::FATAL_ERROR;
  5357. std::ostringstream e;
  5358. switch (this->GetPolicyStatusCMP0038()) {
  5359. case cmPolicies::WARN: {
  5360. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  5361. messageType = MessageType::AUTHOR_WARNING;
  5362. } break;
  5363. case cmPolicies::OLD:
  5364. noMessage = true;
  5365. case cmPolicies::REQUIRED_IF_USED:
  5366. case cmPolicies::REQUIRED_ALWAYS:
  5367. case cmPolicies::NEW:
  5368. // Issue the fatal message.
  5369. break;
  5370. }
  5371. if (!noMessage) {
  5372. e << "Target \"" << this->GetName() << "\" links to itself.";
  5373. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5374. messageType, e.str(), this->GetBacktrace());
  5375. if (messageType == MessageType::FATAL_ERROR) {
  5376. return;
  5377. }
  5378. }
  5379. }
  5380. continue;
  5381. }
  5382. // The entry is meant for this configuration.
  5383. impl.Libraries.emplace_back(this->ResolveLinkItem(name, *btIt),
  5384. evaluated != *le);
  5385. }
  5386. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  5387. for (std::string const& sp : seenProps) {
  5388. if (!this->GetProperty(sp)) {
  5389. this->LinkImplicitNullProperties.insert(sp);
  5390. }
  5391. }
  5392. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  5393. }
  5394. // Get the list of configurations considered to be DEBUG.
  5395. std::vector<std::string> debugConfigs =
  5396. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  5397. cmTargetLinkLibraryType linkType =
  5398. CMP0003_ComputeLinkType(config, debugConfigs);
  5399. cmTarget::LinkLibraryVectorType const& oldllibs =
  5400. this->Target->GetOriginalLinkLibraries();
  5401. for (cmTarget::LibraryID const& oldllib : oldllibs) {
  5402. if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
  5403. std::string name = this->CheckCMP0004(oldllib.first);
  5404. if (name == this->GetName() || name.empty()) {
  5405. continue;
  5406. }
  5407. // Support OLD behavior for CMP0003.
  5408. impl.WrongConfigLibraries.push_back(
  5409. this->ResolveLinkItem(name, cmListFileBacktrace()));
  5410. }
  5411. }
  5412. }
  5413. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  5414. std::string const& name) const
  5415. {
  5416. cmLocalGenerator const* lg = this->LocalGenerator;
  5417. std::string const* lookupName = &name;
  5418. // When target_link_libraries() is called with a LHS target that is
  5419. // not created in the calling directory it adds a directory id suffix
  5420. // that we can use to look up the calling directory. It is that scope
  5421. // in which the item name is meaningful. This case is relatively rare
  5422. // so we allocate a separate string only when the directory id is present.
  5423. std::string::size_type pos = name.find(CMAKE_DIRECTORY_ID_SEP);
  5424. std::string plainName;
  5425. if (pos != std::string::npos) {
  5426. // We will look up the plain name without the directory id suffix.
  5427. plainName = name.substr(0, pos);
  5428. // We will look up in the scope of the directory id.
  5429. // If we do not recognize the id then leave the original
  5430. // syntax in place to produce an indicative error later.
  5431. cmDirectoryId const dirId =
  5432. name.substr(pos + sizeof(CMAKE_DIRECTORY_ID_SEP) - 1);
  5433. if (cmLocalGenerator const* otherLG =
  5434. this->GlobalGenerator->FindLocalGenerator(dirId)) {
  5435. lg = otherLG;
  5436. lookupName = &plainName;
  5437. }
  5438. }
  5439. TargetOrString resolved;
  5440. if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(*lookupName)) {
  5441. resolved.Target = tgt;
  5442. } else if (lookupName == &plainName) {
  5443. resolved.String = std::move(plainName);
  5444. } else {
  5445. resolved.String = name;
  5446. }
  5447. return resolved;
  5448. }
  5449. cmLinkItem cmGeneratorTarget::ResolveLinkItem(
  5450. std::string const& name, cmListFileBacktrace const& bt) const
  5451. {
  5452. TargetOrString resolved = this->ResolveTargetReference(name);
  5453. if (!resolved.Target) {
  5454. return cmLinkItem(resolved.String, bt);
  5455. }
  5456. // Skip targets that will not really be linked. This is probably a
  5457. // name conflict between an external library and an executable
  5458. // within the project.
  5459. if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
  5460. !resolved.Target->IsExecutableWithExports()) {
  5461. return cmLinkItem(resolved.Target->GetName(), bt);
  5462. }
  5463. return cmLinkItem(resolved.Target, bt);
  5464. }
  5465. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  5466. {
  5467. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  5468. // Return the directory in which the target will be built.
  5469. return info->PdbDir;
  5470. }
  5471. return "";
  5472. }
  5473. bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
  5474. {
  5475. return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
  5476. }
  5477. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
  5478. std::string const& gnuName,
  5479. std::string& out,
  5480. const char* newExt) const
  5481. {
  5482. if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
  5483. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  5484. out = gnuName.substr(0, gnuName.size() - 6);
  5485. out += newExt ? newExt : ".lib";
  5486. return true;
  5487. }
  5488. return false;
  5489. }
  5490. bool cmGeneratorTarget::IsExecutableWithExports() const
  5491. {
  5492. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  5493. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  5494. }
  5495. bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
  5496. {
  5497. return (this->IsDLLPlatform() &&
  5498. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5499. this->IsExecutableWithExports()) &&
  5500. // Assemblies which have only managed code do not have
  5501. // import libraries.
  5502. this->GetManagedType(config) != ManagedType::Managed);
  5503. }
  5504. std::string cmGeneratorTarget::GetSupportDirectory() const
  5505. {
  5506. std::string dir = this->LocalGenerator->GetCurrentBinaryDirectory();
  5507. dir += "/CMakeFiles";
  5508. dir += "/";
  5509. dir += this->GetName();
  5510. #if defined(__VMS)
  5511. dir += "_dir";
  5512. #else
  5513. dir += ".dir";
  5514. #endif
  5515. return dir;
  5516. }
  5517. bool cmGeneratorTarget::IsLinkable() const
  5518. {
  5519. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  5520. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5521. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  5522. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  5523. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5524. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  5525. this->IsExecutableWithExports());
  5526. }
  5527. bool cmGeneratorTarget::IsFrameworkOnApple() const
  5528. {
  5529. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  5530. this->GetType() == cmStateEnums::STATIC_LIBRARY) &&
  5531. this->Makefile->IsOn("APPLE") &&
  5532. this->GetPropertyAsBool("FRAMEWORK"));
  5533. }
  5534. bool cmGeneratorTarget::IsAppBundleOnApple() const
  5535. {
  5536. return (this->GetType() == cmStateEnums::EXECUTABLE &&
  5537. this->Makefile->IsOn("APPLE") &&
  5538. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  5539. }
  5540. bool cmGeneratorTarget::IsXCTestOnApple() const
  5541. {
  5542. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  5543. }
  5544. bool cmGeneratorTarget::IsCFBundleOnApple() const
  5545. {
  5546. return (this->GetType() == cmStateEnums::MODULE_LIBRARY &&
  5547. this->Makefile->IsOn("APPLE") && this->GetPropertyAsBool("BUNDLE"));
  5548. }
  5549. cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
  5550. std::string const& propval) const
  5551. {
  5552. // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
  5553. // or only C++/CLI) does only depend on whether the property is an empty
  5554. // string or contains any value at all. In Visual Studio generators
  5555. // this propval is prepended with /clr[:] which results in:
  5556. //
  5557. // 1. propval does not exist: no /clr flag, unmanaged target, has import
  5558. // lib
  5559. // 2. empty propval: add /clr as flag, mixed unmanaged/managed
  5560. // target, has import lib
  5561. // 3. any value (safe,pure): add /clr:[propval] as flag, target with
  5562. // managed code only, no import lib
  5563. return propval.empty() ? ManagedType::Mixed : ManagedType::Managed;
  5564. }
  5565. cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
  5566. const std::string& config) const
  5567. {
  5568. // Only libraries and executables can be managed targets.
  5569. if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
  5570. return ManagedType::Undefined;
  5571. }
  5572. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  5573. return ManagedType::Native;
  5574. }
  5575. // Check imported target.
  5576. if (this->IsImported()) {
  5577. if (cmGeneratorTarget::ImportInfo const* info =
  5578. this->GetImportInfo(config)) {
  5579. return info->Managed;
  5580. }
  5581. return ManagedType::Undefined;
  5582. }
  5583. // Check for explicitly set clr target property.
  5584. if (auto* clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  5585. return this->CheckManagedType(clr);
  5586. }
  5587. // C# targets are always managed. This language specific check
  5588. // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
  5589. // has to be set manually for C# targets.
  5590. return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
  5591. }