cmGeneratorTarget.cxx 274 KB

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