cmGeneratorTarget.cxx 264 KB

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