cmGeneratorTarget.cxx 296 KB

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