cmGeneratorTarget.cxx 295 KB

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