cmGeneratorTarget.cxx 313 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378
  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 <algorithm>
  5. #include <array>
  6. #include <cassert>
  7. #include <cerrno>
  8. #include <cstddef>
  9. #include <cstdio>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <iterator>
  13. #include <queue>
  14. #include <sstream>
  15. #include <type_traits>
  16. #include <unordered_set>
  17. #include <utility>
  18. #include <cm/memory>
  19. #include <cm/optional>
  20. #include <cm/string_view>
  21. #include <cmext/algorithm>
  22. #include <cmext/string_view>
  23. #include "cmsys/RegularExpression.hxx"
  24. #include "cmAlgorithms.h"
  25. #include "cmComputeLinkInformation.h"
  26. #include "cmCryptoHash.h"
  27. #include "cmCustomCommandGenerator.h"
  28. #include "cmCxxModuleUsageEffects.h"
  29. #include "cmEvaluatedTargetProperty.h"
  30. #include "cmFileSet.h"
  31. #include "cmFileTimes.h"
  32. #include "cmGeneratedFileStream.h"
  33. #include "cmGeneratorExpression.h"
  34. #include "cmGeneratorExpressionContext.h"
  35. #include "cmGeneratorExpressionDAGChecker.h"
  36. #include "cmGeneratorExpressionNode.h"
  37. #include "cmGlobalGenerator.h"
  38. #include "cmList.h"
  39. #include "cmLocalGenerator.h"
  40. #include "cmMakefile.h"
  41. #include "cmMessageType.h"
  42. #include "cmOutputConverter.h"
  43. #include "cmPropertyMap.h"
  44. #include "cmRange.h"
  45. #include "cmSourceFile.h"
  46. #include "cmSourceFileLocation.h"
  47. #include "cmSourceFileLocationKind.h"
  48. #include "cmSourceGroup.h"
  49. #include "cmStandardLevel.h"
  50. #include "cmStandardLevelResolver.h"
  51. #include "cmState.h"
  52. #include "cmStringAlgorithms.h"
  53. #include "cmSyntheticTargetCache.h"
  54. #include "cmSystemTools.h"
  55. #include "cmTarget.h"
  56. #include "cmTargetLinkLibraryType.h"
  57. #include "cmTargetPropertyComputer.h"
  58. #include "cmake.h"
  59. namespace {
  60. using LinkInterfaceFor = cmGeneratorTarget::LinkInterfaceFor;
  61. const std::string kINTERFACE_LINK_LIBRARIES = "INTERFACE_LINK_LIBRARIES";
  62. const std::string kINTERFACE_LINK_LIBRARIES_DIRECT =
  63. "INTERFACE_LINK_LIBRARIES_DIRECT";
  64. const std::string kINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE =
  65. "INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE";
  66. }
  67. template <>
  68. cmValue cmTargetPropertyComputer::GetSources<cmGeneratorTarget>(
  69. cmGeneratorTarget const* tgt, cmMakefile const& /* mf */)
  70. {
  71. return tgt->GetSourcesProperty();
  72. }
  73. template <>
  74. const std::string&
  75. cmTargetPropertyComputer::ComputeLocationForBuild<cmGeneratorTarget>(
  76. cmGeneratorTarget const* tgt)
  77. {
  78. return tgt->GetLocation("");
  79. }
  80. template <>
  81. const std::string&
  82. cmTargetPropertyComputer::ComputeLocation<cmGeneratorTarget>(
  83. cmGeneratorTarget const* tgt, const std::string& config)
  84. {
  85. return tgt->GetLocation(config);
  86. }
  87. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  88. class TargetPropertyEntryString : public cmGeneratorTarget::TargetPropertyEntry
  89. {
  90. public:
  91. TargetPropertyEntryString(BT<std::string> propertyValue,
  92. cmLinkImplItem const& item = NoLinkImplItem)
  93. : cmGeneratorTarget::TargetPropertyEntry(item)
  94. , PropertyValue(std::move(propertyValue))
  95. {
  96. }
  97. const std::string& Evaluate(cmLocalGenerator*, const std::string&,
  98. cmGeneratorTarget const*,
  99. cmGeneratorExpressionDAGChecker*,
  100. std::string const&) const override
  101. {
  102. return this->PropertyValue.Value;
  103. }
  104. cmListFileBacktrace GetBacktrace() const override
  105. {
  106. return this->PropertyValue.Backtrace;
  107. }
  108. std::string const& GetInput() const override
  109. {
  110. return this->PropertyValue.Value;
  111. }
  112. private:
  113. BT<std::string> PropertyValue;
  114. };
  115. class TargetPropertyEntryGenex : public cmGeneratorTarget::TargetPropertyEntry
  116. {
  117. public:
  118. TargetPropertyEntryGenex(std::unique_ptr<cmCompiledGeneratorExpression> cge,
  119. cmLinkImplItem const& item = NoLinkImplItem)
  120. : cmGeneratorTarget::TargetPropertyEntry(item)
  121. , ge(std::move(cge))
  122. {
  123. }
  124. const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config,
  125. cmGeneratorTarget const* headTarget,
  126. cmGeneratorExpressionDAGChecker* dagChecker,
  127. std::string const& language) const override
  128. {
  129. return this->ge->Evaluate(lg, config, headTarget, dagChecker, nullptr,
  130. language);
  131. }
  132. cmListFileBacktrace GetBacktrace() const override
  133. {
  134. return this->ge->GetBacktrace();
  135. }
  136. std::string const& GetInput() const override { return this->ge->GetInput(); }
  137. bool GetHadContextSensitiveCondition() const override
  138. {
  139. return this->ge->GetHadContextSensitiveCondition();
  140. }
  141. private:
  142. const std::unique_ptr<cmCompiledGeneratorExpression> ge;
  143. };
  144. class TargetPropertyEntryFileSet
  145. : public cmGeneratorTarget::TargetPropertyEntry
  146. {
  147. public:
  148. TargetPropertyEntryFileSet(
  149. std::vector<std::string> dirs, bool contextSensitiveDirs,
  150. std::unique_ptr<cmCompiledGeneratorExpression> entryCge,
  151. const cmFileSet* fileSet, cmLinkImplItem const& item = NoLinkImplItem)
  152. : cmGeneratorTarget::TargetPropertyEntry(item)
  153. , BaseDirs(std::move(dirs))
  154. , ContextSensitiveDirs(contextSensitiveDirs)
  155. , EntryCge(std::move(entryCge))
  156. , FileSet(fileSet)
  157. {
  158. }
  159. const std::string& Evaluate(cmLocalGenerator* lg, const std::string& config,
  160. cmGeneratorTarget const* headTarget,
  161. cmGeneratorExpressionDAGChecker* dagChecker,
  162. std::string const& /*lang*/) const override
  163. {
  164. std::map<std::string, std::vector<std::string>> filesPerDir;
  165. this->FileSet->EvaluateFileEntry(this->BaseDirs, filesPerDir,
  166. this->EntryCge, lg, config, headTarget,
  167. dagChecker);
  168. std::vector<std::string> files;
  169. for (auto const& it : filesPerDir) {
  170. files.insert(files.end(), it.second.begin(), it.second.end());
  171. }
  172. static std::string filesStr;
  173. filesStr = cmList::to_string(files);
  174. return filesStr;
  175. }
  176. cmListFileBacktrace GetBacktrace() const override
  177. {
  178. return this->EntryCge->GetBacktrace();
  179. }
  180. std::string const& GetInput() const override
  181. {
  182. return this->EntryCge->GetInput();
  183. }
  184. bool GetHadContextSensitiveCondition() const override
  185. {
  186. return this->ContextSensitiveDirs ||
  187. this->EntryCge->GetHadContextSensitiveCondition();
  188. }
  189. private:
  190. const std::vector<std::string> BaseDirs;
  191. const bool ContextSensitiveDirs;
  192. const std::unique_ptr<cmCompiledGeneratorExpression> EntryCge;
  193. const cmFileSet* FileSet;
  194. };
  195. std::unique_ptr<
  196. cmGeneratorTarget::
  197. TargetPropertyEntry> static CreateTargetPropertyEntry(cmake& cmakeInstance,
  198. const BT<
  199. std::string>&
  200. propertyValue,
  201. bool
  202. evaluateForBuildsystem =
  203. false)
  204. {
  205. if (cmGeneratorExpression::Find(propertyValue.Value) != std::string::npos) {
  206. cmGeneratorExpression ge(cmakeInstance, propertyValue.Backtrace);
  207. std::unique_ptr<cmCompiledGeneratorExpression> cge =
  208. ge.Parse(propertyValue.Value);
  209. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  210. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  211. cm::make_unique<TargetPropertyEntryGenex>(std::move(cge)));
  212. }
  213. return std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>(
  214. cm::make_unique<TargetPropertyEntryString>(propertyValue));
  215. }
  216. cmGeneratorTarget::TargetPropertyEntry::TargetPropertyEntry(
  217. cmLinkImplItem const& item)
  218. : LinkImplItem(item)
  219. {
  220. }
  221. bool cmGeneratorTarget::TargetPropertyEntry::GetHadContextSensitiveCondition()
  222. const
  223. {
  224. return false;
  225. }
  226. static void CreatePropertyGeneratorExpressions(
  227. cmake& cmakeInstance, cmBTStringRange entries,
  228. std::vector<std::unique_ptr<cmGeneratorTarget::TargetPropertyEntry>>& items,
  229. bool evaluateForBuildsystem = false)
  230. {
  231. for (auto const& entry : entries) {
  232. items.push_back(
  233. CreateTargetPropertyEntry(cmakeInstance, entry, evaluateForBuildsystem));
  234. }
  235. }
  236. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  237. : Target(t)
  238. {
  239. this->Makefile = this->Target->GetMakefile();
  240. this->LocalGenerator = lg;
  241. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  242. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  243. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  244. t->GetIncludeDirectoriesEntries(),
  245. this->IncludeDirectoriesEntries);
  246. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  247. t->GetCompileOptionsEntries(),
  248. this->CompileOptionsEntries);
  249. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  250. t->GetCompileFeaturesEntries(),
  251. this->CompileFeaturesEntries);
  252. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  253. t->GetCompileDefinitionsEntries(),
  254. this->CompileDefinitionsEntries);
  255. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  256. t->GetLinkOptionsEntries(),
  257. this->LinkOptionsEntries);
  258. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  259. t->GetLinkDirectoriesEntries(),
  260. this->LinkDirectoriesEntries);
  261. CreatePropertyGeneratorExpressions(*lg->GetCMakeInstance(),
  262. t->GetPrecompileHeadersEntries(),
  263. this->PrecompileHeadersEntries);
  264. CreatePropertyGeneratorExpressions(
  265. *lg->GetCMakeInstance(), t->GetSourceEntries(), this->SourceEntries, true);
  266. this->PolicyMap = t->GetPolicyMap();
  267. // Get hard-coded linker language
  268. if (this->Target->GetProperty("HAS_CXX")) {
  269. this->LinkerLanguage = "CXX";
  270. } else {
  271. this->LinkerLanguage = this->Target->GetSafeProperty("LINKER_LANGUAGE");
  272. }
  273. }
  274. cmGeneratorTarget::~cmGeneratorTarget() = default;
  275. cmValue cmGeneratorTarget::GetSourcesProperty() const
  276. {
  277. std::vector<std::string> values;
  278. for (auto const& se : this->SourceEntries) {
  279. values.push_back(se->GetInput());
  280. }
  281. static std::string value;
  282. value = cmList::to_string(values);
  283. return cmValue(value);
  284. }
  285. cmGlobalGenerator* cmGeneratorTarget::GetGlobalGenerator() const
  286. {
  287. return this->GetLocalGenerator()->GetGlobalGenerator();
  288. }
  289. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  290. {
  291. return this->LocalGenerator;
  292. }
  293. cmStateEnums::TargetType cmGeneratorTarget::GetType() const
  294. {
  295. return this->Target->GetType();
  296. }
  297. const std::string& cmGeneratorTarget::GetName() const
  298. {
  299. return this->Target->GetName();
  300. }
  301. std::string cmGeneratorTarget::GetExportName() const
  302. {
  303. cmValue exportName = this->GetProperty("EXPORT_NAME");
  304. if (cmNonempty(exportName)) {
  305. if (!cmGeneratorExpression::IsValidTargetName(*exportName)) {
  306. std::ostringstream e;
  307. e << "EXPORT_NAME property \"" << *exportName << "\" for \""
  308. << this->GetName() << "\": is not valid.";
  309. cmSystemTools::Error(e.str());
  310. return "";
  311. }
  312. return *exportName;
  313. }
  314. return this->GetName();
  315. }
  316. cmValue cmGeneratorTarget::GetProperty(const std::string& prop) const
  317. {
  318. if (cmValue result =
  319. cmTargetPropertyComputer::GetProperty(this, prop, *this->Makefile)) {
  320. return result;
  321. }
  322. if (cmSystemTools::GetFatalErrorOccurred()) {
  323. return nullptr;
  324. }
  325. return this->Target->GetProperty(prop);
  326. }
  327. std::string const& cmGeneratorTarget::GetSafeProperty(
  328. std::string const& prop) const
  329. {
  330. return this->GetProperty(prop);
  331. }
  332. const char* cmGeneratorTarget::GetOutputTargetType(
  333. cmStateEnums::ArtifactType artifact) const
  334. {
  335. if (this->IsFrameworkOnApple() || this->GetGlobalGenerator()->IsXcode()) {
  336. // import file (i.e. .tbd file) is always in same location as library
  337. artifact = cmStateEnums::RuntimeBinaryArtifact;
  338. }
  339. switch (this->GetType()) {
  340. case cmStateEnums::SHARED_LIBRARY:
  341. if (this->IsDLLPlatform()) {
  342. switch (artifact) {
  343. case cmStateEnums::RuntimeBinaryArtifact:
  344. // A DLL shared library is treated as a runtime target.
  345. return "RUNTIME";
  346. case cmStateEnums::ImportLibraryArtifact:
  347. // A DLL import library is treated as an archive target.
  348. return "ARCHIVE";
  349. }
  350. } else {
  351. switch (artifact) {
  352. case cmStateEnums::RuntimeBinaryArtifact:
  353. // For non-DLL platforms shared libraries are treated as
  354. // library targets.
  355. return "LIBRARY";
  356. case cmStateEnums::ImportLibraryArtifact:
  357. // Library import libraries are treated as archive targets.
  358. return "ARCHIVE";
  359. }
  360. }
  361. break;
  362. case cmStateEnums::STATIC_LIBRARY:
  363. // Static libraries are always treated as archive targets.
  364. return "ARCHIVE";
  365. case cmStateEnums::MODULE_LIBRARY:
  366. switch (artifact) {
  367. case cmStateEnums::RuntimeBinaryArtifact:
  368. // Module libraries are always treated as library targets.
  369. return "LIBRARY";
  370. case cmStateEnums::ImportLibraryArtifact:
  371. // Module import libraries are treated as archive targets.
  372. return "ARCHIVE";
  373. }
  374. break;
  375. case cmStateEnums::OBJECT_LIBRARY:
  376. // Object libraries are always treated as object targets.
  377. return "OBJECT";
  378. case cmStateEnums::EXECUTABLE:
  379. switch (artifact) {
  380. case cmStateEnums::RuntimeBinaryArtifact:
  381. // Executables are always treated as runtime targets.
  382. return "RUNTIME";
  383. case cmStateEnums::ImportLibraryArtifact:
  384. // Executable import libraries are treated as archive targets.
  385. return "ARCHIVE";
  386. }
  387. break;
  388. default:
  389. break;
  390. }
  391. return "";
  392. }
  393. std::string cmGeneratorTarget::GetOutputName(
  394. const std::string& config, cmStateEnums::ArtifactType artifact) const
  395. {
  396. // Lookup/compute/cache the output name for this configuration.
  397. OutputNameKey key(config, artifact);
  398. auto i = this->OutputNameMap.find(key);
  399. if (i == this->OutputNameMap.end()) {
  400. // Add empty name in map to detect potential recursion.
  401. OutputNameMapType::value_type entry(key, "");
  402. i = this->OutputNameMap.insert(entry).first;
  403. // Compute output name.
  404. std::vector<std::string> props;
  405. std::string type = this->GetOutputTargetType(artifact);
  406. std::string configUpper = cmSystemTools::UpperCase(config);
  407. if (!type.empty() && !configUpper.empty()) {
  408. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  409. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  410. }
  411. if (!type.empty()) {
  412. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  413. props.push_back(type + "_OUTPUT_NAME");
  414. }
  415. if (!configUpper.empty()) {
  416. // OUTPUT_NAME_<CONFIG>
  417. props.push_back("OUTPUT_NAME_" + configUpper);
  418. // <CONFIG>_OUTPUT_NAME
  419. props.push_back(configUpper + "_OUTPUT_NAME");
  420. }
  421. // OUTPUT_NAME
  422. props.emplace_back("OUTPUT_NAME");
  423. std::string outName;
  424. for (std::string const& p : props) {
  425. if (cmValue outNameProp = this->GetProperty(p)) {
  426. outName = *outNameProp;
  427. break;
  428. }
  429. }
  430. if (outName.empty()) {
  431. outName = this->GetName();
  432. }
  433. // Now evaluate genex and update the previously-prepared map entry.
  434. i->second =
  435. cmGeneratorExpression::Evaluate(outName, this->LocalGenerator, config);
  436. } else if (i->second.empty()) {
  437. // An empty map entry indicates we have been called recursively
  438. // from the above block.
  439. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  440. MessageType::FATAL_ERROR,
  441. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  442. this->GetBacktrace());
  443. }
  444. return i->second;
  445. }
  446. std::string cmGeneratorTarget::GetFilePrefix(
  447. const std::string& config, cmStateEnums::ArtifactType artifact) const
  448. {
  449. if (this->IsImported()) {
  450. cmValue prefix = this->GetFilePrefixInternal(config, artifact);
  451. return prefix ? *prefix : std::string();
  452. }
  453. return this->GetFullNameInternalComponents(config, artifact).prefix;
  454. }
  455. std::string cmGeneratorTarget::GetFileSuffix(
  456. const std::string& config, cmStateEnums::ArtifactType artifact) const
  457. {
  458. if (this->IsImported()) {
  459. cmValue suffix = this->GetFileSuffixInternal(config, artifact);
  460. return suffix ? *suffix : std::string();
  461. }
  462. return this->GetFullNameInternalComponents(config, artifact).suffix;
  463. }
  464. std::string cmGeneratorTarget::GetFilePostfix(const std::string& config) const
  465. {
  466. cmValue postfix = nullptr;
  467. std::string frameworkPostfix;
  468. if (!config.empty()) {
  469. std::string configProp =
  470. cmStrCat(cmSystemTools::UpperCase(config), "_POSTFIX");
  471. postfix = this->GetProperty(configProp);
  472. // Mac application bundles and frameworks have no regular postfix like
  473. // libraries do.
  474. if (!this->IsImported() && postfix &&
  475. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple())) {
  476. postfix = nullptr;
  477. }
  478. // Frameworks created by multi config generators can have a special
  479. // framework postfix.
  480. frameworkPostfix = this->GetFrameworkMultiConfigPostfix(config);
  481. if (!frameworkPostfix.empty()) {
  482. postfix = cmValue(frameworkPostfix);
  483. }
  484. }
  485. return postfix ? *postfix : std::string();
  486. }
  487. std::string cmGeneratorTarget::GetFrameworkMultiConfigPostfix(
  488. const std::string& config) const
  489. {
  490. cmValue postfix = nullptr;
  491. if (!config.empty()) {
  492. std::string configProp = cmStrCat("FRAMEWORK_MULTI_CONFIG_POSTFIX_",
  493. cmSystemTools::UpperCase(config));
  494. postfix = this->GetProperty(configProp);
  495. if (!this->IsImported() && postfix &&
  496. (this->IsFrameworkOnApple() &&
  497. !this->GetGlobalGenerator()->IsMultiConfig())) {
  498. postfix = nullptr;
  499. }
  500. }
  501. return postfix ? *postfix : std::string();
  502. }
  503. cmValue cmGeneratorTarget::GetFilePrefixInternal(
  504. std::string const& config, cmStateEnums::ArtifactType artifact,
  505. const std::string& language) const
  506. {
  507. // no prefix for non-main target types.
  508. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  509. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  510. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  511. this->GetType() != cmStateEnums::EXECUTABLE) {
  512. return nullptr;
  513. }
  514. const bool isImportedLibraryArtifact =
  515. (artifact == cmStateEnums::ImportLibraryArtifact);
  516. // Return an empty prefix for the import library if this platform
  517. // does not support import libraries.
  518. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  519. return nullptr;
  520. }
  521. // The implib option is only allowed for shared libraries, module
  522. // libraries, and executables.
  523. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  524. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  525. this->GetType() != cmStateEnums::EXECUTABLE) {
  526. artifact = cmStateEnums::RuntimeBinaryArtifact;
  527. }
  528. // Compute prefix value.
  529. cmValue targetPrefix =
  530. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_PREFIX")
  531. : this->GetProperty("PREFIX"));
  532. if (!targetPrefix) {
  533. const char* prefixVar = this->Target->GetPrefixVariableInternal(artifact);
  534. if (!language.empty() && cmNonempty(prefixVar)) {
  535. std::string langPrefix = cmStrCat(prefixVar, "_", language);
  536. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  537. }
  538. // if there is no prefix on the target nor specific language
  539. // use the cmake definition.
  540. if (!targetPrefix && prefixVar) {
  541. targetPrefix = this->Makefile->GetDefinition(prefixVar);
  542. }
  543. }
  544. return targetPrefix;
  545. }
  546. cmValue cmGeneratorTarget::GetFileSuffixInternal(
  547. std::string const& config, cmStateEnums::ArtifactType artifact,
  548. const std::string& language) const
  549. {
  550. // no suffix for non-main target types.
  551. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  552. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  553. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  554. this->GetType() != cmStateEnums::EXECUTABLE) {
  555. return nullptr;
  556. }
  557. const bool isImportedLibraryArtifact =
  558. (artifact == cmStateEnums::ImportLibraryArtifact);
  559. // Return an empty suffix for the import library if this platform
  560. // does not support import libraries.
  561. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  562. return nullptr;
  563. }
  564. // The implib option is only allowed for shared libraries, module
  565. // libraries, and executables.
  566. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  567. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  568. this->GetType() != cmStateEnums::EXECUTABLE) {
  569. artifact = cmStateEnums::RuntimeBinaryArtifact;
  570. }
  571. // Compute suffix value.
  572. cmValue targetSuffix =
  573. (isImportedLibraryArtifact ? this->GetProperty("IMPORT_SUFFIX")
  574. : this->GetProperty("SUFFIX"));
  575. if (!targetSuffix) {
  576. const char* suffixVar = this->Target->GetSuffixVariableInternal(artifact);
  577. if (!language.empty() && cmNonempty(suffixVar)) {
  578. std::string langSuffix = cmStrCat(suffixVar, "_", language);
  579. targetSuffix = this->Makefile->GetDefinition(langSuffix);
  580. }
  581. // if there is no suffix on the target nor specific language
  582. // use the cmake definition.
  583. if (!targetSuffix && suffixVar) {
  584. targetSuffix = this->Makefile->GetDefinition(suffixVar);
  585. }
  586. }
  587. return targetSuffix;
  588. }
  589. void cmGeneratorTarget::ClearSourcesCache()
  590. {
  591. this->AllConfigSources.clear();
  592. this->KindedSourcesMap.clear();
  593. this->SourcesAreContextDependent = Tribool::Indeterminate;
  594. this->Objects.clear();
  595. this->VisitedConfigsForObjects.clear();
  596. this->LinkImplMap.clear();
  597. this->LinkImplUsageRequirementsOnlyMap.clear();
  598. this->IncludeDirectoriesCache.clear();
  599. this->CompileOptionsCache.clear();
  600. this->CompileDefinitionsCache.clear();
  601. this->PrecompileHeadersCache.clear();
  602. this->LinkOptionsCache.clear();
  603. this->LinkDirectoriesCache.clear();
  604. this->RuntimeBinaryFullNameCache.clear();
  605. this->ImportLibraryFullNameCache.clear();
  606. }
  607. void cmGeneratorTarget::ClearLinkInterfaceCache()
  608. {
  609. this->LinkInterfaceMap.clear();
  610. this->LinkInterfaceUsageRequirementsOnlyMap.clear();
  611. }
  612. void cmGeneratorTarget::AddSourceCommon(const std::string& src, bool before)
  613. {
  614. this->SourceEntries.insert(
  615. before ? this->SourceEntries.begin() : this->SourceEntries.end(),
  616. CreateTargetPropertyEntry(
  617. *this->LocalGenerator->GetCMakeInstance(),
  618. BT<std::string>(src, this->Makefile->GetBacktrace()), true));
  619. this->ClearSourcesCache();
  620. }
  621. void cmGeneratorTarget::AddSource(const std::string& src, bool before)
  622. {
  623. this->Target->AddSource(src, before);
  624. this->AddSourceCommon(src, before);
  625. }
  626. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  627. {
  628. this->Target->AddTracedSources(srcs);
  629. if (!srcs.empty()) {
  630. this->AddSourceCommon(cmJoin(srcs, ";"));
  631. }
  632. }
  633. void cmGeneratorTarget::AddIncludeDirectory(const std::string& src,
  634. bool before)
  635. {
  636. this->Target->InsertInclude(
  637. BT<std::string>(src, this->Makefile->GetBacktrace()), before);
  638. this->IncludeDirectoriesEntries.insert(
  639. before ? this->IncludeDirectoriesEntries.begin()
  640. : this->IncludeDirectoriesEntries.end(),
  641. CreateTargetPropertyEntry(
  642. *this->Makefile->GetCMakeInstance(),
  643. BT<std::string>(src, this->Makefile->GetBacktrace()), true));
  644. }
  645. void cmGeneratorTarget::AddSystemIncludeDirectory(std::string const& inc,
  646. std::string const& lang)
  647. {
  648. std::string config_upper;
  649. auto const& configs =
  650. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  651. for (auto const& config : configs) {
  652. std::string inc_with_config = inc;
  653. if (!config.empty()) {
  654. cmSystemTools::ReplaceString(inc_with_config, "$<CONFIG>", config);
  655. config_upper = cmSystemTools::UpperCase(config);
  656. }
  657. auto const& key = cmStrCat(config_upper, "/", lang);
  658. this->Target->AddSystemIncludeDirectories({ inc_with_config });
  659. this->SystemIncludesCache[key].emplace_back(inc_with_config);
  660. // SystemIncludesCache should be sorted so that binary search can be used
  661. std::sort(this->SystemIncludesCache[key].begin(),
  662. this->SystemIncludesCache[key].end());
  663. }
  664. }
  665. std::vector<cmSourceFile*> const* cmGeneratorTarget::GetSourceDepends(
  666. cmSourceFile const* sf) const
  667. {
  668. auto i = this->SourceDepends.find(sf);
  669. if (i != this->SourceDepends.end()) {
  670. return &i->second.Depends;
  671. }
  672. return nullptr;
  673. }
  674. namespace {
  675. void handleSystemIncludesDep(cmLocalGenerator* lg,
  676. cmGeneratorTarget const* depTgt,
  677. const std::string& config,
  678. cmGeneratorTarget const* headTarget,
  679. cmGeneratorExpressionDAGChecker* dagChecker,
  680. cmList& result, bool excludeImported,
  681. std::string const& language)
  682. {
  683. if (cmValue dirs =
  684. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES")) {
  685. result.append(cmGeneratorExpression::Evaluate(
  686. *dirs, lg, config, headTarget, dagChecker, depTgt, language));
  687. }
  688. if (!depTgt->GetPropertyAsBool("SYSTEM")) {
  689. return;
  690. }
  691. if (depTgt->IsImported()) {
  692. if (excludeImported) {
  693. return;
  694. }
  695. if (depTgt->GetPropertyAsBool("IMPORTED_NO_SYSTEM")) {
  696. return;
  697. }
  698. }
  699. if (cmValue dirs = depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES")) {
  700. result.append(cmGeneratorExpression::Evaluate(
  701. *dirs, lg, config, headTarget, dagChecker, depTgt, language));
  702. }
  703. if (depTgt->Target->IsFrameworkOnApple() ||
  704. depTgt->IsImportedFrameworkFolderOnApple(config)) {
  705. if (auto fwDescriptor = depTgt->GetGlobalGenerator()->SplitFrameworkPath(
  706. depTgt->GetLocation(config))) {
  707. result.push_back(fwDescriptor->Directory);
  708. result.push_back(fwDescriptor->GetFrameworkPath());
  709. }
  710. }
  711. }
  712. }
  713. /* clang-format off */
  714. #define IMPLEMENT_VISIT(KIND) \
  715. do { \
  716. KindedSources const& kinded = this->GetKindedSources(config); \
  717. for (SourceAndKind const& s : kinded.Sources) { \
  718. if (s.Kind == KIND) { \
  719. data.push_back(s.Source.Value); \
  720. } \
  721. } \
  722. } while (false)
  723. /* clang-format on */
  724. void cmGeneratorTarget::GetObjectSources(
  725. std::vector<cmSourceFile const*>& data, const std::string& config) const
  726. {
  727. IMPLEMENT_VISIT(SourceKindObjectSource);
  728. if (this->VisitedConfigsForObjects.count(config)) {
  729. return;
  730. }
  731. for (cmSourceFile const* it : data) {
  732. this->Objects[it];
  733. }
  734. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  735. this->VisitedConfigsForObjects.insert(config);
  736. }
  737. void cmGeneratorTarget::ComputeObjectMapping()
  738. {
  739. auto const& configs =
  740. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  741. std::set<std::string> configSet(configs.begin(), configs.end());
  742. if (configSet == this->VisitedConfigsForObjects) {
  743. return;
  744. }
  745. for (std::string const& c : configs) {
  746. std::vector<cmSourceFile const*> sourceFiles;
  747. this->GetObjectSources(sourceFiles, c);
  748. }
  749. }
  750. cmValue cmGeneratorTarget::GetFeature(const std::string& feature,
  751. const std::string& config) const
  752. {
  753. if (!config.empty()) {
  754. std::string featureConfig =
  755. cmStrCat(feature, '_', cmSystemTools::UpperCase(config));
  756. if (cmValue value = this->GetProperty(featureConfig)) {
  757. return value;
  758. }
  759. }
  760. if (cmValue value = this->GetProperty(feature)) {
  761. return value;
  762. }
  763. return this->LocalGenerator->GetFeature(feature, config);
  764. }
  765. const char* cmGeneratorTarget::GetLinkPIEProperty(
  766. const std::string& config) const
  767. {
  768. static std::string PICValue;
  769. PICValue = this->GetLinkInterfaceDependentStringAsBoolProperty(
  770. "POSITION_INDEPENDENT_CODE", config);
  771. if (PICValue == "(unset)") {
  772. // POSITION_INDEPENDENT_CODE is not set
  773. return nullptr;
  774. }
  775. auto status = this->GetPolicyStatusCMP0083();
  776. return (status != cmPolicies::WARN && status != cmPolicies::OLD)
  777. ? PICValue.c_str()
  778. : nullptr;
  779. }
  780. bool cmGeneratorTarget::IsIPOEnabled(std::string const& lang,
  781. std::string const& config) const
  782. {
  783. cmValue feature = this->GetFeature("INTERPROCEDURAL_OPTIMIZATION", config);
  784. if (!cmIsOn(feature)) {
  785. // 'INTERPROCEDURAL_OPTIMIZATION' is off, no need to check policies
  786. return false;
  787. }
  788. if (lang != "C" && lang != "CXX" && lang != "CUDA" && lang != "Fortran") {
  789. // We do not define IPO behavior for other languages.
  790. return false;
  791. }
  792. if (lang == "CUDA") {
  793. // CUDA IPO requires both CUDA_ARCHITECTURES and CUDA_SEPARABLE_COMPILATION
  794. if (cmIsOff(this->GetSafeProperty("CUDA_ARCHITECTURES")) ||
  795. cmIsOff(this->GetSafeProperty("CUDA_SEPARABLE_COMPILATION"))) {
  796. return false;
  797. }
  798. }
  799. cmPolicies::PolicyStatus cmp0069 = this->GetPolicyStatusCMP0069();
  800. if (cmp0069 == cmPolicies::OLD || cmp0069 == cmPolicies::WARN) {
  801. if (this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_LEGACY_BEHAVIOR")) {
  802. return true;
  803. }
  804. if (this->PolicyReportedCMP0069) {
  805. // problem is already reported, no need to issue a message
  806. return false;
  807. }
  808. const bool in_try_compile =
  809. this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile();
  810. if (cmp0069 == cmPolicies::WARN && !in_try_compile) {
  811. std::ostringstream w;
  812. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0069) << "\n";
  813. w << "INTERPROCEDURAL_OPTIMIZATION property will be ignored for target "
  814. << "'" << this->GetName() << "'.";
  815. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  816. MessageType::AUTHOR_WARNING, w.str(), this->GetBacktrace());
  817. this->PolicyReportedCMP0069 = true;
  818. }
  819. return false;
  820. }
  821. // Note: check consistency with messages from CheckIPOSupported
  822. const char* message = nullptr;
  823. if (!this->Makefile->IsOn("_CMAKE_" + lang + "_IPO_SUPPORTED_BY_CMAKE")) {
  824. message = "CMake doesn't support IPO for current compiler";
  825. } else if (!this->Makefile->IsOn("_CMAKE_" + lang +
  826. "_IPO_MAY_BE_SUPPORTED_BY_COMPILER")) {
  827. message = "Compiler doesn't support IPO";
  828. } else if (!this->GlobalGenerator->IsIPOSupported()) {
  829. message = "CMake doesn't support IPO for current generator";
  830. }
  831. if (!message) {
  832. // No error/warning messages
  833. return true;
  834. }
  835. if (this->PolicyReportedCMP0069) {
  836. // problem is already reported, no need to issue a message
  837. return false;
  838. }
  839. this->PolicyReportedCMP0069 = true;
  840. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  841. MessageType::FATAL_ERROR, message, this->GetBacktrace());
  842. return false;
  843. }
  844. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  845. {
  846. this->ComputeObjectMapping();
  847. return this->Objects[file];
  848. }
  849. const char* cmGeneratorTarget::GetCustomObjectExtension() const
  850. {
  851. struct compiler_mode
  852. {
  853. std::string variable;
  854. std::string extension;
  855. };
  856. static std::array<compiler_mode, 4> const modes{
  857. { { "CUDA_PTX_COMPILATION", ".ptx" },
  858. { "CUDA_CUBIN_COMPILATION", ".cubin" },
  859. { "CUDA_FATBIN_COMPILATION", ".fatbin" },
  860. { "CUDA_OPTIX_COMPILATION", ".optixir" } }
  861. };
  862. std::string const& compiler =
  863. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
  864. if (!compiler.empty()) {
  865. for (const auto& m : modes) {
  866. const bool has_extension = this->GetPropertyAsBool(m.variable);
  867. if (has_extension) {
  868. return m.extension.c_str();
  869. }
  870. }
  871. }
  872. return nullptr;
  873. }
  874. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  875. {
  876. this->ExplicitObjectName.insert(sf);
  877. }
  878. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  879. {
  880. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  881. auto it = this->ExplicitObjectName.find(file);
  882. return it != this->ExplicitObjectName.end();
  883. }
  884. BTs<std::string> const* cmGeneratorTarget::GetLanguageStandardProperty(
  885. std::string const& lang, std::string const& config) const
  886. {
  887. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  888. auto langStandardIter = this->LanguageStandardMap.find(key);
  889. if (langStandardIter != this->LanguageStandardMap.end()) {
  890. return &langStandardIter->second;
  891. }
  892. return this->Target->GetLanguageStandardProperty(
  893. cmStrCat(lang, "_STANDARD"));
  894. }
  895. cmValue cmGeneratorTarget::GetLanguageStandard(std::string const& lang,
  896. std::string const& config) const
  897. {
  898. BTs<std::string> const* languageStandard =
  899. this->GetLanguageStandardProperty(lang, config);
  900. if (languageStandard) {
  901. return cmValue(languageStandard->Value);
  902. }
  903. return nullptr;
  904. }
  905. cmValue cmGeneratorTarget::GetPropertyWithPairedLanguageSupport(
  906. std::string const& lang, const char* suffix) const
  907. {
  908. cmValue propertyValue = this->Target->GetProperty(cmStrCat(lang, suffix));
  909. if (!propertyValue) {
  910. // Check if we should use the value set by another language.
  911. if (lang == "OBJC") {
  912. propertyValue = this->GetPropertyWithPairedLanguageSupport("C", suffix);
  913. } else if (lang == "OBJCXX" || lang == "CUDA" || lang == "HIP") {
  914. propertyValue =
  915. this->GetPropertyWithPairedLanguageSupport("CXX", suffix);
  916. }
  917. }
  918. return propertyValue;
  919. }
  920. cmValue cmGeneratorTarget::GetLanguageExtensions(std::string const& lang) const
  921. {
  922. return this->GetPropertyWithPairedLanguageSupport(lang, "_EXTENSIONS");
  923. }
  924. bool cmGeneratorTarget::GetLanguageStandardRequired(
  925. std::string const& lang) const
  926. {
  927. return cmIsOn(
  928. this->GetPropertyWithPairedLanguageSupport(lang, "_STANDARD_REQUIRED"));
  929. }
  930. void cmGeneratorTarget::GetModuleDefinitionSources(
  931. std::vector<cmSourceFile const*>& data, const std::string& config) const
  932. {
  933. IMPLEMENT_VISIT(SourceKindModuleDefinition);
  934. }
  935. void cmGeneratorTarget::GetHeaderSources(
  936. std::vector<cmSourceFile const*>& data, const std::string& config) const
  937. {
  938. IMPLEMENT_VISIT(SourceKindHeader);
  939. }
  940. void cmGeneratorTarget::GetCxxModuleSources(
  941. std::vector<cmSourceFile const*>& data, const std::string& config) const
  942. {
  943. IMPLEMENT_VISIT(SourceKindCxxModuleSource);
  944. }
  945. void cmGeneratorTarget::GetExtraSources(std::vector<cmSourceFile const*>& data,
  946. const std::string& config) const
  947. {
  948. IMPLEMENT_VISIT(SourceKindExtra);
  949. }
  950. void cmGeneratorTarget::GetCustomCommands(
  951. std::vector<cmSourceFile const*>& data, const std::string& config) const
  952. {
  953. IMPLEMENT_VISIT(SourceKindCustomCommand);
  954. }
  955. void cmGeneratorTarget::GetExternalObjects(
  956. std::vector<cmSourceFile const*>& data, const std::string& config) const
  957. {
  958. IMPLEMENT_VISIT(SourceKindExternalObject);
  959. }
  960. void cmGeneratorTarget::GetManifests(std::vector<cmSourceFile const*>& data,
  961. const std::string& config) const
  962. {
  963. IMPLEMENT_VISIT(SourceKindManifest);
  964. }
  965. std::set<cmLinkItem> const& cmGeneratorTarget::GetUtilityItems() const
  966. {
  967. if (!this->UtilityItemsDone) {
  968. this->UtilityItemsDone = true;
  969. std::set<BT<std::pair<std::string, bool>>> const& utilities =
  970. this->GetUtilities();
  971. for (BT<std::pair<std::string, bool>> const& i : utilities) {
  972. if (cmGeneratorTarget* gt =
  973. this->LocalGenerator->FindGeneratorTargetToUse(i.Value.first)) {
  974. this->UtilityItems.insert(cmLinkItem(gt, i.Value.second, i.Backtrace));
  975. } else {
  976. this->UtilityItems.insert(
  977. cmLinkItem(i.Value.first, i.Value.second, i.Backtrace));
  978. }
  979. }
  980. }
  981. return this->UtilityItems;
  982. }
  983. const std::string& cmGeneratorTarget::GetLocation(
  984. const std::string& config) const
  985. {
  986. static std::string location;
  987. if (this->IsImported()) {
  988. location = this->Target->ImportedGetFullPath(
  989. config, cmStateEnums::RuntimeBinaryArtifact);
  990. } else {
  991. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  992. }
  993. return location;
  994. }
  995. cm::optional<std::string> cmGeneratorTarget::MaybeGetLocation(
  996. std::string const& config) const
  997. {
  998. cm::optional<std::string> location;
  999. if (cmGeneratorTarget::ImportInfo const* imp = this->GetImportInfo(config)) {
  1000. if (!imp->Location.empty()) {
  1001. location = imp->Location;
  1002. }
  1003. } else {
  1004. location = this->GetFullPath(config, cmStateEnums::RuntimeBinaryArtifact);
  1005. }
  1006. return location;
  1007. }
  1008. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreBuildCommands()
  1009. const
  1010. {
  1011. return this->Target->GetPreBuildCommands();
  1012. }
  1013. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPreLinkCommands()
  1014. const
  1015. {
  1016. return this->Target->GetPreLinkCommands();
  1017. }
  1018. std::vector<cmCustomCommand> const& cmGeneratorTarget::GetPostBuildCommands()
  1019. const
  1020. {
  1021. return this->Target->GetPostBuildCommands();
  1022. }
  1023. void cmGeneratorTarget::AppendCustomCommandSideEffects(
  1024. std::set<cmGeneratorTarget const*>& sideEffects) const
  1025. {
  1026. if (!this->GetPreBuildCommands().empty() ||
  1027. !this->GetPreLinkCommands().empty() ||
  1028. !this->GetPostBuildCommands().empty()) {
  1029. sideEffects.insert(this);
  1030. } else {
  1031. for (auto const& source : this->GetAllConfigSources()) {
  1032. if (source.Source->GetCustomCommand() != nullptr) {
  1033. sideEffects.insert(this);
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. void cmGeneratorTarget::AppendLanguageSideEffects(
  1040. std::map<std::string, std::set<cmGeneratorTarget const*>>& sideEffects) const
  1041. {
  1042. static const std::set<cm::string_view> LANGS_WITH_NO_SIDE_EFFECTS = {
  1043. "C"_s, "CXX"_s, "OBJC"_s, "OBJCXX"_s, "ASM"_s, "CUDA"_s, "HIP"_s
  1044. };
  1045. for (auto const& lang : this->GetAllConfigCompileLanguages()) {
  1046. if (!LANGS_WITH_NO_SIDE_EFFECTS.count(lang)) {
  1047. sideEffects[lang].insert(this);
  1048. }
  1049. }
  1050. }
  1051. bool cmGeneratorTarget::IsInBuildSystem() const
  1052. {
  1053. if (this->IsImported()) {
  1054. return false;
  1055. }
  1056. switch (this->Target->GetType()) {
  1057. case cmStateEnums::EXECUTABLE:
  1058. case cmStateEnums::STATIC_LIBRARY:
  1059. case cmStateEnums::SHARED_LIBRARY:
  1060. case cmStateEnums::MODULE_LIBRARY:
  1061. case cmStateEnums::OBJECT_LIBRARY:
  1062. case cmStateEnums::UTILITY:
  1063. case cmStateEnums::GLOBAL_TARGET:
  1064. return true;
  1065. case cmStateEnums::INTERFACE_LIBRARY:
  1066. // An INTERFACE library is in the build system if it has SOURCES
  1067. // or C++ module filesets.
  1068. if (!this->SourceEntries.empty() ||
  1069. !this->Target->GetHeaderSetsEntries().empty() ||
  1070. !this->Target->GetCxxModuleSetsEntries().empty()) {
  1071. return true;
  1072. }
  1073. break;
  1074. case cmStateEnums::UNKNOWN_LIBRARY:
  1075. break;
  1076. }
  1077. return false;
  1078. }
  1079. bool cmGeneratorTarget::IsNormal() const
  1080. {
  1081. return this->Target->IsNormal();
  1082. }
  1083. bool cmGeneratorTarget::IsRuntimeBinary() const
  1084. {
  1085. return this->Target->IsRuntimeBinary();
  1086. }
  1087. bool cmGeneratorTarget::IsSynthetic() const
  1088. {
  1089. return this->Target->IsSynthetic();
  1090. }
  1091. bool cmGeneratorTarget::IsImported() const
  1092. {
  1093. return this->Target->IsImported();
  1094. }
  1095. bool cmGeneratorTarget::IsImportedGloballyVisible() const
  1096. {
  1097. return this->Target->IsImportedGloballyVisible();
  1098. }
  1099. bool cmGeneratorTarget::CanCompileSources() const
  1100. {
  1101. return this->Target->CanCompileSources();
  1102. }
  1103. const std::string& cmGeneratorTarget::GetLocationForBuild() const
  1104. {
  1105. static std::string location;
  1106. if (this->IsImported()) {
  1107. location = this->Target->ImportedGetFullPath(
  1108. "", cmStateEnums::RuntimeBinaryArtifact);
  1109. return location;
  1110. }
  1111. // Now handle the deprecated build-time configuration location.
  1112. std::string const noConfig;
  1113. location = this->GetDirectory(noConfig);
  1114. cmValue cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  1115. if (cfgid && (*cfgid != ".")) {
  1116. location += "/";
  1117. location += *cfgid;
  1118. }
  1119. if (this->IsAppBundleOnApple()) {
  1120. std::string macdir = this->BuildBundleDirectory("", "", FullLevel);
  1121. if (!macdir.empty()) {
  1122. location += "/";
  1123. location += macdir;
  1124. }
  1125. }
  1126. location += "/";
  1127. location += this->GetFullName("", cmStateEnums::RuntimeBinaryArtifact);
  1128. return location;
  1129. }
  1130. bool cmGeneratorTarget::IsSystemIncludeDirectory(
  1131. const std::string& dir, const std::string& config,
  1132. const std::string& language) const
  1133. {
  1134. std::string config_upper;
  1135. if (!config.empty()) {
  1136. config_upper = cmSystemTools::UpperCase(config);
  1137. }
  1138. std::string key = cmStrCat(config_upper, '/', language);
  1139. auto iter = this->SystemIncludesCache.find(key);
  1140. if (iter == this->SystemIncludesCache.end()) {
  1141. cmGeneratorExpressionDAGChecker dagChecker(
  1142. this, "SYSTEM_INCLUDE_DIRECTORIES", nullptr, nullptr);
  1143. bool excludeImported = this->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  1144. cmList result;
  1145. for (std::string const& it : this->Target->GetSystemIncludeDirectories()) {
  1146. result.append(cmGeneratorExpression::Evaluate(it, this->LocalGenerator,
  1147. config, this, &dagChecker,
  1148. nullptr, language));
  1149. }
  1150. std::vector<cmGeneratorTarget const*> const& deps =
  1151. this->GetLinkImplementationClosure(config);
  1152. for (cmGeneratorTarget const* dep : deps) {
  1153. handleSystemIncludesDep(this->LocalGenerator, dep, config, this,
  1154. &dagChecker, result, excludeImported, language);
  1155. }
  1156. cmLinkImplementation const* impl =
  1157. this->GetLinkImplementation(config, LinkInterfaceFor::Usage);
  1158. if (impl != nullptr) {
  1159. auto runtimeEntries = impl->LanguageRuntimeLibraries.find(language);
  1160. if (runtimeEntries != impl->LanguageRuntimeLibraries.end()) {
  1161. for (auto const& lib : runtimeEntries->second) {
  1162. if (lib.Target) {
  1163. handleSystemIncludesDep(this->LocalGenerator, lib.Target, config,
  1164. this, &dagChecker, result, excludeImported,
  1165. language);
  1166. }
  1167. }
  1168. }
  1169. }
  1170. std::for_each(result.begin(), result.end(),
  1171. cmSystemTools::ConvertToUnixSlashes);
  1172. std::sort(result.begin(), result.end());
  1173. result.erase(std::unique(result.begin(), result.end()), result.end());
  1174. iter = this->SystemIncludesCache.emplace(key, result).first;
  1175. }
  1176. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  1177. }
  1178. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  1179. {
  1180. return this->Target->GetPropertyAsBool(prop);
  1181. }
  1182. bool cmGeneratorTarget::MaybeHaveInterfaceProperty(
  1183. std::string const& prop, cmGeneratorExpressionContext* context,
  1184. LinkInterfaceFor interfaceFor) const
  1185. {
  1186. std::string const key = prop + '@' + context->Config;
  1187. auto i = this->MaybeInterfacePropertyExists.find(key);
  1188. if (i == this->MaybeInterfacePropertyExists.end()) {
  1189. // Insert an entry now in case there is a cycle.
  1190. i = this->MaybeInterfacePropertyExists.emplace(key, false).first;
  1191. bool& maybeInterfaceProp = i->second;
  1192. // If this target itself has a non-empty property value, we are done.
  1193. maybeInterfaceProp = cmNonempty(this->GetProperty(prop));
  1194. // Otherwise, recurse to interface dependencies.
  1195. if (!maybeInterfaceProp) {
  1196. cmGeneratorTarget const* headTarget =
  1197. context->HeadTarget ? context->HeadTarget : this;
  1198. if (cmLinkInterfaceLibraries const* iface =
  1199. this->GetLinkInterfaceLibraries(context->Config, headTarget,
  1200. interfaceFor)) {
  1201. if (iface->HadHeadSensitiveCondition) {
  1202. // With a different head target we may get to a library with
  1203. // this interface property.
  1204. maybeInterfaceProp = true;
  1205. } else {
  1206. // The transitive interface libraries do not depend on the
  1207. // head target, so we can follow them.
  1208. for (cmLinkItem const& lib : iface->Libraries) {
  1209. if (lib.Target &&
  1210. lib.Target->MaybeHaveInterfaceProperty(prop, context,
  1211. interfaceFor)) {
  1212. maybeInterfaceProp = true;
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. }
  1218. }
  1219. }
  1220. return i->second;
  1221. }
  1222. std::string cmGeneratorTarget::EvaluateInterfaceProperty(
  1223. std::string const& prop, cmGeneratorExpressionContext* context,
  1224. cmGeneratorExpressionDAGChecker* dagCheckerParent,
  1225. LinkInterfaceFor interfaceFor) const
  1226. {
  1227. std::string result;
  1228. // If the property does not appear transitively at all, we are done.
  1229. if (!this->MaybeHaveInterfaceProperty(prop, context, interfaceFor)) {
  1230. return result;
  1231. }
  1232. // Evaluate $<TARGET_PROPERTY:this,prop> as if it were compiled. This is
  1233. // a subset of TargetPropertyNode::Evaluate without stringify/parse steps
  1234. // but sufficient for transitive interface properties.
  1235. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace, this, prop,
  1236. nullptr, dagCheckerParent);
  1237. switch (dagChecker.Check()) {
  1238. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1239. dagChecker.ReportError(
  1240. context, "$<TARGET_PROPERTY:" + this->GetName() + "," + prop + ">");
  1241. return result;
  1242. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1243. // No error. We just skip cyclic references.
  1244. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1245. // No error. We have already seen this transitive property.
  1246. return result;
  1247. case cmGeneratorExpressionDAGChecker::DAG:
  1248. break;
  1249. }
  1250. cmGeneratorTarget const* headTarget =
  1251. context->HeadTarget ? context->HeadTarget : this;
  1252. if (cmValue p = this->GetProperty(prop)) {
  1253. result = cmGeneratorExpressionNode::EvaluateDependentExpression(
  1254. *p, context->LG, context, headTarget, &dagChecker, this);
  1255. }
  1256. if (cmLinkInterfaceLibraries const* iface = this->GetLinkInterfaceLibraries(
  1257. context->Config, headTarget, interfaceFor)) {
  1258. context->HadContextSensitiveCondition =
  1259. context->HadContextSensitiveCondition ||
  1260. iface->HadContextSensitiveCondition;
  1261. for (cmLinkItem const& lib : iface->Libraries) {
  1262. // Broken code can have a target in its own link interface.
  1263. // Don't follow such link interface entries so as not to create a
  1264. // self-referencing loop.
  1265. if (lib.Target && lib.Target != this) {
  1266. // Pretend $<TARGET_PROPERTY:lib.Target,prop> appeared in the
  1267. // above property and hand-evaluate it as if it were compiled.
  1268. // Create a context as cmCompiledGeneratorExpression::Evaluate does.
  1269. cmGeneratorExpressionContext libContext(
  1270. context->LG, context->Config, context->Quiet, headTarget, this,
  1271. context->EvaluateForBuildsystem, context->Backtrace,
  1272. context->Language);
  1273. std::string libResult = cmGeneratorExpression::StripEmptyListElements(
  1274. lib.Target->EvaluateInterfaceProperty(prop, &libContext, &dagChecker,
  1275. interfaceFor));
  1276. if (!libResult.empty()) {
  1277. if (result.empty()) {
  1278. result = std::move(libResult);
  1279. } else {
  1280. result.reserve(result.size() + 1 + libResult.size());
  1281. result += ";";
  1282. result += libResult;
  1283. }
  1284. }
  1285. context->HadContextSensitiveCondition =
  1286. context->HadContextSensitiveCondition ||
  1287. libContext.HadContextSensitiveCondition;
  1288. context->HadHeadSensitiveCondition =
  1289. context->HadHeadSensitiveCondition ||
  1290. libContext.HadHeadSensitiveCondition;
  1291. }
  1292. }
  1293. }
  1294. return result;
  1295. }
  1296. namespace {
  1297. enum class IncludeDirectoryFallBack
  1298. {
  1299. BINARY,
  1300. OBJECT
  1301. };
  1302. std::string AddLangSpecificInterfaceIncludeDirectories(
  1303. const cmGeneratorTarget* root, const cmGeneratorTarget* target,
  1304. const std::string& lang, const std::string& config,
  1305. const std::string& propertyName, IncludeDirectoryFallBack mode,
  1306. cmGeneratorExpressionDAGChecker* context)
  1307. {
  1308. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1309. propertyName, nullptr, context };
  1310. switch (dag.Check()) {
  1311. case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
  1312. dag.ReportError(
  1313. nullptr, "$<TARGET_PROPERTY:" + target->GetName() + ",propertyName");
  1314. CM_FALLTHROUGH;
  1315. case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
  1316. // No error. We just skip cyclic references.
  1317. case cmGeneratorExpressionDAGChecker::ALREADY_SEEN:
  1318. // No error. We have already seen this transitive property.
  1319. return "";
  1320. case cmGeneratorExpressionDAGChecker::DAG:
  1321. break;
  1322. }
  1323. std::string directories;
  1324. if (const auto* link_interface = target->GetLinkInterfaceLibraries(
  1325. config, root, LinkInterfaceFor::Usage)) {
  1326. for (const cmLinkItem& library : link_interface->Libraries) {
  1327. if (const cmGeneratorTarget* dependency = library.Target) {
  1328. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1329. auto* lg = dependency->GetLocalGenerator();
  1330. std::string value = dependency->GetSafeProperty(propertyName);
  1331. if (value.empty()) {
  1332. if (mode == IncludeDirectoryFallBack::BINARY) {
  1333. value = lg->GetCurrentBinaryDirectory();
  1334. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1335. value = cmStrCat(lg->GetCurrentBinaryDirectory(), '/',
  1336. lg->GetTargetDirectory(dependency));
  1337. }
  1338. }
  1339. if (!directories.empty()) {
  1340. directories += ";";
  1341. }
  1342. directories += value;
  1343. }
  1344. }
  1345. }
  1346. }
  1347. return directories;
  1348. }
  1349. void AddLangSpecificImplicitIncludeDirectories(
  1350. const cmGeneratorTarget* target, const std::string& lang,
  1351. const std::string& config, const std::string& propertyName,
  1352. IncludeDirectoryFallBack mode, EvaluatedTargetPropertyEntries& entries)
  1353. {
  1354. if (const auto* libraries = target->GetLinkImplementationLibraries(
  1355. config, LinkInterfaceFor::Usage)) {
  1356. cmGeneratorExpressionDAGChecker dag{ target->GetBacktrace(), target,
  1357. propertyName, nullptr, nullptr };
  1358. for (const cmLinkImplItem& library : libraries->Libraries) {
  1359. if (const cmGeneratorTarget* dependency = library.Target) {
  1360. if (!dependency->IsInBuildSystem()) {
  1361. continue;
  1362. }
  1363. if (cm::contains(dependency->GetAllConfigCompileLanguages(), lang)) {
  1364. auto* lg = dependency->GetLocalGenerator();
  1365. EvaluatedTargetPropertyEntry entry{ library, library.Backtrace };
  1366. if (cmValue val = dependency->GetProperty(propertyName)) {
  1367. entry.Values.emplace_back(*val);
  1368. } else {
  1369. if (mode == IncludeDirectoryFallBack::BINARY) {
  1370. entry.Values.emplace_back(lg->GetCurrentBinaryDirectory());
  1371. } else if (mode == IncludeDirectoryFallBack::OBJECT) {
  1372. entry.Values.emplace_back(
  1373. dependency->GetObjectDirectory(config));
  1374. }
  1375. }
  1376. cmExpandList(
  1377. AddLangSpecificInterfaceIncludeDirectories(
  1378. target, dependency, lang, config, propertyName, mode, &dag),
  1379. entry.Values);
  1380. entries.Entries.emplace_back(std::move(entry));
  1381. }
  1382. }
  1383. }
  1384. }
  1385. }
  1386. void AddObjectEntries(cmGeneratorTarget const* headTarget,
  1387. std::string const& config,
  1388. cmGeneratorExpressionDAGChecker* dagChecker,
  1389. EvaluatedTargetPropertyEntries& entries)
  1390. {
  1391. if (cmLinkImplementationLibraries const* impl =
  1392. headTarget->GetLinkImplementationLibraries(config,
  1393. LinkInterfaceFor::Usage)) {
  1394. entries.HadContextSensitiveCondition = impl->HadContextSensitiveCondition;
  1395. for (cmLinkImplItem const& lib : impl->Libraries) {
  1396. if (lib.Target &&
  1397. lib.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1398. std::string uniqueName =
  1399. headTarget->GetGlobalGenerator()->IndexGeneratorTargetUniquely(
  1400. lib.Target);
  1401. std::string genex = "$<TARGET_OBJECTS:" + std::move(uniqueName) + ">";
  1402. cmGeneratorExpression ge(*headTarget->Makefile->GetCMakeInstance(),
  1403. lib.Backtrace);
  1404. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  1405. cge->SetEvaluateForBuildsystem(true);
  1406. EvaluatedTargetPropertyEntry ee(lib, lib.Backtrace);
  1407. cmExpandList(cge->Evaluate(headTarget->GetLocalGenerator(), config,
  1408. headTarget, dagChecker),
  1409. ee.Values);
  1410. if (cge->GetHadContextSensitiveCondition()) {
  1411. ee.ContextDependent = true;
  1412. }
  1413. entries.Entries.emplace_back(std::move(ee));
  1414. }
  1415. }
  1416. }
  1417. }
  1418. void addFileSetEntry(cmGeneratorTarget const* headTarget,
  1419. std::string const& config,
  1420. cmGeneratorExpressionDAGChecker* dagChecker,
  1421. cmFileSet const* fileSet,
  1422. EvaluatedTargetPropertyEntries& entries)
  1423. {
  1424. auto dirCges = fileSet->CompileDirectoryEntries();
  1425. auto dirs = fileSet->EvaluateDirectoryEntries(
  1426. dirCges, headTarget->GetLocalGenerator(), config, headTarget, dagChecker);
  1427. bool contextSensitiveDirs = false;
  1428. for (auto const& dirCge : dirCges) {
  1429. if (dirCge->GetHadContextSensitiveCondition()) {
  1430. contextSensitiveDirs = true;
  1431. break;
  1432. }
  1433. }
  1434. cmake* cm = headTarget->GetLocalGenerator()->GetCMakeInstance();
  1435. for (auto& entryCge : fileSet->CompileFileEntries()) {
  1436. TargetPropertyEntryFileSet tpe(dirs, contextSensitiveDirs,
  1437. std::move(entryCge), fileSet);
  1438. entries.Entries.emplace_back(
  1439. EvaluateTargetPropertyEntry(headTarget, config, "", dagChecker, tpe));
  1440. EvaluatedTargetPropertyEntry const& entry = entries.Entries.back();
  1441. for (auto const& file : entry.Values) {
  1442. auto* sf = headTarget->Makefile->GetOrCreateSource(file);
  1443. if (fileSet->GetType() == "HEADERS"_s) {
  1444. sf->SetProperty("HEADER_FILE_ONLY", "TRUE");
  1445. }
  1446. #ifndef CMAKE_BOOTSTRAP
  1447. std::string e;
  1448. std::string w;
  1449. auto path = sf->ResolveFullPath(&e, &w);
  1450. if (!w.empty()) {
  1451. cm->IssueMessage(MessageType::AUTHOR_WARNING, w, entry.Backtrace);
  1452. }
  1453. if (path.empty()) {
  1454. if (!e.empty()) {
  1455. cm->IssueMessage(MessageType::FATAL_ERROR, e, entry.Backtrace);
  1456. }
  1457. return;
  1458. }
  1459. bool found = false;
  1460. for (auto const& sg : headTarget->Makefile->GetSourceGroups()) {
  1461. if (sg.MatchChildrenFiles(path)) {
  1462. found = true;
  1463. break;
  1464. }
  1465. }
  1466. if (!found) {
  1467. if (fileSet->GetType() == "HEADERS"_s) {
  1468. headTarget->Makefile->GetOrCreateSourceGroup("Header Files")
  1469. ->AddGroupFile(path);
  1470. }
  1471. }
  1472. #endif
  1473. }
  1474. }
  1475. }
  1476. void AddFileSetEntries(cmGeneratorTarget const* headTarget,
  1477. std::string const& config,
  1478. cmGeneratorExpressionDAGChecker* dagChecker,
  1479. EvaluatedTargetPropertyEntries& entries)
  1480. {
  1481. for (auto const& entry : headTarget->Target->GetHeaderSetsEntries()) {
  1482. for (auto const& name : cmList{ entry.Value }) {
  1483. auto const* headerSet = headTarget->Target->GetFileSet(name);
  1484. addFileSetEntry(headTarget, config, dagChecker, headerSet, entries);
  1485. }
  1486. }
  1487. for (auto const& entry : headTarget->Target->GetCxxModuleSetsEntries()) {
  1488. for (auto const& name : cmList{ entry.Value }) {
  1489. auto const* cxxModuleSet = headTarget->Target->GetFileSet(name);
  1490. addFileSetEntry(headTarget, config, dagChecker, cxxModuleSet, entries);
  1491. }
  1492. }
  1493. }
  1494. bool processSources(cmGeneratorTarget const* tgt,
  1495. EvaluatedTargetPropertyEntries& entries,
  1496. std::vector<BT<std::string>>& srcs,
  1497. std::unordered_set<std::string>& uniqueSrcs,
  1498. bool debugSources)
  1499. {
  1500. cmMakefile* mf = tgt->Target->GetMakefile();
  1501. bool contextDependent = entries.HadContextSensitiveCondition;
  1502. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  1503. if (entry.ContextDependent) {
  1504. contextDependent = true;
  1505. }
  1506. cmLinkImplItem const& item = entry.LinkImplItem;
  1507. std::string const& targetName = item.AsStr();
  1508. for (std::string& src : entry.Values) {
  1509. cmSourceFile* sf = mf->GetOrCreateSource(src);
  1510. std::string e;
  1511. std::string w;
  1512. std::string fullPath = sf->ResolveFullPath(&e, &w);
  1513. cmake* cm = tgt->GetLocalGenerator()->GetCMakeInstance();
  1514. if (!w.empty()) {
  1515. cm->IssueMessage(MessageType::AUTHOR_WARNING, w, entry.Backtrace);
  1516. }
  1517. if (fullPath.empty()) {
  1518. if (!e.empty()) {
  1519. cm->IssueMessage(MessageType::FATAL_ERROR, e, entry.Backtrace);
  1520. }
  1521. return contextDependent;
  1522. }
  1523. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src)) {
  1524. std::ostringstream err;
  1525. if (!targetName.empty()) {
  1526. err << "Target \"" << targetName
  1527. << "\" contains relative path in its INTERFACE_SOURCES:\n \""
  1528. << src << "\"";
  1529. } else {
  1530. err << "Found relative path while evaluating sources of \""
  1531. << tgt->GetName() << "\":\n \"" << src << "\"\n";
  1532. }
  1533. tgt->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  1534. err.str());
  1535. return contextDependent;
  1536. }
  1537. src = fullPath;
  1538. }
  1539. std::string usedSources;
  1540. for (std::string const& src : entry.Values) {
  1541. if (uniqueSrcs.insert(src).second) {
  1542. srcs.emplace_back(src, entry.Backtrace);
  1543. if (debugSources) {
  1544. usedSources += " * " + src + "\n";
  1545. }
  1546. }
  1547. }
  1548. if (!usedSources.empty()) {
  1549. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1550. MessageType::LOG,
  1551. std::string("Used sources for target ") + tgt->GetName() + ":\n" +
  1552. usedSources,
  1553. entry.Backtrace);
  1554. }
  1555. }
  1556. return contextDependent;
  1557. }
  1558. }
  1559. std::vector<BT<std::string>> cmGeneratorTarget::GetSourceFilePaths(
  1560. std::string const& config) const
  1561. {
  1562. std::vector<BT<std::string>> files;
  1563. if (!this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1564. // At configure-time, this method can be called as part of getting the
  1565. // LOCATION property or to export() a file to be include()d. However
  1566. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  1567. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  1568. // behavior of CMP0024 and CMP0026 only.
  1569. cmBTStringRange sourceEntries = this->Target->GetSourceEntries();
  1570. for (auto const& entry : sourceEntries) {
  1571. cmList items{ entry.Value };
  1572. for (auto const& item : items) {
  1573. if (cmHasLiteralPrefix(item, "$<TARGET_OBJECTS:") &&
  1574. item.back() == '>') {
  1575. continue;
  1576. }
  1577. files.emplace_back(item);
  1578. }
  1579. }
  1580. return files;
  1581. }
  1582. cmList debugProperties{ this->Makefile->GetDefinition(
  1583. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  1584. bool debugSources =
  1585. !this->DebugSourcesDone && cm::contains(debugProperties, "SOURCES");
  1586. if (this->LocalGenerator->GetGlobalGenerator()->GetConfigureDoneCMP0026()) {
  1587. this->DebugSourcesDone = true;
  1588. }
  1589. cmGeneratorExpressionDAGChecker dagChecker(this, "SOURCES", nullptr,
  1590. nullptr);
  1591. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  1592. this, config, std::string(), &dagChecker, this->SourceEntries);
  1593. std::unordered_set<std::string> uniqueSrcs;
  1594. bool contextDependentDirectSources =
  1595. processSources(this, entries, files, uniqueSrcs, debugSources);
  1596. // Collect INTERFACE_SOURCES of all direct link-dependencies.
  1597. EvaluatedTargetPropertyEntries linkInterfaceSourcesEntries;
  1598. AddInterfaceEntries(this, config, "INTERFACE_SOURCES", std::string(),
  1599. &dagChecker, linkInterfaceSourcesEntries,
  1600. IncludeRuntimeInterface::No, LinkInterfaceFor::Usage);
  1601. std::vector<std::string>::size_type numFilesBefore = files.size();
  1602. bool contextDependentInterfaceSources = processSources(
  1603. this, linkInterfaceSourcesEntries, files, uniqueSrcs, debugSources);
  1604. // Collect TARGET_OBJECTS of direct object link-dependencies.
  1605. bool contextDependentObjects = false;
  1606. std::vector<std::string>::size_type numFilesBefore2 = files.size();
  1607. if (this->GetType() != cmStateEnums::OBJECT_LIBRARY) {
  1608. EvaluatedTargetPropertyEntries linkObjectsEntries;
  1609. AddObjectEntries(this, config, &dagChecker, linkObjectsEntries);
  1610. contextDependentObjects = processSources(this, linkObjectsEntries, files,
  1611. uniqueSrcs, debugSources);
  1612. }
  1613. // Collect this target's file sets.
  1614. std::vector<std::string>::size_type numFilesBefore3 = files.size();
  1615. EvaluatedTargetPropertyEntries fileSetEntries;
  1616. AddFileSetEntries(this, config, &dagChecker, fileSetEntries);
  1617. bool contextDependentFileSets =
  1618. processSources(this, fileSetEntries, files, uniqueSrcs, debugSources);
  1619. // Determine if sources are context-dependent or not.
  1620. if (!contextDependentDirectSources &&
  1621. !(contextDependentInterfaceSources && numFilesBefore < files.size()) &&
  1622. !(contextDependentObjects && numFilesBefore2 < files.size()) &&
  1623. !(contextDependentFileSets && numFilesBefore3 < files.size())) {
  1624. this->SourcesAreContextDependent = Tribool::False;
  1625. } else {
  1626. this->SourcesAreContextDependent = Tribool::True;
  1627. }
  1628. return files;
  1629. }
  1630. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*>& files,
  1631. const std::string& config) const
  1632. {
  1633. std::vector<BT<cmSourceFile*>> tmp = this->GetSourceFiles(config);
  1634. files.reserve(tmp.size());
  1635. for (BT<cmSourceFile*>& v : tmp) {
  1636. files.push_back(v.Value);
  1637. }
  1638. }
  1639. std::vector<BT<cmSourceFile*>> cmGeneratorTarget::GetSourceFiles(
  1640. std::string const& config) const
  1641. {
  1642. std::vector<BT<cmSourceFile*>> files;
  1643. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  1644. // Since we are still configuring not all sources may exist yet,
  1645. // so we need to avoid full source classification because that
  1646. // requires the absolute paths to all sources to be determined.
  1647. // Since this is only for compatibility with old policies that
  1648. // projects should not depend on anymore, just compute the files
  1649. // without memoizing them.
  1650. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1651. std::set<cmSourceFile*> emitted;
  1652. for (BT<std::string> const& s : srcs) {
  1653. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1654. if (emitted.insert(sf).second) {
  1655. files.emplace_back(sf, s.Backtrace);
  1656. }
  1657. }
  1658. return files;
  1659. }
  1660. KindedSources const& kinded = this->GetKindedSources(config);
  1661. files.reserve(kinded.Sources.size());
  1662. for (SourceAndKind const& si : kinded.Sources) {
  1663. files.push_back(si.Source);
  1664. }
  1665. return files;
  1666. }
  1667. void cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1668. std::vector<cmSourceFile*>& files, const std::string& config) const
  1669. {
  1670. std::vector<BT<cmSourceFile*>> tmp =
  1671. this->GetSourceFilesWithoutObjectLibraries(config);
  1672. files.reserve(tmp.size());
  1673. for (BT<cmSourceFile*>& v : tmp) {
  1674. files.push_back(v.Value);
  1675. }
  1676. }
  1677. std::vector<BT<cmSourceFile*>>
  1678. cmGeneratorTarget::GetSourceFilesWithoutObjectLibraries(
  1679. std::string const& config) const
  1680. {
  1681. std::vector<BT<cmSourceFile*>> files;
  1682. KindedSources const& kinded = this->GetKindedSources(config);
  1683. files.reserve(kinded.Sources.size());
  1684. for (SourceAndKind const& si : kinded.Sources) {
  1685. if (si.Source.Value->GetObjectLibrary().empty()) {
  1686. files.push_back(si.Source);
  1687. }
  1688. }
  1689. return files;
  1690. }
  1691. cmGeneratorTarget::KindedSources const& cmGeneratorTarget::GetKindedSources(
  1692. std::string const& config) const
  1693. {
  1694. // If we already processed one configuration and found no dependency
  1695. // on configuration then always use the one result.
  1696. if (this->SourcesAreContextDependent == Tribool::False) {
  1697. return this->KindedSourcesMap.begin()->second;
  1698. }
  1699. // Lookup any existing link implementation for this configuration.
  1700. std::string const key = cmSystemTools::UpperCase(config);
  1701. auto it = this->KindedSourcesMap.find(key);
  1702. if (it != this->KindedSourcesMap.end()) {
  1703. if (!it->second.Initialized) {
  1704. std::ostringstream e;
  1705. e << "The SOURCES of \"" << this->GetName()
  1706. << "\" use a generator expression that depends on the "
  1707. "SOURCES themselves.";
  1708. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1709. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1710. static KindedSources empty;
  1711. return empty;
  1712. }
  1713. return it->second;
  1714. }
  1715. // Add an entry to the map for this configuration.
  1716. KindedSources& files = this->KindedSourcesMap[key];
  1717. this->ComputeKindedSources(files, config);
  1718. files.Initialized = true;
  1719. return files;
  1720. }
  1721. void cmGeneratorTarget::ComputeKindedSources(KindedSources& files,
  1722. std::string const& config) const
  1723. {
  1724. // Get the source file paths by string.
  1725. std::vector<BT<std::string>> srcs = this->GetSourceFilePaths(config);
  1726. cmsys::RegularExpression header_regex(CM_HEADER_REGEX);
  1727. std::vector<cmSourceFile*> badObjLib;
  1728. std::set<cmSourceFile*> emitted;
  1729. for (BT<std::string> const& s : srcs) {
  1730. // Create each source at most once.
  1731. cmSourceFile* sf = this->Makefile->GetOrCreateSource(s.Value);
  1732. if (!emitted.insert(sf).second) {
  1733. continue;
  1734. }
  1735. // Compute the kind (classification) of this source file.
  1736. SourceKind kind;
  1737. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  1738. cmFileSet const* fs = this->GetFileSetForSource(config, sf);
  1739. if (sf->GetCustomCommand()) {
  1740. kind = SourceKindCustomCommand;
  1741. } else if (!this->Target->IsNormal() && !this->Target->IsImported() &&
  1742. fs && (fs->GetType() == "CXX_MODULES"_s)) {
  1743. kind = SourceKindCxxModuleSource;
  1744. } else if (this->Target->GetType() == cmStateEnums::UTILITY ||
  1745. this->Target->GetType() == cmStateEnums::INTERFACE_LIBRARY
  1746. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1747. // NOLINTNEXTLINE(bugprone-branch-clone)
  1748. ) {
  1749. kind = SourceKindExtra;
  1750. } else if (this->IsSourceFilePartOfUnityBatch(sf->ResolveFullPath())) {
  1751. kind = SourceKindUnityBatched;
  1752. // XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
  1753. // NOLINTNEXTLINE(bugprone-branch-clone)
  1754. } else if (sf->GetPropertyAsBool("HEADER_FILE_ONLY")) {
  1755. kind = SourceKindHeader;
  1756. } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  1757. kind = SourceKindExternalObject;
  1758. } else if (!sf->GetOrDetermineLanguage().empty()) {
  1759. kind = SourceKindObjectSource;
  1760. } else if (ext == "def") {
  1761. kind = SourceKindModuleDefinition;
  1762. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1763. badObjLib.push_back(sf);
  1764. }
  1765. } else if (ext == "idl") {
  1766. kind = SourceKindIDL;
  1767. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  1768. badObjLib.push_back(sf);
  1769. }
  1770. } else if (ext == "resx") {
  1771. kind = SourceKindResx;
  1772. } else if (ext == "appxmanifest") {
  1773. kind = SourceKindAppManifest;
  1774. } else if (ext == "manifest") {
  1775. if (sf->GetPropertyAsBool("VS_DEPLOYMENT_CONTENT")) {
  1776. kind = SourceKindExtra;
  1777. } else {
  1778. kind = SourceKindManifest;
  1779. }
  1780. } else if (ext == "pfx") {
  1781. kind = SourceKindCertificate;
  1782. } else if (ext == "xaml") {
  1783. kind = SourceKindXaml;
  1784. } else if (header_regex.find(sf->ResolveFullPath())) {
  1785. kind = SourceKindHeader;
  1786. } else {
  1787. kind = SourceKindExtra;
  1788. }
  1789. // Save this classified source file in the result vector.
  1790. files.Sources.push_back({ BT<cmSourceFile*>(sf, s.Backtrace), kind });
  1791. }
  1792. if (!badObjLib.empty()) {
  1793. std::ostringstream e;
  1794. e << "OBJECT library \"" << this->GetName() << "\" contains:\n";
  1795. for (cmSourceFile* i : badObjLib) {
  1796. e << " " << i->GetLocation().GetName() << "\n";
  1797. }
  1798. e << "but may contain only sources that compile, header files, and "
  1799. "other files that would not affect linking of a normal library.";
  1800. this->GlobalGenerator->GetCMakeInstance()->IssueMessage(
  1801. MessageType::FATAL_ERROR, e.str(), this->GetBacktrace());
  1802. }
  1803. }
  1804. std::vector<cmGeneratorTarget::AllConfigSource> const&
  1805. cmGeneratorTarget::GetAllConfigSources() const
  1806. {
  1807. if (this->AllConfigSources.empty()) {
  1808. this->ComputeAllConfigSources();
  1809. }
  1810. return this->AllConfigSources;
  1811. }
  1812. void cmGeneratorTarget::ComputeAllConfigSources() const
  1813. {
  1814. std::vector<std::string> configs =
  1815. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  1816. std::map<cmSourceFile const*, size_t> index;
  1817. for (size_t ci = 0; ci < configs.size(); ++ci) {
  1818. KindedSources const& sources = this->GetKindedSources(configs[ci]);
  1819. for (SourceAndKind const& src : sources.Sources) {
  1820. auto mi = index.find(src.Source.Value);
  1821. if (mi == index.end()) {
  1822. AllConfigSource acs;
  1823. acs.Source = src.Source.Value;
  1824. acs.Kind = src.Kind;
  1825. this->AllConfigSources.push_back(std::move(acs));
  1826. std::map<cmSourceFile const*, size_t>::value_type entry(
  1827. src.Source.Value, this->AllConfigSources.size() - 1);
  1828. mi = index.insert(entry).first;
  1829. }
  1830. this->AllConfigSources[mi->second].Configs.push_back(ci);
  1831. }
  1832. }
  1833. }
  1834. std::vector<cmGeneratorTarget::AllConfigSource>
  1835. cmGeneratorTarget::GetAllConfigSources(SourceKind kind) const
  1836. {
  1837. std::vector<AllConfigSource> result;
  1838. for (AllConfigSource const& source : this->GetAllConfigSources()) {
  1839. if (source.Kind == kind) {
  1840. result.push_back(source);
  1841. }
  1842. }
  1843. return result;
  1844. }
  1845. std::set<std::string> cmGeneratorTarget::GetAllConfigCompileLanguages() const
  1846. {
  1847. std::set<std::string> languages;
  1848. std::vector<AllConfigSource> const& sources = this->GetAllConfigSources();
  1849. for (AllConfigSource const& si : sources) {
  1850. std::string const& lang = si.Source->GetOrDetermineLanguage();
  1851. if (!lang.empty()) {
  1852. languages.emplace(lang);
  1853. }
  1854. }
  1855. return languages;
  1856. }
  1857. std::string cmGeneratorTarget::GetCompilePDBName(
  1858. const std::string& config) const
  1859. {
  1860. // Check for a per-configuration output directory target property.
  1861. std::string configUpper = cmSystemTools::UpperCase(config);
  1862. std::string configProp = cmStrCat("COMPILE_PDB_NAME_", configUpper);
  1863. cmValue config_name = this->GetProperty(configProp);
  1864. if (cmNonempty(config_name)) {
  1865. NameComponents const& components = GetFullNameInternalComponents(
  1866. config, cmStateEnums::RuntimeBinaryArtifact);
  1867. return components.prefix + *config_name + ".pdb";
  1868. }
  1869. cmValue name = this->GetProperty("COMPILE_PDB_NAME");
  1870. if (cmNonempty(name)) {
  1871. NameComponents const& components = GetFullNameInternalComponents(
  1872. config, cmStateEnums::RuntimeBinaryArtifact);
  1873. return components.prefix + *name + ".pdb";
  1874. }
  1875. return "";
  1876. }
  1877. std::string cmGeneratorTarget::GetCompilePDBPath(
  1878. const std::string& config) const
  1879. {
  1880. std::string dir = this->GetCompilePDBDirectory(config);
  1881. std::string name = this->GetCompilePDBName(config);
  1882. if (dir.empty() && !name.empty() && this->HaveWellDefinedOutputFiles()) {
  1883. dir = this->GetPDBDirectory(config);
  1884. }
  1885. if (!dir.empty()) {
  1886. dir += "/";
  1887. }
  1888. return dir + name;
  1889. }
  1890. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1891. {
  1892. // soname is supported only for shared libraries and modules,
  1893. // and then only when the platform supports an soname flag.
  1894. return ((this->GetType() == cmStateEnums::SHARED_LIBRARY) &&
  1895. !this->GetPropertyAsBool("NO_SONAME") &&
  1896. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1897. }
  1898. bool cmGeneratorTarget::NeedRelinkBeforeInstall(
  1899. const std::string& config) const
  1900. {
  1901. // Only executables and shared libraries can have an rpath and may
  1902. // need relinking.
  1903. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  1904. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  1905. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  1906. return false;
  1907. }
  1908. // If there is no install location this target will not be installed
  1909. // and therefore does not need relinking.
  1910. if (!this->Target->GetHaveInstallRule()) {
  1911. return false;
  1912. }
  1913. // If skipping all rpaths completely then no relinking is needed.
  1914. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1915. return false;
  1916. }
  1917. // If building with the install-tree rpath no relinking is needed.
  1918. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1919. return false;
  1920. }
  1921. // If chrpath is going to be used no relinking is needed.
  1922. if (this->IsChrpathUsed(config)) {
  1923. return false;
  1924. }
  1925. // Check for rpath support on this platform.
  1926. std::string ll = this->GetLinkerLanguage(config);
  1927. if (!ll.empty()) {
  1928. std::string flagVar =
  1929. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG");
  1930. if (!this->Makefile->IsSet(flagVar)) {
  1931. // There is no rpath support on this platform so nothing needs
  1932. // relinking.
  1933. return false;
  1934. }
  1935. } else {
  1936. // No linker language is known. This error will be reported by
  1937. // other code.
  1938. return false;
  1939. }
  1940. // If either a build or install tree rpath is set then the rpath
  1941. // will likely change between the build tree and install tree and
  1942. // this target must be relinked.
  1943. bool have_rpath =
  1944. this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH(config);
  1945. bool is_ninja = this->LocalGenerator->GetGlobalGenerator()->IsNinja();
  1946. if (have_rpath && is_ninja) {
  1947. std::ostringstream w;
  1948. /* clang-format off */
  1949. w <<
  1950. "The install of the " << this->GetName() << " target requires changing "
  1951. "an RPATH from the build tree, but this is not supported with the Ninja "
  1952. "generator unless on an ELF-based or XCOFF-based platform. "
  1953. "The CMAKE_BUILD_WITH_INSTALL_RPATH variable may be set to avoid this "
  1954. "relinking step."
  1955. ;
  1956. /* clang-format on */
  1957. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  1958. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  1959. }
  1960. return have_rpath;
  1961. }
  1962. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1963. {
  1964. // Only certain target types have an rpath.
  1965. if (!(this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  1966. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  1967. this->GetType() == cmStateEnums::EXECUTABLE)) {
  1968. return false;
  1969. }
  1970. // If the target will not be installed we do not need to change its
  1971. // rpath.
  1972. if (!this->Target->GetHaveInstallRule()) {
  1973. return false;
  1974. }
  1975. // Skip chrpath if skipping rpath altogether.
  1976. if (this->Makefile->IsOn("CMAKE_SKIP_RPATH")) {
  1977. return false;
  1978. }
  1979. // Skip chrpath if it does not need to be changed at install time.
  1980. if (this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH")) {
  1981. return false;
  1982. }
  1983. // Allow the user to disable builtin chrpath explicitly.
  1984. if (this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH")) {
  1985. return false;
  1986. }
  1987. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  1988. return true;
  1989. }
  1990. // Enable if the rpath flag uses a separator and the target uses
  1991. // binaries we know how to edit.
  1992. std::string ll = this->GetLinkerLanguage(config);
  1993. if (!ll.empty()) {
  1994. std::string sepVar =
  1995. cmStrCat("CMAKE_SHARED_LIBRARY_RUNTIME_", ll, "_FLAG_SEP");
  1996. cmValue sep = this->Makefile->GetDefinition(sepVar);
  1997. if (cmNonempty(sep)) {
  1998. // TODO: Add binary format check to ABI detection and get rid of
  1999. // CMAKE_EXECUTABLE_FORMAT.
  2000. if (cmValue fmt =
  2001. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT")) {
  2002. if (*fmt == "ELF") {
  2003. return true;
  2004. }
  2005. #if defined(CMake_USE_XCOFF_PARSER)
  2006. if (*fmt == "XCOFF") {
  2007. return true;
  2008. }
  2009. #endif
  2010. }
  2011. }
  2012. }
  2013. return false;
  2014. }
  2015. bool cmGeneratorTarget::IsImportedSharedLibWithoutSOName(
  2016. const std::string& config) const
  2017. {
  2018. if (this->IsImported() && this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  2019. if (cmGeneratorTarget::ImportInfo const* info =
  2020. this->GetImportInfo(config)) {
  2021. return info->NoSOName;
  2022. }
  2023. }
  2024. return false;
  2025. }
  2026. bool cmGeneratorTarget::HasMacOSXRpathInstallNameDir(
  2027. const std::string& config) const
  2028. {
  2029. TargetPtrToBoolMap& cache = this->MacOSXRpathInstallNameDirCache[config];
  2030. const auto lookup = cache.find(this->Target);
  2031. if (lookup != cache.cend()) {
  2032. return lookup->second;
  2033. }
  2034. const bool result = this->DetermineHasMacOSXRpathInstallNameDir(config);
  2035. cache[this->Target] = result;
  2036. return result;
  2037. }
  2038. bool cmGeneratorTarget::DetermineHasMacOSXRpathInstallNameDir(
  2039. const std::string& config) const
  2040. {
  2041. bool install_name_is_rpath = false;
  2042. bool macosx_rpath = false;
  2043. if (!this->IsImported()) {
  2044. if (this->GetType() != cmStateEnums::SHARED_LIBRARY) {
  2045. return false;
  2046. }
  2047. cmValue install_name = this->GetProperty("INSTALL_NAME_DIR");
  2048. bool use_install_name = this->MacOSXUseInstallNameDir();
  2049. if (install_name && use_install_name && *install_name == "@rpath") {
  2050. install_name_is_rpath = true;
  2051. } else if (install_name && use_install_name) {
  2052. return false;
  2053. }
  2054. if (!install_name_is_rpath) {
  2055. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  2056. }
  2057. } else {
  2058. // Lookup the imported soname.
  2059. if (cmGeneratorTarget::ImportInfo const* info =
  2060. this->GetImportInfo(config)) {
  2061. if (!info->NoSOName && !info->SOName.empty()) {
  2062. if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
  2063. install_name_is_rpath = true;
  2064. }
  2065. } else {
  2066. std::string install_name;
  2067. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  2068. if (install_name.find("@rpath") != std::string::npos) {
  2069. install_name_is_rpath = true;
  2070. }
  2071. }
  2072. }
  2073. }
  2074. if (!install_name_is_rpath && !macosx_rpath) {
  2075. return false;
  2076. }
  2077. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  2078. std::ostringstream w;
  2079. w << "Attempting to use ";
  2080. if (macosx_rpath) {
  2081. w << "MACOSX_RPATH";
  2082. } else {
  2083. w << "@rpath";
  2084. }
  2085. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  2086. w << " This could be because you are using a Mac OS X version";
  2087. w << " less than 10.5 or because CMake's platform configuration is";
  2088. w << " corrupt.";
  2089. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  2090. cm->IssueMessage(MessageType::FATAL_ERROR, w.str(), this->GetBacktrace());
  2091. }
  2092. return true;
  2093. }
  2094. bool cmGeneratorTarget::MacOSXRpathInstallNameDirDefault() const
  2095. {
  2096. // we can't do rpaths when unsupported
  2097. if (!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG")) {
  2098. return false;
  2099. }
  2100. cmValue macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  2101. if (macosx_rpath_str) {
  2102. return this->GetPropertyAsBool("MACOSX_RPATH");
  2103. }
  2104. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  2105. if (cmp0042 == cmPolicies::WARN) {
  2106. this->LocalGenerator->GetGlobalGenerator()->AddCMP0042WarnTarget(
  2107. this->GetName());
  2108. }
  2109. return cmp0042 == cmPolicies::NEW;
  2110. }
  2111. bool cmGeneratorTarget::MacOSXUseInstallNameDir() const
  2112. {
  2113. cmValue build_with_install_name =
  2114. this->GetProperty("BUILD_WITH_INSTALL_NAME_DIR");
  2115. if (build_with_install_name) {
  2116. return cmIsOn(*build_with_install_name);
  2117. }
  2118. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  2119. if (cmp0068 == cmPolicies::NEW) {
  2120. return false;
  2121. }
  2122. bool use_install_name = this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  2123. if (use_install_name && cmp0068 == cmPolicies::WARN) {
  2124. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  2125. this->GetName());
  2126. }
  2127. return use_install_name;
  2128. }
  2129. bool cmGeneratorTarget::CanGenerateInstallNameDir(
  2130. InstallNameType name_type) const
  2131. {
  2132. cmPolicies::PolicyStatus cmp0068 = this->GetPolicyStatusCMP0068();
  2133. if (cmp0068 == cmPolicies::NEW) {
  2134. return true;
  2135. }
  2136. bool skip = this->Makefile->IsOn("CMAKE_SKIP_RPATH");
  2137. if (name_type == INSTALL_NAME_FOR_INSTALL) {
  2138. skip |= this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  2139. } else {
  2140. skip |= this->GetPropertyAsBool("SKIP_BUILD_RPATH");
  2141. }
  2142. if (skip && cmp0068 == cmPolicies::WARN) {
  2143. this->LocalGenerator->GetGlobalGenerator()->AddCMP0068WarnTarget(
  2144. this->GetName());
  2145. }
  2146. return !skip;
  2147. }
  2148. std::string cmGeneratorTarget::GetSOName(
  2149. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2150. {
  2151. if (this->IsImported()) {
  2152. // Lookup the imported soname.
  2153. if (cmGeneratorTarget::ImportInfo const* info =
  2154. this->GetImportInfo(config)) {
  2155. if (info->NoSOName) {
  2156. // The imported library has no builtin soname so the name
  2157. // searched at runtime will be just the filename.
  2158. return cmSystemTools::GetFilenameName(info->Location);
  2159. }
  2160. // Use the soname given if any.
  2161. if (this->IsFrameworkOnApple()) {
  2162. auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath(
  2163. info->SOName, cmGlobalGenerator::FrameworkFormat::Strict);
  2164. if (fwDescriptor) {
  2165. return fwDescriptor->GetVersionedName();
  2166. }
  2167. }
  2168. if (cmHasLiteralPrefix(info->SOName, "@rpath/")) {
  2169. return info->SOName.substr(cmStrLen("@rpath/"));
  2170. }
  2171. return info->SOName;
  2172. }
  2173. return "";
  2174. }
  2175. // Compute the soname that will be built.
  2176. return artifact == cmStateEnums::RuntimeBinaryArtifact
  2177. ? this->GetLibraryNames(config).SharedObject
  2178. : this->GetLibraryNames(config).ImportLibrary;
  2179. }
  2180. namespace {
  2181. bool shouldAddFullLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  2182. {
  2183. return level == cmGeneratorTarget::FullLevel;
  2184. }
  2185. bool shouldAddContentLevel(cmGeneratorTarget::BundleDirectoryLevel level)
  2186. {
  2187. return level == cmGeneratorTarget::ContentLevel || shouldAddFullLevel(level);
  2188. }
  2189. }
  2190. std::string cmGeneratorTarget::GetAppBundleDirectory(
  2191. const std::string& config, BundleDirectoryLevel level) const
  2192. {
  2193. std::string fpath = cmStrCat(
  2194. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2195. cmValue ext = this->GetProperty("BUNDLE_EXTENSION");
  2196. fpath += (ext ? *ext : "app");
  2197. if (shouldAddContentLevel(level) &&
  2198. !this->Makefile->PlatformIsAppleEmbedded()) {
  2199. fpath += "/Contents";
  2200. if (shouldAddFullLevel(level)) {
  2201. fpath += "/MacOS";
  2202. }
  2203. }
  2204. return fpath;
  2205. }
  2206. bool cmGeneratorTarget::IsBundleOnApple() const
  2207. {
  2208. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  2209. this->IsCFBundleOnApple();
  2210. }
  2211. bool cmGeneratorTarget::IsWin32Executable(const std::string& config) const
  2212. {
  2213. return cmIsOn(cmGeneratorExpression::Evaluate(
  2214. this->GetSafeProperty("WIN32_EXECUTABLE"), this->LocalGenerator, config));
  2215. }
  2216. std::string cmGeneratorTarget::GetCFBundleDirectory(
  2217. const std::string& config, BundleDirectoryLevel level) const
  2218. {
  2219. std::string fpath = cmStrCat(
  2220. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2221. std::string ext;
  2222. if (cmValue p = this->GetProperty("BUNDLE_EXTENSION")) {
  2223. ext = *p;
  2224. } else {
  2225. if (this->IsXCTestOnApple()) {
  2226. ext = "xctest";
  2227. } else {
  2228. ext = "bundle";
  2229. }
  2230. }
  2231. fpath += ext;
  2232. if (shouldAddContentLevel(level) &&
  2233. !this->Makefile->PlatformIsAppleEmbedded()) {
  2234. fpath += "/Contents";
  2235. if (shouldAddFullLevel(level)) {
  2236. fpath += "/MacOS";
  2237. }
  2238. }
  2239. return fpath;
  2240. }
  2241. std::string cmGeneratorTarget::GetFrameworkDirectory(
  2242. const std::string& config, BundleDirectoryLevel level) const
  2243. {
  2244. std::string fpath = cmStrCat(
  2245. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact), '.');
  2246. cmValue ext = this->GetProperty("BUNDLE_EXTENSION");
  2247. fpath += (ext ? *ext : "framework");
  2248. if (shouldAddFullLevel(level) &&
  2249. !this->Makefile->PlatformIsAppleEmbedded()) {
  2250. fpath += "/Versions/";
  2251. fpath += this->GetFrameworkVersion();
  2252. }
  2253. return fpath;
  2254. }
  2255. std::string cmGeneratorTarget::GetFullName(
  2256. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2257. {
  2258. if (this->IsImported()) {
  2259. return this->GetFullNameImported(config, artifact);
  2260. }
  2261. return this->GetFullNameInternal(config, artifact);
  2262. }
  2263. std::string cmGeneratorTarget::GetInstallNameDirForBuildTree(
  2264. const std::string& config) const
  2265. {
  2266. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  2267. // If building directly for installation then the build tree install_name
  2268. // is the same as the install tree.
  2269. if (this->MacOSXUseInstallNameDir()) {
  2270. std::string installPrefix =
  2271. this->Makefile->GetSafeDefinition("CMAKE_INSTALL_PREFIX");
  2272. return this->GetInstallNameDirForInstallTree(config, installPrefix);
  2273. }
  2274. // Use the build tree directory for the target.
  2275. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_BUILD)) {
  2276. std::string dir;
  2277. if (this->MacOSXRpathInstallNameDirDefault()) {
  2278. dir = "@rpath";
  2279. } else {
  2280. dir = this->GetDirectory(config);
  2281. }
  2282. dir += "/";
  2283. return dir;
  2284. }
  2285. }
  2286. return "";
  2287. }
  2288. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree(
  2289. const std::string& config, const std::string& installPrefix) const
  2290. {
  2291. if (this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME")) {
  2292. std::string dir;
  2293. cmValue install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  2294. if (this->CanGenerateInstallNameDir(INSTALL_NAME_FOR_INSTALL)) {
  2295. if (cmNonempty(install_name_dir)) {
  2296. dir = *install_name_dir;
  2297. cmGeneratorExpression::ReplaceInstallPrefix(dir, installPrefix);
  2298. dir =
  2299. cmGeneratorExpression::Evaluate(dir, this->LocalGenerator, config);
  2300. if (!dir.empty()) {
  2301. dir = cmStrCat(dir, '/');
  2302. }
  2303. }
  2304. }
  2305. if (!install_name_dir) {
  2306. if (this->MacOSXRpathInstallNameDirDefault()) {
  2307. dir = "@rpath/";
  2308. }
  2309. }
  2310. return dir;
  2311. }
  2312. return "";
  2313. }
  2314. cmListFileBacktrace cmGeneratorTarget::GetBacktrace() const
  2315. {
  2316. return this->Target->GetBacktrace();
  2317. }
  2318. const std::set<BT<std::pair<std::string, bool>>>&
  2319. cmGeneratorTarget::GetUtilities() const
  2320. {
  2321. return this->Target->GetUtilities();
  2322. }
  2323. bool cmGeneratorTarget::HaveWellDefinedOutputFiles() const
  2324. {
  2325. return this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  2326. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2327. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  2328. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  2329. this->GetType() == cmStateEnums::EXECUTABLE;
  2330. }
  2331. const std::string* cmGeneratorTarget::GetExportMacro() const
  2332. {
  2333. // Define the symbol for targets that export symbols.
  2334. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  2335. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  2336. this->IsExecutableWithExports()) {
  2337. if (cmValue custom_export_name = this->GetProperty("DEFINE_SYMBOL")) {
  2338. this->ExportMacro = *custom_export_name;
  2339. } else {
  2340. std::string in = cmStrCat(this->GetName(), "_EXPORTS");
  2341. this->ExportMacro = cmSystemTools::MakeCidentifier(in);
  2342. }
  2343. return &this->ExportMacro;
  2344. }
  2345. return nullptr;
  2346. }
  2347. class cmTargetCollectLinkLanguages
  2348. {
  2349. public:
  2350. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  2351. std::string config,
  2352. std::unordered_set<std::string>& languages,
  2353. cmGeneratorTarget const* head, bool secondPass)
  2354. : Config(std::move(config))
  2355. , Languages(languages)
  2356. , HeadTarget(head)
  2357. , SecondPass(secondPass)
  2358. {
  2359. this->Visited.insert(target);
  2360. }
  2361. void Visit(cmLinkItem const& item)
  2362. {
  2363. if (!item.Target) {
  2364. return;
  2365. }
  2366. if (!this->Visited.insert(item.Target).second) {
  2367. return;
  2368. }
  2369. cmLinkInterface const* iface = item.Target->GetLinkInterface(
  2370. this->Config, this->HeadTarget, this->SecondPass);
  2371. if (!iface) {
  2372. return;
  2373. }
  2374. if (iface->HadLinkLanguageSensitiveCondition) {
  2375. this->HadLinkLanguageSensitiveCondition = true;
  2376. }
  2377. for (std::string const& language : iface->Languages) {
  2378. this->Languages.insert(language);
  2379. }
  2380. for (cmLinkItem const& lib : iface->Libraries) {
  2381. this->Visit(lib);
  2382. }
  2383. }
  2384. bool GetHadLinkLanguageSensitiveCondition() const
  2385. {
  2386. return this->HadLinkLanguageSensitiveCondition;
  2387. }
  2388. private:
  2389. std::string Config;
  2390. std::unordered_set<std::string>& Languages;
  2391. cmGeneratorTarget const* HeadTarget;
  2392. std::set<cmGeneratorTarget const*> Visited;
  2393. bool SecondPass;
  2394. bool HadLinkLanguageSensitiveCondition = false;
  2395. };
  2396. cmGeneratorTarget::LinkClosure const* cmGeneratorTarget::GetLinkClosure(
  2397. const std::string& config) const
  2398. {
  2399. // There is no link implementation for targets that cannot compile sources.
  2400. if (!this->CanCompileSources()) {
  2401. static LinkClosure const empty = { {}, {} };
  2402. return &empty;
  2403. }
  2404. std::string key(cmSystemTools::UpperCase(config));
  2405. auto i = this->LinkClosureMap.find(key);
  2406. if (i == this->LinkClosureMap.end()) {
  2407. LinkClosure lc;
  2408. this->ComputeLinkClosure(config, lc);
  2409. LinkClosureMapType::value_type entry(key, lc);
  2410. i = this->LinkClosureMap.insert(entry).first;
  2411. }
  2412. return &i->second;
  2413. }
  2414. class cmTargetSelectLinker
  2415. {
  2416. int Preference = 0;
  2417. cmGeneratorTarget const* Target;
  2418. cmGlobalGenerator* GG;
  2419. std::set<std::string> Preferred;
  2420. public:
  2421. cmTargetSelectLinker(cmGeneratorTarget const* target)
  2422. : Target(target)
  2423. {
  2424. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  2425. }
  2426. void Consider(const std::string& lang)
  2427. {
  2428. int preference = this->GG->GetLinkerPreference(lang);
  2429. if (preference > this->Preference) {
  2430. this->Preference = preference;
  2431. this->Preferred.clear();
  2432. }
  2433. if (preference == this->Preference) {
  2434. this->Preferred.insert(lang);
  2435. }
  2436. }
  2437. std::string Choose()
  2438. {
  2439. if (this->Preferred.empty()) {
  2440. return "";
  2441. }
  2442. if (this->Preferred.size() > 1) {
  2443. std::ostringstream e;
  2444. e << "Target " << this->Target->GetName()
  2445. << " contains multiple languages with the highest linker preference"
  2446. << " (" << this->Preference << "):\n";
  2447. for (std::string const& li : this->Preferred) {
  2448. e << " " << li << "\n";
  2449. }
  2450. e << "Set the LINKER_LANGUAGE property for this target.";
  2451. cmake* cm = this->Target->GetLocalGenerator()->GetCMakeInstance();
  2452. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  2453. this->Target->GetBacktrace());
  2454. }
  2455. return *this->Preferred.begin();
  2456. }
  2457. };
  2458. bool cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  2459. LinkClosure& lc,
  2460. bool secondPass) const
  2461. {
  2462. // Get languages built in this target.
  2463. std::unordered_set<std::string> languages;
  2464. cmLinkImplementation const* impl =
  2465. this->GetLinkImplementation(config, LinkInterfaceFor::Link, secondPass);
  2466. assert(impl);
  2467. languages.insert(impl->Languages.cbegin(), impl->Languages.cend());
  2468. // Add interface languages from linked targets.
  2469. // cmTargetCollectLinkLanguages cll(this, config, languages, this,
  2470. // secondPass);
  2471. cmTargetCollectLinkLanguages cll(this, config, languages, this, secondPass);
  2472. for (cmLinkImplItem const& lib : impl->Libraries) {
  2473. cll.Visit(lib);
  2474. }
  2475. // Store the transitive closure of languages.
  2476. cm::append(lc.Languages, languages);
  2477. // Choose the language whose linker should be used.
  2478. if (secondPass || lc.LinkerLanguage.empty()) {
  2479. // Find the language with the highest preference value.
  2480. cmTargetSelectLinker tsl(this);
  2481. // First select from the languages compiled directly in this target.
  2482. for (std::string const& l : impl->Languages) {
  2483. tsl.Consider(l);
  2484. }
  2485. // Now consider languages that propagate from linked targets.
  2486. for (std::string const& lang : languages) {
  2487. std::string propagates =
  2488. "CMAKE_" + lang + "_LINKER_PREFERENCE_PROPAGATES";
  2489. if (this->Makefile->IsOn(propagates)) {
  2490. tsl.Consider(lang);
  2491. }
  2492. }
  2493. lc.LinkerLanguage = tsl.Choose();
  2494. }
  2495. return impl->HadLinkLanguageSensitiveCondition ||
  2496. cll.GetHadLinkLanguageSensitiveCondition();
  2497. }
  2498. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  2499. LinkClosure& lc) const
  2500. {
  2501. bool secondPass = false;
  2502. {
  2503. LinkClosure linkClosure;
  2504. linkClosure.LinkerLanguage = this->LinkerLanguage;
  2505. bool hasHardCodedLinkerLanguage = this->Target->GetProperty("HAS_CXX") ||
  2506. !this->Target->GetSafeProperty("LINKER_LANGUAGE").empty();
  2507. // Get languages built in this target.
  2508. secondPass = this->ComputeLinkClosure(config, linkClosure, false) &&
  2509. !hasHardCodedLinkerLanguage;
  2510. this->LinkerLanguage = linkClosure.LinkerLanguage;
  2511. if (!secondPass) {
  2512. lc = std::move(linkClosure);
  2513. }
  2514. }
  2515. if (secondPass) {
  2516. LinkClosure linkClosure;
  2517. this->ComputeLinkClosure(config, linkClosure, secondPass);
  2518. lc = std::move(linkClosure);
  2519. // linker language must not be changed between the two passes
  2520. if (this->LinkerLanguage != lc.LinkerLanguage) {
  2521. std::ostringstream e;
  2522. e << "Evaluation of $<LINK_LANGUAGE:...> or $<LINK_LAND_AND_ID:...> "
  2523. "changes\nthe linker language for target \""
  2524. << this->GetName() << "\" (from '" << this->LinkerLanguage << "' to '"
  2525. << lc.LinkerLanguage << "') which is invalid.";
  2526. cmSystemTools::Error(e.str());
  2527. }
  2528. }
  2529. }
  2530. cmGeneratorTarget::NameComponents const&
  2531. cmGeneratorTarget::GetFullNameComponents(
  2532. std::string const& config, cmStateEnums::ArtifactType artifact) const
  2533. {
  2534. return this->GetFullNameInternalComponents(config, artifact);
  2535. }
  2536. std::string cmGeneratorTarget::BuildBundleDirectory(
  2537. const std::string& base, const std::string& config,
  2538. BundleDirectoryLevel level) const
  2539. {
  2540. std::string fpath = base;
  2541. if (this->IsAppBundleOnApple()) {
  2542. fpath += this->GetAppBundleDirectory(config, level);
  2543. }
  2544. if (this->IsFrameworkOnApple()) {
  2545. fpath += this->GetFrameworkDirectory(config, level);
  2546. }
  2547. if (this->IsCFBundleOnApple()) {
  2548. fpath += this->GetCFBundleDirectory(config, level);
  2549. }
  2550. return fpath;
  2551. }
  2552. std::string cmGeneratorTarget::GetMacContentDirectory(
  2553. const std::string& config, cmStateEnums::ArtifactType artifact) const
  2554. {
  2555. // Start with the output directory for the target.
  2556. std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/');
  2557. BundleDirectoryLevel level = ContentLevel;
  2558. if (this->IsFrameworkOnApple()) {
  2559. // additional files with a framework go into the version specific
  2560. // directory
  2561. level = FullLevel;
  2562. }
  2563. fpath = this->BuildBundleDirectory(fpath, config, level);
  2564. return fpath;
  2565. }
  2566. std::string cmGeneratorTarget::GetEffectiveFolderName() const
  2567. {
  2568. std::string effectiveFolder;
  2569. if (!this->GlobalGenerator->UseFolderProperty()) {
  2570. return effectiveFolder;
  2571. }
  2572. cmValue targetFolder = this->GetProperty("FOLDER");
  2573. if (targetFolder) {
  2574. effectiveFolder += *targetFolder;
  2575. }
  2576. return effectiveFolder;
  2577. }
  2578. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  2579. const std::string& config) const
  2580. {
  2581. // There is no compile information for imported targets.
  2582. if (this->IsImported()) {
  2583. return nullptr;
  2584. }
  2585. if (this->GetType() > cmStateEnums::OBJECT_LIBRARY) {
  2586. std::string msg = cmStrCat("cmTarget::GetCompileInfo called for ",
  2587. this->GetName(), " which has type ",
  2588. cmState::GetTargetTypeName(this->GetType()));
  2589. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  2590. return nullptr;
  2591. }
  2592. // Lookup/compute/cache the compile information for this configuration.
  2593. std::string config_upper;
  2594. if (!config.empty()) {
  2595. config_upper = cmSystemTools::UpperCase(config);
  2596. }
  2597. auto i = this->CompileInfoMap.find(config_upper);
  2598. if (i == this->CompileInfoMap.end()) {
  2599. CompileInfo info;
  2600. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  2601. CompileInfoMapType::value_type entry(config_upper, info);
  2602. i = this->CompileInfoMap.insert(entry).first;
  2603. }
  2604. return &i->second;
  2605. }
  2606. cmGeneratorTarget::ModuleDefinitionInfo const*
  2607. cmGeneratorTarget::GetModuleDefinitionInfo(std::string const& config) const
  2608. {
  2609. // A module definition file only makes sense on certain target types.
  2610. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  2611. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  2612. !this->IsExecutableWithExports()) {
  2613. return nullptr;
  2614. }
  2615. // Lookup/compute/cache the compile information for this configuration.
  2616. std::string config_upper;
  2617. if (!config.empty()) {
  2618. config_upper = cmSystemTools::UpperCase(config);
  2619. }
  2620. auto i = this->ModuleDefinitionInfoMap.find(config_upper);
  2621. if (i == this->ModuleDefinitionInfoMap.end()) {
  2622. ModuleDefinitionInfo info;
  2623. this->ComputeModuleDefinitionInfo(config, info);
  2624. ModuleDefinitionInfoMapType::value_type entry(config_upper, info);
  2625. i = this->ModuleDefinitionInfoMap.insert(entry).first;
  2626. }
  2627. return &i->second;
  2628. }
  2629. void cmGeneratorTarget::ComputeModuleDefinitionInfo(
  2630. std::string const& config, ModuleDefinitionInfo& info) const
  2631. {
  2632. this->GetModuleDefinitionSources(info.Sources, config);
  2633. info.WindowsExportAllSymbols =
  2634. this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS") &&
  2635. this->GetPropertyAsBool("WINDOWS_EXPORT_ALL_SYMBOLS");
  2636. #if !defined(CMAKE_BOOTSTRAP)
  2637. info.DefFileGenerated =
  2638. info.WindowsExportAllSymbols || info.Sources.size() > 1;
  2639. #else
  2640. // Our __create_def helper is not available during CMake bootstrap.
  2641. info.DefFileGenerated = false;
  2642. #endif
  2643. if (info.DefFileGenerated) {
  2644. info.DefFile =
  2645. this->GetObjectDirectory(config) /* has slash */ + "exports.def";
  2646. } else if (!info.Sources.empty()) {
  2647. info.DefFile = info.Sources.front()->GetFullPath();
  2648. }
  2649. }
  2650. bool cmGeneratorTarget::IsAIX() const
  2651. {
  2652. return this->Target->IsAIX();
  2653. }
  2654. bool cmGeneratorTarget::IsApple() const
  2655. {
  2656. return this->Target->IsApple();
  2657. }
  2658. bool cmGeneratorTarget::IsDLLPlatform() const
  2659. {
  2660. return this->Target->IsDLLPlatform();
  2661. }
  2662. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string>& result,
  2663. const std::string& config) const
  2664. {
  2665. const char* prop =
  2666. this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS", config);
  2667. if (!prop) {
  2668. return;
  2669. }
  2670. cmGeneratorExpressionDAGChecker dagChecker(this, "AUTOUIC_OPTIONS", nullptr,
  2671. nullptr);
  2672. cmExpandList(cmGeneratorExpression::Evaluate(prop, this->LocalGenerator,
  2673. config, this, &dagChecker),
  2674. result);
  2675. }
  2676. static void processILibs(const std::string& config,
  2677. cmGeneratorTarget const* headTarget,
  2678. cmLinkItem const& item, cmGlobalGenerator* gg,
  2679. std::vector<cmGeneratorTarget const*>& tgts,
  2680. std::set<cmGeneratorTarget const*>& emitted)
  2681. {
  2682. if (item.Target && emitted.insert(item.Target).second) {
  2683. tgts.push_back(item.Target);
  2684. if (cmLinkInterfaceLibraries const* iface =
  2685. item.Target->GetLinkInterfaceLibraries(config, headTarget,
  2686. LinkInterfaceFor::Usage)) {
  2687. for (cmLinkItem const& lib : iface->Libraries) {
  2688. processILibs(config, headTarget, lib, gg, tgts, emitted);
  2689. }
  2690. }
  2691. }
  2692. }
  2693. const std::vector<const cmGeneratorTarget*>&
  2694. cmGeneratorTarget::GetLinkImplementationClosure(
  2695. const std::string& config) const
  2696. {
  2697. // There is no link implementation for targets that cannot compile sources.
  2698. if (!this->CanCompileSources()) {
  2699. static std::vector<const cmGeneratorTarget*> const empty;
  2700. return empty;
  2701. }
  2702. LinkImplClosure& tgts = this->LinkImplClosureMap[config];
  2703. if (!tgts.Done) {
  2704. tgts.Done = true;
  2705. std::set<cmGeneratorTarget const*> emitted;
  2706. cmLinkImplementationLibraries const* impl =
  2707. this->GetLinkImplementationLibraries(config, LinkInterfaceFor::Usage);
  2708. assert(impl);
  2709. for (cmLinkImplItem const& lib : impl->Libraries) {
  2710. processILibs(config, this, lib,
  2711. this->LocalGenerator->GetGlobalGenerator(), tgts, emitted);
  2712. }
  2713. }
  2714. return tgts;
  2715. }
  2716. class cmTargetTraceDependencies
  2717. {
  2718. public:
  2719. cmTargetTraceDependencies(cmGeneratorTarget* target);
  2720. void Trace();
  2721. private:
  2722. cmGeneratorTarget* GeneratorTarget;
  2723. cmMakefile* Makefile;
  2724. cmLocalGenerator* LocalGenerator;
  2725. cmGlobalGenerator const* GlobalGenerator;
  2726. using SourceEntry = cmGeneratorTarget::SourceEntry;
  2727. SourceEntry* CurrentEntry;
  2728. std::queue<cmSourceFile*> SourceQueue;
  2729. std::set<cmSourceFile*> SourcesQueued;
  2730. using NameMapType = std::map<std::string, cmSourcesWithOutput>;
  2731. NameMapType NameMap;
  2732. std::vector<std::string> NewSources;
  2733. void QueueSource(cmSourceFile* sf);
  2734. void FollowName(std::string const& name);
  2735. void FollowNames(std::vector<std::string> const& names);
  2736. bool IsUtility(std::string const& dep);
  2737. void CheckCustomCommand(cmCustomCommand const& cc);
  2738. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  2739. };
  2740. cmTargetTraceDependencies::cmTargetTraceDependencies(cmGeneratorTarget* target)
  2741. : GeneratorTarget(target)
  2742. {
  2743. // Convenience.
  2744. this->Makefile = target->Target->GetMakefile();
  2745. this->LocalGenerator = target->GetLocalGenerator();
  2746. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  2747. this->CurrentEntry = nullptr;
  2748. // Queue all the source files already specified for the target.
  2749. std::set<cmSourceFile*> emitted;
  2750. std::vector<std::string> const& configs =
  2751. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  2752. for (std::string const& c : configs) {
  2753. std::vector<cmSourceFile*> sources;
  2754. this->GeneratorTarget->GetSourceFiles(sources, c);
  2755. for (cmSourceFile* sf : sources) {
  2756. const std::set<cmGeneratorTarget const*> tgts =
  2757. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  2758. if (cm::contains(tgts, this->GeneratorTarget)) {
  2759. std::ostringstream e;
  2760. e << "Evaluation output file\n \"" << sf->ResolveFullPath()
  2761. << "\"\ndepends on the sources of a target it is used in. This "
  2762. "is a dependency loop and is not allowed.";
  2763. this->GeneratorTarget->LocalGenerator->IssueMessage(
  2764. MessageType::FATAL_ERROR, e.str());
  2765. return;
  2766. }
  2767. if (emitted.insert(sf).second && this->SourcesQueued.insert(sf).second) {
  2768. this->SourceQueue.push(sf);
  2769. }
  2770. }
  2771. }
  2772. // Queue pre-build, pre-link, and post-build rule dependencies.
  2773. this->CheckCustomCommands(this->GeneratorTarget->GetPreBuildCommands());
  2774. this->CheckCustomCommands(this->GeneratorTarget->GetPreLinkCommands());
  2775. this->CheckCustomCommands(this->GeneratorTarget->GetPostBuildCommands());
  2776. }
  2777. void cmTargetTraceDependencies::Trace()
  2778. {
  2779. // Process one dependency at a time until the queue is empty.
  2780. while (!this->SourceQueue.empty()) {
  2781. // Get the next source from the queue.
  2782. cmSourceFile* sf = this->SourceQueue.front();
  2783. this->SourceQueue.pop();
  2784. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  2785. // Queue dependencies added explicitly by the user.
  2786. if (cmValue additionalDeps = sf->GetProperty("OBJECT_DEPENDS")) {
  2787. cmList objDeps{ *additionalDeps };
  2788. for (auto& objDep : objDeps) {
  2789. if (cmSystemTools::FileIsFullPath(objDep)) {
  2790. objDep = cmSystemTools::CollapseFullPath(objDep);
  2791. }
  2792. }
  2793. this->FollowNames(objDeps);
  2794. }
  2795. // Queue the source needed to generate this file, if any.
  2796. this->FollowName(sf->ResolveFullPath());
  2797. // Queue dependencies added programmatically by commands.
  2798. this->FollowNames(sf->GetDepends());
  2799. // Queue custom command dependencies.
  2800. if (cmCustomCommand const* cc = sf->GetCustomCommand()) {
  2801. this->CheckCustomCommand(*cc);
  2802. }
  2803. }
  2804. this->CurrentEntry = nullptr;
  2805. this->GeneratorTarget->AddTracedSources(this->NewSources);
  2806. }
  2807. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  2808. {
  2809. if (this->SourcesQueued.insert(sf).second) {
  2810. this->SourceQueue.push(sf);
  2811. // Make sure this file is in the target at the end.
  2812. this->NewSources.push_back(sf->ResolveFullPath());
  2813. }
  2814. }
  2815. void cmTargetTraceDependencies::FollowName(std::string const& name)
  2816. {
  2817. // Use lower bound with key comparison to not repeat the search for the
  2818. // insert position if the name could not be found (which is the common case).
  2819. auto i = this->NameMap.lower_bound(name);
  2820. if (i == this->NameMap.end() || i->first != name) {
  2821. // Check if we know how to generate this file.
  2822. cmSourcesWithOutput sources =
  2823. this->LocalGenerator->GetSourcesWithOutput(name);
  2824. // If we failed to find a target or source and we have a relative path, it
  2825. // might be a valid source if made relative to the current binary
  2826. // directory.
  2827. if (!sources.Target && !sources.Source &&
  2828. !cmSystemTools::FileIsFullPath(name)) {
  2829. auto fullname =
  2830. cmStrCat(this->Makefile->GetCurrentBinaryDirectory(), '/', name);
  2831. fullname = cmSystemTools::CollapseFullPath(
  2832. fullname, this->Makefile->GetHomeOutputDirectory());
  2833. sources = this->LocalGenerator->GetSourcesWithOutput(fullname);
  2834. }
  2835. i = this->NameMap.emplace_hint(i, name, sources);
  2836. }
  2837. if (cmTarget* t = i->second.Target) {
  2838. // The name is a byproduct of a utility target or a PRE_BUILD, PRE_LINK, or
  2839. // POST_BUILD command.
  2840. this->GeneratorTarget->Target->AddUtility(t->GetName(), false);
  2841. }
  2842. if (cmSourceFile* sf = i->second.Source) {
  2843. // For now only follow the dependency if the source file is not a
  2844. // byproduct. Semantics of byproducts in a non-Ninja context will have to
  2845. // be defined first.
  2846. if (!i->second.SourceIsByproduct) {
  2847. // Record the dependency we just followed.
  2848. if (this->CurrentEntry) {
  2849. this->CurrentEntry->Depends.push_back(sf);
  2850. }
  2851. this->QueueSource(sf);
  2852. }
  2853. }
  2854. }
  2855. void cmTargetTraceDependencies::FollowNames(
  2856. std::vector<std::string> const& names)
  2857. {
  2858. for (std::string const& name : names) {
  2859. this->FollowName(name);
  2860. }
  2861. }
  2862. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  2863. {
  2864. // Dependencies on targets (utilities) are supposed to be named by
  2865. // just the target name. However for compatibility we support
  2866. // naming the output file generated by the target (assuming there is
  2867. // no output-name property which old code would not have set). In
  2868. // that case the target name will be the file basename of the
  2869. // dependency.
  2870. std::string util = cmSystemTools::GetFilenameName(dep);
  2871. if (cmSystemTools::GetFilenameLastExtension(util) == ".exe") {
  2872. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  2873. }
  2874. // Check for a target with this name.
  2875. if (cmGeneratorTarget* t =
  2876. this->GeneratorTarget->GetLocalGenerator()->FindGeneratorTargetToUse(
  2877. util)) {
  2878. // If we find the target and the dep was given as a full path,
  2879. // then make sure it was not a full path to something else, and
  2880. // the fact that the name matched a target was just a coincidence.
  2881. if (cmSystemTools::FileIsFullPath(dep)) {
  2882. if (t->GetType() >= cmStateEnums::EXECUTABLE &&
  2883. t->GetType() <= cmStateEnums::MODULE_LIBRARY) {
  2884. // This is really only for compatibility so we do not need to
  2885. // worry about configuration names and output names.
  2886. std::string tLocation = t->GetLocationForBuild();
  2887. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  2888. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  2889. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  2890. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  2891. if (depLocation == tLocation) {
  2892. this->GeneratorTarget->Target->AddUtility(util, false);
  2893. return true;
  2894. }
  2895. }
  2896. } else {
  2897. // The original name of the dependency was not a full path. It
  2898. // must name a target, so add the target-level dependency.
  2899. this->GeneratorTarget->Target->AddUtility(util, true);
  2900. return true;
  2901. }
  2902. }
  2903. // The dependency does not name a target built in this project.
  2904. return false;
  2905. }
  2906. void cmTargetTraceDependencies::CheckCustomCommand(cmCustomCommand const& cc)
  2907. {
  2908. // Collect dependencies referenced by all configurations.
  2909. std::set<std::string> depends;
  2910. for (std::string const& config :
  2911. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig)) {
  2912. for (cmCustomCommandGenerator const& ccg :
  2913. this->LocalGenerator->MakeCustomCommandGenerators(cc, config)) {
  2914. // Collect target-level dependencies referenced in command lines.
  2915. for (auto const& util : ccg.GetUtilities()) {
  2916. this->GeneratorTarget->Target->AddUtility(util);
  2917. }
  2918. // Collect file-level dependencies referenced in DEPENDS.
  2919. depends.insert(ccg.GetDepends().begin(), ccg.GetDepends().end());
  2920. }
  2921. }
  2922. // Queue file-level dependencies.
  2923. for (std::string const& dep : depends) {
  2924. if (!this->IsUtility(dep)) {
  2925. // The dependency does not name a target and may be a file we
  2926. // know how to generate. Queue it.
  2927. this->FollowName(dep);
  2928. }
  2929. }
  2930. }
  2931. void cmTargetTraceDependencies::CheckCustomCommands(
  2932. const std::vector<cmCustomCommand>& commands)
  2933. {
  2934. for (cmCustomCommand const& command : commands) {
  2935. this->CheckCustomCommand(command);
  2936. }
  2937. }
  2938. void cmGeneratorTarget::TraceDependencies()
  2939. {
  2940. // CMake-generated targets have no dependencies to trace. Normally tracing
  2941. // would find nothing anyway, but when building CMake itself the "install"
  2942. // target command ends up referencing the "cmake" target but we do not
  2943. // really want the dependency because "install" depend on "all" anyway.
  2944. if (this->GetType() == cmStateEnums::GLOBAL_TARGET) {
  2945. return;
  2946. }
  2947. // Use a helper object to trace the dependencies.
  2948. cmTargetTraceDependencies tracer(this);
  2949. tracer.Trace();
  2950. }
  2951. std::string cmGeneratorTarget::GetCompilePDBDirectory(
  2952. const std::string& config) const
  2953. {
  2954. if (CompileInfo const* info = this->GetCompileInfo(config)) {
  2955. return info->CompilePdbDir;
  2956. }
  2957. return "";
  2958. }
  2959. std::vector<std::string> cmGeneratorTarget::GetAppleArchs(
  2960. std::string const& config, cm::optional<std::string> lang) const
  2961. {
  2962. cmList archList;
  2963. if (!this->IsApple()) {
  2964. return std::move(archList.data());
  2965. }
  2966. cmValue archs = nullptr;
  2967. if (!config.empty()) {
  2968. std::string defVarName =
  2969. cmStrCat("OSX_ARCHITECTURES_", cmSystemTools::UpperCase(config));
  2970. archs = this->GetProperty(defVarName);
  2971. }
  2972. if (!archs) {
  2973. archs = this->GetProperty("OSX_ARCHITECTURES");
  2974. }
  2975. if (archs) {
  2976. archList.assign(*archs);
  2977. }
  2978. if (archList.empty() &&
  2979. // Fall back to a default architecture if no compiler target is set.
  2980. (!lang ||
  2981. this->Makefile
  2982. ->GetDefinition(cmStrCat("CMAKE_", *lang, "_COMPILER_TARGET"))
  2983. .IsEmpty())) {
  2984. archList.assign(
  2985. this->Makefile->GetDefinition("_CMAKE_APPLE_ARCHS_DEFAULT"));
  2986. }
  2987. return std::move(archList.data());
  2988. }
  2989. void cmGeneratorTarget::AddExplicitLanguageFlags(std::string& flags,
  2990. cmSourceFile const& sf) const
  2991. {
  2992. cmValue lang = sf.GetProperty("LANGUAGE");
  2993. if (!lang) {
  2994. return;
  2995. }
  2996. switch (this->GetPolicyStatusCMP0119()) {
  2997. case cmPolicies::WARN:
  2998. CM_FALLTHROUGH;
  2999. case cmPolicies::OLD:
  3000. // The OLD behavior is to not add explicit language flags.
  3001. return;
  3002. case cmPolicies::REQUIRED_ALWAYS:
  3003. case cmPolicies::REQUIRED_IF_USED:
  3004. case cmPolicies::NEW:
  3005. // The NEW behavior is to add explicit language flags.
  3006. break;
  3007. }
  3008. this->LocalGenerator->AppendFeatureOptions(flags, *lang,
  3009. "EXPLICIT_LANGUAGE");
  3010. }
  3011. void cmGeneratorTarget::AddCUDAArchitectureFlags(cmBuildStep compileOrLink,
  3012. std::string const& config,
  3013. std::string& flags) const
  3014. {
  3015. std::string arch = this->GetSafeProperty("CUDA_ARCHITECTURES");
  3016. if (arch.empty()) {
  3017. switch (this->GetPolicyStatusCMP0104()) {
  3018. case cmPolicies::WARN:
  3019. if (!this->LocalGenerator->GetCMakeInstance()->GetIsInTryCompile()) {
  3020. this->Makefile->IssueMessage(
  3021. MessageType::AUTHOR_WARNING,
  3022. cmPolicies::GetPolicyWarning(cmPolicies::CMP0104) +
  3023. "\nCUDA_ARCHITECTURES is empty for target \"" + this->GetName() +
  3024. "\".");
  3025. }
  3026. CM_FALLTHROUGH;
  3027. case cmPolicies::OLD:
  3028. break;
  3029. default:
  3030. this->Makefile->IssueMessage(
  3031. MessageType::FATAL_ERROR,
  3032. "CUDA_ARCHITECTURES is empty for target \"" + this->GetName() +
  3033. "\".");
  3034. }
  3035. }
  3036. // If CUDA_ARCHITECTURES is false we don't add any architectures.
  3037. if (cmIsOff(arch)) {
  3038. return;
  3039. }
  3040. return this->AddCUDAArchitectureFlagsImpl(compileOrLink, config, "CUDA",
  3041. std::move(arch), flags);
  3042. }
  3043. void cmGeneratorTarget::AddCUDAArchitectureFlagsImpl(cmBuildStep compileOrLink,
  3044. std::string const& config,
  3045. std::string const& lang,
  3046. std::string arch,
  3047. std::string& flags) const
  3048. {
  3049. std::string const& compiler = this->Makefile->GetSafeDefinition(
  3050. cmStrCat("CMAKE_", lang, "_COMPILER_ID"));
  3051. const bool ipoEnabled = this->IsIPOEnabled(lang, config);
  3052. // Check for special modes: `all`, `all-major`.
  3053. if (arch == "all" || arch == "all-major") {
  3054. if (compiler == "NVIDIA" &&
  3055. cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
  3056. this->Makefile->GetDefinition(cmStrCat(
  3057. "CMAKE_", lang, "_COMPILER_VERSION")),
  3058. "11.5")) {
  3059. flags = cmStrCat(flags, " -arch=", arch);
  3060. return;
  3061. }
  3062. if (arch == "all") {
  3063. arch = *this->Makefile->GetDefinition(
  3064. cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL"));
  3065. } else if (arch == "all-major") {
  3066. arch = *this->Makefile->GetDefinition(
  3067. cmStrCat("CMAKE_", lang, "_ARCHITECTURES_ALL_MAJOR"));
  3068. }
  3069. } else if (arch == "native") {
  3070. cmValue native = this->Makefile->GetDefinition(
  3071. cmStrCat("CMAKE_", lang, "_ARCHITECTURES_NATIVE"));
  3072. if (native.IsEmpty()) {
  3073. this->Makefile->IssueMessage(
  3074. MessageType::FATAL_ERROR,
  3075. cmStrCat(lang,
  3076. "_ARCHITECTURES is set to \"native\", but no NVIDIA GPU was "
  3077. "detected."));
  3078. }
  3079. if (compiler == "NVIDIA" &&
  3080. cmSystemTools::VersionCompare(cmSystemTools::OP_GREATER_EQUAL,
  3081. this->Makefile->GetDefinition(cmStrCat(
  3082. "CMAKE_", lang, "_COMPILER_VERSION")),
  3083. "11.6")) {
  3084. flags = cmStrCat(flags, " -arch=", arch);
  3085. return;
  3086. }
  3087. arch = *native;
  3088. }
  3089. struct CudaArchitecture
  3090. {
  3091. std::string name;
  3092. bool real{ true };
  3093. bool virtual_{ true };
  3094. };
  3095. std::vector<CudaArchitecture> architectures;
  3096. {
  3097. cmList options(arch);
  3098. for (auto& option : options) {
  3099. CudaArchitecture architecture;
  3100. // Architecture name is up to the first specifier.
  3101. std::size_t pos = option.find_first_of('-');
  3102. architecture.name = option.substr(0, pos);
  3103. if (pos != std::string::npos) {
  3104. cm::string_view specifier{ option.c_str() + pos + 1,
  3105. option.length() - pos - 1 };
  3106. if (specifier == "real") {
  3107. architecture.real = true;
  3108. architecture.virtual_ = false;
  3109. } else if (specifier == "virtual") {
  3110. architecture.real = false;
  3111. architecture.virtual_ = true;
  3112. } else {
  3113. this->Makefile->IssueMessage(
  3114. MessageType::FATAL_ERROR,
  3115. "Unknown CUDA architecture specifier \"" + std::string(specifier) +
  3116. "\".");
  3117. }
  3118. }
  3119. architectures.emplace_back(architecture);
  3120. }
  3121. }
  3122. if (compiler == "NVIDIA") {
  3123. if (ipoEnabled && compileOrLink == cmBuildStep::Link) {
  3124. if (cmValue cudaIPOFlags = this->Makefile->GetDefinition(
  3125. cmStrCat("CMAKE_", lang, "_LINK_OPTIONS_IPO"))) {
  3126. flags += *cudaIPOFlags;
  3127. }
  3128. }
  3129. for (CudaArchitecture& architecture : architectures) {
  3130. flags +=
  3131. " \"--generate-code=arch=compute_" + architecture.name + ",code=[";
  3132. if (architecture.virtual_) {
  3133. flags += "compute_" + architecture.name;
  3134. if (ipoEnabled || architecture.real) {
  3135. flags += ",";
  3136. }
  3137. }
  3138. if (ipoEnabled) {
  3139. if (compileOrLink == cmBuildStep::Compile) {
  3140. flags += "lto_" + architecture.name;
  3141. } else if (compileOrLink == cmBuildStep::Link) {
  3142. flags += "sm_" + architecture.name;
  3143. }
  3144. } else if (architecture.real) {
  3145. flags += "sm_" + architecture.name;
  3146. }
  3147. flags += "]\"";
  3148. }
  3149. } else if (compiler == "Clang") {
  3150. for (CudaArchitecture& architecture : architectures) {
  3151. flags += " --cuda-gpu-arch=sm_" + architecture.name;
  3152. if (!architecture.real) {
  3153. this->Makefile->IssueMessage(
  3154. MessageType::WARNING,
  3155. "Clang doesn't support disabling CUDA real code generation.");
  3156. }
  3157. if (!architecture.virtual_) {
  3158. flags += " --no-cuda-include-ptx=sm_" + architecture.name;
  3159. }
  3160. }
  3161. }
  3162. }
  3163. void cmGeneratorTarget::AddISPCTargetFlags(std::string& flags) const
  3164. {
  3165. const std::string& arch = this->GetSafeProperty("ISPC_INSTRUCTION_SETS");
  3166. // If ISPC_TARGET is false we don't add any architectures.
  3167. if (cmIsOff(arch)) {
  3168. return;
  3169. }
  3170. std::string const& compiler =
  3171. this->Makefile->GetSafeDefinition("CMAKE_ISPC_COMPILER_ID");
  3172. if (compiler == "Intel") {
  3173. cmList targets(arch);
  3174. if (!targets.empty()) {
  3175. flags += cmStrCat(" --target=", cmWrap("", targets, "", ","));
  3176. }
  3177. }
  3178. }
  3179. void cmGeneratorTarget::AddHIPArchitectureFlags(cmBuildStep compileOrLink,
  3180. std::string const& config,
  3181. std::string& flags) const
  3182. {
  3183. std::string arch = this->GetSafeProperty("HIP_ARCHITECTURES");
  3184. if (arch.empty()) {
  3185. this->Makefile->IssueMessage(MessageType::FATAL_ERROR,
  3186. "HIP_ARCHITECTURES is empty for target \"" +
  3187. this->GetName() + "\".");
  3188. }
  3189. // If HIP_ARCHITECTURES is false we don't add any architectures.
  3190. if (cmIsOff(arch)) {
  3191. return;
  3192. }
  3193. if (this->Makefile->GetSafeDefinition("CMAKE_HIP_PLATFORM") == "nvidia") {
  3194. return this->AddCUDAArchitectureFlagsImpl(compileOrLink, config, "HIP",
  3195. std::move(arch), flags);
  3196. }
  3197. cmList options(arch);
  3198. for (std::string& option : options) {
  3199. flags += " --offload-arch=" + option;
  3200. }
  3201. }
  3202. void cmGeneratorTarget::AddCUDAToolkitFlags(std::string& flags) const
  3203. {
  3204. std::string const& compiler =
  3205. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_ID");
  3206. if (compiler == "Clang") {
  3207. // Pass CUDA toolkit explicitly to Clang.
  3208. // Clang's searching for the system CUDA toolkit isn't very good and it's
  3209. // expected the user will explicitly pass the toolkit path.
  3210. // This also avoids Clang having to search for the toolkit on every
  3211. // invocation.
  3212. std::string toolkitRoot =
  3213. this->Makefile->GetSafeDefinition("CMAKE_CUDA_COMPILER_LIBRARY_ROOT");
  3214. if (!toolkitRoot.empty()) {
  3215. flags += " --cuda-path=" +
  3216. this->LocalGenerator->ConvertToOutputFormat(toolkitRoot,
  3217. cmOutputConverter::SHELL);
  3218. }
  3219. }
  3220. }
  3221. //----------------------------------------------------------------------------
  3222. std::string cmGeneratorTarget::GetFeatureSpecificLinkRuleVariable(
  3223. std::string const& var, std::string const& lang,
  3224. std::string const& config) const
  3225. {
  3226. if (this->IsIPOEnabled(lang, config)) {
  3227. std::string varIPO = var + "_IPO";
  3228. if (this->Makefile->IsDefinitionSet(varIPO)) {
  3229. return varIPO;
  3230. }
  3231. }
  3232. return var;
  3233. }
  3234. //----------------------------------------------------------------------------
  3235. std::string cmGeneratorTarget::GetCreateRuleVariable(
  3236. std::string const& lang, std::string const& config) const
  3237. {
  3238. switch (this->GetType()) {
  3239. case cmStateEnums::STATIC_LIBRARY: {
  3240. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  3241. return this->GetFeatureSpecificLinkRuleVariable(var, lang, config);
  3242. }
  3243. case cmStateEnums::SHARED_LIBRARY:
  3244. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  3245. case cmStateEnums::MODULE_LIBRARY:
  3246. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  3247. case cmStateEnums::EXECUTABLE:
  3248. if (this->IsExecutableWithExports()) {
  3249. std::string linkExeWithExports =
  3250. "CMAKE_" + lang + "_LINK_EXECUTABLE_WITH_EXPORTS";
  3251. if (this->Makefile->IsDefinitionSet(linkExeWithExports)) {
  3252. return linkExeWithExports;
  3253. }
  3254. }
  3255. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  3256. default:
  3257. break;
  3258. }
  3259. return "";
  3260. }
  3261. //----------------------------------------------------------------------------
  3262. std::string cmGeneratorTarget::GetClangTidyExportFixesDirectory(
  3263. const std::string& lang) const
  3264. {
  3265. cmValue val =
  3266. this->GetProperty(cmStrCat(lang, "_CLANG_TIDY_EXPORT_FIXES_DIR"));
  3267. if (!cmNonempty(val)) {
  3268. return {};
  3269. }
  3270. std::string path = *val;
  3271. if (!cmSystemTools::FileIsFullPath(path)) {
  3272. path =
  3273. cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/', path);
  3274. }
  3275. return cmSystemTools::CollapseFullPath(path);
  3276. }
  3277. namespace {
  3278. void processIncludeDirectories(cmGeneratorTarget const* tgt,
  3279. EvaluatedTargetPropertyEntries& entries,
  3280. std::vector<BT<std::string>>& includes,
  3281. std::unordered_set<std::string>& uniqueIncludes,
  3282. bool debugIncludes)
  3283. {
  3284. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  3285. cmLinkImplItem const& item = entry.LinkImplItem;
  3286. std::string const& targetName = item.AsStr();
  3287. bool const fromImported = item.Target && item.Target->IsImported();
  3288. bool const checkCMP0027 = item.CheckCMP0027;
  3289. std::string usedIncludes;
  3290. for (std::string& entryInclude : entry.Values) {
  3291. if (fromImported && !cmSystemTools::FileExists(entryInclude)) {
  3292. std::ostringstream e;
  3293. MessageType messageType = MessageType::FATAL_ERROR;
  3294. if (checkCMP0027) {
  3295. switch (tgt->GetPolicyStatusCMP0027()) {
  3296. case cmPolicies::WARN:
  3297. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  3298. CM_FALLTHROUGH;
  3299. case cmPolicies::OLD:
  3300. messageType = MessageType::AUTHOR_WARNING;
  3301. break;
  3302. case cmPolicies::REQUIRED_ALWAYS:
  3303. case cmPolicies::REQUIRED_IF_USED:
  3304. case cmPolicies::NEW:
  3305. break;
  3306. }
  3307. }
  3308. /* clang-format off */
  3309. e << "Imported target \"" << targetName << "\" includes "
  3310. "non-existent path\n \"" << entryInclude << "\"\nin its "
  3311. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  3312. "* The path was deleted, renamed, or moved to another "
  3313. "location.\n"
  3314. "* An install or uninstall procedure did not complete "
  3315. "successfully.\n"
  3316. "* The installation package was faulty and references files it "
  3317. "does not provide.\n";
  3318. /* clang-format on */
  3319. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  3320. return;
  3321. }
  3322. if (!cmSystemTools::FileIsFullPath(entryInclude)) {
  3323. std::ostringstream e;
  3324. bool noMessage = false;
  3325. MessageType messageType = MessageType::FATAL_ERROR;
  3326. if (!targetName.empty()) {
  3327. /* clang-format off */
  3328. e << "Target \"" << targetName << "\" contains relative "
  3329. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  3330. " \"" << entryInclude << "\"";
  3331. /* clang-format on */
  3332. } else {
  3333. switch (tgt->GetPolicyStatusCMP0021()) {
  3334. case cmPolicies::WARN: {
  3335. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  3336. messageType = MessageType::AUTHOR_WARNING;
  3337. } break;
  3338. case cmPolicies::OLD:
  3339. noMessage = true;
  3340. break;
  3341. case cmPolicies::REQUIRED_IF_USED:
  3342. case cmPolicies::REQUIRED_ALWAYS:
  3343. case cmPolicies::NEW:
  3344. // Issue the fatal message.
  3345. break;
  3346. }
  3347. e << "Found relative path while evaluating include directories of "
  3348. "\""
  3349. << tgt->GetName() << "\":\n \"" << entryInclude << "\"\n";
  3350. }
  3351. if (!noMessage) {
  3352. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  3353. if (messageType == MessageType::FATAL_ERROR) {
  3354. return;
  3355. }
  3356. }
  3357. }
  3358. if (!cmIsOff(entryInclude)) {
  3359. cmSystemTools::ConvertToUnixSlashes(entryInclude);
  3360. }
  3361. if (uniqueIncludes.insert(entryInclude).second) {
  3362. includes.emplace_back(entryInclude, entry.Backtrace);
  3363. if (debugIncludes) {
  3364. usedIncludes += " * " + entryInclude + "\n";
  3365. }
  3366. }
  3367. }
  3368. if (!usedIncludes.empty()) {
  3369. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  3370. MessageType::LOG,
  3371. std::string("Used includes for target ") + tgt->GetName() + ":\n" +
  3372. usedIncludes,
  3373. entry.Backtrace);
  3374. }
  3375. }
  3376. }
  3377. }
  3378. std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
  3379. const std::string& config, const std::string& lang) const
  3380. {
  3381. ConfigAndLanguage cacheKey(config, lang);
  3382. {
  3383. auto it = this->IncludeDirectoriesCache.find(cacheKey);
  3384. if (it != this->IncludeDirectoriesCache.end()) {
  3385. return it->second;
  3386. }
  3387. }
  3388. std::vector<BT<std::string>> includes;
  3389. std::unordered_set<std::string> uniqueIncludes;
  3390. cmGeneratorExpressionDAGChecker dagChecker(this, "INCLUDE_DIRECTORIES",
  3391. nullptr, nullptr);
  3392. cmList debugProperties{ this->Makefile->GetDefinition(
  3393. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  3394. bool debugIncludes = !this->DebugIncludesDone &&
  3395. cm::contains(debugProperties, "INCLUDE_DIRECTORIES");
  3396. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3397. this->DebugIncludesDone = true;
  3398. }
  3399. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3400. this, config, lang, &dagChecker, this->IncludeDirectoriesEntries);
  3401. if (lang == "Swift") {
  3402. AddLangSpecificImplicitIncludeDirectories(
  3403. this, lang, config, "Swift_MODULE_DIRECTORY",
  3404. IncludeDirectoryFallBack::BINARY, entries);
  3405. }
  3406. if (this->CanCompileSources() && (lang != "Swift" && lang != "Fortran")) {
  3407. const std::string propertyName = "ISPC_HEADER_DIRECTORY";
  3408. // If this target has ISPC sources make sure to add the header
  3409. // directory to other compilation units
  3410. if (cm::contains(this->GetAllConfigCompileLanguages(), "ISPC")) {
  3411. if (cmValue val = this->GetProperty(propertyName)) {
  3412. includes.emplace_back(*val);
  3413. } else {
  3414. includes.emplace_back(this->GetObjectDirectory(config));
  3415. }
  3416. }
  3417. AddLangSpecificImplicitIncludeDirectories(
  3418. this, "ISPC", config, propertyName, IncludeDirectoryFallBack::OBJECT,
  3419. entries);
  3420. }
  3421. AddInterfaceEntries(this, config, "INTERFACE_INCLUDE_DIRECTORIES", lang,
  3422. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3423. processIncludeDirectories(this, entries, includes, uniqueIncludes,
  3424. debugIncludes);
  3425. if (this->IsApple()) {
  3426. if (cmLinkImplementationLibraries const* impl =
  3427. this->GetLinkImplementationLibraries(config,
  3428. LinkInterfaceFor::Usage)) {
  3429. for (cmLinkImplItem const& lib : impl->Libraries) {
  3430. std::string libDir;
  3431. if (lib.Target == nullptr) {
  3432. libDir = cmSystemTools::CollapseFullPath(
  3433. lib.AsStr(), this->Makefile->GetHomeOutputDirectory());
  3434. } else if (lib.Target->Target->IsFrameworkOnApple() ||
  3435. this->IsImportedFrameworkFolderOnApple(config)) {
  3436. libDir = lib.Target->GetLocation(config);
  3437. } else {
  3438. continue;
  3439. }
  3440. auto fwDescriptor =
  3441. this->GetGlobalGenerator()->SplitFrameworkPath(libDir);
  3442. if (!fwDescriptor) {
  3443. continue;
  3444. }
  3445. auto fwInclude = fwDescriptor->GetFrameworkPath();
  3446. if (uniqueIncludes.insert(fwInclude).second) {
  3447. includes.emplace_back(fwInclude, cmListFileBacktrace());
  3448. }
  3449. }
  3450. }
  3451. }
  3452. this->IncludeDirectoriesCache.emplace(cacheKey, includes);
  3453. return includes;
  3454. }
  3455. enum class OptionsParse
  3456. {
  3457. None,
  3458. Shell
  3459. };
  3460. namespace {
  3461. const auto DL_BEGIN = "<DEVICE_LINK>"_s;
  3462. const auto DL_END = "</DEVICE_LINK>"_s;
  3463. void processOptions(cmGeneratorTarget const* tgt,
  3464. EvaluatedTargetPropertyEntries const& entries,
  3465. std::vector<BT<std::string>>& options,
  3466. std::unordered_set<std::string>& uniqueOptions,
  3467. bool debugOptions, const char* logName, OptionsParse parse,
  3468. bool processDeviceOptions = false)
  3469. {
  3470. bool splitOption = !processDeviceOptions;
  3471. for (EvaluatedTargetPropertyEntry const& entry : entries.Entries) {
  3472. std::string usedOptions;
  3473. for (std::string const& opt : entry.Values) {
  3474. if (processDeviceOptions && (opt == DL_BEGIN || opt == DL_END)) {
  3475. options.emplace_back(opt, entry.Backtrace);
  3476. splitOption = opt == DL_BEGIN;
  3477. continue;
  3478. }
  3479. if (uniqueOptions.insert(opt).second) {
  3480. if (parse == OptionsParse::Shell &&
  3481. cmHasLiteralPrefix(opt, "SHELL:")) {
  3482. if (splitOption) {
  3483. std::vector<std::string> tmp;
  3484. cmSystemTools::ParseUnixCommandLine(opt.c_str() + 6, tmp);
  3485. for (std::string& o : tmp) {
  3486. options.emplace_back(std::move(o), entry.Backtrace);
  3487. }
  3488. } else {
  3489. options.emplace_back(std::string(opt.c_str() + 6),
  3490. entry.Backtrace);
  3491. }
  3492. } else {
  3493. options.emplace_back(opt, entry.Backtrace);
  3494. }
  3495. if (debugOptions) {
  3496. usedOptions += " * " + opt + "\n";
  3497. }
  3498. }
  3499. }
  3500. if (!usedOptions.empty()) {
  3501. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  3502. MessageType::LOG,
  3503. std::string("Used ") + logName + std::string(" for target ") +
  3504. tgt->GetName() + ":\n" + usedOptions,
  3505. entry.Backtrace);
  3506. }
  3507. }
  3508. }
  3509. std::vector<BT<std::string>> wrapOptions(
  3510. std::vector<std::string>& options, const cmListFileBacktrace& bt,
  3511. const std::vector<std::string>& wrapperFlag, const std::string& wrapperSep,
  3512. bool concatFlagAndArgs)
  3513. {
  3514. std::vector<BT<std::string>> result;
  3515. if (options.empty()) {
  3516. return result;
  3517. }
  3518. if (wrapperFlag.empty()) {
  3519. // nothing specified, insert elements as is
  3520. result.reserve(options.size());
  3521. for (std::string& o : options) {
  3522. result.emplace_back(std::move(o), bt);
  3523. }
  3524. return result;
  3525. }
  3526. for (std::vector<std::string>::size_type index = 0; index < options.size();
  3527. index++) {
  3528. if (cmHasLiteralPrefix(options[index], "LINKER:")) {
  3529. // LINKER wrapper specified, insert elements as is
  3530. result.emplace_back(std::move(options[index]), bt);
  3531. continue;
  3532. }
  3533. if (cmHasLiteralPrefix(options[index], "-Wl,")) {
  3534. // replace option by LINKER wrapper
  3535. result.emplace_back(options[index].replace(0, 4, "LINKER:"), bt);
  3536. continue;
  3537. }
  3538. if (cmHasLiteralPrefix(options[index], "-Xlinker=")) {
  3539. // replace option by LINKER wrapper
  3540. result.emplace_back(options[index].replace(0, 9, "LINKER:"), bt);
  3541. continue;
  3542. }
  3543. if (options[index] == "-Xlinker") {
  3544. // replace option by LINKER wrapper
  3545. if (index + 1 < options.size()) {
  3546. result.emplace_back("LINKER:" + options[++index], bt);
  3547. } else {
  3548. result.emplace_back(std::move(options[index]), bt);
  3549. }
  3550. continue;
  3551. }
  3552. // collect all options which must be transformed
  3553. std::vector<std::string> opts;
  3554. while (index < options.size()) {
  3555. if (!cmHasLiteralPrefix(options[index], "LINKER:") &&
  3556. !cmHasLiteralPrefix(options[index], "-Wl,") &&
  3557. !cmHasLiteralPrefix(options[index], "-Xlinker")) {
  3558. opts.emplace_back(std::move(options[index++]));
  3559. } else {
  3560. --index;
  3561. break;
  3562. }
  3563. }
  3564. if (opts.empty()) {
  3565. continue;
  3566. }
  3567. if (!wrapperSep.empty()) {
  3568. if (concatFlagAndArgs) {
  3569. // insert flag elements except last one
  3570. for (auto i = wrapperFlag.begin(); i != wrapperFlag.end() - 1; ++i) {
  3571. result.emplace_back(*i, bt);
  3572. }
  3573. // concatenate last flag element and all list values
  3574. // in one option
  3575. result.emplace_back(wrapperFlag.back() + cmJoin(opts, wrapperSep), bt);
  3576. } else {
  3577. for (std::string const& i : wrapperFlag) {
  3578. result.emplace_back(i, bt);
  3579. }
  3580. // concatenate all list values in one option
  3581. result.emplace_back(cmJoin(opts, wrapperSep), bt);
  3582. }
  3583. } else {
  3584. // prefix each element of list with wrapper
  3585. if (concatFlagAndArgs) {
  3586. std::transform(opts.begin(), opts.end(), opts.begin(),
  3587. [&wrapperFlag](std::string const& o) -> std::string {
  3588. return wrapperFlag.back() + o;
  3589. });
  3590. }
  3591. for (std::string& o : opts) {
  3592. for (auto i = wrapperFlag.begin(),
  3593. e = concatFlagAndArgs ? wrapperFlag.end() - 1
  3594. : wrapperFlag.end();
  3595. i != e; ++i) {
  3596. result.emplace_back(*i, bt);
  3597. }
  3598. result.emplace_back(std::move(o), bt);
  3599. }
  3600. }
  3601. }
  3602. return result;
  3603. }
  3604. }
  3605. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string>& result,
  3606. const std::string& config,
  3607. const std::string& language) const
  3608. {
  3609. std::vector<BT<std::string>> tmp = this->GetCompileOptions(config, language);
  3610. result.reserve(tmp.size());
  3611. for (BT<std::string>& v : tmp) {
  3612. result.emplace_back(std::move(v.Value));
  3613. }
  3614. }
  3615. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileOptions(
  3616. std::string const& config, std::string const& language) const
  3617. {
  3618. ConfigAndLanguage cacheKey(config, language);
  3619. {
  3620. auto it = this->CompileOptionsCache.find(cacheKey);
  3621. if (it != this->CompileOptionsCache.end()) {
  3622. return it->second;
  3623. }
  3624. }
  3625. std::vector<BT<std::string>> result;
  3626. std::unordered_set<std::string> uniqueOptions;
  3627. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_OPTIONS", nullptr,
  3628. nullptr);
  3629. cmList debugProperties{ this->Makefile->GetDefinition(
  3630. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  3631. bool debugOptions = !this->DebugCompileOptionsDone &&
  3632. cm::contains(debugProperties, "COMPILE_OPTIONS");
  3633. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3634. this->DebugCompileOptionsDone = true;
  3635. }
  3636. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3637. this, config, language, &dagChecker, this->CompileOptionsEntries);
  3638. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_OPTIONS", language,
  3639. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3640. processOptions(this, entries, result, uniqueOptions, debugOptions,
  3641. "compile options", OptionsParse::Shell);
  3642. CompileOptionsCache.emplace(cacheKey, result);
  3643. return result;
  3644. }
  3645. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string>& result,
  3646. const std::string& config) const
  3647. {
  3648. std::vector<BT<std::string>> tmp = this->GetCompileFeatures(config);
  3649. result.reserve(tmp.size());
  3650. for (BT<std::string>& v : tmp) {
  3651. result.emplace_back(std::move(v.Value));
  3652. }
  3653. }
  3654. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileFeatures(
  3655. std::string const& config) const
  3656. {
  3657. std::vector<BT<std::string>> result;
  3658. std::unordered_set<std::string> uniqueFeatures;
  3659. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_FEATURES", nullptr,
  3660. nullptr);
  3661. cmList debugProperties{ this->Makefile->GetDefinition(
  3662. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  3663. bool debugFeatures = !this->DebugCompileFeaturesDone &&
  3664. cm::contains(debugProperties, "COMPILE_FEATURES");
  3665. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3666. this->DebugCompileFeaturesDone = true;
  3667. }
  3668. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3669. this, config, std::string(), &dagChecker, this->CompileFeaturesEntries);
  3670. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_FEATURES",
  3671. std::string(), &dagChecker, entries,
  3672. IncludeRuntimeInterface::Yes);
  3673. processOptions(this, entries, result, uniqueFeatures, debugFeatures,
  3674. "compile features", OptionsParse::None);
  3675. return result;
  3676. }
  3677. void cmGeneratorTarget::GetCompileDefinitions(
  3678. std::vector<std::string>& result, const std::string& config,
  3679. const std::string& language) const
  3680. {
  3681. std::vector<BT<std::string>> tmp =
  3682. this->GetCompileDefinitions(config, language);
  3683. result.reserve(tmp.size());
  3684. for (BT<std::string>& v : tmp) {
  3685. result.emplace_back(std::move(v.Value));
  3686. }
  3687. }
  3688. std::vector<BT<std::string>> cmGeneratorTarget::GetCompileDefinitions(
  3689. std::string const& config, std::string const& language) const
  3690. {
  3691. ConfigAndLanguage cacheKey(config, language);
  3692. {
  3693. auto it = this->CompileDefinitionsCache.find(cacheKey);
  3694. if (it != this->CompileDefinitionsCache.end()) {
  3695. return it->second;
  3696. }
  3697. }
  3698. std::vector<BT<std::string>> list;
  3699. std::unordered_set<std::string> uniqueOptions;
  3700. cmGeneratorExpressionDAGChecker dagChecker(this, "COMPILE_DEFINITIONS",
  3701. nullptr, nullptr);
  3702. cmList debugProperties{ this->Makefile->GetDefinition(
  3703. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  3704. bool debugDefines = !this->DebugCompileDefinitionsDone &&
  3705. cm::contains(debugProperties, "COMPILE_DEFINITIONS");
  3706. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3707. this->DebugCompileDefinitionsDone = true;
  3708. }
  3709. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3710. this, config, language, &dagChecker, this->CompileDefinitionsEntries);
  3711. AddInterfaceEntries(this, config, "INTERFACE_COMPILE_DEFINITIONS", language,
  3712. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3713. if (!config.empty()) {
  3714. std::string configPropName =
  3715. "COMPILE_DEFINITIONS_" + cmSystemTools::UpperCase(config);
  3716. cmValue configProp = this->GetProperty(configPropName);
  3717. if (configProp) {
  3718. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) {
  3719. case cmPolicies::WARN: {
  3720. this->LocalGenerator->IssueMessage(
  3721. MessageType::AUTHOR_WARNING,
  3722. cmPolicies::GetPolicyWarning(cmPolicies::CMP0043));
  3723. CM_FALLTHROUGH;
  3724. }
  3725. case cmPolicies::OLD: {
  3726. std::unique_ptr<TargetPropertyEntry> entry =
  3727. CreateTargetPropertyEntry(
  3728. *this->LocalGenerator->GetCMakeInstance(), *configProp);
  3729. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  3730. this, config, language, &dagChecker, *entry));
  3731. } break;
  3732. case cmPolicies::NEW:
  3733. case cmPolicies::REQUIRED_ALWAYS:
  3734. case cmPolicies::REQUIRED_IF_USED:
  3735. break;
  3736. }
  3737. }
  3738. }
  3739. processOptions(this, entries, list, uniqueOptions, debugDefines,
  3740. "compile definitions", OptionsParse::None);
  3741. this->CompileDefinitionsCache.emplace(cacheKey, list);
  3742. return list;
  3743. }
  3744. std::vector<BT<std::string>> cmGeneratorTarget::GetPrecompileHeaders(
  3745. const std::string& config, const std::string& language) const
  3746. {
  3747. ConfigAndLanguage cacheKey(config, language);
  3748. {
  3749. auto it = this->PrecompileHeadersCache.find(cacheKey);
  3750. if (it != this->PrecompileHeadersCache.end()) {
  3751. return it->second;
  3752. }
  3753. }
  3754. std::unordered_set<std::string> uniqueOptions;
  3755. cmGeneratorExpressionDAGChecker dagChecker(this, "PRECOMPILE_HEADERS",
  3756. nullptr, nullptr);
  3757. cmList debugProperties{ this->Makefile->GetDefinition(
  3758. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  3759. bool debugDefines = !this->DebugPrecompileHeadersDone &&
  3760. std::find(debugProperties.begin(), debugProperties.end(),
  3761. "PRECOMPILE_HEADERS") != debugProperties.end();
  3762. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  3763. this->DebugPrecompileHeadersDone = true;
  3764. }
  3765. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  3766. this, config, language, &dagChecker, this->PrecompileHeadersEntries);
  3767. AddInterfaceEntries(this, config, "INTERFACE_PRECOMPILE_HEADERS", language,
  3768. &dagChecker, entries, IncludeRuntimeInterface::Yes);
  3769. std::vector<BT<std::string>> list;
  3770. processOptions(this, entries, list, uniqueOptions, debugDefines,
  3771. "precompile headers", OptionsParse::None);
  3772. this->PrecompileHeadersCache.emplace(cacheKey, list);
  3773. return list;
  3774. }
  3775. std::string cmGeneratorTarget::GetPchHeader(const std::string& config,
  3776. const std::string& language,
  3777. const std::string& arch) const
  3778. {
  3779. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3780. language != "OBJCXX") {
  3781. return std::string();
  3782. }
  3783. if (this->GetPropertyAsBool("DISABLE_PRECOMPILE_HEADERS")) {
  3784. return std::string();
  3785. }
  3786. const cmGeneratorTarget* generatorTarget = this;
  3787. cmValue pchReuseFrom =
  3788. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3789. const auto inserted =
  3790. this->PchHeaders.insert(std::make_pair(language + config + arch, ""));
  3791. if (inserted.second) {
  3792. const std::vector<BT<std::string>> headers =
  3793. this->GetPrecompileHeaders(config, language);
  3794. if (headers.empty() && !pchReuseFrom) {
  3795. return std::string();
  3796. }
  3797. std::string& filename = inserted.first->second;
  3798. if (pchReuseFrom) {
  3799. generatorTarget =
  3800. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3801. }
  3802. const std::map<std::string, std::string> languageToExtension = {
  3803. { "C", ".h" },
  3804. { "CXX", ".hxx" },
  3805. { "OBJC", ".objc.h" },
  3806. { "OBJCXX", ".objcxx.hxx" }
  3807. };
  3808. filename = generatorTarget->GetSupportDirectory();
  3809. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  3810. filename = cmStrCat(filename, "/", config);
  3811. }
  3812. filename =
  3813. cmStrCat(filename, "/cmake_pch", arch.empty() ? "" : cmStrCat("_", arch),
  3814. languageToExtension.at(language));
  3815. const std::string filename_tmp = cmStrCat(filename, ".tmp");
  3816. if (!pchReuseFrom) {
  3817. cmValue pchPrologue =
  3818. this->Makefile->GetDefinition("CMAKE_PCH_PROLOGUE");
  3819. cmValue pchEpilogue =
  3820. this->Makefile->GetDefinition("CMAKE_PCH_EPILOGUE");
  3821. std::string firstHeaderOnDisk;
  3822. {
  3823. cmGeneratedFileStream file(
  3824. filename_tmp, false,
  3825. this->GetGlobalGenerator()->GetMakefileEncoding());
  3826. file << "/* generated by CMake */\n\n";
  3827. if (pchPrologue) {
  3828. file << *pchPrologue << "\n";
  3829. }
  3830. if (this->GetGlobalGenerator()->IsXcode()) {
  3831. file << "#ifndef CMAKE_SKIP_PRECOMPILE_HEADERS\n";
  3832. }
  3833. if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
  3834. file << "#ifdef __cplusplus\n";
  3835. }
  3836. for (auto const& header_bt : headers) {
  3837. if (header_bt.Value.empty()) {
  3838. continue;
  3839. }
  3840. if (header_bt.Value[0] == '<' || header_bt.Value[0] == '\"') {
  3841. file << "#include " << header_bt.Value << "\n";
  3842. } else {
  3843. file << "#include \"" << header_bt.Value << "\"\n";
  3844. }
  3845. if (cmSystemTools::FileExists(header_bt.Value) &&
  3846. firstHeaderOnDisk.empty()) {
  3847. firstHeaderOnDisk = header_bt.Value;
  3848. }
  3849. }
  3850. if (language == "CXX" && !this->GetGlobalGenerator()->IsXcode()) {
  3851. file << "#endif // __cplusplus\n";
  3852. }
  3853. if (this->GetGlobalGenerator()->IsXcode()) {
  3854. file << "#endif // CMAKE_SKIP_PRECOMPILE_HEADERS\n";
  3855. }
  3856. if (pchEpilogue) {
  3857. file << *pchEpilogue << "\n";
  3858. }
  3859. }
  3860. if (!firstHeaderOnDisk.empty()) {
  3861. cmFileTimes::Copy(firstHeaderOnDisk, filename_tmp);
  3862. }
  3863. cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
  3864. }
  3865. }
  3866. return inserted.first->second;
  3867. }
  3868. std::string cmGeneratorTarget::GetPchSource(const std::string& config,
  3869. const std::string& language,
  3870. const std::string& arch) const
  3871. {
  3872. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3873. language != "OBJCXX") {
  3874. return std::string();
  3875. }
  3876. const auto inserted =
  3877. this->PchSources.insert(std::make_pair(language + config + arch, ""));
  3878. if (inserted.second) {
  3879. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  3880. if (pchHeader.empty()) {
  3881. return std::string();
  3882. }
  3883. std::string& filename = inserted.first->second;
  3884. const cmGeneratorTarget* generatorTarget = this;
  3885. cmValue pchReuseFrom =
  3886. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3887. if (pchReuseFrom) {
  3888. generatorTarget =
  3889. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3890. }
  3891. filename = cmStrCat(generatorTarget->GetSupportDirectory(), "/cmake_pch");
  3892. // For GCC the source extension will be transformed into .h[xx].gch
  3893. if (!this->Makefile->IsOn("CMAKE_LINK_PCH")) {
  3894. const std::map<std::string, std::string> languageToExtension = {
  3895. { "C", ".h.c" },
  3896. { "CXX", ".hxx.cxx" },
  3897. { "OBJC", ".objc.h.m" },
  3898. { "OBJCXX", ".objcxx.hxx.mm" }
  3899. };
  3900. filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat("_", arch),
  3901. languageToExtension.at(language));
  3902. } else {
  3903. const std::map<std::string, std::string> languageToExtension = {
  3904. { "C", ".c" }, { "CXX", ".cxx" }, { "OBJC", ".m" }, { "OBJCXX", ".mm" }
  3905. };
  3906. filename = cmStrCat(filename, arch.empty() ? "" : cmStrCat("_", arch),
  3907. languageToExtension.at(language));
  3908. }
  3909. const std::string filename_tmp = cmStrCat(filename, ".tmp");
  3910. if (!pchReuseFrom) {
  3911. {
  3912. cmGeneratedFileStream file(filename_tmp);
  3913. file << "/* generated by CMake */\n";
  3914. }
  3915. cmFileTimes::Copy(pchHeader, filename_tmp);
  3916. cmSystemTools::MoveFileIfDifferent(filename_tmp, filename);
  3917. }
  3918. }
  3919. return inserted.first->second;
  3920. }
  3921. std::string cmGeneratorTarget::GetPchFileObject(const std::string& config,
  3922. const std::string& language,
  3923. const std::string& arch)
  3924. {
  3925. if (language != "C" && language != "CXX" && language != "OBJC" &&
  3926. language != "OBJCXX") {
  3927. return std::string();
  3928. }
  3929. const auto inserted =
  3930. this->PchObjectFiles.insert(std::make_pair(language + config + arch, ""));
  3931. if (inserted.second) {
  3932. const std::string pchSource = this->GetPchSource(config, language, arch);
  3933. if (pchSource.empty()) {
  3934. return std::string();
  3935. }
  3936. std::string& filename = inserted.first->second;
  3937. auto* pchSf = this->Makefile->GetOrCreateSource(
  3938. pchSource, false, cmSourceFileLocationKind::Known);
  3939. filename = cmStrCat(this->ObjectDirectory, this->GetObjectName(pchSf));
  3940. if (this->GetGlobalGenerator()->IsMultiConfig()) {
  3941. cmSystemTools::ReplaceString(
  3942. filename, this->GetGlobalGenerator()->GetCMakeCFGIntDir(), config);
  3943. }
  3944. }
  3945. return inserted.first->second;
  3946. }
  3947. std::string cmGeneratorTarget::GetPchFile(const std::string& config,
  3948. const std::string& language,
  3949. const std::string& arch)
  3950. {
  3951. const auto inserted =
  3952. this->PchFiles.insert(std::make_pair(language + config + arch, ""));
  3953. if (inserted.second) {
  3954. std::string& pchFile = inserted.first->second;
  3955. const std::string pchExtension =
  3956. this->Makefile->GetSafeDefinition("CMAKE_PCH_EXTENSION");
  3957. if (this->Makefile->IsOn("CMAKE_LINK_PCH")) {
  3958. auto replaceExtension = [](const std::string& str,
  3959. const std::string& ext) -> std::string {
  3960. auto dot_pos = str.rfind('.');
  3961. std::string result;
  3962. if (dot_pos != std::string::npos) {
  3963. result = str.substr(0, dot_pos);
  3964. }
  3965. result += ext;
  3966. return result;
  3967. };
  3968. cmGeneratorTarget* generatorTarget = this;
  3969. cmValue pchReuseFrom =
  3970. generatorTarget->GetProperty("PRECOMPILE_HEADERS_REUSE_FROM");
  3971. if (pchReuseFrom) {
  3972. generatorTarget =
  3973. this->GetGlobalGenerator()->FindGeneratorTarget(*pchReuseFrom);
  3974. }
  3975. const std::string pchFileObject =
  3976. generatorTarget->GetPchFileObject(config, language, arch);
  3977. if (!pchExtension.empty()) {
  3978. pchFile = replaceExtension(pchFileObject, pchExtension);
  3979. }
  3980. } else {
  3981. pchFile = this->GetPchHeader(config, language, arch);
  3982. pchFile += pchExtension;
  3983. }
  3984. }
  3985. return inserted.first->second;
  3986. }
  3987. std::string cmGeneratorTarget::GetPchCreateCompileOptions(
  3988. const std::string& config, const std::string& language,
  3989. const std::string& arch)
  3990. {
  3991. const auto inserted = this->PchCreateCompileOptions.insert(
  3992. std::make_pair(language + config + arch, ""));
  3993. if (inserted.second) {
  3994. std::string& createOptionList = inserted.first->second;
  3995. if (this->GetPropertyAsBool("PCH_WARN_INVALID")) {
  3996. createOptionList = this->Makefile->GetSafeDefinition(
  3997. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH"));
  3998. }
  3999. if (this->GetPropertyAsBool("PCH_INSTANTIATE_TEMPLATES")) {
  4000. std::string varName = cmStrCat(
  4001. "CMAKE_", language, "_COMPILE_OPTIONS_INSTANTIATE_TEMPLATES_PCH");
  4002. std::string instantiateOption =
  4003. this->Makefile->GetSafeDefinition(varName);
  4004. if (!instantiateOption.empty()) {
  4005. createOptionList = cmStrCat(createOptionList, ";", instantiateOption);
  4006. }
  4007. }
  4008. const std::string createOptVar =
  4009. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_CREATE_PCH");
  4010. createOptionList = cmStrCat(
  4011. createOptionList, ";", this->Makefile->GetSafeDefinition(createOptVar));
  4012. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  4013. const std::string pchFile = this->GetPchFile(config, language, arch);
  4014. cmSystemTools::ReplaceString(createOptionList, "<PCH_HEADER>", pchHeader);
  4015. cmSystemTools::ReplaceString(createOptionList, "<PCH_FILE>", pchFile);
  4016. }
  4017. return inserted.first->second;
  4018. }
  4019. std::string cmGeneratorTarget::GetPchUseCompileOptions(
  4020. const std::string& config, const std::string& language,
  4021. const std::string& arch)
  4022. {
  4023. const auto inserted = this->PchUseCompileOptions.insert(
  4024. std::make_pair(language + config + arch, ""));
  4025. if (inserted.second) {
  4026. std::string& useOptionList = inserted.first->second;
  4027. if (this->GetPropertyAsBool("PCH_WARN_INVALID")) {
  4028. useOptionList = this->Makefile->GetSafeDefinition(
  4029. cmStrCat("CMAKE_", language, "_COMPILE_OPTIONS_INVALID_PCH"));
  4030. }
  4031. const std::string useOptVar =
  4032. cmStrCat(language, "_COMPILE_OPTIONS_USE_PCH");
  4033. std::string const& useOptionListProperty =
  4034. this->GetSafeProperty(useOptVar);
  4035. useOptionList = cmStrCat(
  4036. useOptionList, ";",
  4037. useOptionListProperty.empty()
  4038. ? this->Makefile->GetSafeDefinition(cmStrCat("CMAKE_", useOptVar))
  4039. : useOptionListProperty);
  4040. const std::string pchHeader = this->GetPchHeader(config, language, arch);
  4041. const std::string pchFile = this->GetPchFile(config, language, arch);
  4042. cmSystemTools::ReplaceString(useOptionList, "<PCH_HEADER>", pchHeader);
  4043. cmSystemTools::ReplaceString(useOptionList, "<PCH_FILE>", pchFile);
  4044. }
  4045. return inserted.first->second;
  4046. }
  4047. void cmGeneratorTarget::AddSourceFileToUnityBatch(
  4048. const std::string& sourceFilename)
  4049. {
  4050. this->UnityBatchedSourceFiles.insert(sourceFilename);
  4051. }
  4052. bool cmGeneratorTarget::IsSourceFilePartOfUnityBatch(
  4053. const std::string& sourceFilename) const
  4054. {
  4055. if (!this->GetPropertyAsBool("UNITY_BUILD")) {
  4056. return false;
  4057. }
  4058. return this->UnityBatchedSourceFiles.find(sourceFilename) !=
  4059. this->UnityBatchedSourceFiles.end();
  4060. }
  4061. void cmGeneratorTarget::GetLinkOptions(std::vector<std::string>& result,
  4062. const std::string& config,
  4063. const std::string& language) const
  4064. {
  4065. if (this->IsDeviceLink() &&
  4066. this->GetPolicyStatusCMP0105() != cmPolicies::NEW) {
  4067. // link options are not propagated to the device link step
  4068. return;
  4069. }
  4070. std::vector<BT<std::string>> tmp = this->GetLinkOptions(config, language);
  4071. result.reserve(tmp.size());
  4072. for (BT<std::string>& v : tmp) {
  4073. result.emplace_back(std::move(v.Value));
  4074. }
  4075. }
  4076. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkOptions(
  4077. std::string const& config, std::string const& language) const
  4078. {
  4079. ConfigAndLanguage cacheKey(
  4080. config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
  4081. {
  4082. auto it = this->LinkOptionsCache.find(cacheKey);
  4083. if (it != this->LinkOptionsCache.end()) {
  4084. return it->second;
  4085. }
  4086. }
  4087. std::vector<BT<std::string>> result;
  4088. std::unordered_set<std::string> uniqueOptions;
  4089. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_OPTIONS", nullptr,
  4090. nullptr);
  4091. cmList debugProperties{ this->Makefile->GetDefinition(
  4092. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  4093. bool debugOptions = !this->DebugLinkOptionsDone &&
  4094. cm::contains(debugProperties, "LINK_OPTIONS");
  4095. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4096. this->DebugLinkOptionsDone = true;
  4097. }
  4098. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  4099. this, config, language, &dagChecker, this->LinkOptionsEntries);
  4100. AddInterfaceEntries(this, config, "INTERFACE_LINK_OPTIONS", language,
  4101. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  4102. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  4103. ? LinkInterfaceFor::Link
  4104. : LinkInterfaceFor::Usage);
  4105. processOptions(this, entries, result, uniqueOptions, debugOptions,
  4106. "link options", OptionsParse::Shell, this->IsDeviceLink());
  4107. if (this->IsDeviceLink()) {
  4108. // wrap host link options
  4109. const std::string wrapper(this->Makefile->GetSafeDefinition(
  4110. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG"));
  4111. cmList wrapperFlag{ wrapper };
  4112. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  4113. "CMAKE_" + language + "_DEVICE_COMPILER_WRAPPER_FLAG_SEP"));
  4114. bool concatFlagAndArgs = true;
  4115. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  4116. concatFlagAndArgs = false;
  4117. wrapperFlag.pop_back();
  4118. }
  4119. auto it = result.begin();
  4120. while (it != result.end()) {
  4121. if (it->Value == DL_BEGIN) {
  4122. // device link options, no treatment
  4123. it = result.erase(it);
  4124. it = std::find_if(it, result.end(), [](const BT<std::string>& item) {
  4125. return item.Value == DL_END;
  4126. });
  4127. if (it != result.end()) {
  4128. it = result.erase(it);
  4129. }
  4130. } else {
  4131. // host link options must be wrapped
  4132. std::vector<std::string> options;
  4133. cmSystemTools::ParseUnixCommandLine(it->Value.c_str(), options);
  4134. auto hostOptions = wrapOptions(options, it->Backtrace, wrapperFlag,
  4135. wrapperSep, concatFlagAndArgs);
  4136. it = result.erase(it);
  4137. // some compilers (like gcc 4.8 or Intel 19.0 or XLC 16) do not respect
  4138. // C++11 standard: 'std::vector::insert()' do not returns an iterator,
  4139. // so need to recompute the iterator after insertion.
  4140. if (it == result.end()) {
  4141. cm::append(result, hostOptions);
  4142. it = result.end();
  4143. } else {
  4144. auto index = it - result.begin();
  4145. result.insert(it, hostOptions.begin(), hostOptions.end());
  4146. it = result.begin() + index + hostOptions.size();
  4147. }
  4148. }
  4149. }
  4150. }
  4151. // Last step: replace "LINKER:" prefixed elements by
  4152. // actual linker wrapper
  4153. result = this->ResolveLinkerWrapper(result, language);
  4154. this->LinkOptionsCache.emplace(cacheKey, result);
  4155. return result;
  4156. }
  4157. std::vector<BT<std::string>>& cmGeneratorTarget::ResolveLinkerWrapper(
  4158. std::vector<BT<std::string>>& result, const std::string& language,
  4159. bool joinItems) const
  4160. {
  4161. // replace "LINKER:" prefixed elements by actual linker wrapper
  4162. const std::string wrapper(this->Makefile->GetSafeDefinition(
  4163. "CMAKE_" + language +
  4164. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG"
  4165. : "_LINKER_WRAPPER_FLAG")));
  4166. cmList wrapperFlag{ wrapper };
  4167. const std::string wrapperSep(this->Makefile->GetSafeDefinition(
  4168. "CMAKE_" + language +
  4169. (this->IsDeviceLink() ? "_DEVICE_LINKER_WRAPPER_FLAG_SEP"
  4170. : "_LINKER_WRAPPER_FLAG_SEP")));
  4171. bool concatFlagAndArgs = true;
  4172. if (!wrapperFlag.empty() && wrapperFlag.back() == " ") {
  4173. concatFlagAndArgs = false;
  4174. wrapperFlag.pop_back();
  4175. }
  4176. const std::string LINKER{ "LINKER:" };
  4177. const std::string SHELL{ "SHELL:" };
  4178. const std::string LINKER_SHELL = LINKER + SHELL;
  4179. std::vector<BT<std::string>>::iterator entry;
  4180. while ((entry = std::find_if(result.begin(), result.end(),
  4181. [&LINKER](BT<std::string> const& item) -> bool {
  4182. return item.Value.compare(0, LINKER.length(),
  4183. LINKER) == 0;
  4184. })) != result.end()) {
  4185. std::string value = std::move(entry->Value);
  4186. cmListFileBacktrace bt = std::move(entry->Backtrace);
  4187. entry = result.erase(entry);
  4188. std::vector<std::string> linkerOptions;
  4189. if (value.compare(0, LINKER_SHELL.length(), LINKER_SHELL) == 0) {
  4190. cmSystemTools::ParseUnixCommandLine(
  4191. value.c_str() + LINKER_SHELL.length(), linkerOptions);
  4192. } else {
  4193. linkerOptions = cmTokenize(value.substr(LINKER.length()), ",");
  4194. }
  4195. if (linkerOptions.empty() ||
  4196. (linkerOptions.size() == 1 && linkerOptions.front().empty())) {
  4197. continue;
  4198. }
  4199. // for now, raise an error if prefix SHELL: is part of arguments
  4200. if (std::find_if(linkerOptions.begin(), linkerOptions.end(),
  4201. [&SHELL](const std::string& item) -> bool {
  4202. return item.find(SHELL) != std::string::npos;
  4203. }) != linkerOptions.end()) {
  4204. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4205. MessageType::FATAL_ERROR,
  4206. "'SHELL:' prefix is not supported as part of 'LINKER:' arguments.",
  4207. this->GetBacktrace());
  4208. return result;
  4209. }
  4210. std::vector<BT<std::string>> options = wrapOptions(
  4211. linkerOptions, bt, wrapperFlag, wrapperSep, concatFlagAndArgs);
  4212. if (joinItems) {
  4213. result.insert(entry,
  4214. cmJoin(cmRange<decltype(options.cbegin())>(
  4215. options.cbegin(), options.cend()),
  4216. " "_s));
  4217. } else {
  4218. result.insert(entry, options.begin(), options.end());
  4219. }
  4220. }
  4221. return result;
  4222. }
  4223. void cmGeneratorTarget::GetStaticLibraryLinkOptions(
  4224. std::vector<std::string>& result, const std::string& config,
  4225. const std::string& language) const
  4226. {
  4227. std::vector<BT<std::string>> tmp =
  4228. this->GetStaticLibraryLinkOptions(config, language);
  4229. result.reserve(tmp.size());
  4230. for (BT<std::string>& v : tmp) {
  4231. result.emplace_back(std::move(v.Value));
  4232. }
  4233. }
  4234. std::vector<BT<std::string>> cmGeneratorTarget::GetStaticLibraryLinkOptions(
  4235. std::string const& config, std::string const& language) const
  4236. {
  4237. std::vector<BT<std::string>> result;
  4238. std::unordered_set<std::string> uniqueOptions;
  4239. cmGeneratorExpressionDAGChecker dagChecker(this, "STATIC_LIBRARY_OPTIONS",
  4240. nullptr, nullptr);
  4241. EvaluatedTargetPropertyEntries entries;
  4242. if (cmValue linkOptions = this->GetProperty("STATIC_LIBRARY_OPTIONS")) {
  4243. std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
  4244. *this->LocalGenerator->GetCMakeInstance(), *linkOptions);
  4245. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  4246. this, config, language, &dagChecker, *entry));
  4247. }
  4248. processOptions(this, entries, result, uniqueOptions, false,
  4249. "static library link options", OptionsParse::Shell);
  4250. return result;
  4251. }
  4252. namespace {
  4253. void processLinkDirectories(cmGeneratorTarget const* tgt,
  4254. EvaluatedTargetPropertyEntries& entries,
  4255. std::vector<BT<std::string>>& directories,
  4256. std::unordered_set<std::string>& uniqueDirectories,
  4257. bool debugDirectories)
  4258. {
  4259. for (EvaluatedTargetPropertyEntry& entry : entries.Entries) {
  4260. cmLinkImplItem const& item = entry.LinkImplItem;
  4261. std::string const& targetName = item.AsStr();
  4262. std::string usedDirectories;
  4263. for (std::string& entryDirectory : entry.Values) {
  4264. if (!cmSystemTools::FileIsFullPath(entryDirectory)) {
  4265. std::ostringstream e;
  4266. bool noMessage = false;
  4267. MessageType messageType = MessageType::FATAL_ERROR;
  4268. if (!targetName.empty()) {
  4269. /* clang-format off */
  4270. e << "Target \"" << targetName << "\" contains relative "
  4271. "path in its INTERFACE_LINK_DIRECTORIES:\n"
  4272. " \"" << entryDirectory << "\"";
  4273. /* clang-format on */
  4274. } else {
  4275. switch (tgt->GetPolicyStatusCMP0081()) {
  4276. case cmPolicies::WARN: {
  4277. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0081) << "\n";
  4278. messageType = MessageType::AUTHOR_WARNING;
  4279. } break;
  4280. case cmPolicies::OLD:
  4281. noMessage = true;
  4282. break;
  4283. case cmPolicies::REQUIRED_IF_USED:
  4284. case cmPolicies::REQUIRED_ALWAYS:
  4285. case cmPolicies::NEW:
  4286. // Issue the fatal message.
  4287. break;
  4288. }
  4289. e << "Found relative path while evaluating link directories of "
  4290. "\""
  4291. << tgt->GetName() << "\":\n \"" << entryDirectory << "\"\n";
  4292. }
  4293. if (!noMessage) {
  4294. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  4295. if (messageType == MessageType::FATAL_ERROR) {
  4296. return;
  4297. }
  4298. }
  4299. }
  4300. // Sanitize the path the same way the link_directories command does
  4301. // in case projects set the LINK_DIRECTORIES property directly.
  4302. cmSystemTools::ConvertToUnixSlashes(entryDirectory);
  4303. if (uniqueDirectories.insert(entryDirectory).second) {
  4304. directories.emplace_back(entryDirectory, entry.Backtrace);
  4305. if (debugDirectories) {
  4306. usedDirectories += " * " + entryDirectory + "\n";
  4307. }
  4308. }
  4309. }
  4310. if (!usedDirectories.empty()) {
  4311. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  4312. MessageType::LOG,
  4313. std::string("Used link directories for target ") + tgt->GetName() +
  4314. ":\n" + usedDirectories,
  4315. entry.Backtrace);
  4316. }
  4317. }
  4318. }
  4319. }
  4320. void cmGeneratorTarget::GetLinkDirectories(std::vector<std::string>& result,
  4321. const std::string& config,
  4322. const std::string& language) const
  4323. {
  4324. std::vector<BT<std::string>> tmp =
  4325. this->GetLinkDirectories(config, language);
  4326. result.reserve(tmp.size());
  4327. for (BT<std::string>& v : tmp) {
  4328. result.emplace_back(std::move(v.Value));
  4329. }
  4330. }
  4331. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDirectories(
  4332. std::string const& config, std::string const& language) const
  4333. {
  4334. ConfigAndLanguage cacheKey(
  4335. config, cmStrCat(language, this->IsDeviceLink() ? "-device" : ""));
  4336. {
  4337. auto it = this->LinkDirectoriesCache.find(cacheKey);
  4338. if (it != this->LinkDirectoriesCache.end()) {
  4339. return it->second;
  4340. }
  4341. }
  4342. std::vector<BT<std::string>> result;
  4343. std::unordered_set<std::string> uniqueDirectories;
  4344. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DIRECTORIES", nullptr,
  4345. nullptr);
  4346. cmList debugProperties{ this->Makefile->GetDefinition(
  4347. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  4348. bool debugDirectories = !this->DebugLinkDirectoriesDone &&
  4349. cm::contains(debugProperties, "LINK_DIRECTORIES");
  4350. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  4351. this->DebugLinkDirectoriesDone = true;
  4352. }
  4353. EvaluatedTargetPropertyEntries entries = EvaluateTargetPropertyEntries(
  4354. this, config, language, &dagChecker, this->LinkDirectoriesEntries);
  4355. AddInterfaceEntries(this, config, "INTERFACE_LINK_DIRECTORIES", language,
  4356. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  4357. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  4358. ? LinkInterfaceFor::Link
  4359. : LinkInterfaceFor::Usage);
  4360. processLinkDirectories(this, entries, result, uniqueDirectories,
  4361. debugDirectories);
  4362. this->LinkDirectoriesCache.emplace(cacheKey, result);
  4363. return result;
  4364. }
  4365. void cmGeneratorTarget::GetLinkDepends(std::vector<std::string>& result,
  4366. const std::string& config,
  4367. const std::string& language) const
  4368. {
  4369. std::vector<BT<std::string>> tmp = this->GetLinkDepends(config, language);
  4370. result.reserve(tmp.size());
  4371. for (BT<std::string>& v : tmp) {
  4372. result.emplace_back(std::move(v.Value));
  4373. }
  4374. }
  4375. std::vector<BT<std::string>> cmGeneratorTarget::GetLinkDepends(
  4376. std::string const& config, std::string const& language) const
  4377. {
  4378. std::vector<BT<std::string>> result;
  4379. std::unordered_set<std::string> uniqueOptions;
  4380. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_DEPENDS", nullptr,
  4381. nullptr);
  4382. EvaluatedTargetPropertyEntries entries;
  4383. if (cmValue linkDepends = this->GetProperty("LINK_DEPENDS")) {
  4384. cmList depends{ *linkDepends };
  4385. for (const auto& depend : depends) {
  4386. std::unique_ptr<TargetPropertyEntry> entry = CreateTargetPropertyEntry(
  4387. *this->LocalGenerator->GetCMakeInstance(), depend);
  4388. entries.Entries.emplace_back(EvaluateTargetPropertyEntry(
  4389. this, config, language, &dagChecker, *entry));
  4390. }
  4391. }
  4392. AddInterfaceEntries(this, config, "INTERFACE_LINK_DEPENDS", language,
  4393. &dagChecker, entries, IncludeRuntimeInterface::Yes,
  4394. this->GetPolicyStatusCMP0099() == cmPolicies::NEW
  4395. ? LinkInterfaceFor::Link
  4396. : LinkInterfaceFor::Usage);
  4397. processOptions(this, entries, result, uniqueOptions, false, "link depends",
  4398. OptionsParse::None);
  4399. return result;
  4400. }
  4401. void cmGeneratorTarget::ComputeTargetManifest(const std::string& config) const
  4402. {
  4403. if (this->IsImported()) {
  4404. return;
  4405. }
  4406. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  4407. // Get the names.
  4408. cmGeneratorTarget::Names targetNames;
  4409. if (this->GetType() == cmStateEnums::EXECUTABLE) {
  4410. targetNames = this->GetExecutableNames(config);
  4411. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  4412. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4413. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4414. targetNames = this->GetLibraryNames(config);
  4415. } else {
  4416. return;
  4417. }
  4418. // Get the directory.
  4419. std::string dir =
  4420. this->GetDirectory(config, cmStateEnums::RuntimeBinaryArtifact);
  4421. // Add each name.
  4422. std::string f;
  4423. if (!targetNames.Output.empty()) {
  4424. f = cmStrCat(dir, '/', targetNames.Output);
  4425. gg->AddToManifest(f);
  4426. }
  4427. if (!targetNames.SharedObject.empty()) {
  4428. f = cmStrCat(dir, '/', targetNames.SharedObject);
  4429. gg->AddToManifest(f);
  4430. }
  4431. if (!targetNames.Real.empty()) {
  4432. f = cmStrCat(dir, '/', targetNames.Real);
  4433. gg->AddToManifest(f);
  4434. }
  4435. if (!targetNames.PDB.empty()) {
  4436. f = cmStrCat(dir, '/', targetNames.PDB);
  4437. gg->AddToManifest(f);
  4438. }
  4439. dir = this->GetDirectory(config, cmStateEnums::ImportLibraryArtifact);
  4440. if (!targetNames.ImportOutput.empty()) {
  4441. f = cmStrCat(dir, '/', targetNames.ImportOutput);
  4442. gg->AddToManifest(f);
  4443. }
  4444. if (!targetNames.ImportLibrary.empty()) {
  4445. f = cmStrCat(dir, '/', targetNames.ImportLibrary);
  4446. gg->AddToManifest(f);
  4447. }
  4448. if (!targetNames.ImportReal.empty()) {
  4449. f = cmStrCat(dir, '/', targetNames.ImportReal);
  4450. gg->AddToManifest(f);
  4451. }
  4452. }
  4453. cm::optional<cmStandardLevel> cmGeneratorTarget::GetExplicitStandardLevel(
  4454. std::string const& lang, std::string const& config) const
  4455. {
  4456. cm::optional<cmStandardLevel> level;
  4457. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  4458. auto i = this->ExplicitStandardLevel.find(key);
  4459. if (i != this->ExplicitStandardLevel.end()) {
  4460. level = i->second;
  4461. }
  4462. return level;
  4463. }
  4464. void cmGeneratorTarget::UpdateExplicitStandardLevel(std::string const& lang,
  4465. std::string const& config,
  4466. cmStandardLevel level)
  4467. {
  4468. auto e = this->ExplicitStandardLevel.emplace(
  4469. cmStrCat(cmSystemTools::UpperCase(config), '-', lang), level);
  4470. if (!e.second && e.first->second < level) {
  4471. e.first->second = level;
  4472. }
  4473. }
  4474. bool cmGeneratorTarget::ComputeCompileFeatures(std::string const& config)
  4475. {
  4476. cmStandardLevelResolver standardResolver(this->Makefile);
  4477. for (std::string const& lang :
  4478. this->Makefile->GetState()->GetEnabledLanguages()) {
  4479. if (cmValue languageStd = this->GetLanguageStandard(lang, config)) {
  4480. if (cm::optional<cmStandardLevel> langLevel =
  4481. standardResolver.LanguageStandardLevel(lang, *languageStd)) {
  4482. this->UpdateExplicitStandardLevel(lang, config, *langLevel);
  4483. }
  4484. }
  4485. }
  4486. // Compute the language standard based on the compile features.
  4487. std::vector<BT<std::string>> features = this->GetCompileFeatures(config);
  4488. for (BT<std::string> const& f : features) {
  4489. std::string lang;
  4490. if (!standardResolver.CompileFeatureKnown(this->Target->GetName(), f.Value,
  4491. lang, nullptr)) {
  4492. return false;
  4493. }
  4494. std::string key = cmStrCat(cmSystemTools::UpperCase(config), '-', lang);
  4495. cmValue currentLanguageStandard = this->GetLanguageStandard(lang, config);
  4496. cm::optional<cmStandardLevel> featureLevel;
  4497. std::string newRequiredStandard;
  4498. if (!standardResolver.GetNewRequiredStandard(
  4499. this->Target->GetName(), f.Value, currentLanguageStandard,
  4500. featureLevel, newRequiredStandard)) {
  4501. return false;
  4502. }
  4503. if (featureLevel) {
  4504. this->UpdateExplicitStandardLevel(lang, config, *featureLevel);
  4505. }
  4506. if (!newRequiredStandard.empty()) {
  4507. BTs<std::string>& languageStandardProperty =
  4508. this->LanguageStandardMap[key];
  4509. if (languageStandardProperty.Value != newRequiredStandard) {
  4510. languageStandardProperty.Value = newRequiredStandard;
  4511. languageStandardProperty.Backtraces.clear();
  4512. }
  4513. languageStandardProperty.Backtraces.emplace_back(f.Backtrace);
  4514. }
  4515. }
  4516. return true;
  4517. }
  4518. bool cmGeneratorTarget::ComputeCompileFeatures(
  4519. std::string const& config, std::set<LanguagePair> const& languagePairs)
  4520. {
  4521. for (const auto& language : languagePairs) {
  4522. BTs<std::string> const* generatorTargetLanguageStandard =
  4523. this->GetLanguageStandardProperty(language.first, config);
  4524. if (!generatorTargetLanguageStandard) {
  4525. // If the standard isn't explicitly set we copy it over from the
  4526. // specified paired language.
  4527. std::string key =
  4528. cmStrCat(cmSystemTools::UpperCase(config), '-', language.first);
  4529. BTs<std::string> const* standardToCopy =
  4530. this->GetLanguageStandardProperty(language.second, config);
  4531. if (standardToCopy) {
  4532. this->LanguageStandardMap[key] = *standardToCopy;
  4533. generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
  4534. } else {
  4535. cmValue defaultStandard = this->Makefile->GetDefinition(
  4536. cmStrCat("CMAKE_", language.second, "_STANDARD_DEFAULT"));
  4537. if (defaultStandard) {
  4538. this->LanguageStandardMap[key] = BTs<std::string>(*defaultStandard);
  4539. generatorTargetLanguageStandard = &this->LanguageStandardMap[key];
  4540. }
  4541. }
  4542. // Custom updates for the CUDA standard.
  4543. if (generatorTargetLanguageStandard != nullptr &&
  4544. (language.first == "CUDA")) {
  4545. if (generatorTargetLanguageStandard->Value == "98") {
  4546. this->LanguageStandardMap[key].Value = "03";
  4547. }
  4548. }
  4549. }
  4550. }
  4551. return true;
  4552. }
  4553. std::string cmGeneratorTarget::GetImportedLibName(
  4554. std::string const& config) const
  4555. {
  4556. if (cmGeneratorTarget::ImportInfo const* info =
  4557. this->GetImportInfo(config)) {
  4558. return info->LibName;
  4559. }
  4560. return std::string();
  4561. }
  4562. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  4563. cmStateEnums::ArtifactType artifact,
  4564. bool realname) const
  4565. {
  4566. if (this->IsImported()) {
  4567. return this->Target->ImportedGetFullPath(config, artifact);
  4568. }
  4569. return this->NormalGetFullPath(config, artifact, realname);
  4570. }
  4571. std::string cmGeneratorTarget::NormalGetFullPath(
  4572. const std::string& config, cmStateEnums::ArtifactType artifact,
  4573. bool realname) const
  4574. {
  4575. std::string fpath = cmStrCat(this->GetDirectory(config, artifact), '/');
  4576. if (this->IsAppBundleOnApple()) {
  4577. fpath =
  4578. cmStrCat(this->BuildBundleDirectory(fpath, config, FullLevel), '/');
  4579. }
  4580. // Add the full name of the target.
  4581. switch (artifact) {
  4582. case cmStateEnums::RuntimeBinaryArtifact:
  4583. if (realname) {
  4584. fpath += this->NormalGetRealName(config);
  4585. } else {
  4586. fpath +=
  4587. this->GetFullName(config, cmStateEnums::RuntimeBinaryArtifact);
  4588. }
  4589. break;
  4590. case cmStateEnums::ImportLibraryArtifact:
  4591. if (realname) {
  4592. fpath +=
  4593. this->NormalGetRealName(config, cmStateEnums::ImportLibraryArtifact);
  4594. } else {
  4595. fpath +=
  4596. this->GetFullName(config, cmStateEnums::ImportLibraryArtifact);
  4597. }
  4598. break;
  4599. }
  4600. return fpath;
  4601. }
  4602. std::string cmGeneratorTarget::NormalGetRealName(
  4603. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4604. {
  4605. // This should not be called for imported targets.
  4606. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4607. // enforcement of the limited imported target API.
  4608. if (this->IsImported()) {
  4609. std::string msg = cmStrCat("NormalGetRealName called on imported target: ",
  4610. this->GetName());
  4611. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4612. }
  4613. Names names = this->GetType() == cmStateEnums::EXECUTABLE
  4614. ? this->GetExecutableNames(config)
  4615. : this->GetLibraryNames(config);
  4616. // Compute the real name that will be built.
  4617. return artifact == cmStateEnums::RuntimeBinaryArtifact ? names.Real
  4618. : names.ImportReal;
  4619. }
  4620. cmGeneratorTarget::Names cmGeneratorTarget::GetLibraryNames(
  4621. const std::string& config) const
  4622. {
  4623. cmGeneratorTarget::Names targetNames;
  4624. // This should not be called for imported targets.
  4625. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4626. // enforcement of the limited imported target API.
  4627. if (this->IsImported()) {
  4628. std::string msg =
  4629. cmStrCat("GetLibraryNames called on imported target: ", this->GetName());
  4630. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4631. }
  4632. // Check for library version properties.
  4633. cmValue version = this->GetProperty("VERSION");
  4634. cmValue soversion = this->GetProperty("SOVERSION");
  4635. if (!this->HasSOName(config) ||
  4636. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  4637. this->IsFrameworkOnApple()) {
  4638. // Versioning is supported only for shared libraries and modules,
  4639. // and then only when the platform supports an soname flag.
  4640. version = nullptr;
  4641. soversion = nullptr;
  4642. }
  4643. if (version && !soversion) {
  4644. // The soversion must be set if the library version is set. Use
  4645. // the library version as the soversion.
  4646. soversion = version;
  4647. }
  4648. if (!version && soversion) {
  4649. // Use the soversion as the library version.
  4650. version = soversion;
  4651. }
  4652. // Get the components of the library name.
  4653. NameComponents const& components = this->GetFullNameInternalComponents(
  4654. config, cmStateEnums::RuntimeBinaryArtifact);
  4655. // The library name.
  4656. targetNames.Base = components.base;
  4657. targetNames.Output =
  4658. cmStrCat(components.prefix, targetNames.Base, components.suffix);
  4659. if (this->IsFrameworkOnApple()) {
  4660. targetNames.Real = components.prefix;
  4661. if (!this->Makefile->PlatformIsAppleEmbedded()) {
  4662. targetNames.Real +=
  4663. cmStrCat("Versions/", this->GetFrameworkVersion(), '/');
  4664. }
  4665. targetNames.Real += cmStrCat(targetNames.Base, components.suffix);
  4666. targetNames.SharedObject = targetNames.Real;
  4667. } else {
  4668. // The library's soname.
  4669. this->ComputeVersionedName(targetNames.SharedObject, components.prefix,
  4670. targetNames.Base, components.suffix,
  4671. targetNames.Output, soversion);
  4672. // The library's real name on disk.
  4673. this->ComputeVersionedName(targetNames.Real, components.prefix,
  4674. targetNames.Base, components.suffix,
  4675. targetNames.Output, version);
  4676. }
  4677. // The import library names.
  4678. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  4679. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  4680. NameComponents const& importComponents =
  4681. this->GetFullNameInternalComponents(config,
  4682. cmStateEnums::ImportLibraryArtifact);
  4683. targetNames.ImportOutput = cmStrCat(
  4684. importComponents.prefix, importComponents.base, importComponents.suffix);
  4685. if (this->IsFrameworkOnApple() && this->IsSharedLibraryWithExports()) {
  4686. targetNames.ImportReal = components.prefix;
  4687. if (!this->Makefile->PlatformIsAppleEmbedded()) {
  4688. targetNames.ImportReal +=
  4689. cmStrCat("Versions/", this->GetFrameworkVersion(), '/');
  4690. }
  4691. targetNames.ImportReal +=
  4692. cmStrCat(importComponents.base, importComponents.suffix);
  4693. targetNames.ImportLibrary = targetNames.ImportOutput;
  4694. } else {
  4695. // The import library's soname.
  4696. this->ComputeVersionedName(
  4697. targetNames.ImportLibrary, importComponents.prefix,
  4698. importComponents.base, importComponents.suffix,
  4699. targetNames.ImportOutput, soversion);
  4700. // The import library's real name on disk.
  4701. this->ComputeVersionedName(
  4702. targetNames.ImportReal, importComponents.prefix, importComponents.base,
  4703. importComponents.suffix, targetNames.ImportOutput, version);
  4704. }
  4705. }
  4706. // The program database file name.
  4707. targetNames.PDB = this->GetPDBName(config);
  4708. return targetNames;
  4709. }
  4710. cmGeneratorTarget::Names cmGeneratorTarget::GetExecutableNames(
  4711. const std::string& config) const
  4712. {
  4713. cmGeneratorTarget::Names targetNames;
  4714. // This should not be called for imported targets.
  4715. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4716. // enforcement of the limited imported target API.
  4717. if (this->IsImported()) {
  4718. std::string msg = cmStrCat(
  4719. "GetExecutableNames called on imported target: ", this->GetName());
  4720. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  4721. }
  4722. // This versioning is supported only for executables and then only
  4723. // when the platform supports symbolic links.
  4724. #if defined(_WIN32) && !defined(__CYGWIN__)
  4725. cmValue version;
  4726. #else
  4727. // Check for executable version properties.
  4728. cmValue version = this->GetProperty("VERSION");
  4729. if (this->GetType() != cmStateEnums::EXECUTABLE ||
  4730. this->Makefile->IsOn("XCODE")) {
  4731. version = nullptr;
  4732. }
  4733. #endif
  4734. // Get the components of the executable name.
  4735. NameComponents const& components = this->GetFullNameInternalComponents(
  4736. config, cmStateEnums::RuntimeBinaryArtifact);
  4737. // The executable name.
  4738. targetNames.Base = components.base;
  4739. targetNames.Output =
  4740. components.prefix + targetNames.Base + components.suffix;
  4741. // The executable's real name on disk.
  4742. #if defined(__CYGWIN__)
  4743. targetNames.Real = components.prefix + targetNames.Base;
  4744. #else
  4745. targetNames.Real = targetNames.Output;
  4746. #endif
  4747. if (version) {
  4748. targetNames.Real += "-";
  4749. targetNames.Real += *version;
  4750. }
  4751. #if defined(__CYGWIN__)
  4752. targetNames.Real += components.suffix;
  4753. #endif
  4754. // The import library name.
  4755. targetNames.ImportLibrary =
  4756. this->GetFullNameInternal(config, cmStateEnums::ImportLibraryArtifact);
  4757. targetNames.ImportReal = targetNames.ImportLibrary;
  4758. targetNames.ImportOutput = targetNames.ImportLibrary;
  4759. // The program database file name.
  4760. targetNames.PDB = this->GetPDBName(config);
  4761. return targetNames;
  4762. }
  4763. std::string cmGeneratorTarget::GetFullNameInternal(
  4764. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4765. {
  4766. NameComponents const& components =
  4767. this->GetFullNameInternalComponents(config, artifact);
  4768. return components.prefix + components.base + components.suffix;
  4769. }
  4770. std::string cmGeneratorTarget::ImportedGetLocation(
  4771. const std::string& config) const
  4772. {
  4773. assert(this->IsImported());
  4774. return this->Target->ImportedGetFullPath(
  4775. config, cmStateEnums::RuntimeBinaryArtifact);
  4776. }
  4777. std::string cmGeneratorTarget::GetFullNameImported(
  4778. const std::string& config, cmStateEnums::ArtifactType artifact) const
  4779. {
  4780. return cmSystemTools::GetFilenameName(
  4781. this->Target->ImportedGetFullPath(config, artifact));
  4782. }
  4783. cmGeneratorTarget::NameComponents const&
  4784. cmGeneratorTarget::GetFullNameInternalComponents(
  4785. std::string const& config, cmStateEnums::ArtifactType artifact) const
  4786. {
  4787. assert(artifact == cmStateEnums::RuntimeBinaryArtifact ||
  4788. artifact == cmStateEnums::ImportLibraryArtifact);
  4789. FullNameCache& cache = artifact == cmStateEnums::RuntimeBinaryArtifact
  4790. ? RuntimeBinaryFullNameCache
  4791. : ImportLibraryFullNameCache;
  4792. auto search = cache.find(config);
  4793. if (search != cache.end()) {
  4794. return search->second;
  4795. }
  4796. // Use just the target name for non-main target types.
  4797. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  4798. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  4799. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  4800. this->GetType() != cmStateEnums::EXECUTABLE) {
  4801. NameComponents components;
  4802. components.base = this->GetName();
  4803. return cache.emplace(config, std::move(components)).first->second;
  4804. }
  4805. const bool isImportedLibraryArtifact =
  4806. (artifact == cmStateEnums::ImportLibraryArtifact);
  4807. // Return an empty name for the import library if this platform
  4808. // does not support import libraries.
  4809. if (isImportedLibraryArtifact && !this->NeedImportLibraryName(config)) {
  4810. return cache.emplace(config, NameComponents()).first->second;
  4811. }
  4812. NameComponents parts;
  4813. std::string& outPrefix = parts.prefix;
  4814. std::string& outBase = parts.base;
  4815. std::string& outSuffix = parts.suffix;
  4816. // retrieve prefix and suffix
  4817. std::string ll = this->GetLinkerLanguage(config);
  4818. cmValue targetPrefix = this->GetFilePrefixInternal(config, artifact, ll);
  4819. cmValue targetSuffix = this->GetFileSuffixInternal(config, artifact, ll);
  4820. // The implib option is only allowed for shared libraries, module
  4821. // libraries, and executables.
  4822. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  4823. this->GetType() != cmStateEnums::MODULE_LIBRARY &&
  4824. this->GetType() != cmStateEnums::EXECUTABLE) {
  4825. artifact = cmStateEnums::RuntimeBinaryArtifact;
  4826. }
  4827. // Compute the full name for main target types.
  4828. std::string configPostfix = this->GetFilePostfix(config);
  4829. // frameworks have directory prefix
  4830. std::string fw_prefix;
  4831. if (this->IsFrameworkOnApple()) {
  4832. fw_prefix =
  4833. cmStrCat(this->GetFrameworkDirectory(config, ContentLevel), '/');
  4834. targetPrefix = cmValue(fw_prefix);
  4835. if (!isImportedLibraryArtifact) {
  4836. // no suffix
  4837. targetSuffix = nullptr;
  4838. }
  4839. }
  4840. if (this->IsCFBundleOnApple()) {
  4841. fw_prefix = cmStrCat(this->GetCFBundleDirectory(config, FullLevel), '/');
  4842. targetPrefix = cmValue(fw_prefix);
  4843. targetSuffix = nullptr;
  4844. }
  4845. // Begin the final name with the prefix.
  4846. outPrefix = targetPrefix ? *targetPrefix : "";
  4847. // Append the target name or property-specified name.
  4848. outBase += this->GetOutputName(config, artifact);
  4849. // Append the per-configuration postfix.
  4850. // When using Xcode, the postfix should be part of the suffix rather than
  4851. // the base, because the suffix ends up being used in Xcode's
  4852. // EXECUTABLE_SUFFIX attribute.
  4853. if (this->IsFrameworkOnApple() && this->GetGlobalGenerator()->IsXcode()) {
  4854. configPostfix += *targetSuffix;
  4855. targetSuffix = cmValue(configPostfix);
  4856. } else {
  4857. outBase += configPostfix;
  4858. }
  4859. // Name shared libraries with their version number on some platforms.
  4860. if (cmValue soversion = this->GetProperty("SOVERSION")) {
  4861. cmValue dllProp;
  4862. if (this->IsDLLPlatform()) {
  4863. dllProp = this->GetProperty("DLL_NAME_WITH_SOVERSION");
  4864. }
  4865. if (this->GetType() == cmStateEnums::SHARED_LIBRARY &&
  4866. !isImportedLibraryArtifact &&
  4867. (dllProp.IsOn() ||
  4868. (!dllProp.IsSet() &&
  4869. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION")))) {
  4870. outBase += "-";
  4871. outBase += *soversion;
  4872. }
  4873. }
  4874. // Append the suffix.
  4875. outSuffix = targetSuffix ? *targetSuffix : "";
  4876. return cache.emplace(config, std::move(parts)).first->second;
  4877. }
  4878. std::string cmGeneratorTarget::GetLinkerLanguage(
  4879. const std::string& config) const
  4880. {
  4881. return this->GetLinkClosure(config)->LinkerLanguage;
  4882. }
  4883. std::string cmGeneratorTarget::GetPDBOutputName(
  4884. const std::string& config) const
  4885. {
  4886. std::string base =
  4887. this->GetOutputName(config, cmStateEnums::RuntimeBinaryArtifact);
  4888. std::vector<std::string> props;
  4889. std::string configUpper = cmSystemTools::UpperCase(config);
  4890. if (!configUpper.empty()) {
  4891. // PDB_NAME_<CONFIG>
  4892. props.push_back("PDB_NAME_" + configUpper);
  4893. }
  4894. // PDB_NAME
  4895. props.emplace_back("PDB_NAME");
  4896. for (std::string const& p : props) {
  4897. if (cmValue outName = this->GetProperty(p)) {
  4898. base = *outName;
  4899. break;
  4900. }
  4901. }
  4902. return base;
  4903. }
  4904. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  4905. {
  4906. NameComponents const& parts = this->GetFullNameInternalComponents(
  4907. config, cmStateEnums::RuntimeBinaryArtifact);
  4908. std::vector<std::string> props;
  4909. std::string configUpper = cmSystemTools::UpperCase(config);
  4910. if (!configUpper.empty()) {
  4911. // PDB_NAME_<CONFIG>
  4912. props.push_back("PDB_NAME_" + configUpper);
  4913. }
  4914. // PDB_NAME
  4915. props.emplace_back("PDB_NAME");
  4916. for (std::string const& p : props) {
  4917. if (cmValue outName = this->GetProperty(p)) {
  4918. return parts.prefix + *outName + ".pdb";
  4919. }
  4920. }
  4921. return parts.prefix + parts.base + ".pdb";
  4922. }
  4923. std::string cmGeneratorTarget::GetObjectDirectory(
  4924. std::string const& config) const
  4925. {
  4926. std::string obj_dir =
  4927. this->GlobalGenerator->ExpandCFGIntDir(this->ObjectDirectory, config);
  4928. #if defined(__APPLE__)
  4929. // Replace Xcode's placeholder for the object file directory since
  4930. // installation and export scripts need to know the real directory.
  4931. // Xcode has build-time settings (e.g. for sanitizers) that affect this,
  4932. // but we use the default here. Users that want to enable sanitizers
  4933. // will do so at the cost of object library installation and export.
  4934. cmSystemTools::ReplaceString(obj_dir, "$(OBJECT_FILE_DIR_normal:base)",
  4935. "Objects-normal");
  4936. #endif
  4937. return obj_dir;
  4938. }
  4939. void cmGeneratorTarget::GetTargetObjectNames(
  4940. std::string const& config, std::vector<std::string>& objects) const
  4941. {
  4942. std::vector<cmSourceFile const*> objectSources;
  4943. this->GetObjectSources(objectSources, config);
  4944. std::map<cmSourceFile const*, std::string> mapping;
  4945. for (cmSourceFile const* sf : objectSources) {
  4946. mapping[sf];
  4947. }
  4948. this->LocalGenerator->ComputeObjectFilenames(mapping, this);
  4949. for (cmSourceFile const* src : objectSources) {
  4950. // Find the object file name corresponding to this source file.
  4951. auto map_it = mapping.find(src);
  4952. // It must exist because we populated the mapping just above.
  4953. assert(!map_it->second.empty());
  4954. objects.push_back(map_it->second);
  4955. }
  4956. // We need to compute the relative path from the root of
  4957. // of the object directory to handle subdirectory paths
  4958. std::string rootObjectDir = this->GetObjectDirectory(config);
  4959. rootObjectDir = cmSystemTools::CollapseFullPath(rootObjectDir);
  4960. auto ispcObjects = this->GetGeneratedISPCObjects(config);
  4961. for (std::string const& output : ispcObjects) {
  4962. auto relativePathFromObjectDir = output.substr(rootObjectDir.size());
  4963. objects.push_back(relativePathFromObjectDir);
  4964. }
  4965. }
  4966. bool cmGeneratorTarget::StrictTargetComparison::operator()(
  4967. cmGeneratorTarget const* t1, cmGeneratorTarget const* t2) const
  4968. {
  4969. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  4970. if (nameResult == 0) {
  4971. return strcmp(
  4972. t1->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str(),
  4973. t2->GetLocalGenerator()->GetCurrentBinaryDirectory().c_str()) < 0;
  4974. }
  4975. return nameResult < 0;
  4976. }
  4977. struct cmGeneratorTarget::SourceFileFlags
  4978. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  4979. {
  4980. struct SourceFileFlags flags;
  4981. this->ConstructSourceFileFlags();
  4982. auto si = this->SourceFlagsMap.find(sf);
  4983. if (si != this->SourceFlagsMap.end()) {
  4984. flags = si->second;
  4985. } else {
  4986. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  4987. // were not listed in one of the other lists.
  4988. if (cmValue location = sf->GetProperty("MACOSX_PACKAGE_LOCATION")) {
  4989. flags.MacFolder = location->c_str();
  4990. const bool stripResources =
  4991. this->GlobalGenerator->ShouldStripResourcePath(this->Makefile);
  4992. if (*location == "Resources") {
  4993. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  4994. if (stripResources) {
  4995. flags.MacFolder = "";
  4996. }
  4997. } else if (cmHasLiteralPrefix(*location, "Resources/")) {
  4998. flags.Type = cmGeneratorTarget::SourceFileTypeDeepResource;
  4999. if (stripResources) {
  5000. flags.MacFolder += cmStrLen("Resources/");
  5001. }
  5002. } else {
  5003. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  5004. }
  5005. }
  5006. }
  5007. return flags;
  5008. }
  5009. void cmGeneratorTarget::ConstructSourceFileFlags() const
  5010. {
  5011. if (this->SourceFileFlagsConstructed) {
  5012. return;
  5013. }
  5014. this->SourceFileFlagsConstructed = true;
  5015. // Process public headers to mark the source files.
  5016. if (cmValue files = this->GetProperty("PUBLIC_HEADER")) {
  5017. cmList relFiles{ *files };
  5018. for (auto const& relFile : relFiles) {
  5019. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  5020. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  5021. flags.MacFolder = "Headers";
  5022. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  5023. }
  5024. }
  5025. }
  5026. // Process private headers after public headers so that they take
  5027. // precedence if a file is listed in both.
  5028. if (cmValue files = this->GetProperty("PRIVATE_HEADER")) {
  5029. cmList relFiles{ *files };
  5030. for (auto const& relFile : relFiles) {
  5031. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  5032. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  5033. flags.MacFolder = "PrivateHeaders";
  5034. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  5035. }
  5036. }
  5037. }
  5038. // Mark sources listed as resources.
  5039. if (cmValue files = this->GetProperty("RESOURCE")) {
  5040. cmList relFiles{ *files };
  5041. for (auto const& relFile : relFiles) {
  5042. if (cmSourceFile* sf = this->Makefile->GetSource(relFile)) {
  5043. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  5044. flags.MacFolder = "";
  5045. if (!this->GlobalGenerator->ShouldStripResourcePath(this->Makefile)) {
  5046. flags.MacFolder = "Resources";
  5047. }
  5048. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  5049. }
  5050. }
  5051. }
  5052. }
  5053. const cmGeneratorTarget::CompatibleInterfacesBase&
  5054. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  5055. {
  5056. cmGeneratorTarget::CompatibleInterfaces& compat =
  5057. this->CompatibleInterfacesMap[config];
  5058. if (!compat.Done) {
  5059. compat.Done = true;
  5060. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  5061. compat.PropsString.insert("AUTOUIC_OPTIONS");
  5062. std::vector<cmGeneratorTarget const*> const& deps =
  5063. this->GetLinkImplementationClosure(config);
  5064. for (cmGeneratorTarget const* li : deps) {
  5065. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  5066. if (cmValue prop = li->GetProperty("COMPATIBLE_INTERFACE_" #X)) { \
  5067. cmList props(*prop); \
  5068. compat.Props##x.insert(props.begin(), props.end()); \
  5069. }
  5070. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  5071. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  5072. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  5073. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  5074. #undef CM_READ_COMPATIBLE_INTERFACE
  5075. }
  5076. }
  5077. return compat;
  5078. }
  5079. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  5080. const std::string& p, const std::string& config) const
  5081. {
  5082. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5083. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5084. return false;
  5085. }
  5086. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  5087. }
  5088. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  5089. const std::string& p, const std::string& config) const
  5090. {
  5091. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5092. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5093. return false;
  5094. }
  5095. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  5096. }
  5097. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  5098. const std::string& p, const std::string& config) const
  5099. {
  5100. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5101. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5102. return false;
  5103. }
  5104. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  5105. }
  5106. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  5107. const std::string& p, const std::string& config) const
  5108. {
  5109. if (this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  5110. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  5111. return false;
  5112. }
  5113. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  5114. }
  5115. enum CompatibleType
  5116. {
  5117. BoolType,
  5118. StringType,
  5119. NumberMinType,
  5120. NumberMaxType
  5121. };
  5122. template <typename PropertyType>
  5123. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  5124. const std::string& prop,
  5125. const std::string& config,
  5126. CompatibleType, PropertyType*);
  5127. template <>
  5128. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  5129. const std::string& prop,
  5130. const std::string& config,
  5131. CompatibleType /*unused*/,
  5132. bool* /*unused*/)
  5133. {
  5134. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5135. }
  5136. template <>
  5137. const char* getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  5138. const std::string& prop,
  5139. const std::string& config,
  5140. CompatibleType t,
  5141. const char** /*unused*/)
  5142. {
  5143. switch (t) {
  5144. case BoolType:
  5145. assert(false &&
  5146. "String compatibility check function called for boolean");
  5147. return nullptr;
  5148. case StringType:
  5149. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5150. case NumberMinType:
  5151. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  5152. case NumberMaxType:
  5153. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  5154. }
  5155. assert(false && "Unreachable!");
  5156. return nullptr;
  5157. }
  5158. template <typename PropertyType>
  5159. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  5160. cmGeneratorTarget const* dependee,
  5161. const std::string& propName,
  5162. std::set<std::string>& emitted,
  5163. const std::string& config, CompatibleType t,
  5164. PropertyType* /*unused*/)
  5165. {
  5166. cmValue prop = dependee->GetProperty(propName);
  5167. if (!prop) {
  5168. return;
  5169. }
  5170. cmList props{ *prop };
  5171. std::string pdir =
  5172. cmStrCat(cmSystemTools::GetCMakeRoot(), "/Help/prop_tgt/");
  5173. for (std::string const& p : props) {
  5174. std::string pname = cmSystemTools::HelpFileName(p);
  5175. std::string pfile = pdir + pname + ".rst";
  5176. if (cmSystemTools::FileExists(pfile, true)) {
  5177. std::ostringstream e;
  5178. e << "Target \"" << dependee->GetName() << "\" has property \"" << p
  5179. << "\" listed in its " << propName
  5180. << " property. "
  5181. "This is not allowed. Only user-defined properties may appear "
  5182. "listed in the "
  5183. << propName << " property.";
  5184. depender->GetLocalGenerator()->IssueMessage(MessageType::FATAL_ERROR,
  5185. e.str());
  5186. return;
  5187. }
  5188. if (emitted.insert(p).second) {
  5189. getLinkInterfaceDependentProperty<PropertyType>(depender, p, config, t,
  5190. nullptr);
  5191. if (cmSystemTools::GetErrorOccurredFlag()) {
  5192. return;
  5193. }
  5194. }
  5195. }
  5196. }
  5197. namespace {
  5198. std::string intersect(const std::set<std::string>& s1,
  5199. const std::set<std::string>& s2)
  5200. {
  5201. std::set<std::string> intersect;
  5202. std::set_intersection(s1.begin(), s1.end(), s2.begin(), s2.end(),
  5203. std::inserter(intersect, intersect.begin()));
  5204. if (!intersect.empty()) {
  5205. return *intersect.begin();
  5206. }
  5207. return "";
  5208. }
  5209. std::string intersect(const std::set<std::string>& s1,
  5210. const std::set<std::string>& s2,
  5211. const std::set<std::string>& s3)
  5212. {
  5213. std::string result;
  5214. result = intersect(s1, s2);
  5215. if (!result.empty()) {
  5216. return result;
  5217. }
  5218. result = intersect(s1, s3);
  5219. if (!result.empty()) {
  5220. return result;
  5221. }
  5222. return intersect(s2, s3);
  5223. }
  5224. std::string intersect(const std::set<std::string>& s1,
  5225. const std::set<std::string>& s2,
  5226. const std::set<std::string>& s3,
  5227. const std::set<std::string>& s4)
  5228. {
  5229. std::string result;
  5230. result = intersect(s1, s2);
  5231. if (!result.empty()) {
  5232. return result;
  5233. }
  5234. result = intersect(s1, s3);
  5235. if (!result.empty()) {
  5236. return result;
  5237. }
  5238. result = intersect(s1, s4);
  5239. if (!result.empty()) {
  5240. return result;
  5241. }
  5242. return intersect(s2, s3, s4);
  5243. }
  5244. }
  5245. void cmGeneratorTarget::CheckPropertyCompatibility(
  5246. cmComputeLinkInformation& info, const std::string& config) const
  5247. {
  5248. const cmComputeLinkInformation::ItemVector& deps = info.GetItems();
  5249. std::set<std::string> emittedBools;
  5250. static const std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  5251. std::set<std::string> emittedStrings;
  5252. static const std::string strString = "COMPATIBLE_INTERFACE_STRING";
  5253. std::set<std::string> emittedMinNumbers;
  5254. static const std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  5255. std::set<std::string> emittedMaxNumbers;
  5256. static const std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  5257. for (auto const& dep : deps) {
  5258. if (!dep.Target || dep.Target->GetType() == cmStateEnums::OBJECT_LIBRARY) {
  5259. continue;
  5260. }
  5261. checkPropertyConsistency<bool>(this, dep.Target, strBool, emittedBools,
  5262. config, BoolType, nullptr);
  5263. if (cmSystemTools::GetErrorOccurredFlag()) {
  5264. return;
  5265. }
  5266. checkPropertyConsistency<const char*>(this, dep.Target, strString,
  5267. emittedStrings, config, StringType,
  5268. nullptr);
  5269. if (cmSystemTools::GetErrorOccurredFlag()) {
  5270. return;
  5271. }
  5272. checkPropertyConsistency<const char*>(this, dep.Target, strNumMin,
  5273. emittedMinNumbers, config,
  5274. NumberMinType, nullptr);
  5275. if (cmSystemTools::GetErrorOccurredFlag()) {
  5276. return;
  5277. }
  5278. checkPropertyConsistency<const char*>(this, dep.Target, strNumMax,
  5279. emittedMaxNumbers, config,
  5280. NumberMaxType, nullptr);
  5281. if (cmSystemTools::GetErrorOccurredFlag()) {
  5282. return;
  5283. }
  5284. }
  5285. std::string prop = intersect(emittedBools, emittedStrings, emittedMinNumbers,
  5286. emittedMaxNumbers);
  5287. if (!prop.empty()) {
  5288. // Use a sorted std::vector to keep the error message sorted.
  5289. std::vector<std::string> props;
  5290. auto i = emittedBools.find(prop);
  5291. if (i != emittedBools.end()) {
  5292. props.push_back(strBool);
  5293. }
  5294. i = emittedStrings.find(prop);
  5295. if (i != emittedStrings.end()) {
  5296. props.push_back(strString);
  5297. }
  5298. i = emittedMinNumbers.find(prop);
  5299. if (i != emittedMinNumbers.end()) {
  5300. props.push_back(strNumMin);
  5301. }
  5302. i = emittedMaxNumbers.find(prop);
  5303. if (i != emittedMaxNumbers.end()) {
  5304. props.push_back(strNumMax);
  5305. }
  5306. std::sort(props.begin(), props.end());
  5307. std::string propsString = cmStrCat(
  5308. cmJoin(cmMakeRange(props).retreat(1), ", "), " and the ", props.back());
  5309. std::ostringstream e;
  5310. e << "Property \"" << prop << "\" appears in both the " << propsString
  5311. << " property in the dependencies of target \"" << this->GetName()
  5312. << "\". This is not allowed. A property may only require "
  5313. "compatibility "
  5314. "in a boolean interpretation, a numeric minimum, a numeric maximum "
  5315. "or a "
  5316. "string interpretation, but not a mixture.";
  5317. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  5318. }
  5319. }
  5320. template <typename PropertyType>
  5321. std::string valueAsString(PropertyType);
  5322. template <>
  5323. std::string valueAsString<bool>(bool value)
  5324. {
  5325. return value ? "TRUE" : "FALSE";
  5326. }
  5327. template <>
  5328. std::string valueAsString<const char*>(const char* value)
  5329. {
  5330. return value ? value : "(unset)";
  5331. }
  5332. template <>
  5333. std::string valueAsString<std::string>(std::string value)
  5334. {
  5335. return value;
  5336. }
  5337. template <>
  5338. std::string valueAsString<cmValue>(cmValue value)
  5339. {
  5340. return value ? *value : std::string("(unset)");
  5341. }
  5342. template <>
  5343. std::string valueAsString<std::nullptr_t>(std::nullptr_t /*unused*/)
  5344. {
  5345. return "(unset)";
  5346. }
  5347. static std::string compatibilityType(CompatibleType t)
  5348. {
  5349. switch (t) {
  5350. case BoolType:
  5351. return "Boolean compatibility";
  5352. case StringType:
  5353. return "String compatibility";
  5354. case NumberMaxType:
  5355. return "Numeric maximum compatibility";
  5356. case NumberMinType:
  5357. return "Numeric minimum compatibility";
  5358. }
  5359. assert(false && "Unreachable!");
  5360. return "";
  5361. }
  5362. static std::string compatibilityAgree(CompatibleType t, bool dominant)
  5363. {
  5364. switch (t) {
  5365. case BoolType:
  5366. case StringType:
  5367. return dominant ? "(Disagree)\n" : "(Agree)\n";
  5368. case NumberMaxType:
  5369. case NumberMinType:
  5370. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  5371. }
  5372. assert(false && "Unreachable!");
  5373. return "";
  5374. }
  5375. template <typename PropertyType>
  5376. PropertyType getTypedProperty(
  5377. cmGeneratorTarget const* tgt, const std::string& prop,
  5378. cmGeneratorExpressionInterpreter* genexInterpreter = nullptr);
  5379. template <>
  5380. bool getTypedProperty<bool>(cmGeneratorTarget const* tgt,
  5381. const std::string& prop,
  5382. cmGeneratorExpressionInterpreter* genexInterpreter)
  5383. {
  5384. if (genexInterpreter == nullptr) {
  5385. return tgt->GetPropertyAsBool(prop);
  5386. }
  5387. cmValue value = tgt->GetProperty(prop);
  5388. return cmIsOn(genexInterpreter->Evaluate(value ? *value : "", prop));
  5389. }
  5390. template <>
  5391. const char* getTypedProperty<const char*>(
  5392. cmGeneratorTarget const* tgt, const std::string& prop,
  5393. cmGeneratorExpressionInterpreter* genexInterpreter)
  5394. {
  5395. cmValue value = tgt->GetProperty(prop);
  5396. if (genexInterpreter == nullptr) {
  5397. return value.GetCStr();
  5398. }
  5399. return genexInterpreter->Evaluate(value ? *value : "", prop).c_str();
  5400. }
  5401. template <>
  5402. std::string getTypedProperty<std::string>(
  5403. cmGeneratorTarget const* tgt, const std::string& prop,
  5404. cmGeneratorExpressionInterpreter* genexInterpreter)
  5405. {
  5406. cmValue value = tgt->GetProperty(prop);
  5407. if (genexInterpreter == nullptr) {
  5408. return valueAsString(value);
  5409. }
  5410. return genexInterpreter->Evaluate(value ? *value : "", prop);
  5411. }
  5412. template <typename PropertyType>
  5413. PropertyType impliedValue(PropertyType);
  5414. template <>
  5415. bool impliedValue<bool>(bool /*unused*/)
  5416. {
  5417. return false;
  5418. }
  5419. template <>
  5420. const char* impliedValue<const char*>(const char* /*unused*/)
  5421. {
  5422. return "";
  5423. }
  5424. template <>
  5425. std::string impliedValue<std::string>(std::string /*unused*/) // NOLINT(*)
  5426. {
  5427. return std::string();
  5428. }
  5429. template <typename PropertyType>
  5430. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  5431. PropertyType rhs,
  5432. CompatibleType t);
  5433. template <>
  5434. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  5435. CompatibleType /*unused*/)
  5436. {
  5437. return { lhs == rhs, lhs };
  5438. }
  5439. static std::pair<bool, const char*> consistentStringProperty(const char* lhs,
  5440. const char* rhs)
  5441. {
  5442. const bool b = strcmp(lhs, rhs) == 0;
  5443. return { b, b ? lhs : nullptr };
  5444. }
  5445. static std::pair<bool, std::string> consistentStringProperty(
  5446. const std::string& lhs, const std::string& rhs)
  5447. {
  5448. const bool b = lhs == rhs;
  5449. return { b, b ? lhs : valueAsString(nullptr) };
  5450. }
  5451. static std::pair<bool, const char*> consistentNumberProperty(const char* lhs,
  5452. const char* rhs,
  5453. CompatibleType t)
  5454. {
  5455. char* pEnd;
  5456. long lnum = strtol(lhs, &pEnd, 0);
  5457. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE) {
  5458. return { false, nullptr };
  5459. }
  5460. long rnum = strtol(rhs, &pEnd, 0);
  5461. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE) {
  5462. return { false, nullptr };
  5463. }
  5464. if (t == NumberMaxType) {
  5465. return { true, std::max(lnum, rnum) == lnum ? lhs : rhs };
  5466. }
  5467. return { true, std::min(lnum, rnum) == lnum ? lhs : rhs };
  5468. }
  5469. template <>
  5470. std::pair<bool, const char*> consistentProperty(const char* lhs,
  5471. const char* rhs,
  5472. CompatibleType t)
  5473. {
  5474. if (!lhs && !rhs) {
  5475. return { true, lhs };
  5476. }
  5477. if (!lhs) {
  5478. return { true, rhs };
  5479. }
  5480. if (!rhs) {
  5481. return { true, lhs };
  5482. }
  5483. switch (t) {
  5484. case BoolType: {
  5485. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5486. return { same, same ? lhs : nullptr };
  5487. }
  5488. case StringType:
  5489. return consistentStringProperty(lhs, rhs);
  5490. case NumberMinType:
  5491. case NumberMaxType:
  5492. return consistentNumberProperty(lhs, rhs, t);
  5493. }
  5494. assert(false && "Unreachable!");
  5495. return { false, nullptr };
  5496. }
  5497. static std::pair<bool, std::string> consistentProperty(const std::string& lhs,
  5498. const std::string& rhs,
  5499. CompatibleType t)
  5500. {
  5501. const std::string null_ptr = valueAsString(nullptr);
  5502. if (lhs == null_ptr && rhs == null_ptr) {
  5503. return { true, lhs };
  5504. }
  5505. if (lhs == null_ptr) {
  5506. return { true, rhs };
  5507. }
  5508. if (rhs == null_ptr) {
  5509. return { true, lhs };
  5510. }
  5511. switch (t) {
  5512. case BoolType: {
  5513. bool same = cmIsOn(lhs) == cmIsOn(rhs);
  5514. return { same, same ? lhs : null_ptr };
  5515. }
  5516. case StringType:
  5517. return consistentStringProperty(lhs, rhs);
  5518. case NumberMinType:
  5519. case NumberMaxType: {
  5520. auto value = consistentNumberProperty(lhs.c_str(), rhs.c_str(), t);
  5521. return { value.first,
  5522. value.first ? std::string(value.second) : null_ptr };
  5523. }
  5524. }
  5525. assert(false && "Unreachable!");
  5526. return { false, null_ptr };
  5527. }
  5528. template <typename PropertyType>
  5529. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  5530. const std::string& p,
  5531. const std::string& config,
  5532. const char* defaultValue,
  5533. CompatibleType t,
  5534. PropertyType* /*unused*/)
  5535. {
  5536. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p);
  5537. std::vector<std::string> headPropKeys = tgt->GetPropertyKeys();
  5538. const bool explicitlySet = cm::contains(headPropKeys, p);
  5539. const bool impliedByUse = tgt->IsNullImpliedByLinkLibraries(p);
  5540. assert((impliedByUse ^ explicitlySet) || (!impliedByUse && !explicitlySet));
  5541. std::vector<cmGeneratorTarget const*> const& deps =
  5542. tgt->GetLinkImplementationClosure(config);
  5543. if (deps.empty()) {
  5544. return propContent;
  5545. }
  5546. bool propInitialized = explicitlySet;
  5547. std::string report = cmStrCat(" * Target \"", tgt->GetName());
  5548. if (explicitlySet) {
  5549. report += "\" has property content \"";
  5550. report += valueAsString<PropertyType>(propContent);
  5551. report += "\"\n";
  5552. } else if (impliedByUse) {
  5553. report += "\" property is implied by use.\n";
  5554. } else {
  5555. report += "\" property not set.\n";
  5556. }
  5557. std::string interfaceProperty = "INTERFACE_" + p;
  5558. std::unique_ptr<cmGeneratorExpressionInterpreter> genexInterpreter;
  5559. if (p == "POSITION_INDEPENDENT_CODE") {
  5560. genexInterpreter = cm::make_unique<cmGeneratorExpressionInterpreter>(
  5561. tgt->GetLocalGenerator(), config, tgt);
  5562. }
  5563. for (cmGeneratorTarget const* theTarget : deps) {
  5564. // An error should be reported if one dependency
  5565. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  5566. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  5567. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  5568. // with a dependency.
  5569. std::vector<std::string> propKeys = theTarget->GetPropertyKeys();
  5570. const bool ifaceIsSet = cm::contains(propKeys, interfaceProperty);
  5571. PropertyType ifacePropContent = getTypedProperty<PropertyType>(
  5572. theTarget, interfaceProperty, genexInterpreter.get());
  5573. std::string reportEntry;
  5574. if (ifaceIsSet) {
  5575. reportEntry += " * Target \"";
  5576. reportEntry += theTarget->GetName();
  5577. reportEntry += "\" property value \"";
  5578. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  5579. reportEntry += "\" ";
  5580. }
  5581. if (explicitlySet) {
  5582. if (ifaceIsSet) {
  5583. std::pair<bool, PropertyType> consistent =
  5584. consistentProperty(propContent, ifacePropContent, t);
  5585. report += reportEntry;
  5586. report += compatibilityAgree(t, propContent != consistent.second);
  5587. if (!consistent.first) {
  5588. std::ostringstream e;
  5589. e << "Property " << p << " on target \"" << tgt->GetName()
  5590. << "\" does\nnot match the "
  5591. "INTERFACE_"
  5592. << p
  5593. << " property requirement\nof "
  5594. "dependency \""
  5595. << theTarget->GetName() << "\".\n";
  5596. cmSystemTools::Error(e.str());
  5597. break;
  5598. }
  5599. propContent = consistent.second;
  5600. continue;
  5601. }
  5602. // Explicitly set on target and not set in iface. Can't disagree.
  5603. continue;
  5604. }
  5605. if (impliedByUse) {
  5606. propContent = impliedValue<PropertyType>(propContent);
  5607. if (ifaceIsSet) {
  5608. std::pair<bool, PropertyType> consistent =
  5609. consistentProperty(propContent, ifacePropContent, t);
  5610. report += reportEntry;
  5611. report += compatibilityAgree(t, propContent != consistent.second);
  5612. if (!consistent.first) {
  5613. std::ostringstream e;
  5614. e << "Property " << p << " on target \"" << tgt->GetName()
  5615. << "\" is\nimplied to be " << defaultValue
  5616. << " because it was used to determine the link libraries\n"
  5617. "already. The INTERFACE_"
  5618. << p << " property on\ndependency \"" << theTarget->GetName()
  5619. << "\" is in conflict.\n";
  5620. cmSystemTools::Error(e.str());
  5621. break;
  5622. }
  5623. propContent = consistent.second;
  5624. continue;
  5625. }
  5626. // Implicitly set on target and not set in iface. Can't disagree.
  5627. continue;
  5628. }
  5629. if (ifaceIsSet) {
  5630. if (propInitialized) {
  5631. std::pair<bool, PropertyType> consistent =
  5632. consistentProperty(propContent, ifacePropContent, t);
  5633. report += reportEntry;
  5634. report += compatibilityAgree(t, propContent != consistent.second);
  5635. if (!consistent.first) {
  5636. std::ostringstream e;
  5637. e << "The INTERFACE_" << p << " property of \""
  5638. << theTarget->GetName() << "\" does\nnot agree with the value of "
  5639. << p << " already determined\nfor \"" << tgt->GetName() << "\".\n";
  5640. cmSystemTools::Error(e.str());
  5641. break;
  5642. }
  5643. propContent = consistent.second;
  5644. continue;
  5645. }
  5646. report += reportEntry + "(Interface set)\n";
  5647. propContent = ifacePropContent;
  5648. propInitialized = true;
  5649. } else {
  5650. // Not set. Nothing to agree on.
  5651. continue;
  5652. }
  5653. }
  5654. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  5655. report, compatibilityType(t));
  5656. return propContent;
  5657. }
  5658. bool cmGeneratorTarget::SetDeviceLink(bool deviceLink)
  5659. {
  5660. bool previous = this->DeviceLink;
  5661. this->DeviceLink = deviceLink;
  5662. return previous;
  5663. }
  5664. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  5665. const std::string& p, const std::string& config) const
  5666. {
  5667. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  5668. BoolType, nullptr);
  5669. }
  5670. std::string cmGeneratorTarget::GetLinkInterfaceDependentStringAsBoolProperty(
  5671. const std::string& p, const std::string& config) const
  5672. {
  5673. return checkInterfacePropertyCompatibility<std::string>(
  5674. this, p, config, "FALSE", BoolType, nullptr);
  5675. }
  5676. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  5677. const std::string& p, const std::string& config) const
  5678. {
  5679. return checkInterfacePropertyCompatibility<const char*>(
  5680. this, p, config, "empty", StringType, nullptr);
  5681. }
  5682. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  5683. const std::string& p, const std::string& config) const
  5684. {
  5685. return checkInterfacePropertyCompatibility<const char*>(
  5686. this, p, config, "empty", NumberMinType, nullptr);
  5687. }
  5688. const char* cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  5689. const std::string& p, const std::string& config) const
  5690. {
  5691. return checkInterfacePropertyCompatibility<const char*>(
  5692. this, p, config, "empty", NumberMaxType, nullptr);
  5693. }
  5694. cmComputeLinkInformation* cmGeneratorTarget::GetLinkInformation(
  5695. const std::string& config) const
  5696. {
  5697. // Lookup any existing information for this configuration.
  5698. std::string key(cmSystemTools::UpperCase(config));
  5699. auto i = this->LinkInformation.find(key);
  5700. if (i == this->LinkInformation.end()) {
  5701. // Compute information for this configuration.
  5702. auto info = cm::make_unique<cmComputeLinkInformation>(this, config);
  5703. if (info && !info->Compute()) {
  5704. info.reset();
  5705. }
  5706. // Store the information for this configuration.
  5707. i = this->LinkInformation.emplace(key, std::move(info)).first;
  5708. if (i->second) {
  5709. this->CheckPropertyCompatibility(*i->second, config);
  5710. }
  5711. }
  5712. return i->second.get();
  5713. }
  5714. void cmGeneratorTarget::CheckLinkLibraries() const
  5715. {
  5716. bool linkLibrariesOnlyTargets =
  5717. this->GetPropertyAsBool("LINK_LIBRARIES_ONLY_TARGETS");
  5718. // Evaluate the link interface of this target if needed for extra checks.
  5719. if (linkLibrariesOnlyTargets) {
  5720. std::vector<std::string> const& configs =
  5721. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  5722. for (std::string const& config : configs) {
  5723. this->GetLinkInterfaceLibraries(config, this, LinkInterfaceFor::Link);
  5724. }
  5725. }
  5726. // Check link the implementation for each generated configuration.
  5727. for (auto const& hmp : this->LinkImplMap) {
  5728. HeadToLinkImplementationMap const& hm = hmp.second;
  5729. // There could be several entries used when computing the pre-CMP0022
  5730. // default link interface. Check only the entry for our own link impl.
  5731. auto const hmi = hm.find(this);
  5732. if (hmi == hm.end() || !hmi->second.LibrariesDone) {
  5733. continue;
  5734. }
  5735. for (cmLinkImplItem const& item : hmi->second.Libraries) {
  5736. if (!this->VerifyLinkItemColons(LinkItemRole::Implementation, item)) {
  5737. return;
  5738. }
  5739. if (linkLibrariesOnlyTargets &&
  5740. !this->VerifyLinkItemIsTarget(LinkItemRole::Implementation, item)) {
  5741. return;
  5742. }
  5743. }
  5744. }
  5745. // Check link the interface for each generated combination of
  5746. // configuration and consuming head target. We should not need to
  5747. // consider LinkInterfaceUsageRequirementsOnlyMap because its entries
  5748. // should be a subset of LinkInterfaceMap (with LINK_ONLY left out).
  5749. for (auto const& hmp : this->LinkInterfaceMap) {
  5750. for (auto const& hmi : hmp.second) {
  5751. if (!hmi.second.LibrariesDone) {
  5752. continue;
  5753. }
  5754. for (cmLinkItem const& item : hmi.second.Libraries) {
  5755. if (!this->VerifyLinkItemColons(LinkItemRole::Interface, item)) {
  5756. return;
  5757. }
  5758. if (linkLibrariesOnlyTargets &&
  5759. !this->VerifyLinkItemIsTarget(LinkItemRole::Interface, item)) {
  5760. return;
  5761. }
  5762. }
  5763. }
  5764. }
  5765. }
  5766. namespace {
  5767. cm::string_view missingTargetPossibleReasons =
  5768. "Possible reasons include:\n"
  5769. " * There is a typo in the target name.\n"
  5770. " * A find_package call is missing for an IMPORTED target.\n"
  5771. " * An ALIAS target is missing.\n"_s;
  5772. }
  5773. bool cmGeneratorTarget::VerifyLinkItemColons(LinkItemRole role,
  5774. cmLinkItem const& item) const
  5775. {
  5776. if (item.Target || cmHasPrefix(item.AsStr(), "<LINK_GROUP:"_s) ||
  5777. item.AsStr().find("::") == std::string::npos) {
  5778. return true;
  5779. }
  5780. MessageType messageType = MessageType::FATAL_ERROR;
  5781. std::string e;
  5782. switch (this->GetLocalGenerator()->GetPolicyStatus(cmPolicies::CMP0028)) {
  5783. case cmPolicies::WARN: {
  5784. e = cmStrCat(cmPolicies::GetPolicyWarning(cmPolicies::CMP0028), "\n");
  5785. messageType = MessageType::AUTHOR_WARNING;
  5786. } break;
  5787. case cmPolicies::OLD:
  5788. return true;
  5789. case cmPolicies::REQUIRED_IF_USED:
  5790. case cmPolicies::REQUIRED_ALWAYS:
  5791. case cmPolicies::NEW:
  5792. // Issue the fatal message.
  5793. break;
  5794. }
  5795. if (role == LinkItemRole::Implementation) {
  5796. e = cmStrCat(e, "Target \"", this->GetName(), "\" links to");
  5797. } else {
  5798. e = cmStrCat(e, "The link interface of target \"", this->GetName(),
  5799. "\" contains");
  5800. }
  5801. e =
  5802. cmStrCat(e, ":\n ", item.AsStr(), "\n", "but the target was not found. ",
  5803. missingTargetPossibleReasons);
  5804. cmListFileBacktrace backtrace = item.Backtrace;
  5805. if (backtrace.Empty()) {
  5806. backtrace = this->GetBacktrace();
  5807. }
  5808. this->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(messageType, e,
  5809. backtrace);
  5810. return false;
  5811. }
  5812. bool cmGeneratorTarget::VerifyLinkItemIsTarget(LinkItemRole role,
  5813. cmLinkItem const& item) const
  5814. {
  5815. if (item.Target) {
  5816. return true;
  5817. }
  5818. std::string const& str = item.AsStr();
  5819. if (!str.empty() &&
  5820. (str[0] == '-' || str[0] == '$' || str[0] == '`' ||
  5821. str.find_first_of("/\\") != std::string::npos ||
  5822. cmHasPrefix(str, "<LINK_LIBRARY:"_s) ||
  5823. cmHasPrefix(str, "<LINK_GROUP:"_s))) {
  5824. return true;
  5825. }
  5826. std::string e = cmStrCat("Target \"", this->GetName(),
  5827. "\" has LINK_LIBRARIES_ONLY_TARGETS enabled, but ",
  5828. role == LinkItemRole::Implementation
  5829. ? "it links to"
  5830. : "its link interface contains",
  5831. ":\n ", item.AsStr(), "\nwhich is not a target. ",
  5832. missingTargetPossibleReasons);
  5833. cmListFileBacktrace backtrace = item.Backtrace;
  5834. if (backtrace.Empty()) {
  5835. backtrace = this->GetBacktrace();
  5836. }
  5837. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  5838. MessageType::FATAL_ERROR, e, backtrace);
  5839. return false;
  5840. }
  5841. void cmGeneratorTarget::GetTargetVersion(int& major, int& minor) const
  5842. {
  5843. int patch;
  5844. this->GetTargetVersion("VERSION", major, minor, patch);
  5845. }
  5846. void cmGeneratorTarget::GetTargetVersionFallback(
  5847. const std::string& property, const std::string& fallback_property,
  5848. int& major, int& minor, int& patch) const
  5849. {
  5850. if (this->GetProperty(property)) {
  5851. this->GetTargetVersion(property, major, minor, patch);
  5852. } else {
  5853. this->GetTargetVersion(fallback_property, major, minor, patch);
  5854. }
  5855. }
  5856. void cmGeneratorTarget::GetTargetVersion(const std::string& property,
  5857. int& major, int& minor,
  5858. int& patch) const
  5859. {
  5860. // Set the default values.
  5861. major = 0;
  5862. minor = 0;
  5863. patch = 0;
  5864. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  5865. if (cmValue version = this->GetProperty(property)) {
  5866. // Try to parse the version number and store the results that were
  5867. // successfully parsed.
  5868. int parsed_major;
  5869. int parsed_minor;
  5870. int parsed_patch;
  5871. switch (sscanf(version->c_str(), "%d.%d.%d", &parsed_major, &parsed_minor,
  5872. &parsed_patch)) {
  5873. case 3:
  5874. patch = parsed_patch;
  5875. CM_FALLTHROUGH;
  5876. case 2:
  5877. minor = parsed_minor;
  5878. CM_FALLTHROUGH;
  5879. case 1:
  5880. major = parsed_major;
  5881. CM_FALLTHROUGH;
  5882. default:
  5883. break;
  5884. }
  5885. }
  5886. }
  5887. std::string cmGeneratorTarget::GetRuntimeLinkLibrary(
  5888. std::string const& lang, std::string const& config) const
  5889. {
  5890. // This is activated by the presence of a default selection whether or
  5891. // not it is overridden by a property.
  5892. cmValue runtimeLibraryDefault = this->Makefile->GetDefinition(
  5893. cmStrCat("CMAKE_", lang, "_RUNTIME_LIBRARY_DEFAULT"));
  5894. if (!cmNonempty(runtimeLibraryDefault)) {
  5895. return std::string();
  5896. }
  5897. cmValue runtimeLibraryValue =
  5898. this->Target->GetProperty(cmStrCat(lang, "_RUNTIME_LIBRARY"));
  5899. if (!runtimeLibraryValue) {
  5900. runtimeLibraryValue = runtimeLibraryDefault;
  5901. }
  5902. return cmSystemTools::UpperCase(cmGeneratorExpression::Evaluate(
  5903. *runtimeLibraryValue, this->LocalGenerator, config, this));
  5904. }
  5905. std::string cmGeneratorTarget::GetFortranModuleDirectory(
  5906. std::string const& working_dir) const
  5907. {
  5908. if (!this->FortranModuleDirectoryCreated) {
  5909. this->FortranModuleDirectory =
  5910. this->CreateFortranModuleDirectory(working_dir);
  5911. this->FortranModuleDirectoryCreated = true;
  5912. }
  5913. return this->FortranModuleDirectory;
  5914. }
  5915. bool cmGeneratorTarget::IsFortranBuildingInstrinsicModules() const
  5916. {
  5917. if (cmValue prop =
  5918. this->GetProperty("Fortran_BUILDING_INSTRINSIC_MODULES")) {
  5919. return cmIsOn(*prop);
  5920. }
  5921. return false;
  5922. }
  5923. std::string cmGeneratorTarget::CreateFortranModuleDirectory(
  5924. std::string const& working_dir) const
  5925. {
  5926. std::string mod_dir;
  5927. std::string target_mod_dir;
  5928. if (cmValue prop = this->GetProperty("Fortran_MODULE_DIRECTORY")) {
  5929. target_mod_dir = *prop;
  5930. } else {
  5931. std::string const& default_mod_dir =
  5932. this->LocalGenerator->GetCurrentBinaryDirectory();
  5933. if (default_mod_dir != working_dir) {
  5934. target_mod_dir = default_mod_dir;
  5935. }
  5936. }
  5937. cmValue moddir_flag =
  5938. this->Makefile->GetDefinition("CMAKE_Fortran_MODDIR_FLAG");
  5939. if (!target_mod_dir.empty() && moddir_flag) {
  5940. // Compute the full path to the module directory.
  5941. if (cmSystemTools::FileIsFullPath(target_mod_dir)) {
  5942. // Already a full path.
  5943. mod_dir = target_mod_dir;
  5944. } else {
  5945. // Interpret relative to the current output directory.
  5946. mod_dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  5947. '/', target_mod_dir);
  5948. }
  5949. // Make sure the module output directory exists.
  5950. cmSystemTools::MakeDirectory(mod_dir);
  5951. }
  5952. return mod_dir;
  5953. }
  5954. void cmGeneratorTarget::AddISPCGeneratedHeader(std::string const& header,
  5955. std::string const& config)
  5956. {
  5957. std::string config_upper;
  5958. if (!config.empty()) {
  5959. config_upper = cmSystemTools::UpperCase(config);
  5960. }
  5961. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5962. if (iter == this->ISPCGeneratedHeaders.end()) {
  5963. std::vector<std::string> headers;
  5964. headers.emplace_back(header);
  5965. this->ISPCGeneratedHeaders.insert({ config_upper, headers });
  5966. } else {
  5967. iter->second.emplace_back(header);
  5968. }
  5969. }
  5970. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCHeaders(
  5971. std::string const& config) const
  5972. {
  5973. std::string config_upper;
  5974. if (!config.empty()) {
  5975. config_upper = cmSystemTools::UpperCase(config);
  5976. }
  5977. auto iter = this->ISPCGeneratedHeaders.find(config_upper);
  5978. if (iter == this->ISPCGeneratedHeaders.end()) {
  5979. return std::vector<std::string>{};
  5980. }
  5981. return iter->second;
  5982. }
  5983. void cmGeneratorTarget::AddISPCGeneratedObject(std::vector<std::string>&& objs,
  5984. std::string const& config)
  5985. {
  5986. std::string config_upper;
  5987. if (!config.empty()) {
  5988. config_upper = cmSystemTools::UpperCase(config);
  5989. }
  5990. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  5991. if (iter == this->ISPCGeneratedObjects.end()) {
  5992. this->ISPCGeneratedObjects.insert({ config_upper, objs });
  5993. } else {
  5994. iter->second.insert(iter->second.end(), objs.begin(), objs.end());
  5995. }
  5996. }
  5997. std::vector<std::string> cmGeneratorTarget::GetGeneratedISPCObjects(
  5998. std::string const& config) const
  5999. {
  6000. std::string config_upper;
  6001. if (!config.empty()) {
  6002. config_upper = cmSystemTools::UpperCase(config);
  6003. }
  6004. auto iter = this->ISPCGeneratedObjects.find(config_upper);
  6005. if (iter == this->ISPCGeneratedObjects.end()) {
  6006. return std::vector<std::string>{};
  6007. }
  6008. return iter->second;
  6009. }
  6010. std::string cmGeneratorTarget::GetFrameworkVersion() const
  6011. {
  6012. assert(this->GetType() != cmStateEnums::INTERFACE_LIBRARY);
  6013. if (cmValue fversion = this->GetProperty("FRAMEWORK_VERSION")) {
  6014. return *fversion;
  6015. }
  6016. if (cmValue tversion = this->GetProperty("VERSION")) {
  6017. return *tversion;
  6018. }
  6019. return "A";
  6020. }
  6021. void cmGeneratorTarget::ComputeVersionedName(
  6022. std::string& vName, std::string const& prefix, std::string const& base,
  6023. std::string const& suffix, std::string const& name, cmValue version) const
  6024. {
  6025. vName = this->IsApple() ? (prefix + base) : name;
  6026. if (version) {
  6027. vName += ".";
  6028. vName += *version;
  6029. }
  6030. vName += this->IsApple() ? suffix : std::string();
  6031. }
  6032. std::vector<std::string> cmGeneratorTarget::GetPropertyKeys() const
  6033. {
  6034. return this->Target->GetProperties().GetKeys();
  6035. }
  6036. void cmGeneratorTarget::ReportPropertyOrigin(
  6037. const std::string& p, const std::string& result, const std::string& report,
  6038. const std::string& compatibilityType) const
  6039. {
  6040. cmList debugProperties{ this->Target->GetMakefile()->GetDefinition(
  6041. "CMAKE_DEBUG_TARGET_PROPERTIES") };
  6042. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p] &&
  6043. cm::contains(debugProperties, p);
  6044. if (this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  6045. this->DebugCompatiblePropertiesDone[p] = true;
  6046. }
  6047. if (!debugOrigin) {
  6048. return;
  6049. }
  6050. std::string areport =
  6051. cmStrCat(compatibilityType, " of property \"", p, "\" for target \"",
  6052. this->GetName(), "\" (result: \"", result, "\"):\n", report);
  6053. this->LocalGenerator->GetCMakeInstance()->IssueMessage(MessageType::LOG,
  6054. areport);
  6055. }
  6056. bool cmGeneratorTarget::IsLinkLookupScope(std::string const& n,
  6057. cmLocalGenerator const*& lg) const
  6058. {
  6059. if (cmHasLiteralPrefix(n, CMAKE_DIRECTORY_ID_SEP)) {
  6060. cmDirectoryId const dirId = n.substr(cmStrLen(CMAKE_DIRECTORY_ID_SEP));
  6061. if (dirId.String.empty()) {
  6062. lg = this->LocalGenerator;
  6063. return true;
  6064. }
  6065. if (cmLocalGenerator const* otherLG =
  6066. this->GlobalGenerator->FindLocalGenerator(dirId)) {
  6067. lg = otherLG;
  6068. return true;
  6069. }
  6070. }
  6071. return false;
  6072. }
  6073. cm::optional<cmLinkItem> cmGeneratorTarget::LookupLinkItem(
  6074. std::string const& n, cmListFileBacktrace const& bt,
  6075. LookupLinkItemScope* scope, LookupSelf lookupSelf) const
  6076. {
  6077. cm::optional<cmLinkItem> maybeItem;
  6078. if (this->IsLinkLookupScope(n, scope->LG)) {
  6079. return maybeItem;
  6080. }
  6081. std::string name = this->CheckCMP0004(n);
  6082. if (name.empty() ||
  6083. (lookupSelf == LookupSelf::No && name == this->GetName())) {
  6084. return maybeItem;
  6085. }
  6086. maybeItem = this->ResolveLinkItem(BT<std::string>(name, bt), scope->LG);
  6087. return maybeItem;
  6088. }
  6089. void cmGeneratorTarget::ExpandLinkItems(
  6090. std::string const& prop, cmBTStringRange entries, std::string const& config,
  6091. cmGeneratorTarget const* headTarget, LinkInterfaceFor interfaceFor,
  6092. LinkInterfaceField field, cmLinkInterface& iface) const
  6093. {
  6094. if (entries.empty()) {
  6095. return;
  6096. }
  6097. // Keep this logic in sync with ComputeLinkImplementationLibraries.
  6098. cmGeneratorExpressionDAGChecker dagChecker(this, prop, nullptr, nullptr);
  6099. // The $<LINK_ONLY> expression may be in a link interface to specify
  6100. // private link dependencies that are otherwise excluded from usage
  6101. // requirements.
  6102. if (interfaceFor == LinkInterfaceFor::Usage) {
  6103. dagChecker.SetTransitivePropertiesOnly();
  6104. dagChecker.SetTransitivePropertiesOnlyCMP0131();
  6105. }
  6106. cmMakefile const* mf = this->LocalGenerator->GetMakefile();
  6107. LookupLinkItemScope scope{ this->LocalGenerator };
  6108. for (BT<std::string> const& entry : entries) {
  6109. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
  6110. entry.Backtrace);
  6111. std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(entry.Value);
  6112. cge->SetEvaluateForBuildsystem(true);
  6113. cmList libs{ cge->Evaluate(this->LocalGenerator, config, headTarget,
  6114. &dagChecker, this,
  6115. headTarget->LinkerLanguage) };
  6116. for (auto const& lib : libs) {
  6117. if (cm::optional<cmLinkItem> maybeItem = this->LookupLinkItem(
  6118. lib, cge->GetBacktrace(), &scope,
  6119. field == LinkInterfaceField::Libraries ? LookupSelf::No
  6120. : LookupSelf::Yes)) {
  6121. cmLinkItem item = std::move(*maybeItem);
  6122. if (field == LinkInterfaceField::HeadInclude) {
  6123. iface.HeadInclude.emplace_back(std::move(item));
  6124. continue;
  6125. }
  6126. if (field == LinkInterfaceField::HeadExclude) {
  6127. iface.HeadExclude.emplace_back(std::move(item));
  6128. continue;
  6129. }
  6130. if (!item.Target) {
  6131. // Report explicitly linked object files separately.
  6132. std::string const& maybeObj = item.AsStr();
  6133. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  6134. cmSourceFile const* sf =
  6135. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  6136. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  6137. iface.Objects.emplace_back(std::move(item));
  6138. continue;
  6139. }
  6140. }
  6141. }
  6142. iface.Libraries.emplace_back(std::move(item));
  6143. }
  6144. }
  6145. if (cge->GetHadHeadSensitiveCondition()) {
  6146. iface.HadHeadSensitiveCondition = true;
  6147. }
  6148. if (cge->GetHadContextSensitiveCondition()) {
  6149. iface.HadContextSensitiveCondition = true;
  6150. }
  6151. if (cge->GetHadLinkLanguageSensitiveCondition()) {
  6152. iface.HadLinkLanguageSensitiveCondition = true;
  6153. }
  6154. }
  6155. }
  6156. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  6157. const std::string& config, cmGeneratorTarget const* head) const
  6158. {
  6159. return this->GetLinkInterface(config, head, false);
  6160. }
  6161. cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(
  6162. const std::string& config, cmGeneratorTarget const* head,
  6163. bool secondPass) const
  6164. {
  6165. // Imported targets have their own link interface.
  6166. if (this->IsImported()) {
  6167. return this->GetImportLinkInterface(config, head, LinkInterfaceFor::Link,
  6168. secondPass);
  6169. }
  6170. // Link interfaces are not supported for executables that do not
  6171. // export symbols.
  6172. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  6173. !this->IsExecutableWithExports()) {
  6174. return nullptr;
  6175. }
  6176. // Lookup any existing link interface for this configuration.
  6177. cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config);
  6178. // If the link interface does not depend on the head target
  6179. // then reuse the one from the head we computed first.
  6180. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6181. head = hm.begin()->first;
  6182. }
  6183. cmOptionalLinkInterface& iface = hm[head];
  6184. if (secondPass) {
  6185. iface = cmOptionalLinkInterface();
  6186. }
  6187. if (!iface.LibrariesDone) {
  6188. iface.LibrariesDone = true;
  6189. this->ComputeLinkInterfaceLibraries(config, iface, head,
  6190. LinkInterfaceFor::Link);
  6191. }
  6192. if (!iface.AllDone) {
  6193. iface.AllDone = true;
  6194. if (iface.Exists) {
  6195. this->ComputeLinkInterface(config, iface, head, secondPass);
  6196. this->ComputeLinkInterfaceRuntimeLibraries(config, iface);
  6197. }
  6198. }
  6199. return iface.Exists ? &iface : nullptr;
  6200. }
  6201. void cmGeneratorTarget::ComputeLinkInterface(
  6202. const std::string& config, cmOptionalLinkInterface& iface,
  6203. cmGeneratorTarget const* headTarget) const
  6204. {
  6205. this->ComputeLinkInterface(config, iface, headTarget, false);
  6206. }
  6207. void cmGeneratorTarget::ComputeLinkInterface(
  6208. const std::string& config, cmOptionalLinkInterface& iface,
  6209. cmGeneratorTarget const* headTarget, bool secondPass) const
  6210. {
  6211. if (iface.Explicit) {
  6212. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6213. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  6214. this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6215. // Shared libraries may have runtime implementation dependencies
  6216. // on other shared libraries that are not in the interface.
  6217. std::set<cmLinkItem> emitted;
  6218. for (cmLinkItem const& lib : iface.Libraries) {
  6219. emitted.insert(lib);
  6220. }
  6221. if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  6222. cmLinkImplementation const* impl = this->GetLinkImplementation(
  6223. config, LinkInterfaceFor::Link, secondPass);
  6224. for (cmLinkImplItem const& lib : impl->Libraries) {
  6225. if (emitted.insert(lib).second) {
  6226. if (lib.Target) {
  6227. // This is a runtime dependency on another shared library.
  6228. if (lib.Target->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6229. iface.SharedDeps.push_back(lib);
  6230. }
  6231. } else {
  6232. // TODO: Recognize shared library file names. Perhaps this
  6233. // should be moved to cmComputeLinkInformation, but that
  6234. // creates a chicken-and-egg problem since this list is needed
  6235. // for its construction.
  6236. }
  6237. }
  6238. }
  6239. }
  6240. }
  6241. } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN ||
  6242. this->GetPolicyStatusCMP0022() == cmPolicies::OLD) {
  6243. // The link implementation is the default link interface.
  6244. cmLinkImplementationLibraries const* impl =
  6245. this->GetLinkImplementationLibrariesInternal(config, headTarget,
  6246. LinkInterfaceFor::Link);
  6247. iface.ImplementationIsInterface = true;
  6248. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  6249. }
  6250. if (this->LinkLanguagePropagatesToDependents()) {
  6251. // Targets using this archive need its language runtime libraries.
  6252. if (cmLinkImplementation const* impl = this->GetLinkImplementation(
  6253. config, LinkInterfaceFor::Link, secondPass)) {
  6254. iface.Languages = impl->Languages;
  6255. }
  6256. }
  6257. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  6258. // Construct the property name suffix for this configuration.
  6259. std::string suffix = "_";
  6260. if (!config.empty()) {
  6261. suffix += cmSystemTools::UpperCase(config);
  6262. } else {
  6263. suffix += "NOCONFIG";
  6264. }
  6265. // How many repetitions are needed if this library has cyclic
  6266. // dependencies?
  6267. std::string propName = cmStrCat("LINK_INTERFACE_MULTIPLICITY", suffix);
  6268. if (cmValue config_reps = this->GetProperty(propName)) {
  6269. sscanf(config_reps->c_str(), "%u", &iface.Multiplicity);
  6270. } else if (cmValue reps =
  6271. this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) {
  6272. sscanf(reps->c_str(), "%u", &iface.Multiplicity);
  6273. }
  6274. }
  6275. }
  6276. const cmLinkInterfaceLibraries* cmGeneratorTarget::GetLinkInterfaceLibraries(
  6277. const std::string& config, cmGeneratorTarget const* head,
  6278. LinkInterfaceFor interfaceFor) const
  6279. {
  6280. // Imported targets have their own link interface.
  6281. if (this->IsImported()) {
  6282. return this->GetImportLinkInterface(config, head, interfaceFor);
  6283. }
  6284. // Link interfaces are not supported for executables that do not
  6285. // export symbols.
  6286. if (this->GetType() == cmStateEnums::EXECUTABLE &&
  6287. !this->IsExecutableWithExports()) {
  6288. return nullptr;
  6289. }
  6290. // Lookup any existing link interface for this configuration.
  6291. cmHeadToLinkInterfaceMap& hm =
  6292. (interfaceFor == LinkInterfaceFor::Usage
  6293. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  6294. : this->GetHeadToLinkInterfaceMap(config));
  6295. // If the link interface does not depend on the head target
  6296. // then reuse the one from the head we computed first.
  6297. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6298. head = hm.begin()->first;
  6299. }
  6300. cmOptionalLinkInterface& iface = hm[head];
  6301. if (!iface.LibrariesDone) {
  6302. iface.LibrariesDone = true;
  6303. this->ComputeLinkInterfaceLibraries(config, iface, head, interfaceFor);
  6304. }
  6305. return iface.Exists ? &iface : nullptr;
  6306. }
  6307. std::string cmGeneratorTarget::GetDirectory(
  6308. const std::string& config, cmStateEnums::ArtifactType artifact) const
  6309. {
  6310. if (this->IsImported()) {
  6311. auto fullPath = this->Target->ImportedGetFullPath(config, artifact);
  6312. if (this->IsFrameworkOnApple()) {
  6313. auto fwDescriptor = this->GetGlobalGenerator()->SplitFrameworkPath(
  6314. fullPath, cmGlobalGenerator::FrameworkFormat::Strict);
  6315. if (fwDescriptor) {
  6316. return fwDescriptor->Directory;
  6317. }
  6318. }
  6319. // Return the directory from which the target is imported.
  6320. return cmSystemTools::GetFilenamePath(fullPath);
  6321. }
  6322. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  6323. // Return the directory in which the target will be built.
  6324. switch (artifact) {
  6325. case cmStateEnums::RuntimeBinaryArtifact:
  6326. return info->OutDir;
  6327. case cmStateEnums::ImportLibraryArtifact:
  6328. return info->ImpDir;
  6329. }
  6330. }
  6331. return "";
  6332. }
  6333. bool cmGeneratorTarget::UsesDefaultOutputDir(
  6334. const std::string& config, cmStateEnums::ArtifactType artifact) const
  6335. {
  6336. std::string dir;
  6337. return this->ComputeOutputDir(config, artifact, dir);
  6338. }
  6339. cmGeneratorTarget::OutputInfo const* cmGeneratorTarget::GetOutputInfo(
  6340. const std::string& config) const
  6341. {
  6342. // There is no output information for imported targets.
  6343. if (this->IsImported()) {
  6344. return nullptr;
  6345. }
  6346. // Synthetic targets don't have output.
  6347. if (this->IsSynthetic()) {
  6348. return nullptr;
  6349. }
  6350. // Only libraries and executables have well-defined output files.
  6351. if (!this->HaveWellDefinedOutputFiles()) {
  6352. std::string msg = cmStrCat("cmGeneratorTarget::GetOutputInfo called for ",
  6353. this->GetName(), " which has type ",
  6354. cmState::GetTargetTypeName(this->GetType()));
  6355. this->LocalGenerator->IssueMessage(MessageType::INTERNAL_ERROR, msg);
  6356. return nullptr;
  6357. }
  6358. // Lookup/compute/cache the output information for this configuration.
  6359. std::string config_upper;
  6360. if (!config.empty()) {
  6361. config_upper = cmSystemTools::UpperCase(config);
  6362. }
  6363. auto i = this->OutputInfoMap.find(config_upper);
  6364. if (i == this->OutputInfoMap.end()) {
  6365. // Add empty info in map to detect potential recursion.
  6366. OutputInfo info;
  6367. OutputInfoMapType::value_type entry(config_upper, info);
  6368. i = this->OutputInfoMap.insert(entry).first;
  6369. // Compute output directories.
  6370. this->ComputeOutputDir(config, cmStateEnums::RuntimeBinaryArtifact,
  6371. info.OutDir);
  6372. this->ComputeOutputDir(config, cmStateEnums::ImportLibraryArtifact,
  6373. info.ImpDir);
  6374. if (!this->ComputePDBOutputDir("PDB", config, info.PdbDir)) {
  6375. info.PdbDir = info.OutDir;
  6376. }
  6377. // Now update the previously-prepared map entry.
  6378. i->second = info;
  6379. } else if (i->second.empty()) {
  6380. // An empty map entry indicates we have been called recursively
  6381. // from the above block.
  6382. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  6383. MessageType::FATAL_ERROR,
  6384. "Target '" + this->GetName() + "' OUTPUT_DIRECTORY depends on itself.",
  6385. this->GetBacktrace());
  6386. return nullptr;
  6387. }
  6388. return &i->second;
  6389. }
  6390. bool cmGeneratorTarget::ComputeOutputDir(const std::string& config,
  6391. cmStateEnums::ArtifactType artifact,
  6392. std::string& out) const
  6393. {
  6394. bool usesDefaultOutputDir = false;
  6395. std::string conf = config;
  6396. // Look for a target property defining the target output directory
  6397. // based on the target type.
  6398. std::string targetTypeName = this->GetOutputTargetType(artifact);
  6399. std::string propertyName;
  6400. if (!targetTypeName.empty()) {
  6401. propertyName = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY");
  6402. }
  6403. // Check for a per-configuration output directory target property.
  6404. std::string configUpper = cmSystemTools::UpperCase(conf);
  6405. std::string configProp;
  6406. if (!targetTypeName.empty()) {
  6407. configProp = cmStrCat(targetTypeName, "_OUTPUT_DIRECTORY_", configUpper);
  6408. }
  6409. // Select an output directory.
  6410. if (cmValue config_outdir = this->GetProperty(configProp)) {
  6411. // Use the user-specified per-configuration output directory.
  6412. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  6413. config, this);
  6414. // Skip per-configuration subdirectory.
  6415. conf.clear();
  6416. } else if (cmValue outdir = this->GetProperty(propertyName)) {
  6417. // Use the user-specified output directory.
  6418. out = cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator,
  6419. config, this);
  6420. // Skip per-configuration subdirectory if the value contained a
  6421. // generator expression.
  6422. if (out != *outdir) {
  6423. conf.clear();
  6424. }
  6425. } else if (this->GetType() == cmStateEnums::EXECUTABLE) {
  6426. // Lookup the output path for executables.
  6427. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  6428. } else if (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  6429. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6430. this->GetType() == cmStateEnums::MODULE_LIBRARY) {
  6431. // Lookup the output path for libraries.
  6432. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  6433. }
  6434. if (out.empty()) {
  6435. // Default to the current output directory.
  6436. usesDefaultOutputDir = true;
  6437. out = ".";
  6438. }
  6439. // Convert the output path to a full path in case it is
  6440. // specified as a relative path. Treat a relative path as
  6441. // relative to the current output directory for this makefile.
  6442. out = (cmSystemTools::CollapseFullPath(
  6443. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  6444. // The generator may add the configuration's subdirectory.
  6445. if (!conf.empty()) {
  6446. bool useEPN =
  6447. this->GlobalGenerator->UseEffectivePlatformName(this->Makefile);
  6448. std::string suffix =
  6449. usesDefaultOutputDir && useEPN ? "${EFFECTIVE_PLATFORM_NAME}" : "";
  6450. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  6451. "/", conf, suffix, out);
  6452. }
  6453. return usesDefaultOutputDir;
  6454. }
  6455. bool cmGeneratorTarget::ComputePDBOutputDir(const std::string& kind,
  6456. const std::string& config,
  6457. std::string& out) const
  6458. {
  6459. // Look for a target property defining the target output directory
  6460. // based on the target type.
  6461. std::string propertyName;
  6462. if (!kind.empty()) {
  6463. propertyName = cmStrCat(kind, "_OUTPUT_DIRECTORY");
  6464. }
  6465. std::string conf = config;
  6466. // Check for a per-configuration output directory target property.
  6467. std::string configUpper = cmSystemTools::UpperCase(conf);
  6468. std::string configProp;
  6469. if (!kind.empty()) {
  6470. configProp = cmStrCat(kind, "_OUTPUT_DIRECTORY_", configUpper);
  6471. }
  6472. // Select an output directory.
  6473. if (cmValue config_outdir = this->GetProperty(configProp)) {
  6474. // Use the user-specified per-configuration output directory.
  6475. out = cmGeneratorExpression::Evaluate(*config_outdir, this->LocalGenerator,
  6476. config);
  6477. // Skip per-configuration subdirectory.
  6478. conf.clear();
  6479. } else if (cmValue outdir = this->GetProperty(propertyName)) {
  6480. // Use the user-specified output directory.
  6481. out =
  6482. cmGeneratorExpression::Evaluate(*outdir, this->LocalGenerator, config);
  6483. // Skip per-configuration subdirectory if the value contained a
  6484. // generator expression.
  6485. if (out != *outdir) {
  6486. conf.clear();
  6487. }
  6488. }
  6489. if (out.empty()) {
  6490. return false;
  6491. }
  6492. // Convert the output path to a full path in case it is
  6493. // specified as a relative path. Treat a relative path as
  6494. // relative to the current output directory for this makefile.
  6495. out = (cmSystemTools::CollapseFullPath(
  6496. out, this->LocalGenerator->GetCurrentBinaryDirectory()));
  6497. // The generator may add the configuration's subdirectory.
  6498. if (!conf.empty()) {
  6499. this->LocalGenerator->GetGlobalGenerator()->AppendDirectoryForConfig(
  6500. "/", conf, "", out);
  6501. }
  6502. return true;
  6503. }
  6504. bool cmGeneratorTarget::HaveInstallTreeRPATH(const std::string& config) const
  6505. {
  6506. std::string install_rpath;
  6507. this->GetInstallRPATH(config, install_rpath);
  6508. return !install_rpath.empty() &&
  6509. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  6510. }
  6511. bool cmGeneratorTarget::GetBuildRPATH(const std::string& config,
  6512. std::string& rpath) const
  6513. {
  6514. return this->GetRPATH(config, "BUILD_RPATH", rpath);
  6515. }
  6516. bool cmGeneratorTarget::GetInstallRPATH(const std::string& config,
  6517. std::string& rpath) const
  6518. {
  6519. return this->GetRPATH(config, "INSTALL_RPATH", rpath);
  6520. }
  6521. bool cmGeneratorTarget::GetRPATH(const std::string& config,
  6522. const std::string& prop,
  6523. std::string& rpath) const
  6524. {
  6525. cmValue value = this->GetProperty(prop);
  6526. if (!value) {
  6527. return false;
  6528. }
  6529. rpath =
  6530. cmGeneratorExpression::Evaluate(*value, this->LocalGenerator, config);
  6531. return true;
  6532. }
  6533. void cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  6534. const std::string& config, cmOptionalLinkInterface& iface,
  6535. cmGeneratorTarget const* headTarget, LinkInterfaceFor interfaceFor) const
  6536. {
  6537. // Construct the property name suffix for this configuration.
  6538. std::string suffix = "_";
  6539. if (!config.empty()) {
  6540. suffix += cmSystemTools::UpperCase(config);
  6541. } else {
  6542. suffix += "NOCONFIG";
  6543. }
  6544. // An explicit list of interface libraries may be set for shared
  6545. // libraries and executables that export symbols.
  6546. bool haveExplicitLibraries = false;
  6547. cmValue explicitLibrariesCMP0022OLD;
  6548. std::string linkIfacePropCMP0022OLD;
  6549. bool const cmp0022NEW = (this->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  6550. this->GetPolicyStatusCMP0022() != cmPolicies::WARN);
  6551. if (cmp0022NEW) {
  6552. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  6553. haveExplicitLibraries = !this->Target->GetLinkInterfaceEntries().empty() ||
  6554. !this->Target->GetLinkInterfaceDirectEntries().empty() ||
  6555. !this->Target->GetLinkInterfaceDirectExcludeEntries().empty();
  6556. } else {
  6557. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  6558. // shared lib or executable.
  6559. if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6560. this->IsExecutableWithExports()) {
  6561. // Lookup the per-configuration property.
  6562. linkIfacePropCMP0022OLD = cmStrCat("LINK_INTERFACE_LIBRARIES", suffix);
  6563. explicitLibrariesCMP0022OLD = this->GetProperty(linkIfacePropCMP0022OLD);
  6564. // If not set, try the generic property.
  6565. if (!explicitLibrariesCMP0022OLD) {
  6566. linkIfacePropCMP0022OLD = "LINK_INTERFACE_LIBRARIES";
  6567. explicitLibrariesCMP0022OLD =
  6568. this->GetProperty(linkIfacePropCMP0022OLD);
  6569. }
  6570. }
  6571. if (explicitLibrariesCMP0022OLD &&
  6572. this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6573. !this->PolicyWarnedCMP0022) {
  6574. // Compare the explicitly set old link interface properties to the
  6575. // preferred new link interface property one and warn if different.
  6576. cmValue newExplicitLibraries =
  6577. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  6578. if (newExplicitLibraries &&
  6579. (*newExplicitLibraries != *explicitLibrariesCMP0022OLD)) {
  6580. std::ostringstream w;
  6581. /* clang-format off */
  6582. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6583. "Target \"" << this->GetName() << "\" has an "
  6584. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  6585. linkIfacePropCMP0022OLD << " properties."
  6586. "\n"
  6587. "INTERFACE_LINK_LIBRARIES:\n"
  6588. " " << *newExplicitLibraries << "\n" <<
  6589. linkIfacePropCMP0022OLD << ":\n"
  6590. " " << *explicitLibrariesCMP0022OLD << "\n";
  6591. /* clang-format on */
  6592. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  6593. w.str());
  6594. this->PolicyWarnedCMP0022 = true;
  6595. }
  6596. }
  6597. haveExplicitLibraries = static_cast<bool>(explicitLibrariesCMP0022OLD);
  6598. }
  6599. // There is no implicit link interface for executables or modules
  6600. // so if none was explicitly set then there is no link interface.
  6601. if (!haveExplicitLibraries &&
  6602. (this->GetType() == cmStateEnums::EXECUTABLE ||
  6603. (this->GetType() == cmStateEnums::MODULE_LIBRARY))) {
  6604. return;
  6605. }
  6606. iface.Exists = true;
  6607. // If CMP0022 is NEW then the plain tll signature sets the
  6608. // INTERFACE_LINK_LIBRARIES property. Even if the project
  6609. // clears it, the link interface is still explicit.
  6610. iface.Explicit = cmp0022NEW || explicitLibrariesCMP0022OLD;
  6611. if (cmp0022NEW) {
  6612. // The interface libraries are specified by INTERFACE_LINK_LIBRARIES.
  6613. // Use its special representation directly to get backtraces.
  6614. this->ExpandLinkItems(
  6615. kINTERFACE_LINK_LIBRARIES, this->Target->GetLinkInterfaceEntries(),
  6616. config, headTarget, interfaceFor, LinkInterfaceField::Libraries, iface);
  6617. this->ExpandLinkItems(kINTERFACE_LINK_LIBRARIES_DIRECT,
  6618. this->Target->GetLinkInterfaceDirectEntries(),
  6619. config, headTarget, interfaceFor,
  6620. LinkInterfaceField::HeadInclude, iface);
  6621. this->ExpandLinkItems(kINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
  6622. this->Target->GetLinkInterfaceDirectExcludeEntries(),
  6623. config, headTarget, interfaceFor,
  6624. LinkInterfaceField::HeadExclude, iface);
  6625. } else if (explicitLibrariesCMP0022OLD) {
  6626. // The interface libraries have been explicitly set in pre-CMP0022 style.
  6627. std::vector<BT<std::string>> entries;
  6628. entries.emplace_back(*explicitLibrariesCMP0022OLD);
  6629. this->ExpandLinkItems(linkIfacePropCMP0022OLD, cmMakeRange(entries),
  6630. config, headTarget, interfaceFor,
  6631. LinkInterfaceField::Libraries, iface);
  6632. }
  6633. // If the link interface is explicit, do not fall back to the link impl.
  6634. if (iface.Explicit) {
  6635. return;
  6636. }
  6637. // The link implementation is the default link interface.
  6638. if (cmLinkImplementationLibraries const* impl =
  6639. this->GetLinkImplementationLibrariesInternal(config, headTarget,
  6640. interfaceFor)) {
  6641. iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(),
  6642. impl->Libraries.end());
  6643. if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  6644. !this->PolicyWarnedCMP0022 && interfaceFor == LinkInterfaceFor::Link) {
  6645. // Compare the link implementation fallback link interface to the
  6646. // preferred new link interface property and warn if different.
  6647. cmLinkInterface ifaceNew;
  6648. this->ExpandLinkItems(kINTERFACE_LINK_LIBRARIES,
  6649. this->Target->GetLinkInterfaceEntries(), config,
  6650. headTarget, interfaceFor,
  6651. LinkInterfaceField::Libraries, ifaceNew);
  6652. if (ifaceNew.Libraries != iface.Libraries) {
  6653. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  6654. std::string newLibraries = cmJoin(ifaceNew.Libraries, ";");
  6655. if (oldLibraries.empty()) {
  6656. oldLibraries = "(empty)";
  6657. }
  6658. if (newLibraries.empty()) {
  6659. newLibraries = "(empty)";
  6660. }
  6661. std::ostringstream w;
  6662. /* clang-format off */
  6663. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  6664. "Target \"" << this->GetName() << "\" has an "
  6665. "INTERFACE_LINK_LIBRARIES property. "
  6666. "This should be preferred as the source of the link interface "
  6667. "for this library but because CMP0022 is not set CMake is "
  6668. "ignoring the property and using the link implementation "
  6669. "as the link interface instead."
  6670. "\n"
  6671. "INTERFACE_LINK_LIBRARIES:\n"
  6672. " " << newLibraries << "\n"
  6673. "Link implementation:\n"
  6674. " " << oldLibraries << "\n";
  6675. /* clang-format on */
  6676. this->LocalGenerator->IssueMessage(MessageType::AUTHOR_WARNING,
  6677. w.str());
  6678. this->PolicyWarnedCMP0022 = true;
  6679. }
  6680. }
  6681. }
  6682. }
  6683. namespace {
  6684. template <typename ReturnType>
  6685. ReturnType constructItem(cmGeneratorTarget* target,
  6686. cmListFileBacktrace const& bt);
  6687. template <>
  6688. inline cmLinkImplItem constructItem(cmGeneratorTarget* target,
  6689. cmListFileBacktrace const& bt)
  6690. {
  6691. return cmLinkImplItem(cmLinkItem(target, false, bt), false);
  6692. }
  6693. template <>
  6694. inline cmLinkItem constructItem(cmGeneratorTarget* target,
  6695. cmListFileBacktrace const& bt)
  6696. {
  6697. return cmLinkItem(target, false, bt);
  6698. }
  6699. template <typename ValueType>
  6700. std::vector<ValueType> computeImplicitLanguageTargets(
  6701. std::string const& lang, std::string const& config,
  6702. cmGeneratorTarget const* currentTarget)
  6703. {
  6704. cmListFileBacktrace bt;
  6705. std::vector<ValueType> result;
  6706. cmLocalGenerator* lg = currentTarget->GetLocalGenerator();
  6707. std::string const& runtimeLibrary =
  6708. currentTarget->GetRuntimeLinkLibrary(lang, config);
  6709. if (cmValue runtimeLinkOptions = currentTarget->Makefile->GetDefinition(
  6710. "CMAKE_" + lang + "_RUNTIME_LIBRARIES_" + runtimeLibrary)) {
  6711. cmList libsList{ *runtimeLinkOptions };
  6712. result.reserve(libsList.size());
  6713. for (auto const& i : libsList) {
  6714. cmGeneratorTarget::TargetOrString resolved =
  6715. currentTarget->ResolveTargetReference(i, lg);
  6716. if (resolved.Target) {
  6717. result.emplace_back(constructItem<ValueType>(resolved.Target, bt));
  6718. }
  6719. }
  6720. }
  6721. return result;
  6722. }
  6723. }
  6724. void cmGeneratorTarget::ComputeLinkInterfaceRuntimeLibraries(
  6725. const std::string& config, cmOptionalLinkInterface& iface) const
  6726. {
  6727. for (std::string const& lang : iface.Languages) {
  6728. if ((lang == "CUDA" || lang == "HIP") &&
  6729. iface.LanguageRuntimeLibraries.find(lang) ==
  6730. iface.LanguageRuntimeLibraries.end()) {
  6731. auto implicitTargets =
  6732. computeImplicitLanguageTargets<cmLinkItem>(lang, config, this);
  6733. iface.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6734. }
  6735. }
  6736. }
  6737. void cmGeneratorTarget::ComputeLinkImplementationRuntimeLibraries(
  6738. const std::string& config, cmOptionalLinkImplementation& impl) const
  6739. {
  6740. for (std::string const& lang : impl.Languages) {
  6741. if ((lang == "CUDA" || lang == "HIP") &&
  6742. impl.LanguageRuntimeLibraries.find(lang) ==
  6743. impl.LanguageRuntimeLibraries.end()) {
  6744. auto implicitTargets =
  6745. computeImplicitLanguageTargets<cmLinkImplItem>(lang, config, this);
  6746. impl.LanguageRuntimeLibraries[lang] = std::move(implicitTargets);
  6747. }
  6748. }
  6749. }
  6750. const cmLinkInterface* cmGeneratorTarget::GetImportLinkInterface(
  6751. const std::string& config, cmGeneratorTarget const* headTarget,
  6752. LinkInterfaceFor interfaceFor, bool secondPass) const
  6753. {
  6754. cmGeneratorTarget::ImportInfo const* info = this->GetImportInfo(config);
  6755. if (!info) {
  6756. return nullptr;
  6757. }
  6758. cmHeadToLinkInterfaceMap& hm =
  6759. (interfaceFor == LinkInterfaceFor::Usage
  6760. ? this->GetHeadToLinkInterfaceUsageRequirementsMap(config)
  6761. : this->GetHeadToLinkInterfaceMap(config));
  6762. // If the link interface does not depend on the head target
  6763. // then reuse the one from the head we computed first.
  6764. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  6765. headTarget = hm.begin()->first;
  6766. }
  6767. cmOptionalLinkInterface& iface = hm[headTarget];
  6768. if (secondPass) {
  6769. iface = cmOptionalLinkInterface();
  6770. }
  6771. if (!iface.AllDone) {
  6772. iface.AllDone = true;
  6773. iface.LibrariesDone = true;
  6774. iface.Multiplicity = info->Multiplicity;
  6775. cmExpandList(info->Languages, iface.Languages);
  6776. this->ExpandLinkItems(kINTERFACE_LINK_LIBRARIES_DIRECT,
  6777. cmMakeRange(info->LibrariesHeadInclude), config,
  6778. headTarget, interfaceFor,
  6779. LinkInterfaceField::HeadInclude, iface);
  6780. this->ExpandLinkItems(kINTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE,
  6781. cmMakeRange(info->LibrariesHeadExclude), config,
  6782. headTarget, interfaceFor,
  6783. LinkInterfaceField::HeadExclude, iface);
  6784. this->ExpandLinkItems(info->LibrariesProp, cmMakeRange(info->Libraries),
  6785. config, headTarget, interfaceFor,
  6786. LinkInterfaceField::Libraries, iface);
  6787. cmList deps{ info->SharedDeps };
  6788. LookupLinkItemScope scope{ this->LocalGenerator };
  6789. for (auto const& dep : deps) {
  6790. if (cm::optional<cmLinkItem> maybeItem = this->LookupLinkItem(
  6791. dep, cmListFileBacktrace(), &scope, LookupSelf::No)) {
  6792. iface.SharedDeps.emplace_back(std::move(*maybeItem));
  6793. }
  6794. }
  6795. }
  6796. return &iface;
  6797. }
  6798. cmGeneratorTarget::ImportInfo const* cmGeneratorTarget::GetImportInfo(
  6799. const std::string& config) const
  6800. {
  6801. // There is no imported information for non-imported targets.
  6802. if (!this->IsImported()) {
  6803. return nullptr;
  6804. }
  6805. // Lookup/compute/cache the import information for this
  6806. // configuration.
  6807. std::string config_upper;
  6808. if (!config.empty()) {
  6809. config_upper = cmSystemTools::UpperCase(config);
  6810. } else {
  6811. config_upper = "NOCONFIG";
  6812. }
  6813. auto i = this->ImportInfoMap.find(config_upper);
  6814. if (i == this->ImportInfoMap.end()) {
  6815. ImportInfo info;
  6816. this->ComputeImportInfo(config_upper, info);
  6817. ImportInfoMapType::value_type entry(config_upper, info);
  6818. i = this->ImportInfoMap.insert(entry).first;
  6819. }
  6820. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6821. return &i->second;
  6822. }
  6823. // If the location is empty then the target is not available for
  6824. // this configuration.
  6825. if (i->second.Location.empty() && i->second.ImportLibrary.empty()) {
  6826. return nullptr;
  6827. }
  6828. // Return the import information.
  6829. return &i->second;
  6830. }
  6831. void cmGeneratorTarget::ComputeImportInfo(std::string const& desired_config,
  6832. ImportInfo& info) const
  6833. {
  6834. // This method finds information about an imported target from its
  6835. // properties. The "IMPORTED_" namespace is reserved for properties
  6836. // defined by the project exporting the target.
  6837. // Initialize members.
  6838. info.NoSOName = false;
  6839. cmValue loc = nullptr;
  6840. cmValue imp = nullptr;
  6841. std::string suffix;
  6842. if (!this->Target->GetMappedConfig(desired_config, loc, imp, suffix)) {
  6843. return;
  6844. }
  6845. // Get the link interface.
  6846. {
  6847. // Use the INTERFACE_LINK_LIBRARIES special representation directly
  6848. // to get backtraces.
  6849. cmBTStringRange entries = this->Target->GetLinkInterfaceEntries();
  6850. if (!entries.empty()) {
  6851. info.LibrariesProp = "INTERFACE_LINK_LIBRARIES";
  6852. for (BT<std::string> const& entry : entries) {
  6853. info.Libraries.emplace_back(entry);
  6854. }
  6855. } else if (this->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
  6856. std::string linkProp =
  6857. cmStrCat("IMPORTED_LINK_INTERFACE_LIBRARIES", suffix);
  6858. cmValue propertyLibs = this->GetProperty(linkProp);
  6859. if (!propertyLibs) {
  6860. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  6861. propertyLibs = this->GetProperty(linkProp);
  6862. }
  6863. if (propertyLibs) {
  6864. info.LibrariesProp = linkProp;
  6865. info.Libraries.emplace_back(*propertyLibs);
  6866. }
  6867. }
  6868. }
  6869. for (BT<std::string> const& entry :
  6870. this->Target->GetLinkInterfaceDirectEntries()) {
  6871. info.LibrariesHeadInclude.emplace_back(entry);
  6872. }
  6873. for (BT<std::string> const& entry :
  6874. this->Target->GetLinkInterfaceDirectExcludeEntries()) {
  6875. info.LibrariesHeadExclude.emplace_back(entry);
  6876. }
  6877. if (this->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
  6878. if (loc) {
  6879. info.LibName = *loc;
  6880. }
  6881. return;
  6882. }
  6883. // A provided configuration has been chosen. Load the
  6884. // configuration's properties.
  6885. // Get the location.
  6886. if (loc) {
  6887. info.Location = *loc;
  6888. } else {
  6889. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  6890. if (cmValue config_location = this->GetProperty(impProp)) {
  6891. info.Location = *config_location;
  6892. } else if (cmValue location = this->GetProperty("IMPORTED_LOCATION")) {
  6893. info.Location = *location;
  6894. }
  6895. }
  6896. // Get the soname.
  6897. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6898. std::string soProp = cmStrCat("IMPORTED_SONAME", suffix);
  6899. if (cmValue config_soname = this->GetProperty(soProp)) {
  6900. info.SOName = *config_soname;
  6901. } else if (cmValue soname = this->GetProperty("IMPORTED_SONAME")) {
  6902. info.SOName = *soname;
  6903. }
  6904. }
  6905. // Get the "no-soname" mark.
  6906. if (this->GetType() == cmStateEnums::SHARED_LIBRARY) {
  6907. std::string soProp = cmStrCat("IMPORTED_NO_SONAME", suffix);
  6908. if (cmValue config_no_soname = this->GetProperty(soProp)) {
  6909. info.NoSOName = cmIsOn(*config_no_soname);
  6910. } else if (cmValue no_soname = this->GetProperty("IMPORTED_NO_SONAME")) {
  6911. info.NoSOName = cmIsOn(*no_soname);
  6912. }
  6913. }
  6914. // Get the import library.
  6915. if (imp) {
  6916. info.ImportLibrary = *imp;
  6917. } else if (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  6918. this->IsExecutableWithExports()) {
  6919. std::string impProp = cmStrCat("IMPORTED_IMPLIB", suffix);
  6920. if (cmValue config_implib = this->GetProperty(impProp)) {
  6921. info.ImportLibrary = *config_implib;
  6922. } else if (cmValue implib = this->GetProperty("IMPORTED_IMPLIB")) {
  6923. info.ImportLibrary = *implib;
  6924. }
  6925. }
  6926. // Get the link dependencies.
  6927. {
  6928. std::string linkProp =
  6929. cmStrCat("IMPORTED_LINK_DEPENDENT_LIBRARIES", suffix);
  6930. if (cmValue config_libs = this->GetProperty(linkProp)) {
  6931. info.SharedDeps = *config_libs;
  6932. } else if (cmValue libs =
  6933. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES")) {
  6934. info.SharedDeps = *libs;
  6935. }
  6936. }
  6937. // Get the link languages.
  6938. if (this->LinkLanguagePropagatesToDependents()) {
  6939. std::string linkProp =
  6940. cmStrCat("IMPORTED_LINK_INTERFACE_LANGUAGES", suffix);
  6941. if (cmValue config_libs = this->GetProperty(linkProp)) {
  6942. info.Languages = *config_libs;
  6943. } else if (cmValue libs =
  6944. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES")) {
  6945. info.Languages = *libs;
  6946. }
  6947. }
  6948. // Get information if target is managed assembly.
  6949. {
  6950. std::string linkProp = "IMPORTED_COMMON_LANGUAGE_RUNTIME";
  6951. if (cmValue pc = this->GetProperty(linkProp + suffix)) {
  6952. info.Managed = this->CheckManagedType(*pc);
  6953. } else if (cmValue p = this->GetProperty(linkProp)) {
  6954. info.Managed = this->CheckManagedType(*p);
  6955. }
  6956. }
  6957. // Get the cyclic repetition count.
  6958. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  6959. std::string linkProp =
  6960. cmStrCat("IMPORTED_LINK_INTERFACE_MULTIPLICITY", suffix);
  6961. if (cmValue config_reps = this->GetProperty(linkProp)) {
  6962. sscanf(config_reps->c_str(), "%u", &info.Multiplicity);
  6963. } else if (cmValue reps =
  6964. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY")) {
  6965. sscanf(reps->c_str(), "%u", &info.Multiplicity);
  6966. }
  6967. }
  6968. }
  6969. cmHeadToLinkInterfaceMap& cmGeneratorTarget::GetHeadToLinkInterfaceMap(
  6970. const std::string& config) const
  6971. {
  6972. return this->LinkInterfaceMap[cmSystemTools::UpperCase(config)];
  6973. }
  6974. cmHeadToLinkInterfaceMap&
  6975. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  6976. const std::string& config) const
  6977. {
  6978. return this
  6979. ->LinkInterfaceUsageRequirementsOnlyMap[cmSystemTools::UpperCase(config)];
  6980. }
  6981. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6982. const std::string& config, LinkInterfaceFor implFor) const
  6983. {
  6984. return this->GetLinkImplementation(config, implFor, false);
  6985. }
  6986. const cmLinkImplementation* cmGeneratorTarget::GetLinkImplementation(
  6987. const std::string& config, LinkInterfaceFor implFor, bool secondPass) const
  6988. {
  6989. // There is no link implementation for targets that cannot compile sources.
  6990. if (!this->CanCompileSources()) {
  6991. return nullptr;
  6992. }
  6993. HeadToLinkImplementationMap& hm =
  6994. (implFor == LinkInterfaceFor::Usage
  6995. ? this->GetHeadToLinkImplementationUsageRequirementsMap(config)
  6996. : this->GetHeadToLinkImplementationMap(config));
  6997. cmOptionalLinkImplementation& impl = hm[this];
  6998. if (secondPass) {
  6999. impl = cmOptionalLinkImplementation();
  7000. }
  7001. if (!impl.LibrariesDone) {
  7002. impl.LibrariesDone = true;
  7003. this->ComputeLinkImplementationLibraries(config, impl, this, implFor);
  7004. }
  7005. if (!impl.LanguagesDone) {
  7006. impl.LanguagesDone = true;
  7007. this->ComputeLinkImplementationLanguages(config, impl);
  7008. this->ComputeLinkImplementationRuntimeLibraries(config, impl);
  7009. }
  7010. return &impl;
  7011. }
  7012. cmGeneratorTarget::HeadToLinkImplementationMap&
  7013. cmGeneratorTarget::GetHeadToLinkImplementationMap(
  7014. std::string const& config) const
  7015. {
  7016. return this->LinkImplMap[cmSystemTools::UpperCase(config)];
  7017. }
  7018. cmGeneratorTarget::HeadToLinkImplementationMap&
  7019. cmGeneratorTarget::GetHeadToLinkImplementationUsageRequirementsMap(
  7020. std::string const& config) const
  7021. {
  7022. return this
  7023. ->LinkImplUsageRequirementsOnlyMap[cmSystemTools::UpperCase(config)];
  7024. }
  7025. bool cmGeneratorTarget::GetConfigCommonSourceFilesForXcode(
  7026. std::vector<cmSourceFile*>& files) const
  7027. {
  7028. std::vector<std::string> const& configs =
  7029. this->Makefile->GetGeneratorConfigs(cmMakefile::IncludeEmptyConfig);
  7030. auto it = configs.begin();
  7031. const std::string& firstConfig = *it;
  7032. this->GetSourceFilesWithoutObjectLibraries(files, firstConfig);
  7033. for (; it != configs.end(); ++it) {
  7034. std::vector<cmSourceFile*> configFiles;
  7035. this->GetSourceFilesWithoutObjectLibraries(configFiles, *it);
  7036. if (configFiles != files) {
  7037. std::string firstConfigFiles;
  7038. const char* sep = "";
  7039. for (cmSourceFile* f : files) {
  7040. firstConfigFiles += sep;
  7041. firstConfigFiles += f->ResolveFullPath();
  7042. sep = "\n ";
  7043. }
  7044. std::string thisConfigFiles;
  7045. sep = "";
  7046. for (cmSourceFile* f : configFiles) {
  7047. thisConfigFiles += sep;
  7048. thisConfigFiles += f->ResolveFullPath();
  7049. sep = "\n ";
  7050. }
  7051. std::ostringstream e;
  7052. /* clang-format off */
  7053. e << "Target \"" << this->GetName()
  7054. << "\" has source files which vary by "
  7055. "configuration. This is not supported by the \""
  7056. << this->GlobalGenerator->GetName()
  7057. << "\" generator.\n"
  7058. "Config \"" << firstConfig << "\":\n"
  7059. " " << firstConfigFiles << "\n"
  7060. "Config \"" << *it << "\":\n"
  7061. " " << thisConfigFiles << "\n";
  7062. /* clang-format on */
  7063. this->LocalGenerator->IssueMessage(MessageType::FATAL_ERROR, e.str());
  7064. return false;
  7065. }
  7066. }
  7067. return true;
  7068. }
  7069. void cmGeneratorTarget::GetObjectLibrariesCMP0026(
  7070. std::vector<cmGeneratorTarget*>& objlibs) const
  7071. {
  7072. // At configure-time, this method can be called as part of getting the
  7073. // LOCATION property or to export() a file to be include()d. However
  7074. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  7075. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  7076. // behavior of CMP0024 and CMP0026 only.
  7077. cmBTStringRange rng = this->Target->GetSourceEntries();
  7078. for (auto const& entry : rng) {
  7079. cmList files{ entry.Value };
  7080. for (auto const& li : files) {
  7081. if (cmHasLiteralPrefix(li, "$<TARGET_OBJECTS:") && li.back() == '>') {
  7082. std::string objLibName = li.substr(17, li.size() - 18);
  7083. if (cmGeneratorExpression::Find(objLibName) != std::string::npos) {
  7084. continue;
  7085. }
  7086. cmGeneratorTarget* objLib =
  7087. this->LocalGenerator->FindGeneratorTargetToUse(objLibName);
  7088. if (objLib) {
  7089. objlibs.push_back(objLib);
  7090. }
  7091. }
  7092. }
  7093. }
  7094. }
  7095. std::string cmGeneratorTarget::CheckCMP0004(std::string const& item) const
  7096. {
  7097. // Strip whitespace off the library names because we used to do this
  7098. // in case variables were expanded at generate time. We no longer
  7099. // do the expansion but users link to libraries like " ${VAR} ".
  7100. std::string lib = item;
  7101. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  7102. if (pos != std::string::npos) {
  7103. lib = lib.substr(pos);
  7104. }
  7105. pos = lib.find_last_not_of(" \t\r\n");
  7106. if (pos != std::string::npos) {
  7107. lib = lib.substr(0, pos + 1);
  7108. }
  7109. if (lib != item) {
  7110. cmake* cm = this->LocalGenerator->GetCMakeInstance();
  7111. switch (this->GetPolicyStatusCMP0004()) {
  7112. case cmPolicies::WARN: {
  7113. std::ostringstream w;
  7114. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0004) << "\n"
  7115. << "Target \"" << this->GetName() << "\" links to item \"" << item
  7116. << "\" which has leading or trailing whitespace.";
  7117. cm->IssueMessage(MessageType::AUTHOR_WARNING, w.str(),
  7118. this->GetBacktrace());
  7119. }
  7120. CM_FALLTHROUGH;
  7121. case cmPolicies::OLD:
  7122. break;
  7123. case cmPolicies::NEW: {
  7124. std::ostringstream e;
  7125. e << "Target \"" << this->GetName() << "\" links to item \"" << item
  7126. << "\" which has leading or trailing whitespace. "
  7127. << "This is now an error according to policy CMP0004.";
  7128. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  7129. this->GetBacktrace());
  7130. } break;
  7131. case cmPolicies::REQUIRED_IF_USED:
  7132. case cmPolicies::REQUIRED_ALWAYS: {
  7133. std::ostringstream e;
  7134. e << cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0004) << "\n"
  7135. << "Target \"" << this->GetName() << "\" links to item \"" << item
  7136. << "\" which has leading or trailing whitespace.";
  7137. cm->IssueMessage(MessageType::FATAL_ERROR, e.str(),
  7138. this->GetBacktrace());
  7139. } break;
  7140. }
  7141. }
  7142. return lib;
  7143. }
  7144. bool cmGeneratorTarget::IsDeprecated() const
  7145. {
  7146. cmValue deprecation = this->GetProperty("DEPRECATION");
  7147. return cmNonempty(deprecation);
  7148. }
  7149. std::string cmGeneratorTarget::GetDeprecation() const
  7150. {
  7151. // find DEPRECATION property
  7152. if (cmValue deprecation = this->GetProperty("DEPRECATION")) {
  7153. return *deprecation;
  7154. }
  7155. return std::string();
  7156. }
  7157. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  7158. const std::string& config) const
  7159. {
  7160. // Targets that do not compile anything have no languages.
  7161. if (!this->CanCompileSources()) {
  7162. return;
  7163. }
  7164. std::vector<cmSourceFile*> sourceFiles;
  7165. this->GetSourceFiles(sourceFiles, config);
  7166. for (cmSourceFile* src : sourceFiles) {
  7167. const std::string& lang = src->GetOrDetermineLanguage();
  7168. if (!lang.empty()) {
  7169. languages.insert(lang);
  7170. }
  7171. }
  7172. std::vector<cmGeneratorTarget*> objectLibraries;
  7173. std::vector<cmSourceFile const*> externalObjects;
  7174. if (!this->GlobalGenerator->GetConfigureDoneCMP0026()) {
  7175. std::vector<cmGeneratorTarget*> objectTargets;
  7176. this->GetObjectLibrariesCMP0026(objectTargets);
  7177. objectLibraries.reserve(objectTargets.size());
  7178. for (cmGeneratorTarget* gt : objectTargets) {
  7179. objectLibraries.push_back(gt);
  7180. }
  7181. } else {
  7182. this->GetExternalObjects(externalObjects, config);
  7183. for (cmSourceFile const* extObj : externalObjects) {
  7184. std::string objLib = extObj->GetObjectLibrary();
  7185. if (cmGeneratorTarget* tgt =
  7186. this->LocalGenerator->FindGeneratorTargetToUse(objLib)) {
  7187. auto const objLibIt =
  7188. std::find_if(objectLibraries.cbegin(), objectLibraries.cend(),
  7189. [tgt](cmGeneratorTarget* t) { return t == tgt; });
  7190. if (objectLibraries.cend() == objLibIt) {
  7191. objectLibraries.push_back(tgt);
  7192. }
  7193. }
  7194. }
  7195. }
  7196. for (cmGeneratorTarget* objLib : objectLibraries) {
  7197. objLib->GetLanguages(languages, config);
  7198. }
  7199. }
  7200. bool cmGeneratorTarget::IsLanguageUsed(std::string const& language,
  7201. std::string const& config) const
  7202. {
  7203. std::set<std::string> languages;
  7204. this->GetLanguages(languages, config);
  7205. return languages.count(language);
  7206. }
  7207. bool cmGeneratorTarget::IsCSharpOnly() const
  7208. {
  7209. // Only certain target types may compile CSharp.
  7210. if (this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  7211. this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  7212. this->GetType() != cmStateEnums::EXECUTABLE) {
  7213. return false;
  7214. }
  7215. std::set<std::string> languages = this->GetAllConfigCompileLanguages();
  7216. // Consider an explicit linker language property, but *not* the
  7217. // computed linker language that may depend on linked targets.
  7218. cmValue linkLang = this->GetProperty("LINKER_LANGUAGE");
  7219. if (cmNonempty(linkLang)) {
  7220. languages.insert(*linkLang);
  7221. }
  7222. return languages.size() == 1 && languages.count("CSharp") > 0;
  7223. }
  7224. bool cmGeneratorTarget::IsDotNetSdkTarget() const
  7225. {
  7226. return !this->GetProperty("DOTNET_SDK").IsEmpty();
  7227. }
  7228. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  7229. const std::string& config, cmOptionalLinkImplementation& impl) const
  7230. {
  7231. // This target needs runtime libraries for its source languages.
  7232. std::set<std::string> languages;
  7233. // Get languages used in our source files.
  7234. this->GetLanguages(languages, config);
  7235. // Copy the set of languages to the link implementation.
  7236. impl.Languages.insert(impl.Languages.begin(), languages.begin(),
  7237. languages.end());
  7238. }
  7239. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  7240. {
  7241. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) {
  7242. return false;
  7243. }
  7244. std::string build_rpath;
  7245. if (this->GetBuildRPATH(config, build_rpath)) {
  7246. return true;
  7247. }
  7248. if (cmLinkImplementationLibraries const* impl =
  7249. this->GetLinkImplementationLibraries(config, LinkInterfaceFor::Link)) {
  7250. return !impl->Libraries.empty();
  7251. }
  7252. return false;
  7253. }
  7254. cmLinkImplementationLibraries const*
  7255. cmGeneratorTarget::GetLinkImplementationLibraries(
  7256. const std::string& config, LinkInterfaceFor implFor) const
  7257. {
  7258. return this->GetLinkImplementationLibrariesInternal(config, this, implFor);
  7259. }
  7260. cmLinkImplementationLibraries const*
  7261. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  7262. const std::string& config, cmGeneratorTarget const* head,
  7263. LinkInterfaceFor implFor) const
  7264. {
  7265. // There is no link implementation for targets that cannot compile sources.
  7266. if (!this->CanCompileSources()) {
  7267. return nullptr;
  7268. }
  7269. // Populate the link implementation libraries for this configuration.
  7270. HeadToLinkImplementationMap& hm =
  7271. (implFor == LinkInterfaceFor::Usage
  7272. ? this->GetHeadToLinkImplementationUsageRequirementsMap(config)
  7273. : this->GetHeadToLinkImplementationMap(config));
  7274. // If the link implementation does not depend on the head target
  7275. // then reuse the one from the head we computed first.
  7276. if (!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) {
  7277. head = hm.begin()->first;
  7278. }
  7279. cmOptionalLinkImplementation& impl = hm[head];
  7280. if (!impl.LibrariesDone) {
  7281. impl.LibrariesDone = true;
  7282. this->ComputeLinkImplementationLibraries(config, impl, head, implFor);
  7283. }
  7284. return &impl;
  7285. }
  7286. bool cmGeneratorTarget::IsNullImpliedByLinkLibraries(
  7287. const std::string& p) const
  7288. {
  7289. return cm::contains(this->LinkImplicitNullProperties, p);
  7290. }
  7291. namespace {
  7292. class TransitiveLinkImpl
  7293. {
  7294. cmGeneratorTarget const* Self;
  7295. std::string const& Config;
  7296. LinkInterfaceFor ImplFor;
  7297. cmLinkImplementation& Impl;
  7298. std::set<cmLinkItem> Emitted;
  7299. std::set<cmLinkItem> Excluded;
  7300. std::unordered_set<cmGeneratorTarget const*> Followed;
  7301. void Follow(cmGeneratorTarget const* target);
  7302. public:
  7303. TransitiveLinkImpl(cmGeneratorTarget const* self, std::string const& config,
  7304. LinkInterfaceFor implFor, cmLinkImplementation& impl)
  7305. : Self(self)
  7306. , Config(config)
  7307. , ImplFor(implFor)
  7308. , Impl(impl)
  7309. {
  7310. }
  7311. void Compute();
  7312. };
  7313. void TransitiveLinkImpl::Follow(cmGeneratorTarget const* target)
  7314. {
  7315. if (!target || !this->Followed.insert(target).second ||
  7316. target->GetPolicyStatusCMP0022() == cmPolicies::OLD ||
  7317. target->GetPolicyStatusCMP0022() == cmPolicies::WARN) {
  7318. return;
  7319. }
  7320. // Get this target's usage requirements.
  7321. cmLinkInterfaceLibraries const* iface =
  7322. target->GetLinkInterfaceLibraries(this->Config, this->Self, this->ImplFor);
  7323. if (!iface) {
  7324. return;
  7325. }
  7326. if (iface->HadContextSensitiveCondition) {
  7327. this->Impl.HadContextSensitiveCondition = true;
  7328. }
  7329. // Process 'INTERFACE_LINK_LIBRARIES_DIRECT' usage requirements.
  7330. for (cmLinkItem const& item : iface->HeadInclude) {
  7331. // Inject direct dependencies from the item's usage requirements
  7332. // before the item itself.
  7333. this->Follow(item.Target);
  7334. // Add the item itself, but at most once.
  7335. if (this->Emitted.insert(item).second) {
  7336. this->Impl.Libraries.emplace_back(item, /* checkCMP0027= */ false);
  7337. }
  7338. }
  7339. // Follow transitive dependencies.
  7340. for (cmLinkItem const& item : iface->Libraries) {
  7341. this->Follow(item.Target);
  7342. }
  7343. // Record exclusions from 'INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE'
  7344. // usage requirements.
  7345. for (cmLinkItem const& item : iface->HeadExclude) {
  7346. this->Excluded.insert(item);
  7347. }
  7348. }
  7349. void TransitiveLinkImpl::Compute()
  7350. {
  7351. // Save the original items and start with an empty list.
  7352. std::vector<cmLinkImplItem> original = std::move(this->Impl.Libraries);
  7353. // Avoid injecting any original items as usage requirements.
  7354. // This gives LINK_LIBRARIES final control over the order
  7355. // if it explicitly lists everything.
  7356. this->Emitted.insert(original.cbegin(), original.cend());
  7357. // Process each original item.
  7358. for (cmLinkImplItem& item : original) {
  7359. // Inject direct dependencies listed in 'INTERFACE_LINK_LIBRARIES_DIRECT'
  7360. // usage requirements before the item itself.
  7361. this->Follow(item.Target);
  7362. // Add the item itself.
  7363. this->Impl.Libraries.emplace_back(std::move(item));
  7364. }
  7365. // Remove items listed in 'INTERFACE_LINK_LIBRARIES_DIRECT_EXCLUDE'
  7366. // usage requirements found through any dependency above.
  7367. this->Impl.Libraries.erase(
  7368. std::remove_if(this->Impl.Libraries.begin(), this->Impl.Libraries.end(),
  7369. [this](cmLinkImplItem const& item) {
  7370. return this->Excluded.find(item) != this->Excluded.end();
  7371. }),
  7372. this->Impl.Libraries.end());
  7373. }
  7374. void ComputeLinkImplTransitive(cmGeneratorTarget const* self,
  7375. std::string const& config,
  7376. LinkInterfaceFor implFor,
  7377. cmLinkImplementation& impl)
  7378. {
  7379. TransitiveLinkImpl transitiveLinkImpl(self, config, implFor, impl);
  7380. transitiveLinkImpl.Compute();
  7381. }
  7382. }
  7383. bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache,
  7384. std::string const& config)
  7385. {
  7386. cmOptionalLinkImplementation impl;
  7387. this->ComputeLinkImplementationLibraries(config, impl, this,
  7388. LinkInterfaceFor::Link);
  7389. cmCxxModuleUsageEffects usage(this);
  7390. auto& SyntheticDeps = this->Configs[config].SyntheticDeps;
  7391. for (auto const& entry : impl.Libraries) {
  7392. auto const* gt = entry.Target;
  7393. if (!gt || !gt->IsImported()) {
  7394. continue;
  7395. }
  7396. if (gt->HaveCxx20ModuleSources()) {
  7397. auto hasher = cmCryptoHash::New("SHA3_512");
  7398. constexpr size_t HASH_TRUNCATION = 12;
  7399. auto dirhash = hasher->HashString(
  7400. gt->GetLocalGenerator()->GetCurrentBinaryDirectory());
  7401. std::string safeName = gt->GetName();
  7402. cmSystemTools::ReplaceString(safeName, ":", "_");
  7403. auto targetIdent =
  7404. hasher->HashString(cmStrCat("@d_", dirhash, "@u_", usage.GetHash()));
  7405. std::string targetName =
  7406. cmStrCat(safeName, "@synth_", targetIdent.substr(0, HASH_TRUNCATION));
  7407. // Check the cache to see if this instance of the imported target has
  7408. // already been created.
  7409. auto cached = cache.CxxModuleTargets.find(targetName);
  7410. cmGeneratorTarget const* synthDep = nullptr;
  7411. if (cached == cache.CxxModuleTargets.end()) {
  7412. auto const* model = gt->Target;
  7413. auto* mf = gt->Makefile;
  7414. auto* lg = gt->GetLocalGenerator();
  7415. auto* tgt = mf->AddSynthesizedTarget(cmStateEnums::INTERFACE_LIBRARY,
  7416. targetName);
  7417. // Copy relevant information from the existing IMPORTED target.
  7418. // Copy policies to the target.
  7419. tgt->CopyPolicyStatuses(model);
  7420. // Copy file sets.
  7421. {
  7422. auto fsNames = model->GetAllFileSetNames();
  7423. for (auto const& fsName : fsNames) {
  7424. auto const* fs = model->GetFileSet(fsName);
  7425. if (!fs) {
  7426. mf->IssueMessage(MessageType::INTERNAL_ERROR,
  7427. cmStrCat("Failed to find file set named '",
  7428. fsName, "' on target '",
  7429. tgt->GetName(), '\''));
  7430. continue;
  7431. }
  7432. auto* newFs = tgt
  7433. ->GetOrCreateFileSet(fs->GetName(), fs->GetType(),
  7434. fs->GetVisibility())
  7435. .first;
  7436. newFs->CopyEntries(fs);
  7437. }
  7438. }
  7439. // Copy imported C++ module properties.
  7440. tgt->CopyImportedCxxModulesEntries(model);
  7441. // Copy other properties which may affect the C++ module BMI
  7442. // generation.
  7443. tgt->CopyImportedCxxModulesProperties(model);
  7444. // Apply usage requirements to the target.
  7445. usage.ApplyToTarget(tgt);
  7446. // Create the generator target and attach it to the local generator.
  7447. auto gtp = cm::make_unique<cmGeneratorTarget>(tgt, lg);
  7448. synthDep = gtp.get();
  7449. lg->AddGeneratorTarget(std::move(gtp));
  7450. } else {
  7451. synthDep = cached->second;
  7452. }
  7453. SyntheticDeps[gt].push_back(synthDep);
  7454. }
  7455. }
  7456. return true;
  7457. }
  7458. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  7459. const std::string& config, cmOptionalLinkImplementation& impl,
  7460. cmGeneratorTarget const* head, LinkInterfaceFor implFor) const
  7461. {
  7462. cmLocalGenerator const* lg = this->LocalGenerator;
  7463. cmMakefile const* mf = lg->GetMakefile();
  7464. cmBTStringRange entryRange = this->Target->GetLinkImplementationEntries();
  7465. auto const& synthTargetsForConfig = this->Configs[config].SyntheticDeps;
  7466. // Collect libraries directly linked in this configuration.
  7467. for (auto const& entry : entryRange) {
  7468. // Keep this logic in sync with ExpandLinkItems.
  7469. cmGeneratorExpressionDAGChecker dagChecker(this, "LINK_LIBRARIES", nullptr,
  7470. nullptr);
  7471. // The $<LINK_ONLY> expression may be used to specify link dependencies
  7472. // that are otherwise excluded from usage requirements.
  7473. if (implFor == LinkInterfaceFor::Usage) {
  7474. dagChecker.SetTransitivePropertiesOnly();
  7475. switch (this->GetPolicyStatusCMP0131()) {
  7476. case cmPolicies::WARN:
  7477. case cmPolicies::OLD:
  7478. break;
  7479. case cmPolicies::REQUIRED_IF_USED:
  7480. case cmPolicies::REQUIRED_ALWAYS:
  7481. case cmPolicies::NEW:
  7482. dagChecker.SetTransitivePropertiesOnlyCMP0131();
  7483. break;
  7484. }
  7485. }
  7486. cmGeneratorExpression ge(*this->LocalGenerator->GetCMakeInstance(),
  7487. entry.Backtrace);
  7488. std::unique_ptr<cmCompiledGeneratorExpression> const cge =
  7489. ge.Parse(entry.Value);
  7490. cge->SetEvaluateForBuildsystem(true);
  7491. std::string const& evaluated =
  7492. cge->Evaluate(this->LocalGenerator, config, head, &dagChecker, nullptr,
  7493. this->LinkerLanguage);
  7494. bool const checkCMP0027 = evaluated != entry.Value;
  7495. cmList llibs(evaluated);
  7496. if (cge->GetHadHeadSensitiveCondition()) {
  7497. impl.HadHeadSensitiveCondition = true;
  7498. }
  7499. if (cge->GetHadContextSensitiveCondition()) {
  7500. impl.HadContextSensitiveCondition = true;
  7501. }
  7502. if (cge->GetHadLinkLanguageSensitiveCondition()) {
  7503. impl.HadLinkLanguageSensitiveCondition = true;
  7504. }
  7505. for (auto const& lib : llibs) {
  7506. if (this->IsLinkLookupScope(lib, lg)) {
  7507. continue;
  7508. }
  7509. // Skip entries that resolve to the target itself or are empty.
  7510. std::string name = this->CheckCMP0004(lib);
  7511. if (this->GetPolicyStatusCMP0108() == cmPolicies::NEW) {
  7512. // resolve alias name
  7513. auto* target = this->Makefile->FindTargetToUse(name);
  7514. if (target) {
  7515. name = target->GetName();
  7516. }
  7517. }
  7518. if (name == this->GetName() || name.empty()) {
  7519. if (name == this->GetName()) {
  7520. bool noMessage = false;
  7521. MessageType messageType = MessageType::FATAL_ERROR;
  7522. std::ostringstream e;
  7523. switch (this->GetPolicyStatusCMP0038()) {
  7524. case cmPolicies::WARN: {
  7525. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  7526. messageType = MessageType::AUTHOR_WARNING;
  7527. } break;
  7528. case cmPolicies::OLD:
  7529. noMessage = true;
  7530. break;
  7531. case cmPolicies::REQUIRED_IF_USED:
  7532. case cmPolicies::REQUIRED_ALWAYS:
  7533. case cmPolicies::NEW:
  7534. // Issue the fatal message.
  7535. break;
  7536. }
  7537. if (!noMessage) {
  7538. e << "Target \"" << this->GetName() << "\" links to itself.";
  7539. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  7540. messageType, e.str(), this->GetBacktrace());
  7541. if (messageType == MessageType::FATAL_ERROR) {
  7542. return;
  7543. }
  7544. }
  7545. }
  7546. continue;
  7547. }
  7548. // The entry is meant for this configuration.
  7549. cmLinkItem item =
  7550. this->ResolveLinkItem(BT<std::string>(name, entry.Backtrace), lg);
  7551. if (item.Target) {
  7552. auto depsForTarget = synthTargetsForConfig.find(item.Target);
  7553. if (depsForTarget != synthTargetsForConfig.end()) {
  7554. for (auto const* depForTarget : depsForTarget->second) {
  7555. cmLinkItem synthItem(depForTarget, item.Cross, item.Backtrace);
  7556. impl.Libraries.emplace_back(std::move(synthItem), false);
  7557. }
  7558. }
  7559. } else {
  7560. // Report explicitly linked object files separately.
  7561. std::string const& maybeObj = item.AsStr();
  7562. if (cmSystemTools::FileIsFullPath(maybeObj)) {
  7563. cmSourceFile const* sf =
  7564. mf->GetSource(maybeObj, cmSourceFileLocationKind::Known);
  7565. if (sf && sf->GetPropertyAsBool("EXTERNAL_OBJECT")) {
  7566. impl.Objects.emplace_back(std::move(item));
  7567. continue;
  7568. }
  7569. }
  7570. }
  7571. impl.Libraries.emplace_back(std::move(item), checkCMP0027);
  7572. }
  7573. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  7574. for (std::string const& sp : seenProps) {
  7575. if (!this->GetProperty(sp)) {
  7576. this->LinkImplicitNullProperties.insert(sp);
  7577. }
  7578. }
  7579. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  7580. }
  7581. // Update the list of direct link dependencies from usage requirements.
  7582. if (head == this) {
  7583. ComputeLinkImplTransitive(this, config, implFor, impl);
  7584. }
  7585. // Get the list of configurations considered to be DEBUG.
  7586. std::vector<std::string> debugConfigs =
  7587. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  7588. cmTargetLinkLibraryType linkType =
  7589. CMP0003_ComputeLinkType(config, debugConfigs);
  7590. cmTarget::LinkLibraryVectorType const& oldllibs =
  7591. this->Target->GetOriginalLinkLibraries();
  7592. for (cmTarget::LibraryID const& oldllib : oldllibs) {
  7593. if (oldllib.second != GENERAL_LibraryType && oldllib.second != linkType) {
  7594. std::string name = this->CheckCMP0004(oldllib.first);
  7595. if (name == this->GetName() || name.empty()) {
  7596. continue;
  7597. }
  7598. // Support OLD behavior for CMP0003.
  7599. impl.WrongConfigLibraries.push_back(
  7600. this->ResolveLinkItem(BT<std::string>(name)));
  7601. }
  7602. }
  7603. }
  7604. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  7605. std::string const& name) const
  7606. {
  7607. return this->ResolveTargetReference(name, this->LocalGenerator);
  7608. }
  7609. cmGeneratorTarget::TargetOrString cmGeneratorTarget::ResolveTargetReference(
  7610. std::string const& name, cmLocalGenerator const* lg) const
  7611. {
  7612. TargetOrString resolved;
  7613. if (cmGeneratorTarget* tgt = lg->FindGeneratorTargetToUse(name)) {
  7614. resolved.Target = tgt;
  7615. } else {
  7616. resolved.String = name;
  7617. }
  7618. return resolved;
  7619. }
  7620. cmLinkItem cmGeneratorTarget::ResolveLinkItem(
  7621. BT<std::string> const& name) const
  7622. {
  7623. return this->ResolveLinkItem(name, this->LocalGenerator);
  7624. }
  7625. cmLinkItem cmGeneratorTarget::ResolveLinkItem(BT<std::string> const& name,
  7626. cmLocalGenerator const* lg) const
  7627. {
  7628. auto bt = name.Backtrace;
  7629. TargetOrString resolved = this->ResolveTargetReference(name.Value, lg);
  7630. if (!resolved.Target) {
  7631. return cmLinkItem(resolved.String, false, bt);
  7632. }
  7633. // Check deprecation, issue message with `bt` backtrace.
  7634. if (resolved.Target->IsDeprecated()) {
  7635. std::ostringstream w;
  7636. /* clang-format off */
  7637. w <<
  7638. "The library that is being linked to, " << resolved.Target->GetName() <<
  7639. ", is marked as being deprecated by the owner. The message provided by "
  7640. "the developer is: \n" << resolved.Target->GetDeprecation() << "\n";
  7641. /* clang-format on */
  7642. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  7643. MessageType::AUTHOR_WARNING, w.str(), bt);
  7644. }
  7645. // Skip targets that will not really be linked. This is probably a
  7646. // name conflict between an external library and an executable
  7647. // within the project.
  7648. if (resolved.Target->GetType() == cmStateEnums::EXECUTABLE &&
  7649. !resolved.Target->IsExecutableWithExports()) {
  7650. return cmLinkItem(resolved.Target->GetName(), false, bt);
  7651. }
  7652. return cmLinkItem(resolved.Target, false, bt);
  7653. }
  7654. bool cmGeneratorTarget::HasPackageReferences() const
  7655. {
  7656. return this->IsInBuildSystem() &&
  7657. !this->GetProperty("VS_PACKAGE_REFERENCES")->empty();
  7658. }
  7659. std::vector<std::string> cmGeneratorTarget::GetPackageReferences() const
  7660. {
  7661. cmList packageReferences;
  7662. if (this->IsInBuildSystem()) {
  7663. if (cmValue vsPackageReferences =
  7664. this->GetProperty("VS_PACKAGE_REFERENCES")) {
  7665. packageReferences.assign(*vsPackageReferences);
  7666. }
  7667. }
  7668. return std::move(packageReferences.data());
  7669. }
  7670. std::string cmGeneratorTarget::GetPDBDirectory(const std::string& config) const
  7671. {
  7672. if (OutputInfo const* info = this->GetOutputInfo(config)) {
  7673. // Return the directory in which the target will be built.
  7674. return info->PdbDir;
  7675. }
  7676. return "";
  7677. }
  7678. bool cmGeneratorTarget::HasImplibGNUtoMS(std::string const& config) const
  7679. {
  7680. return this->HasImportLibrary(config) && this->GetPropertyAsBool("GNUtoMS");
  7681. }
  7682. bool cmGeneratorTarget::GetImplibGNUtoMS(std::string const& config,
  7683. std::string const& gnuName,
  7684. std::string& out,
  7685. const char* newExt) const
  7686. {
  7687. if (this->HasImplibGNUtoMS(config) && gnuName.size() > 6 &&
  7688. gnuName.substr(gnuName.size() - 6) == ".dll.a") {
  7689. out = cmStrCat(cm::string_view(gnuName).substr(0, gnuName.size() - 6),
  7690. newExt ? newExt : ".lib");
  7691. return true;
  7692. }
  7693. return false;
  7694. }
  7695. bool cmGeneratorTarget::HasContextDependentSources() const
  7696. {
  7697. return this->SourcesAreContextDependent == Tribool::True;
  7698. }
  7699. bool cmGeneratorTarget::IsExecutableWithExports() const
  7700. {
  7701. return this->Target->IsExecutableWithExports();
  7702. }
  7703. bool cmGeneratorTarget::IsSharedLibraryWithExports() const
  7704. {
  7705. return this->Target->IsSharedLibraryWithExports();
  7706. }
  7707. bool cmGeneratorTarget::HasImportLibrary(std::string const& config) const
  7708. {
  7709. bool generate_Stubs = true;
  7710. if (this->GetGlobalGenerator()->IsXcode()) {
  7711. // take care of CMAKE_XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS variable
  7712. // as well as XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS property
  7713. if (cmValue propGenStubs =
  7714. this->GetProperty("XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS")) {
  7715. generate_Stubs = propGenStubs == "YES";
  7716. } else if (cmValue varGenStubs = this->Makefile->GetDefinition(
  7717. "CMAKE_XCODE_ATTRIBUTE_GENERATE_TEXT_BASED_STUBS")) {
  7718. generate_Stubs = varGenStubs == "YES";
  7719. }
  7720. }
  7721. return (this->IsDLLPlatform() &&
  7722. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  7723. this->IsExecutableWithExports()) &&
  7724. // Assemblies which have only managed code do not have
  7725. // import libraries.
  7726. this->GetManagedType(config) != ManagedType::Managed) ||
  7727. (this->IsAIX() && this->IsExecutableWithExports()) ||
  7728. (this->Makefile->PlatformSupportsAppleTextStubs() &&
  7729. this->IsSharedLibraryWithExports() && generate_Stubs);
  7730. }
  7731. bool cmGeneratorTarget::NeedImportLibraryName(std::string const& config) const
  7732. {
  7733. return this->HasImportLibrary(config) ||
  7734. // On DLL platforms we always generate the import library name
  7735. // just in case the sources have export markup.
  7736. (this->IsDLLPlatform() &&
  7737. (this->GetType() == cmStateEnums::EXECUTABLE ||
  7738. this->GetType() == cmStateEnums::MODULE_LIBRARY));
  7739. }
  7740. std::string cmGeneratorTarget::GetSupportDirectory() const
  7741. {
  7742. std::string dir = cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
  7743. "/CMakeFiles/", this->GetName());
  7744. #if defined(__VMS)
  7745. dir += "_dir";
  7746. #else
  7747. dir += ".dir";
  7748. #endif
  7749. return dir;
  7750. }
  7751. bool cmGeneratorTarget::IsLinkable() const
  7752. {
  7753. return (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  7754. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  7755. this->GetType() == cmStateEnums::MODULE_LIBRARY ||
  7756. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY ||
  7757. this->GetType() == cmStateEnums::OBJECT_LIBRARY ||
  7758. this->GetType() == cmStateEnums::INTERFACE_LIBRARY ||
  7759. this->IsExecutableWithExports());
  7760. }
  7761. bool cmGeneratorTarget::HasLinkDependencyFile(std::string const& config) const
  7762. {
  7763. if (this->GetType() != cmStateEnums::EXECUTABLE &&
  7764. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  7765. this->GetType() != cmStateEnums::MODULE_LIBRARY) {
  7766. return false;
  7767. }
  7768. if (this->Target->GetProperty("LINK_DEPENDS_NO_SHARED").IsOn()) {
  7769. // Do not use the linker dependency file because it includes shared
  7770. // libraries as well
  7771. return false;
  7772. }
  7773. const std::string depsUseLinker{ "CMAKE_LINK_DEPENDS_USE_LINKER" };
  7774. auto linkLanguage = this->GetLinkerLanguage(config);
  7775. const std::string langDepsUseLinker{ cmStrCat("CMAKE_", linkLanguage,
  7776. "_LINK_DEPENDS_USE_LINKER") };
  7777. return (!this->Makefile->IsDefinitionSet(depsUseLinker) ||
  7778. this->Makefile->IsOn(depsUseLinker)) &&
  7779. this->Makefile->IsOn(langDepsUseLinker);
  7780. }
  7781. bool cmGeneratorTarget::IsFrameworkOnApple() const
  7782. {
  7783. return this->Target->IsFrameworkOnApple();
  7784. }
  7785. bool cmGeneratorTarget::IsImportedFrameworkFolderOnApple(
  7786. const std::string& config) const
  7787. {
  7788. return this->IsApple() && this->IsImported() &&
  7789. (this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  7790. this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  7791. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY) &&
  7792. cmSystemTools::IsPathToFramework(this->GetLocation(config));
  7793. }
  7794. bool cmGeneratorTarget::IsAppBundleOnApple() const
  7795. {
  7796. return this->Target->IsAppBundleOnApple();
  7797. }
  7798. bool cmGeneratorTarget::IsXCTestOnApple() const
  7799. {
  7800. return (this->IsCFBundleOnApple() && this->GetPropertyAsBool("XCTEST"));
  7801. }
  7802. bool cmGeneratorTarget::IsCFBundleOnApple() const
  7803. {
  7804. return (this->GetType() == cmStateEnums::MODULE_LIBRARY && this->IsApple() &&
  7805. this->GetPropertyAsBool("BUNDLE"));
  7806. }
  7807. cmGeneratorTarget::ManagedType cmGeneratorTarget::CheckManagedType(
  7808. std::string const& propval) const
  7809. {
  7810. // The type of the managed assembly (mixed unmanaged C++ and C++/CLI,
  7811. // or only C++/CLI) does only depend on whether the property is an empty
  7812. // string or contains any value at all. In Visual Studio generators
  7813. // this propval is prepended with /clr[:] which results in:
  7814. //
  7815. // 1. propval does not exist: no /clr flag, unmanaged target, has import
  7816. // lib
  7817. // 2. empty propval: add /clr as flag, mixed unmanaged/managed
  7818. // target, has import lib
  7819. // 3. netcore propval: add /clr:netcore as flag, mixed
  7820. // unmanaged/managed target, has import lib.
  7821. // 4. any value (safe,pure): add /clr:[propval] as flag, target with
  7822. // managed code only, no import lib
  7823. if (propval.empty() || propval == "netcore") {
  7824. return ManagedType::Mixed;
  7825. }
  7826. return ManagedType::Managed;
  7827. }
  7828. cmGeneratorTarget::ManagedType cmGeneratorTarget::GetManagedType(
  7829. const std::string& config) const
  7830. {
  7831. // Only libraries and executables can be managed targets.
  7832. if (this->GetType() > cmStateEnums::SHARED_LIBRARY) {
  7833. return ManagedType::Undefined;
  7834. }
  7835. if (this->GetType() == cmStateEnums::STATIC_LIBRARY) {
  7836. return ManagedType::Native;
  7837. }
  7838. // Check imported target.
  7839. if (this->IsImported()) {
  7840. if (cmGeneratorTarget::ImportInfo const* info =
  7841. this->GetImportInfo(config)) {
  7842. return info->Managed;
  7843. }
  7844. return ManagedType::Undefined;
  7845. }
  7846. // Check for explicitly set clr target property.
  7847. if (cmValue clr = this->GetProperty("COMMON_LANGUAGE_RUNTIME")) {
  7848. return this->CheckManagedType(*clr);
  7849. }
  7850. // C# targets are always managed. This language specific check
  7851. // is added to avoid that the COMMON_LANGUAGE_RUNTIME target property
  7852. // has to be set manually for C# targets.
  7853. return this->IsCSharpOnly() ? ManagedType::Managed : ManagedType::Native;
  7854. }
  7855. bool cmGeneratorTarget::AddHeaderSetVerification()
  7856. {
  7857. if (!this->GetPropertyAsBool("VERIFY_INTERFACE_HEADER_SETS")) {
  7858. return true;
  7859. }
  7860. if (this->GetType() != cmStateEnums::STATIC_LIBRARY &&
  7861. this->GetType() != cmStateEnums::SHARED_LIBRARY &&
  7862. this->GetType() != cmStateEnums::UNKNOWN_LIBRARY &&
  7863. this->GetType() != cmStateEnums::OBJECT_LIBRARY &&
  7864. this->GetType() != cmStateEnums::INTERFACE_LIBRARY &&
  7865. !this->IsExecutableWithExports()) {
  7866. return true;
  7867. }
  7868. auto verifyValue = this->GetProperty("INTERFACE_HEADER_SETS_TO_VERIFY");
  7869. const bool all = verifyValue.IsEmpty();
  7870. std::set<std::string> verifySet;
  7871. if (!all) {
  7872. cmList verifyList{ verifyValue };
  7873. verifySet.insert(verifyList.begin(), verifyList.end());
  7874. }
  7875. cmTarget* verifyTarget = nullptr;
  7876. cmTarget* allVerifyTarget =
  7877. this->GlobalGenerator->GetMakefiles().front()->FindTargetToUse(
  7878. "all_verify_interface_header_sets", true);
  7879. auto interfaceFileSetEntries = this->Target->GetInterfaceHeaderSetsEntries();
  7880. std::set<cmFileSet*> fileSets;
  7881. for (auto const& entry : interfaceFileSetEntries) {
  7882. for (auto const& name : cmList{ entry.Value }) {
  7883. if (all || verifySet.count(name)) {
  7884. fileSets.insert(this->Target->GetFileSet(name));
  7885. verifySet.erase(name);
  7886. }
  7887. }
  7888. }
  7889. if (!verifySet.empty()) {
  7890. this->Makefile->IssueMessage(
  7891. MessageType::FATAL_ERROR,
  7892. cmStrCat("Property INTERFACE_HEADER_SETS_TO_VERIFY of target \"",
  7893. this->GetName(),
  7894. "\" contained the following header sets that are nonexistent "
  7895. "or not INTERFACE:\n ",
  7896. cmJoin(verifySet, "\n ")));
  7897. return false;
  7898. }
  7899. cm::optional<std::set<std::string>> languages;
  7900. for (auto* fileSet : fileSets) {
  7901. auto dirCges = fileSet->CompileDirectoryEntries();
  7902. auto fileCges = fileSet->CompileFileEntries();
  7903. static auto const contextSensitive =
  7904. [](const std::unique_ptr<cmCompiledGeneratorExpression>& cge) {
  7905. return cge->GetHadContextSensitiveCondition();
  7906. };
  7907. bool dirCgesContextSensitive = false;
  7908. bool fileCgesContextSensitive = false;
  7909. std::vector<std::string> dirs;
  7910. std::map<std::string, std::vector<std::string>> filesPerDir;
  7911. bool first = true;
  7912. for (auto const& config : this->Makefile->GetGeneratorConfigs(
  7913. cmMakefile::GeneratorConfigQuery::IncludeEmptyConfig)) {
  7914. if (first || dirCgesContextSensitive) {
  7915. dirs = fileSet->EvaluateDirectoryEntries(dirCges, this->LocalGenerator,
  7916. config, this);
  7917. dirCgesContextSensitive =
  7918. std::any_of(dirCges.begin(), dirCges.end(), contextSensitive);
  7919. }
  7920. if (first || fileCgesContextSensitive) {
  7921. filesPerDir.clear();
  7922. for (auto const& fileCge : fileCges) {
  7923. fileSet->EvaluateFileEntry(dirs, filesPerDir, fileCge,
  7924. this->LocalGenerator, config, this);
  7925. if (fileCge->GetHadContextSensitiveCondition()) {
  7926. fileCgesContextSensitive = true;
  7927. }
  7928. }
  7929. }
  7930. for (auto const& files : filesPerDir) {
  7931. for (auto const& file : files.second) {
  7932. std::string filename = this->GenerateHeaderSetVerificationFile(
  7933. *this->Makefile->GetOrCreateSource(file), files.first, languages);
  7934. if (filename.empty()) {
  7935. continue;
  7936. }
  7937. if (!verifyTarget) {
  7938. {
  7939. cmMakefile::PolicyPushPop polScope(this->Makefile);
  7940. this->Makefile->SetPolicy(cmPolicies::CMP0119, cmPolicies::NEW);
  7941. verifyTarget = this->Makefile->AddLibrary(
  7942. cmStrCat(this->GetName(), "_verify_interface_header_sets"),
  7943. cmStateEnums::OBJECT_LIBRARY, {}, true);
  7944. }
  7945. verifyTarget->AddLinkLibrary(
  7946. *this->Makefile, this->GetName(),
  7947. cmTargetLinkLibraryType::GENERAL_LibraryType);
  7948. verifyTarget->SetProperty("AUTOMOC", "OFF");
  7949. verifyTarget->SetProperty("AUTORCC", "OFF");
  7950. verifyTarget->SetProperty("AUTOUIC", "OFF");
  7951. verifyTarget->SetProperty("DISABLE_PRECOMPILE_HEADERS", "ON");
  7952. verifyTarget->SetProperty("UNITY_BUILD", "OFF");
  7953. cm::optional<std::map<std::string, cmValue>>
  7954. perConfigCompileDefinitions;
  7955. verifyTarget->FinalizeTargetConfiguration(
  7956. this->Makefile->GetCompileDefinitionsEntries(),
  7957. perConfigCompileDefinitions);
  7958. if (!allVerifyTarget) {
  7959. allVerifyTarget = this->GlobalGenerator->GetMakefiles()
  7960. .front()
  7961. ->AddNewUtilityTarget(
  7962. "all_verify_interface_header_sets", true);
  7963. }
  7964. allVerifyTarget->AddUtility(verifyTarget->GetName(), false);
  7965. }
  7966. if (fileCgesContextSensitive) {
  7967. filename = cmStrCat("$<$<CONFIG:", config, ">:", filename, ">");
  7968. }
  7969. verifyTarget->AddSource(filename);
  7970. }
  7971. }
  7972. if (!dirCgesContextSensitive && !fileCgesContextSensitive) {
  7973. break;
  7974. }
  7975. first = false;
  7976. }
  7977. }
  7978. if (verifyTarget) {
  7979. this->LocalGenerator->AddGeneratorTarget(
  7980. cm::make_unique<cmGeneratorTarget>(verifyTarget, this->LocalGenerator));
  7981. }
  7982. return true;
  7983. }
  7984. std::string cmGeneratorTarget::GenerateHeaderSetVerificationFile(
  7985. cmSourceFile& source, const std::string& dir,
  7986. cm::optional<std::set<std::string>>& languages) const
  7987. {
  7988. std::string extension;
  7989. std::string language = source.GetOrDetermineLanguage();
  7990. if (source.GetPropertyAsBool("SKIP_LINTING")) {
  7991. return std::string{};
  7992. }
  7993. if (language.empty()) {
  7994. if (!languages) {
  7995. languages.emplace();
  7996. for (auto const& tgtSource : this->GetAllConfigSources()) {
  7997. auto const& tgtSourceLanguage =
  7998. tgtSource.Source->GetOrDetermineLanguage();
  7999. if (tgtSourceLanguage == "CXX") {
  8000. languages->insert("CXX");
  8001. break; // C++ overrides everything else, so we don't need to keep
  8002. // checking.
  8003. }
  8004. if (tgtSourceLanguage == "C") {
  8005. languages->insert("C");
  8006. }
  8007. }
  8008. if (languages->empty()) {
  8009. std::vector<std::string> languagesVector;
  8010. this->GlobalGenerator->GetEnabledLanguages(languagesVector);
  8011. languages->insert(languagesVector.begin(), languagesVector.end());
  8012. }
  8013. }
  8014. if (languages->count("CXX")) {
  8015. language = "CXX";
  8016. } else if (languages->count("C")) {
  8017. language = "C";
  8018. }
  8019. }
  8020. if (language == "C") {
  8021. extension = ".c";
  8022. } else if (language == "CXX") {
  8023. extension = ".cxx";
  8024. } else {
  8025. return "";
  8026. }
  8027. std::string headerFilename = dir;
  8028. if (!headerFilename.empty()) {
  8029. headerFilename += '/';
  8030. }
  8031. headerFilename += source.GetLocation().GetName();
  8032. auto filename = cmStrCat(
  8033. this->LocalGenerator->GetCurrentBinaryDirectory(), '/', this->GetName(),
  8034. "_verify_interface_header_sets/", headerFilename, extension);
  8035. auto* verificationSource = this->Makefile->GetOrCreateSource(filename);
  8036. verificationSource->SetProperty("LANGUAGE", language);
  8037. cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(filename));
  8038. cmGeneratedFileStream fout(filename);
  8039. fout.SetCopyIfDifferent(true);
  8040. // The IWYU "associated" pragma tells include-what-you-use to
  8041. // consider the headerFile as part of the entire language
  8042. // unit within include-what-you-use and as a result allows
  8043. // one to get IWYU advice for headers.
  8044. fout << "#include <" << headerFilename << "> // IWYU pragma: associated\n";
  8045. fout.close();
  8046. return filename;
  8047. }
  8048. std::string cmGeneratorTarget::GetImportedXcFrameworkPath(
  8049. const std::string& config) const
  8050. {
  8051. if (!(this->IsApple() && this->IsImported() &&
  8052. (this->GetType() == cmStateEnums::SHARED_LIBRARY ||
  8053. this->GetType() == cmStateEnums::STATIC_LIBRARY ||
  8054. this->GetType() == cmStateEnums::UNKNOWN_LIBRARY))) {
  8055. return {};
  8056. }
  8057. std::string desiredConfig = config;
  8058. if (config.empty()) {
  8059. desiredConfig = "NOCONFIG";
  8060. }
  8061. std::string result;
  8062. cmValue loc = nullptr;
  8063. cmValue imp = nullptr;
  8064. std::string suffix;
  8065. if (this->Target->GetMappedConfig(desiredConfig, loc, imp, suffix)) {
  8066. if (loc) {
  8067. result = *loc;
  8068. } else {
  8069. std::string impProp = cmStrCat("IMPORTED_LOCATION", suffix);
  8070. if (cmValue configLocation = this->GetProperty(impProp)) {
  8071. result = *configLocation;
  8072. } else if (cmValue location = this->GetProperty("IMPORTED_LOCATION")) {
  8073. result = *location;
  8074. }
  8075. }
  8076. if (cmSystemTools::IsPathToXcFramework(result)) {
  8077. return result;
  8078. }
  8079. }
  8080. return {};
  8081. }
  8082. bool cmGeneratorTarget::HaveFortranSources(std::string const& config) const
  8083. {
  8084. auto sources = this->GetSourceFiles(config);
  8085. return std::any_of(sources.begin(), sources.end(),
  8086. [](BT<cmSourceFile*> const& sf) -> bool {
  8087. return sf.Value->GetLanguage() == "Fortran"_s;
  8088. });
  8089. }
  8090. bool cmGeneratorTarget::HaveFortranSources() const
  8091. {
  8092. auto sources = cmGeneratorTarget::GetAllConfigSources();
  8093. return std::any_of(sources.begin(), sources.end(),
  8094. [](AllConfigSource const& sf) -> bool {
  8095. return sf.Source->GetLanguage() == "Fortran"_s;
  8096. });
  8097. }
  8098. bool cmGeneratorTarget::HaveCxx20ModuleSources(std::string* errorMessage) const
  8099. {
  8100. auto const& fs_names = this->Target->GetAllFileSetNames();
  8101. return std::any_of(
  8102. fs_names.begin(), fs_names.end(),
  8103. [this, errorMessage](std::string const& name) -> bool {
  8104. auto const* file_set = this->Target->GetFileSet(name);
  8105. if (!file_set) {
  8106. auto message = cmStrCat("Target \"", this->Target->GetName(),
  8107. "\" is tracked to have file set \"", name,
  8108. "\", but it was not found.");
  8109. if (errorMessage) {
  8110. *errorMessage = std::move(message);
  8111. } else {
  8112. this->Makefile->IssueMessage(MessageType::INTERNAL_ERROR, message);
  8113. }
  8114. return false;
  8115. }
  8116. auto const& fs_type = file_set->GetType();
  8117. return fs_type == "CXX_MODULES"_s;
  8118. });
  8119. }
  8120. cmGeneratorTarget::Cxx20SupportLevel cmGeneratorTarget::HaveCxxModuleSupport(
  8121. std::string const& config) const
  8122. {
  8123. auto const* state = this->Makefile->GetState();
  8124. if (!state->GetLanguageEnabled("CXX")) {
  8125. return Cxx20SupportLevel::MissingCxx;
  8126. }
  8127. cmValue standardDefault =
  8128. this->Makefile->GetDefinition("CMAKE_CXX_STANDARD_DEFAULT");
  8129. if (!standardDefault || standardDefault->empty()) {
  8130. // We do not know any meaningful C++ standard levels for this compiler.
  8131. return Cxx20SupportLevel::NoCxx20;
  8132. }
  8133. cmStandardLevelResolver standardResolver(this->Makefile);
  8134. cmStandardLevel const cxxStd20 =
  8135. *standardResolver.LanguageStandardLevel("CXX", "20");
  8136. cm::optional<cmStandardLevel> explicitLevel =
  8137. this->GetExplicitStandardLevel("CXX", config);
  8138. if (!explicitLevel || *explicitLevel < cxxStd20) {
  8139. return Cxx20SupportLevel::NoCxx20;
  8140. }
  8141. cmValue scandepRule =
  8142. this->Makefile->GetDefinition("CMAKE_CXX_SCANDEP_SOURCE");
  8143. if (!scandepRule) {
  8144. return Cxx20SupportLevel::MissingRule;
  8145. }
  8146. return Cxx20SupportLevel::Supported;
  8147. }
  8148. void cmGeneratorTarget::CheckCxxModuleStatus(std::string const& config) const
  8149. {
  8150. bool haveScannableSources = false;
  8151. // Check for `CXX_MODULE*` file sets and a lack of support.
  8152. if (this->HaveCxx20ModuleSources()) {
  8153. haveScannableSources = true;
  8154. }
  8155. if (!haveScannableSources) {
  8156. // Check to see if there are regular sources that have requested scanning.
  8157. auto sources = this->GetSourceFiles(config);
  8158. for (auto const& source : sources) {
  8159. auto const* sf = source.Value;
  8160. auto const& lang = sf->GetLanguage();
  8161. if (lang != "CXX"_s) {
  8162. continue;
  8163. }
  8164. // Ignore sources which do not need dyndep.
  8165. if (this->NeedDyndepForSource(lang, config, sf)) {
  8166. haveScannableSources = true;
  8167. }
  8168. }
  8169. }
  8170. // If there isn't anything scannable, ignore it.
  8171. if (!haveScannableSources) {
  8172. return;
  8173. }
  8174. // If the generator doesn't support modules at all, error that we have
  8175. // sources that require the support.
  8176. if (!this->GetGlobalGenerator()->CheckCxxModuleSupport(
  8177. cmGlobalGenerator::CxxModuleSupportQuery::Expected)) {
  8178. this->Makefile->IssueMessage(
  8179. MessageType::FATAL_ERROR,
  8180. cmStrCat(
  8181. "The target named \"", this->GetName(),
  8182. "\" has C++ sources that may use modules, but modules are not "
  8183. "supported by this generator. See the cmake-cxxmodules(7) manual "
  8184. "and the CMAKE_CXX_SCAN_FOR_MODULES variable."));
  8185. return;
  8186. }
  8187. switch (this->HaveCxxModuleSupport(config)) {
  8188. case cmGeneratorTarget::Cxx20SupportLevel::MissingCxx:
  8189. this->Makefile->IssueMessage(
  8190. MessageType::FATAL_ERROR,
  8191. cmStrCat("The target named \"", this->GetName(),
  8192. "\" has C++ sources that use modules, but the \"CXX\" "
  8193. "language has not been enabled."));
  8194. break;
  8195. case cmGeneratorTarget::Cxx20SupportLevel::NoCxx20: {
  8196. cmStandardLevelResolver standardResolver(this->Makefile);
  8197. auto effStandard =
  8198. standardResolver.GetEffectiveStandard(this, "CXX", config);
  8199. if (effStandard.empty()) {
  8200. effStandard = "; no C++ standard found";
  8201. } else {
  8202. effStandard = cmStrCat("; found \"cxx_std_", effStandard, '"');
  8203. }
  8204. this->Makefile->IssueMessage(
  8205. MessageType::FATAL_ERROR,
  8206. cmStrCat(
  8207. "The target named \"", this->GetName(),
  8208. "\" has C++ sources that use modules, but does not include "
  8209. "\"cxx_std_20\" (or newer) among its `target_compile_features`",
  8210. effStandard, '.'));
  8211. } break;
  8212. case cmGeneratorTarget::Cxx20SupportLevel::MissingRule: {
  8213. this->Makefile->IssueMessage(
  8214. MessageType::FATAL_ERROR,
  8215. cmStrCat("The target named \"", this->GetName(),
  8216. "\" has C++ sources that may use modules, but the compiler "
  8217. "does not provide a way to discover the import graph "
  8218. "dependencies. See the cmake-cxxmodules(7) manual "
  8219. "and the CMAKE_CXX_SCAN_FOR_MODULES variable."));
  8220. } break;
  8221. case cmGeneratorTarget::Cxx20SupportLevel::Supported:
  8222. // All is well.
  8223. break;
  8224. }
  8225. }
  8226. bool cmGeneratorTarget::NeedCxxModuleSupport(std::string const& lang,
  8227. std::string const& config) const
  8228. {
  8229. if (lang != "CXX"_s) {
  8230. return false;
  8231. }
  8232. return this->HaveCxxModuleSupport(config) == Cxx20SupportLevel::Supported &&
  8233. this->GetGlobalGenerator()->CheckCxxModuleSupport(
  8234. cmGlobalGenerator::CxxModuleSupportQuery::Inspect);
  8235. }
  8236. bool cmGeneratorTarget::NeedDyndep(std::string const& lang,
  8237. std::string const& config) const
  8238. {
  8239. return lang == "Fortran"_s || this->NeedCxxModuleSupport(lang, config);
  8240. }
  8241. cmFileSet const* cmGeneratorTarget::GetFileSetForSource(
  8242. std::string const& config, cmSourceFile const* sf) const
  8243. {
  8244. this->BuildFileSetInfoCache(config);
  8245. auto const& path = sf->GetFullPath();
  8246. auto const& per_config = this->Configs[config];
  8247. auto const fsit = per_config.FileSetCache.find(path);
  8248. if (fsit == per_config.FileSetCache.end()) {
  8249. return nullptr;
  8250. }
  8251. return fsit->second;
  8252. }
  8253. bool cmGeneratorTarget::NeedDyndepForSource(std::string const& lang,
  8254. std::string const& config,
  8255. cmSourceFile const* sf) const
  8256. {
  8257. // Fortran always needs to be scanned.
  8258. if (lang == "Fortran"_s) {
  8259. return true;
  8260. }
  8261. // Only C++ code needs scanned otherwise.
  8262. if (lang != "CXX"_s) {
  8263. return false;
  8264. }
  8265. // Any file in `CXX_MODULES` file sets need scanned (it being `CXX` is
  8266. // enforced elsewhere).
  8267. auto const* fs = this->GetFileSetForSource(config, sf);
  8268. if (fs && fs->GetType() == "CXX_MODULES"_s) {
  8269. return true;
  8270. }
  8271. bool haveRule = false;
  8272. switch (this->HaveCxxModuleSupport(config)) {
  8273. case Cxx20SupportLevel::MissingCxx:
  8274. case Cxx20SupportLevel::NoCxx20:
  8275. return false;
  8276. case Cxx20SupportLevel::MissingRule:
  8277. break;
  8278. case Cxx20SupportLevel::Supported:
  8279. haveRule = true;
  8280. break;
  8281. }
  8282. bool haveGeneratorSupport =
  8283. this->GetGlobalGenerator()->CheckCxxModuleSupport(
  8284. cmGlobalGenerator::CxxModuleSupportQuery::Inspect);
  8285. auto const sfProp = sf->GetProperty("CXX_SCAN_FOR_MODULES");
  8286. if (sfProp.IsSet()) {
  8287. return sfProp.IsOn();
  8288. }
  8289. auto const tgtProp = this->GetProperty("CXX_SCAN_FOR_MODULES");
  8290. if (tgtProp.IsSet()) {
  8291. return tgtProp.IsOn();
  8292. }
  8293. bool policyAnswer = false;
  8294. switch (this->GetPolicyStatusCMP0155()) {
  8295. case cmPolicies::WARN:
  8296. case cmPolicies::OLD:
  8297. // The OLD behavior is to not scan the source.
  8298. policyAnswer = false;
  8299. break;
  8300. case cmPolicies::REQUIRED_ALWAYS:
  8301. case cmPolicies::REQUIRED_IF_USED:
  8302. case cmPolicies::NEW:
  8303. // The NEW behavior is to scan the source if the compiler supports
  8304. // scanning and the generator supports it.
  8305. policyAnswer = haveRule && haveGeneratorSupport;
  8306. break;
  8307. }
  8308. return policyAnswer;
  8309. }
  8310. void cmGeneratorTarget::BuildFileSetInfoCache(std::string const& config) const
  8311. {
  8312. auto& per_config = this->Configs[config];
  8313. if (per_config.BuiltFileSetCache) {
  8314. return;
  8315. }
  8316. auto const* tgt = this->Target;
  8317. for (auto const& name : tgt->GetAllFileSetNames()) {
  8318. auto const* file_set = tgt->GetFileSet(name);
  8319. if (!file_set) {
  8320. tgt->GetMakefile()->IssueMessage(
  8321. MessageType::INTERNAL_ERROR,
  8322. cmStrCat("Target \"", tgt->GetName(),
  8323. "\" is tracked to have file set \"", name,
  8324. "\", but it was not found."));
  8325. continue;
  8326. }
  8327. auto fileEntries = file_set->CompileFileEntries();
  8328. auto directoryEntries = file_set->CompileDirectoryEntries();
  8329. auto directories = file_set->EvaluateDirectoryEntries(
  8330. directoryEntries, this->LocalGenerator, config, this);
  8331. std::map<std::string, std::vector<std::string>> files;
  8332. for (auto const& entry : fileEntries) {
  8333. file_set->EvaluateFileEntry(directories, files, entry,
  8334. this->LocalGenerator, config, this);
  8335. }
  8336. for (auto const& it : files) {
  8337. for (auto const& filename : it.second) {
  8338. per_config.FileSetCache[filename] = file_set;
  8339. }
  8340. }
  8341. }
  8342. per_config.BuiltFileSetCache = true;
  8343. }