cmGeneratorTarget.cxx 271 KB

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