cmTarget.cxx 204 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmListFileCache.h"
  18. #include "cmGeneratorExpression.h"
  19. #include "cmGeneratorExpressionDAGChecker.h"
  20. #include <cmsys/RegularExpression.hxx>
  21. #include <map>
  22. #include <set>
  23. #include <stdlib.h> // required for atof
  24. #include <assert.h>
  25. #include <errno.h>
  26. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  27. {
  28. switch( targetType )
  29. {
  30. case cmTarget::STATIC_LIBRARY:
  31. return "STATIC_LIBRARY";
  32. case cmTarget::MODULE_LIBRARY:
  33. return "MODULE_LIBRARY";
  34. case cmTarget::SHARED_LIBRARY:
  35. return "SHARED_LIBRARY";
  36. case cmTarget::OBJECT_LIBRARY:
  37. return "OBJECT_LIBRARY";
  38. case cmTarget::EXECUTABLE:
  39. return "EXECUTABLE";
  40. case cmTarget::UTILITY:
  41. return "UTILITY";
  42. case cmTarget::GLOBAL_TARGET:
  43. return "GLOBAL_TARGET";
  44. case cmTarget::INTERFACE_LIBRARY:
  45. return "INTERFACE_LIBRARY";
  46. case cmTarget::UNKNOWN_LIBRARY:
  47. return "UNKNOWN_LIBRARY";
  48. }
  49. assert(0 && "Unexpected target type");
  50. return 0;
  51. }
  52. //----------------------------------------------------------------------------
  53. struct cmTarget::OutputInfo
  54. {
  55. std::string OutDir;
  56. std::string ImpDir;
  57. std::string PdbDir;
  58. };
  59. //----------------------------------------------------------------------------
  60. struct cmTarget::ImportInfo
  61. {
  62. bool NoSOName;
  63. std::string Location;
  64. std::string SOName;
  65. std::string ImportLibrary;
  66. cmTarget::LinkInterface LinkInterface;
  67. };
  68. //----------------------------------------------------------------------------
  69. struct cmTarget::CompileInfo
  70. {
  71. std::string CompilePdbDir;
  72. };
  73. struct TargetConfigPair : public std::pair<cmTarget const* , std::string> {
  74. TargetConfigPair(cmTarget const* tgt, const std::string &config)
  75. : std::pair<cmTarget const* , std::string>(tgt, config) {}
  76. };
  77. //----------------------------------------------------------------------------
  78. class cmTargetInternals
  79. {
  80. public:
  81. cmTargetInternals()
  82. {
  83. this->PolicyWarnedCMP0022 = false;
  84. }
  85. cmTargetInternals(cmTargetInternals const&)
  86. {
  87. this->PolicyWarnedCMP0022 = false;
  88. }
  89. ~cmTargetInternals();
  90. // The backtrace when the target was created.
  91. cmListFileBacktrace Backtrace;
  92. // Cache link interface computation from each configuration.
  93. struct OptionalLinkInterface: public cmTarget::LinkInterface
  94. {
  95. OptionalLinkInterface():
  96. Exists(false), Complete(false), ExplicitLibraries(0) {}
  97. bool Exists;
  98. bool Complete;
  99. const char* ExplicitLibraries;
  100. };
  101. void ComputeLinkInterface(cmTarget const* thisTarget,
  102. const char* config, OptionalLinkInterface& iface,
  103. cmTarget const* head,
  104. const char *explicitLibraries) const;
  105. typedef std::map<TargetConfigPair, OptionalLinkInterface>
  106. LinkInterfaceMapType;
  107. LinkInterfaceMapType LinkInterfaceMap;
  108. bool PolicyWarnedCMP0022;
  109. typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
  110. OutputInfoMapType OutputInfoMap;
  111. typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
  112. ImportInfoMapType;
  113. ImportInfoMapType ImportInfoMap;
  114. typedef std::map<std::string, cmTarget::CompileInfo> CompileInfoMapType;
  115. CompileInfoMapType CompileInfoMap;
  116. // Cache link implementation computation from each configuration.
  117. typedef std::map<TargetConfigPair,
  118. cmTarget::LinkImplementation> LinkImplMapType;
  119. LinkImplMapType LinkImplMap;
  120. typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
  121. LinkClosureMapType;
  122. LinkClosureMapType LinkClosureMap;
  123. struct TargetPropertyEntry {
  124. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  125. const std::string &targetName = std::string())
  126. : ge(cge), TargetName(targetName)
  127. {}
  128. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  129. std::vector<std::string> CachedEntries;
  130. const std::string TargetName;
  131. };
  132. std::vector<TargetPropertyEntry*> IncludeDirectoriesEntries;
  133. std::vector<TargetPropertyEntry*> CompileOptionsEntries;
  134. std::vector<TargetPropertyEntry*> CompileDefinitionsEntries;
  135. std::vector<cmValueWithOrigin> LinkImplementationPropertyEntries;
  136. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  137. CachedLinkInterfaceIncludeDirectoriesEntries;
  138. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  139. CachedLinkInterfaceCompileOptionsEntries;
  140. mutable std::map<std::string, std::vector<TargetPropertyEntry*> >
  141. CachedLinkInterfaceCompileDefinitionsEntries;
  142. mutable std::map<std::string, bool> CacheLinkInterfaceIncludeDirectoriesDone;
  143. mutable std::map<std::string, bool> CacheLinkInterfaceCompileDefinitionsDone;
  144. mutable std::map<std::string, bool> CacheLinkInterfaceCompileOptionsDone;
  145. };
  146. //----------------------------------------------------------------------------
  147. void deleteAndClear(
  148. std::vector<cmTargetInternals::TargetPropertyEntry*> &entries)
  149. {
  150. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  151. it = entries.begin(),
  152. end = entries.end();
  153. it != end; ++it)
  154. {
  155. delete *it;
  156. }
  157. entries.clear();
  158. }
  159. //----------------------------------------------------------------------------
  160. void deleteAndClear(
  161. std::map<std::string,
  162. std::vector<cmTargetInternals::TargetPropertyEntry*> > &entries)
  163. {
  164. for (std::map<std::string,
  165. std::vector<cmTargetInternals::TargetPropertyEntry*> >::iterator
  166. it = entries.begin(), end = entries.end(); it != end; ++it)
  167. {
  168. deleteAndClear(it->second);
  169. }
  170. }
  171. //----------------------------------------------------------------------------
  172. cmTargetInternals::~cmTargetInternals()
  173. {
  174. deleteAndClear(this->CachedLinkInterfaceIncludeDirectoriesEntries);
  175. deleteAndClear(this->CachedLinkInterfaceCompileOptionsEntries);
  176. deleteAndClear(this->CachedLinkInterfaceCompileDefinitionsEntries);
  177. }
  178. //----------------------------------------------------------------------------
  179. cmTarget::cmTarget()
  180. {
  181. #define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
  182. this->PolicyStatus ## POLICY = cmPolicies::WARN;
  183. CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
  184. #undef INITIALIZE_TARGET_POLICY_MEMBER
  185. this->Makefile = 0;
  186. this->LinkLibrariesAnalyzed = false;
  187. this->HaveInstallRule = false;
  188. this->DLLPlatform = false;
  189. this->IsApple = false;
  190. this->IsImportedTarget = false;
  191. this->BuildInterfaceIncludesAppended = false;
  192. this->DebugIncludesDone = false;
  193. this->DebugCompileOptionsDone = false;
  194. this->DebugCompileDefinitionsDone = false;
  195. }
  196. //----------------------------------------------------------------------------
  197. void cmTarget::DefineProperties(cmake *cm)
  198. {
  199. cm->DefineProperty
  200. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  201. "", "", true);
  202. cm->DefineProperty
  203. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  204. "", "", true);
  205. cm->DefineProperty
  206. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  207. "", "", true);
  208. }
  209. void cmTarget::SetType(TargetType type, const char* name)
  210. {
  211. this->Name = name;
  212. // only add dependency information for library targets
  213. this->TargetTypeValue = type;
  214. if(this->TargetTypeValue >= STATIC_LIBRARY
  215. && this->TargetTypeValue <= MODULE_LIBRARY)
  216. {
  217. this->RecordDependencies = true;
  218. }
  219. else
  220. {
  221. this->RecordDependencies = false;
  222. }
  223. }
  224. //----------------------------------------------------------------------------
  225. void cmTarget::SetMakefile(cmMakefile* mf)
  226. {
  227. // Set our makefile.
  228. this->Makefile = mf;
  229. // set the cmake instance of the properties
  230. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  231. // Check whether this is a DLL platform.
  232. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  233. this->Makefile->IsOn("CYGWIN") ||
  234. this->Makefile->IsOn("MINGW"));
  235. // Check whether we are targeting an Apple platform.
  236. this->IsApple = this->Makefile->IsOn("APPLE");
  237. // Setup default property values.
  238. if (this->GetType() != INTERFACE_LIBRARY)
  239. {
  240. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  241. this->SetPropertyDefault("INSTALL_RPATH", "");
  242. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  243. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  244. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  245. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  246. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  247. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  248. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  249. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  250. this->SetPropertyDefault("Fortran_FORMAT", 0);
  251. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  252. this->SetPropertyDefault("GNUtoMS", 0);
  253. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  254. this->SetPropertyDefault("AUTOMOC", 0);
  255. this->SetPropertyDefault("AUTOUIC", 0);
  256. this->SetPropertyDefault("AUTORCC", 0);
  257. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  258. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  259. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  260. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  261. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  262. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  263. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  264. this->SetPropertyDefault("MACOSX_RPATH", 0);
  265. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  266. }
  267. // Collect the set of configuration types.
  268. std::vector<std::string> configNames;
  269. mf->GetConfigurations(configNames);
  270. // Setup per-configuration property default values.
  271. const char* configProps[] = {
  272. "ARCHIVE_OUTPUT_DIRECTORY_",
  273. "LIBRARY_OUTPUT_DIRECTORY_",
  274. "RUNTIME_OUTPUT_DIRECTORY_",
  275. "PDB_OUTPUT_DIRECTORY_",
  276. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  277. "MAP_IMPORTED_CONFIG_",
  278. 0};
  279. for(std::vector<std::string>::iterator ci = configNames.begin();
  280. ci != configNames.end(); ++ci)
  281. {
  282. std::string configUpper = cmSystemTools::UpperCase(*ci);
  283. for(const char** p = configProps; *p; ++p)
  284. {
  285. if (this->TargetTypeValue == INTERFACE_LIBRARY
  286. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  287. {
  288. continue;
  289. }
  290. std::string property = *p;
  291. property += configUpper;
  292. this->SetPropertyDefault(property.c_str(), 0);
  293. }
  294. // Initialize per-configuration name postfix property from the
  295. // variable only for non-executable targets. This preserves
  296. // compatibility with previous CMake versions in which executables
  297. // did not support this variable. Projects may still specify the
  298. // property directly.
  299. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  300. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  301. {
  302. std::string property = cmSystemTools::UpperCase(*ci);
  303. property += "_POSTFIX";
  304. this->SetPropertyDefault(property.c_str(), 0);
  305. }
  306. }
  307. // Save the backtrace of target construction.
  308. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  309. if (!this->IsImported())
  310. {
  311. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  312. // of the same directory property:
  313. const std::vector<cmValueWithOrigin> parentIncludes =
  314. this->Makefile->GetIncludeDirectoriesEntries();
  315. for (std::vector<cmValueWithOrigin>::const_iterator it
  316. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  317. {
  318. this->InsertInclude(*it);
  319. }
  320. const std::set<cmStdString> parentSystemIncludes =
  321. this->Makefile->GetSystemIncludeDirectories();
  322. for (std::set<cmStdString>::const_iterator it
  323. = parentSystemIncludes.begin();
  324. it != parentSystemIncludes.end(); ++it)
  325. {
  326. this->SystemIncludeDirectories.insert(*it);
  327. }
  328. const std::vector<cmValueWithOrigin> parentOptions =
  329. this->Makefile->GetCompileOptionsEntries();
  330. for (std::vector<cmValueWithOrigin>::const_iterator it
  331. = parentOptions.begin(); it != parentOptions.end(); ++it)
  332. {
  333. this->InsertCompileOption(*it);
  334. }
  335. }
  336. if (this->GetType() != INTERFACE_LIBRARY)
  337. {
  338. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  339. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  340. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  341. }
  342. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  343. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  344. {
  345. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  346. }
  347. if (this->GetType() != INTERFACE_LIBRARY)
  348. {
  349. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  350. }
  351. // Record current policies for later use.
  352. #define CAPTURE_TARGET_POLICY(POLICY) \
  353. this->PolicyStatus ## POLICY = \
  354. this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
  355. CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
  356. #undef CAPTURE_TARGET_POLICY
  357. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  358. {
  359. // This policy is checked in a few conditions. The properties relevant
  360. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  361. // so ensure that the conditions don't lead to nonsense.
  362. this->PolicyStatusCMP0022 = cmPolicies::NEW;
  363. }
  364. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  365. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  366. }
  367. //----------------------------------------------------------------------------
  368. void cmTarget::AddUtility(const char *u, cmMakefile *makefile)
  369. {
  370. this->Utilities.insert(u);
  371. if(makefile)
  372. {
  373. makefile->GetBacktrace(UtilityBacktraces[u]);
  374. }
  375. }
  376. //----------------------------------------------------------------------------
  377. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(const char *u) const
  378. {
  379. std::map<cmStdString, cmListFileBacktrace>::const_iterator i =
  380. this->UtilityBacktraces.find(u);
  381. if(i == this->UtilityBacktraces.end()) return 0;
  382. return &i->second;
  383. }
  384. //----------------------------------------------------------------------------
  385. void cmTarget::FinishConfigure()
  386. {
  387. // Erase any cached link information that might have been comptued
  388. // on-demand during the configuration. This ensures that build
  389. // system generation uses up-to-date information even if other cache
  390. // invalidation code in this source file is buggy.
  391. this->ClearLinkMaps();
  392. // Do old-style link dependency analysis.
  393. this->AnalyzeLibDependencies(*this->Makefile);
  394. }
  395. //----------------------------------------------------------------------------
  396. void cmTarget::ClearLinkMaps()
  397. {
  398. this->Internal->LinkImplMap.clear();
  399. this->Internal->LinkInterfaceMap.clear();
  400. this->Internal->LinkClosureMap.clear();
  401. for (cmTargetLinkInformationMap::const_iterator it
  402. = this->LinkInformation.begin();
  403. it != this->LinkInformation.end(); ++it)
  404. {
  405. delete it->second;
  406. }
  407. this->LinkInformation.clear();
  408. }
  409. //----------------------------------------------------------------------------
  410. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  411. {
  412. return this->Internal->Backtrace;
  413. }
  414. //----------------------------------------------------------------------------
  415. std::string cmTarget::GetSupportDirectory() const
  416. {
  417. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  418. dir += cmake::GetCMakeFilesDirectory();
  419. dir += "/";
  420. dir += this->Name;
  421. #if defined(__VMS)
  422. dir += "_dir";
  423. #else
  424. dir += ".dir";
  425. #endif
  426. return dir;
  427. }
  428. //----------------------------------------------------------------------------
  429. bool cmTarget::IsExecutableWithExports() const
  430. {
  431. return (this->GetType() == cmTarget::EXECUTABLE &&
  432. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  433. }
  434. //----------------------------------------------------------------------------
  435. bool cmTarget::IsLinkable() const
  436. {
  437. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  438. this->GetType() == cmTarget::SHARED_LIBRARY ||
  439. this->GetType() == cmTarget::MODULE_LIBRARY ||
  440. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  441. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  442. this->IsExecutableWithExports());
  443. }
  444. //----------------------------------------------------------------------------
  445. bool cmTarget::HasImportLibrary() const
  446. {
  447. return (this->DLLPlatform &&
  448. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  449. this->IsExecutableWithExports()));
  450. }
  451. //----------------------------------------------------------------------------
  452. bool cmTarget::IsFrameworkOnApple() const
  453. {
  454. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  455. this->Makefile->IsOn("APPLE") &&
  456. this->GetPropertyAsBool("FRAMEWORK"));
  457. }
  458. //----------------------------------------------------------------------------
  459. bool cmTarget::IsAppBundleOnApple() const
  460. {
  461. return (this->GetType() == cmTarget::EXECUTABLE &&
  462. this->Makefile->IsOn("APPLE") &&
  463. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  464. }
  465. //----------------------------------------------------------------------------
  466. bool cmTarget::IsCFBundleOnApple() const
  467. {
  468. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  469. this->Makefile->IsOn("APPLE") &&
  470. this->GetPropertyAsBool("BUNDLE"));
  471. }
  472. //----------------------------------------------------------------------------
  473. bool cmTarget::IsBundleOnApple() const
  474. {
  475. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  476. this->IsCFBundleOnApple();
  477. }
  478. //----------------------------------------------------------------------------
  479. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files) const
  480. {
  481. assert(this->GetType() != INTERFACE_LIBRARY);
  482. for(std::vector<cmSourceFile*>::const_iterator
  483. si = this->SourceFiles.begin();
  484. si != this->SourceFiles.end(); ++si)
  485. {
  486. std::string e;
  487. if((*si)->GetFullPath(&e).empty())
  488. {
  489. if(!e.empty())
  490. {
  491. cmake* cm = this->Makefile->GetCMakeInstance();
  492. cm->IssueMessage(cmake::FATAL_ERROR, e,
  493. this->GetBacktrace());
  494. }
  495. return;
  496. }
  497. }
  498. files = this->SourceFiles;
  499. }
  500. //----------------------------------------------------------------------------
  501. void cmTarget::AddSourceFile(cmSourceFile* sf)
  502. {
  503. if (std::find(this->SourceFiles.begin(), this->SourceFiles.end(), sf)
  504. == this->SourceFiles.end())
  505. {
  506. this->SourceFiles.push_back(sf);
  507. }
  508. }
  509. //----------------------------------------------------------------------------
  510. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  511. {
  512. for(std::vector<std::string>::const_iterator i = srcs.begin();
  513. i != srcs.end(); ++i)
  514. {
  515. const char* src = i->c_str();
  516. if(src[0] == '$' && src[1] == '<')
  517. {
  518. this->ProcessSourceExpression(*i);
  519. }
  520. else
  521. {
  522. this->AddSource(src);
  523. }
  524. }
  525. }
  526. //----------------------------------------------------------------------------
  527. cmSourceFile* cmTarget::AddSource(const char* s)
  528. {
  529. std::string src = s;
  530. // For backwards compatibility replace varibles in source names.
  531. // This should eventually be removed.
  532. this->Makefile->ExpandVariablesInString(src);
  533. if (src != s)
  534. {
  535. cmOStringStream e;
  536. bool noMessage = false;
  537. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  538. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  539. {
  540. case cmPolicies::WARN:
  541. e << (this->Makefile->GetPolicies()
  542. ->GetPolicyWarning(cmPolicies::CMP0049)) << "\n";
  543. break;
  544. case cmPolicies::OLD:
  545. noMessage = true;
  546. break;
  547. case cmPolicies::REQUIRED_ALWAYS:
  548. case cmPolicies::REQUIRED_IF_USED:
  549. case cmPolicies::NEW:
  550. messageType = cmake::FATAL_ERROR;
  551. }
  552. if (!noMessage)
  553. {
  554. e << "Legacy variable expansion in source file \""
  555. << s << "\" expanded to \"" << src << "\" in target \""
  556. << this->GetName() << "\". This behavior will be removed in a "
  557. "future version of CMake.";
  558. this->Makefile->IssueMessage(messageType, e.str().c_str());
  559. if (messageType == cmake::FATAL_ERROR)
  560. {
  561. return 0;
  562. }
  563. }
  564. }
  565. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  566. this->AddSourceFile(sf);
  567. return sf;
  568. }
  569. //----------------------------------------------------------------------------
  570. void cmTarget::ProcessSourceExpression(std::string const& expr)
  571. {
  572. if(cmHasLiteralPrefix(expr.c_str(), "$<TARGET_OBJECTS:") &&
  573. expr[expr.size()-1] == '>')
  574. {
  575. std::string objLibName = expr.substr(17, expr.size()-18);
  576. this->ObjectLibraries.push_back(objLibName);
  577. }
  578. else
  579. {
  580. cmOStringStream e;
  581. e << "Unrecognized generator expression:\n"
  582. << " " << expr;
  583. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  584. }
  585. }
  586. //----------------------------------------------------------------------------
  587. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  588. const char *selfname,
  589. const LinkLibraryVectorType& libs )
  590. {
  591. // Only add on libraries we haven't added on before.
  592. // Assumption: the global link libraries could only grow, never shrink
  593. LinkLibraryVectorType::const_iterator i = libs.begin();
  594. i += this->PrevLinkedLibraries.size();
  595. for( ; i != libs.end(); ++i )
  596. {
  597. // This is equivalent to the target_link_libraries plain signature.
  598. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  599. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  600. this->GetDebugGeneratorExpressions(i->first.c_str(), i->second).c_str());
  601. }
  602. this->PrevLinkedLibraries = libs;
  603. }
  604. //----------------------------------------------------------------------------
  605. void cmTarget::AddLinkDirectory(const char* d)
  606. {
  607. // Make sure we don't add unnecessary search directories.
  608. if(this->LinkDirectoriesEmmitted.insert(d).second)
  609. {
  610. this->LinkDirectories.push_back(d);
  611. }
  612. }
  613. //----------------------------------------------------------------------------
  614. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  615. {
  616. return this->LinkDirectories;
  617. }
  618. //----------------------------------------------------------------------------
  619. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config) const
  620. {
  621. // No configuration is always optimized.
  622. if(!(config && *config))
  623. {
  624. return cmTarget::OPTIMIZED;
  625. }
  626. // Get the list of configurations considered to be DEBUG.
  627. std::vector<std::string> const& debugConfigs =
  628. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  629. // Check if any entry in the list matches this configuration.
  630. std::string configUpper = cmSystemTools::UpperCase(config);
  631. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  632. i != debugConfigs.end(); ++i)
  633. {
  634. if(*i == configUpper)
  635. {
  636. return cmTarget::DEBUG;
  637. }
  638. }
  639. // The current configuration is not a debug configuration.
  640. return cmTarget::OPTIMIZED;
  641. }
  642. //----------------------------------------------------------------------------
  643. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  644. const char* target )
  645. {
  646. // Clear the dependencies. The cache variable must exist iff we are
  647. // recording dependency information for this target.
  648. std::string depname = target;
  649. depname += "_LIB_DEPENDS";
  650. if (this->RecordDependencies)
  651. {
  652. mf.AddCacheDefinition(depname.c_str(), "",
  653. "Dependencies for target", cmCacheManager::STATIC);
  654. }
  655. else
  656. {
  657. if (mf.GetDefinition( depname.c_str() ))
  658. {
  659. std::string message = "Target ";
  660. message += target;
  661. message += " has dependency information when it shouldn't.\n";
  662. message += "Your cache is probably stale. Please remove the entry\n ";
  663. message += depname;
  664. message += "\nfrom the cache.";
  665. cmSystemTools::Error( message.c_str() );
  666. }
  667. }
  668. }
  669. //----------------------------------------------------------------------------
  670. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  671. {
  672. return this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  673. NameResolvesToFramework(libname);
  674. }
  675. //----------------------------------------------------------------------------
  676. void cmTarget::GetDirectLinkLibraries(const char *config,
  677. std::vector<std::string> &libs,
  678. cmTarget const* head) const
  679. {
  680. const char *prop = this->GetProperty("LINK_LIBRARIES");
  681. if (prop)
  682. {
  683. cmListFileBacktrace lfbt;
  684. cmGeneratorExpression ge(lfbt);
  685. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  686. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  687. this->GetName(),
  688. "LINK_LIBRARIES", 0, 0);
  689. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  690. config,
  691. false,
  692. head,
  693. &dagChecker),
  694. libs);
  695. std::set<cmStdString> seenProps = cge->GetSeenTargetProperties();
  696. for (std::set<cmStdString>::const_iterator it = seenProps.begin();
  697. it != seenProps.end(); ++it)
  698. {
  699. if (!this->GetProperty(it->c_str()))
  700. {
  701. this->LinkImplicitNullProperties.insert(*it);
  702. }
  703. }
  704. }
  705. }
  706. //----------------------------------------------------------------------------
  707. void cmTarget::GetInterfaceLinkLibraries(const char *config,
  708. std::vector<std::string> &libs,
  709. cmTarget const* head) const
  710. {
  711. const char *prop = this->GetProperty("INTERFACE_LINK_LIBRARIES");
  712. if (prop)
  713. {
  714. cmListFileBacktrace lfbt;
  715. cmGeneratorExpression ge(lfbt);
  716. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  717. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  718. this->GetName(),
  719. "INTERFACE_LINK_LIBRARIES", 0, 0);
  720. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  721. config,
  722. false,
  723. head,
  724. &dagChecker),
  725. libs);
  726. }
  727. }
  728. //----------------------------------------------------------------------------
  729. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  730. cmTarget::LinkLibraryType llt) const
  731. {
  732. if (llt == GENERAL)
  733. {
  734. return value;
  735. }
  736. // Get the list of configurations considered to be DEBUG.
  737. std::vector<std::string> const& debugConfigs =
  738. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  739. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  740. if (debugConfigs.size() > 1)
  741. {
  742. for(std::vector<std::string>::const_iterator
  743. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  744. {
  745. configString += ",$<CONFIG:" + *li + ">";
  746. }
  747. configString = "$<OR:" + configString + ">";
  748. }
  749. if (llt == OPTIMIZED)
  750. {
  751. configString = "$<NOT:" + configString + ">";
  752. }
  753. return "$<" + configString + ":" + value + ">";
  754. }
  755. //----------------------------------------------------------------------------
  756. static std::string targetNameGenex(const char *lib)
  757. {
  758. return std::string("$<TARGET_NAME:") + lib + ">";
  759. }
  760. //----------------------------------------------------------------------------
  761. bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
  762. {
  763. bool ret = true;
  764. if (!this->TLLCommands.empty())
  765. {
  766. if (this->TLLCommands.back().first != signature)
  767. {
  768. ret = false;
  769. }
  770. }
  771. cmListFileBacktrace lfbt;
  772. this->Makefile->GetBacktrace(lfbt);
  773. this->TLLCommands.push_back(std::make_pair(signature, lfbt));
  774. return ret;
  775. }
  776. //----------------------------------------------------------------------------
  777. void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
  778. TLLSignature sig) const
  779. {
  780. std::vector<cmListFileBacktrace> sigs;
  781. typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
  782. for(Container::const_iterator it = this->TLLCommands.begin();
  783. it != this->TLLCommands.end(); ++it)
  784. {
  785. if (it->first == sig)
  786. {
  787. sigs.push_back(it->second);
  788. }
  789. }
  790. if (!sigs.empty())
  791. {
  792. const char *sigString
  793. = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  794. : "plain");
  795. s << "The uses of the " << sigString << " signature are here:\n";
  796. std::set<cmStdString> emitted;
  797. for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin();
  798. it != sigs.end(); ++it)
  799. {
  800. cmListFileBacktrace::const_iterator i = it->begin();
  801. if(i != it->end())
  802. {
  803. cmListFileContext const& lfc = *i;
  804. cmOStringStream line;
  805. line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
  806. if (emitted.insert(line.str()).second)
  807. {
  808. s << line.str();
  809. }
  810. ++i;
  811. }
  812. }
  813. }
  814. }
  815. //----------------------------------------------------------------------------
  816. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  817. const char *target, const char* lib,
  818. LinkLibraryType llt)
  819. {
  820. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  821. {
  822. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  823. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  824. ? targetNameGenex(lib)
  825. : std::string(lib);
  826. this->AppendProperty("LINK_LIBRARIES",
  827. this->GetDebugGeneratorExpressions(libName,
  828. llt).c_str());
  829. }
  830. if (cmGeneratorExpression::Find(lib) != std::string::npos
  831. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  832. || (strcmp( target, lib ) == 0))
  833. {
  834. return;
  835. }
  836. cmTarget::LibraryID tmp;
  837. tmp.first = lib;
  838. tmp.second = llt;
  839. this->LinkLibraries.push_back( tmp );
  840. this->OriginalLinkLibraries.push_back(tmp);
  841. this->ClearLinkMaps();
  842. // Add the explicit dependency information for this target. This is
  843. // simply a set of libraries separated by ";". There should always
  844. // be a trailing ";". These library names are not canonical, in that
  845. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  846. // We shouldn't remove duplicates here because external libraries
  847. // may be purposefully duplicated to handle recursive dependencies,
  848. // and we removing one instance will break the link line. Duplicates
  849. // will be appropriately eliminated at emit time.
  850. if(this->RecordDependencies)
  851. {
  852. std::string targetEntry = target;
  853. targetEntry += "_LIB_DEPENDS";
  854. std::string dependencies;
  855. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  856. if( old_val )
  857. {
  858. dependencies += old_val;
  859. }
  860. switch (llt)
  861. {
  862. case cmTarget::GENERAL:
  863. dependencies += "general";
  864. break;
  865. case cmTarget::DEBUG:
  866. dependencies += "debug";
  867. break;
  868. case cmTarget::OPTIMIZED:
  869. dependencies += "optimized";
  870. break;
  871. }
  872. dependencies += ";";
  873. dependencies += lib;
  874. dependencies += ";";
  875. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  876. "Dependencies for the target",
  877. cmCacheManager::STATIC );
  878. }
  879. }
  880. //----------------------------------------------------------------------------
  881. void
  882. cmTarget::AddSystemIncludeDirectories(const std::set<cmStdString> &incs)
  883. {
  884. for(std::set<cmStdString>::const_iterator li = incs.begin();
  885. li != incs.end(); ++li)
  886. {
  887. this->SystemIncludeDirectories.insert(*li);
  888. }
  889. }
  890. //----------------------------------------------------------------------------
  891. void
  892. cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
  893. {
  894. for(std::vector<std::string>::const_iterator li = incs.begin();
  895. li != incs.end(); ++li)
  896. {
  897. this->SystemIncludeDirectories.insert(*li);
  898. }
  899. }
  900. //----------------------------------------------------------------------------
  901. void
  902. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  903. {
  904. // There are two key parts of the dependency analysis: (1)
  905. // determining the libraries in the link line, and (2) constructing
  906. // the dependency graph for those libraries.
  907. //
  908. // The latter is done using the cache entries that record the
  909. // dependencies of each library.
  910. //
  911. // The former is a more thorny issue, since it is not clear how to
  912. // determine if two libraries listed on the link line refer to the a
  913. // single library or not. For example, consider the link "libraries"
  914. // /usr/lib/libtiff.so -ltiff
  915. // Is this one library or two? The solution implemented here is the
  916. // simplest (and probably the only practical) one: two libraries are
  917. // the same if their "link strings" are identical. Thus, the two
  918. // libraries above are considered distinct. This also means that for
  919. // dependency analysis to be effective, the CMake user must specify
  920. // libraries build by his project without using any linker flags or
  921. // file extensions. That is,
  922. // LINK_LIBRARIES( One Two )
  923. // instead of
  924. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  925. // The former is probably what most users would do, but it never
  926. // hurts to document the assumptions. :-) Therefore, in the analysis
  927. // code, the "canonical name" of a library is simply its name as
  928. // given to a LINK_LIBRARIES command.
  929. //
  930. // Also, we will leave the original link line intact; we will just add any
  931. // dependencies that were missing.
  932. //
  933. // There is a problem with recursive external libraries
  934. // (i.e. libraries with no dependency information that are
  935. // recursively dependent). We must make sure that the we emit one of
  936. // the libraries twice to satisfy the recursion, but we shouldn't
  937. // emit it more times than necessary. In particular, we must make
  938. // sure that handling this improbable case doesn't cost us when
  939. // dealing with the common case of non-recursive libraries. The
  940. // solution is to assume that the recursion is satisfied at one node
  941. // of the dependency tree. To illustrate, assume libA and libB are
  942. // extrenal and mutually dependent. Suppose libX depends on
  943. // libA, and libY on libA and libX. Then
  944. // TARGET_LINK_LIBRARIES( Y X A B A )
  945. // TARGET_LINK_LIBRARIES( X A B A )
  946. // TARGET_LINK_LIBRARIES( Exec Y )
  947. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  948. // specify the dependencies, since the mutual dependency of A and B
  949. // is resolved *every time libA is specified*.
  950. //
  951. // Something like
  952. // TARGET_LINK_LIBRARIES( Y X A B A )
  953. // TARGET_LINK_LIBRARIES( X A B )
  954. // TARGET_LINK_LIBRARIES( Exec Y )
  955. // would result in "-lY -lX -lA -lB", and the mutual dependency
  956. // information is lost. This is because in some case (Y), the mutual
  957. // dependency of A and B is listed, while in another other case (X),
  958. // it is not. Depending on which line actually emits A, the mutual
  959. // dependency may or may not be on the final link line. We can't
  960. // handle this pathalogical case cleanly without emitting extra
  961. // libraries for the normal cases. Besides, the dependency
  962. // information for X is wrong anyway: if we build an executable
  963. // depending on X alone, we would not have the mutual dependency on
  964. // A and B resolved.
  965. //
  966. // IMPROVEMENTS:
  967. // -- The current algorithm will not always pick the "optimal" link line
  968. // when recursive dependencies are present. It will instead break the
  969. // cycles at an aribtrary point. The majority of projects won't have
  970. // cyclic dependencies, so this is probably not a big deal. Note that
  971. // the link line is always correct, just not necessary optimal.
  972. {
  973. // Expand variables in link library names. This is for backwards
  974. // compatibility with very early CMake versions and should
  975. // eventually be removed. This code was moved here from the end of
  976. // old source list processing code which was called just before this
  977. // method.
  978. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  979. p != this->LinkLibraries.end(); ++p)
  980. {
  981. this->Makefile->ExpandVariablesInString(p->first, true, true);
  982. }
  983. }
  984. // The dependency map.
  985. DependencyMap dep_map;
  986. // 1. Build the dependency graph
  987. //
  988. for(LinkLibraryVectorType::reverse_iterator lib
  989. = this->LinkLibraries.rbegin();
  990. lib != this->LinkLibraries.rend(); ++lib)
  991. {
  992. this->GatherDependencies( mf, *lib, dep_map);
  993. }
  994. // 2. Remove any dependencies that are already satisfied in the original
  995. // link line.
  996. //
  997. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  998. lib != this->LinkLibraries.end(); ++lib)
  999. {
  1000. for( LinkLibraryVectorType::iterator lib2 = lib;
  1001. lib2 != this->LinkLibraries.end(); ++lib2)
  1002. {
  1003. this->DeleteDependency( dep_map, *lib, *lib2);
  1004. }
  1005. }
  1006. // 3. Create the new link line by simply emitting any dependencies that are
  1007. // missing. Start from the back and keep adding.
  1008. //
  1009. std::set<DependencyMap::key_type> done, visited;
  1010. std::vector<DependencyMap::key_type> newLinkLibraries;
  1011. for(LinkLibraryVectorType::reverse_iterator lib =
  1012. this->LinkLibraries.rbegin();
  1013. lib != this->LinkLibraries.rend(); ++lib)
  1014. {
  1015. // skip zero size library entries, this may happen
  1016. // if a variable expands to nothing.
  1017. if (lib->first.size() != 0)
  1018. {
  1019. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  1020. }
  1021. }
  1022. // 4. Add the new libraries to the link line.
  1023. //
  1024. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1025. newLinkLibraries.rbegin();
  1026. k != newLinkLibraries.rend(); ++k )
  1027. {
  1028. // get the llt from the dep_map
  1029. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  1030. }
  1031. this->LinkLibrariesAnalyzed = true;
  1032. }
  1033. //----------------------------------------------------------------------------
  1034. void cmTarget::InsertDependency( DependencyMap& depMap,
  1035. const LibraryID& lib,
  1036. const LibraryID& dep)
  1037. {
  1038. depMap[lib].push_back(dep);
  1039. }
  1040. //----------------------------------------------------------------------------
  1041. void cmTarget::DeleteDependency( DependencyMap& depMap,
  1042. const LibraryID& lib,
  1043. const LibraryID& dep)
  1044. {
  1045. // Make sure there is an entry in the map for lib. If so, delete all
  1046. // dependencies to dep. There may be repeated entries because of
  1047. // external libraries that are specified multiple times.
  1048. DependencyMap::iterator map_itr = depMap.find( lib );
  1049. if( map_itr != depMap.end() )
  1050. {
  1051. DependencyList& depList = map_itr->second;
  1052. DependencyList::iterator itr;
  1053. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  1054. depList.end() )
  1055. {
  1056. depList.erase( itr );
  1057. }
  1058. }
  1059. }
  1060. //----------------------------------------------------------------------------
  1061. void cmTarget::Emit(const LibraryID lib,
  1062. const DependencyMap& dep_map,
  1063. std::set<LibraryID>& emitted,
  1064. std::set<LibraryID>& visited,
  1065. DependencyList& link_line )
  1066. {
  1067. // It's already been emitted
  1068. if( emitted.find(lib) != emitted.end() )
  1069. {
  1070. return;
  1071. }
  1072. // Emit the dependencies only if this library node hasn't been
  1073. // visited before. If it has, then we have a cycle. The recursion
  1074. // that got us here should take care of everything.
  1075. if( visited.insert(lib).second )
  1076. {
  1077. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1078. {
  1079. const DependencyList& dep_on = dep_map.find( lib )->second;
  1080. DependencyList::const_reverse_iterator i;
  1081. // To cater for recursive external libraries, we must emit
  1082. // duplicates on this link line *unless* they were emitted by
  1083. // some other node, in which case we assume that the recursion
  1084. // was resolved then. We making the simplifying assumption that
  1085. // any duplicates on a single link line are on purpose, and must
  1086. // be preserved.
  1087. // This variable will keep track of the libraries that were
  1088. // emitted directly from the current node, and not from a
  1089. // recursive call. This way, if we come across a library that
  1090. // has already been emitted, we repeat it iff it has been
  1091. // emitted here.
  1092. std::set<DependencyMap::key_type> emitted_here;
  1093. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1094. {
  1095. if( emitted_here.find(*i) != emitted_here.end() )
  1096. {
  1097. // a repeat. Must emit.
  1098. emitted.insert(*i);
  1099. link_line.push_back( *i );
  1100. }
  1101. else
  1102. {
  1103. // Emit only if no-one else has
  1104. if( emitted.find(*i) == emitted.end() )
  1105. {
  1106. // emit dependencies
  1107. Emit( *i, dep_map, emitted, visited, link_line );
  1108. // emit self
  1109. emitted.insert(*i);
  1110. emitted_here.insert(*i);
  1111. link_line.push_back( *i );
  1112. }
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. //----------------------------------------------------------------------------
  1119. void cmTarget::GatherDependencies( const cmMakefile& mf,
  1120. const LibraryID& lib,
  1121. DependencyMap& dep_map)
  1122. {
  1123. // If the library is already in the dependency map, then it has
  1124. // already been fully processed.
  1125. if( dep_map.find(lib) != dep_map.end() )
  1126. {
  1127. return;
  1128. }
  1129. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  1130. if( deps && strcmp(deps,"") != 0 )
  1131. {
  1132. // Make sure this library is in the map, even if it has an empty
  1133. // set of dependencies. This distinguishes the case of explicitly
  1134. // no dependencies with that of unspecified dependencies.
  1135. dep_map[lib];
  1136. // Parse the dependency information, which is a set of
  1137. // type, library pairs separated by ";". There is always a trailing ";".
  1138. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1139. std::string depline = deps;
  1140. std::string::size_type start = 0;
  1141. std::string::size_type end;
  1142. end = depline.find( ";", start );
  1143. while( end != std::string::npos )
  1144. {
  1145. std::string l = depline.substr( start, end-start );
  1146. if( l.size() != 0 )
  1147. {
  1148. if (l == "debug")
  1149. {
  1150. llt = cmTarget::DEBUG;
  1151. }
  1152. else if (l == "optimized")
  1153. {
  1154. llt = cmTarget::OPTIMIZED;
  1155. }
  1156. else if (l == "general")
  1157. {
  1158. llt = cmTarget::GENERAL;
  1159. }
  1160. else
  1161. {
  1162. LibraryID lib2(l,llt);
  1163. this->InsertDependency( dep_map, lib, lib2);
  1164. this->GatherDependencies( mf, lib2, dep_map);
  1165. llt = cmTarget::GENERAL;
  1166. }
  1167. }
  1168. start = end+1; // skip the ;
  1169. end = depline.find( ";", start );
  1170. }
  1171. // cannot depend on itself
  1172. this->DeleteDependency( dep_map, lib, lib);
  1173. }
  1174. }
  1175. //----------------------------------------------------------------------------
  1176. static bool whiteListedInterfaceProperty(const std::string& prop)
  1177. {
  1178. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1179. {
  1180. return true;
  1181. }
  1182. static const char* builtIns[] = {
  1183. // ###: This must remain sorted. It is processed with a binary search.
  1184. "COMPATIBLE_INTERFACE_BOOL",
  1185. "COMPATIBLE_INTERFACE_NUMBER_MAX",
  1186. "COMPATIBLE_INTERFACE_NUMBER_MIN",
  1187. "COMPATIBLE_INTERFACE_STRING",
  1188. "EXPORT_NAME",
  1189. "IMPORTED",
  1190. "NAME",
  1191. "TYPE"
  1192. };
  1193. if (std::binary_search(cmArrayBegin(builtIns),
  1194. cmArrayEnd(builtIns),
  1195. prop.c_str(),
  1196. cmStrCmp(prop.c_str())))
  1197. {
  1198. return true;
  1199. }
  1200. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1201. {
  1202. return true;
  1203. }
  1204. return false;
  1205. }
  1206. //----------------------------------------------------------------------------
  1207. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1208. {
  1209. if (this->GetType() == INTERFACE_LIBRARY
  1210. && !whiteListedInterfaceProperty(prop))
  1211. {
  1212. cmOStringStream e;
  1213. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1214. "The property \"" << prop << "\" is not allowed.";
  1215. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1216. return;
  1217. }
  1218. if (prop == "NAME")
  1219. {
  1220. cmOStringStream e;
  1221. e << "NAME property is read-only\n";
  1222. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1223. return;
  1224. }
  1225. if(prop == "INCLUDE_DIRECTORIES")
  1226. {
  1227. cmListFileBacktrace lfbt;
  1228. this->Makefile->GetBacktrace(lfbt);
  1229. cmGeneratorExpression ge(lfbt);
  1230. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  1231. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1232. this->Internal->IncludeDirectoriesEntries.push_back(
  1233. new cmTargetInternals::TargetPropertyEntry(cge));
  1234. return;
  1235. }
  1236. if(prop == "COMPILE_OPTIONS")
  1237. {
  1238. cmListFileBacktrace lfbt;
  1239. this->Makefile->GetBacktrace(lfbt);
  1240. cmGeneratorExpression ge(lfbt);
  1241. deleteAndClear(this->Internal->CompileOptionsEntries);
  1242. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1243. this->Internal->CompileOptionsEntries.push_back(
  1244. new cmTargetInternals::TargetPropertyEntry(cge));
  1245. return;
  1246. }
  1247. if(prop == "COMPILE_DEFINITIONS")
  1248. {
  1249. cmListFileBacktrace lfbt;
  1250. this->Makefile->GetBacktrace(lfbt);
  1251. cmGeneratorExpression ge(lfbt);
  1252. deleteAndClear(this->Internal->CompileDefinitionsEntries);
  1253. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1254. this->Internal->CompileDefinitionsEntries.push_back(
  1255. new cmTargetInternals::TargetPropertyEntry(cge));
  1256. return;
  1257. }
  1258. if(prop == "EXPORT_NAME" && this->IsImported())
  1259. {
  1260. cmOStringStream e;
  1261. e << "EXPORT_NAME property can't be set on imported targets (\""
  1262. << this->Name << "\")\n";
  1263. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1264. return;
  1265. }
  1266. if (prop == "LINK_LIBRARIES")
  1267. {
  1268. this->Internal->LinkImplementationPropertyEntries.clear();
  1269. cmListFileBacktrace lfbt;
  1270. this->Makefile->GetBacktrace(lfbt);
  1271. cmValueWithOrigin entry(value, lfbt);
  1272. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1273. return;
  1274. }
  1275. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  1276. this->MaybeInvalidatePropertyCache(prop);
  1277. }
  1278. //----------------------------------------------------------------------------
  1279. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1280. bool asString)
  1281. {
  1282. if (this->GetType() == INTERFACE_LIBRARY
  1283. && !whiteListedInterfaceProperty(prop))
  1284. {
  1285. cmOStringStream e;
  1286. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1287. "The property \"" << prop << "\" is not allowed.";
  1288. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1289. return;
  1290. }
  1291. if (prop == "NAME")
  1292. {
  1293. cmOStringStream e;
  1294. e << "NAME property is read-only\n";
  1295. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1296. return;
  1297. }
  1298. if(prop == "INCLUDE_DIRECTORIES")
  1299. {
  1300. cmListFileBacktrace lfbt;
  1301. this->Makefile->GetBacktrace(lfbt);
  1302. cmGeneratorExpression ge(lfbt);
  1303. this->Internal->IncludeDirectoriesEntries.push_back(
  1304. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1305. return;
  1306. }
  1307. if(prop == "COMPILE_OPTIONS")
  1308. {
  1309. cmListFileBacktrace lfbt;
  1310. this->Makefile->GetBacktrace(lfbt);
  1311. cmGeneratorExpression ge(lfbt);
  1312. this->Internal->CompileOptionsEntries.push_back(
  1313. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1314. return;
  1315. }
  1316. if(prop == "COMPILE_DEFINITIONS")
  1317. {
  1318. cmListFileBacktrace lfbt;
  1319. this->Makefile->GetBacktrace(lfbt);
  1320. cmGeneratorExpression ge(lfbt);
  1321. this->Internal->CompileDefinitionsEntries.push_back(
  1322. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1323. return;
  1324. }
  1325. if(prop == "EXPORT_NAME" && this->IsImported())
  1326. {
  1327. cmOStringStream e;
  1328. e << "EXPORT_NAME property can't be set on imported targets (\""
  1329. << this->Name << "\")\n";
  1330. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  1331. return;
  1332. }
  1333. if (prop == "LINK_LIBRARIES")
  1334. {
  1335. cmListFileBacktrace lfbt;
  1336. this->Makefile->GetBacktrace(lfbt);
  1337. cmValueWithOrigin entry(value, lfbt);
  1338. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1339. return;
  1340. }
  1341. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  1342. this->MaybeInvalidatePropertyCache(prop);
  1343. }
  1344. //----------------------------------------------------------------------------
  1345. const char* cmTarget::GetExportName() const
  1346. {
  1347. const char *exportName = this->GetProperty("EXPORT_NAME");
  1348. if (exportName && *exportName)
  1349. {
  1350. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1351. {
  1352. cmOStringStream e;
  1353. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1354. << this->GetName() << "\": is not valid.";
  1355. cmSystemTools::Error(e.str().c_str());
  1356. return "";
  1357. }
  1358. return exportName;
  1359. }
  1360. return this->GetName();
  1361. }
  1362. //----------------------------------------------------------------------------
  1363. void cmTarget::AppendBuildInterfaceIncludes()
  1364. {
  1365. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1366. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1367. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1368. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1369. !this->IsExecutableWithExports())
  1370. {
  1371. return;
  1372. }
  1373. if (this->BuildInterfaceIncludesAppended)
  1374. {
  1375. return;
  1376. }
  1377. this->BuildInterfaceIncludesAppended = true;
  1378. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1379. {
  1380. const char *binDir = this->Makefile->GetStartOutputDirectory();
  1381. const char *srcDir = this->Makefile->GetStartDirectory();
  1382. const std::string dirs = std::string(binDir ? binDir : "")
  1383. + std::string(binDir ? ";" : "")
  1384. + std::string(srcDir ? srcDir : "");
  1385. if (!dirs.empty())
  1386. {
  1387. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1388. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1389. }
  1390. }
  1391. }
  1392. //----------------------------------------------------------------------------
  1393. void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
  1394. bool before)
  1395. {
  1396. cmGeneratorExpression ge(entry.Backtrace);
  1397. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1398. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  1399. : this->Internal->IncludeDirectoriesEntries.end();
  1400. this->Internal->IncludeDirectoriesEntries.insert(position,
  1401. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1402. }
  1403. //----------------------------------------------------------------------------
  1404. void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
  1405. bool before)
  1406. {
  1407. cmGeneratorExpression ge(entry.Backtrace);
  1408. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1409. = before ? this->Internal->CompileOptionsEntries.begin()
  1410. : this->Internal->CompileOptionsEntries.end();
  1411. this->Internal->CompileOptionsEntries.insert(position,
  1412. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1413. }
  1414. //----------------------------------------------------------------------------
  1415. void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry)
  1416. {
  1417. cmGeneratorExpression ge(entry.Backtrace);
  1418. this->Internal->CompileDefinitionsEntries.push_back(
  1419. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1420. }
  1421. //----------------------------------------------------------------------------
  1422. static void processIncludeDirectories(cmTarget const* tgt,
  1423. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1424. std::vector<std::string> &includes,
  1425. std::set<std::string> &uniqueIncludes,
  1426. cmGeneratorExpressionDAGChecker *dagChecker,
  1427. const char *config, bool debugIncludes)
  1428. {
  1429. cmMakefile *mf = tgt->GetMakefile();
  1430. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1431. it = entries.begin(), end = entries.end(); it != end; ++it)
  1432. {
  1433. bool testIsOff = true;
  1434. bool cacheIncludes = false;
  1435. std::vector<std::string> entryIncludes = (*it)->CachedEntries;
  1436. if(!entryIncludes.empty())
  1437. {
  1438. testIsOff = false;
  1439. }
  1440. else
  1441. {
  1442. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1443. config,
  1444. false,
  1445. tgt,
  1446. dagChecker),
  1447. entryIncludes);
  1448. if (mf->IsGeneratingBuildSystem()
  1449. && !(*it)->ge->GetHadContextSensitiveCondition())
  1450. {
  1451. cacheIncludes = true;
  1452. }
  1453. }
  1454. std::string usedIncludes;
  1455. cmListFileBacktrace lfbt;
  1456. for(std::vector<std::string>::iterator
  1457. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1458. {
  1459. std::string targetName = (*it)->TargetName;
  1460. std::string evaluatedTargetName;
  1461. {
  1462. cmGeneratorExpression ge(lfbt);
  1463. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1464. ge.Parse(targetName);
  1465. evaluatedTargetName = cge->Evaluate(mf, config, false, tgt, 0, 0);
  1466. }
  1467. cmTarget *dependentTarget = mf->FindTargetToUse(targetName);
  1468. const bool fromImported = dependentTarget
  1469. && dependentTarget->IsImported();
  1470. cmTarget *evaluatedDependentTarget =
  1471. (targetName != evaluatedTargetName)
  1472. ? mf->FindTargetToUse(evaluatedTargetName)
  1473. : 0;
  1474. targetName = evaluatedTargetName;
  1475. const bool fromEvaluatedImported = evaluatedDependentTarget
  1476. && evaluatedDependentTarget->IsImported();
  1477. if ((fromImported || fromEvaluatedImported)
  1478. && !cmSystemTools::FileExists(li->c_str()))
  1479. {
  1480. cmOStringStream e;
  1481. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1482. if (fromEvaluatedImported)
  1483. {
  1484. switch(mf->GetPolicyStatus(cmPolicies::CMP0027))
  1485. {
  1486. case cmPolicies::WARN:
  1487. e << (mf->GetPolicies()
  1488. ->GetPolicyWarning(cmPolicies::CMP0027)) << "\n";
  1489. case cmPolicies::OLD:
  1490. messageType = cmake::AUTHOR_WARNING;
  1491. break;
  1492. case cmPolicies::REQUIRED_ALWAYS:
  1493. case cmPolicies::REQUIRED_IF_USED:
  1494. case cmPolicies::NEW:
  1495. break;
  1496. }
  1497. }
  1498. e << "Imported target \"" << targetName << "\" includes "
  1499. "non-existent path\n \"" << *li << "\"\nin its "
  1500. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1501. "* The path was deleted, renamed, or moved to another "
  1502. "location.\n"
  1503. "* An install or uninstall procedure did not complete "
  1504. "successfully.\n"
  1505. "* The installation package was faulty and references files it "
  1506. "does not provide.\n";
  1507. tgt->GetMakefile()->IssueMessage(messageType, e.str().c_str());
  1508. return;
  1509. }
  1510. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1511. {
  1512. cmOStringStream e;
  1513. bool noMessage = false;
  1514. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1515. if (!targetName.empty())
  1516. {
  1517. e << "Target \"" << targetName << "\" contains relative "
  1518. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1519. " \"" << *li << "\"";
  1520. }
  1521. else
  1522. {
  1523. switch(tgt->GetPolicyStatusCMP0021())
  1524. {
  1525. case cmPolicies::WARN:
  1526. {
  1527. e << (mf->GetPolicies()
  1528. ->GetPolicyWarning(cmPolicies::CMP0021)) << "\n";
  1529. messageType = cmake::AUTHOR_WARNING;
  1530. }
  1531. break;
  1532. case cmPolicies::OLD:
  1533. noMessage = true;
  1534. case cmPolicies::REQUIRED_IF_USED:
  1535. case cmPolicies::REQUIRED_ALWAYS:
  1536. case cmPolicies::NEW:
  1537. // Issue the fatal message.
  1538. break;
  1539. }
  1540. e << "Found relative path while evaluating include directories of "
  1541. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1542. }
  1543. if (!noMessage)
  1544. {
  1545. tgt->GetMakefile()->IssueMessage(messageType, e.str().c_str());
  1546. if (messageType == cmake::FATAL_ERROR)
  1547. {
  1548. return;
  1549. }
  1550. }
  1551. }
  1552. if (testIsOff && !cmSystemTools::IsOff(li->c_str()))
  1553. {
  1554. cmSystemTools::ConvertToUnixSlashes(*li);
  1555. }
  1556. std::string inc = *li;
  1557. if(uniqueIncludes.insert(inc).second)
  1558. {
  1559. includes.push_back(inc);
  1560. if (debugIncludes)
  1561. {
  1562. usedIncludes += " * " + inc + "\n";
  1563. }
  1564. }
  1565. }
  1566. if (cacheIncludes)
  1567. {
  1568. (*it)->CachedEntries = entryIncludes;
  1569. }
  1570. if (!usedIncludes.empty())
  1571. {
  1572. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1573. std::string("Used includes for target ")
  1574. + tgt->GetName() + ":\n"
  1575. + usedIncludes, (*it)->ge->GetBacktrace());
  1576. }
  1577. }
  1578. }
  1579. //----------------------------------------------------------------------------
  1580. std::vector<std::string>
  1581. cmTarget::GetIncludeDirectories(const char *config) const
  1582. {
  1583. std::vector<std::string> includes;
  1584. std::set<std::string> uniqueIncludes;
  1585. cmListFileBacktrace lfbt;
  1586. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1587. this->GetName(),
  1588. "INCLUDE_DIRECTORIES", 0, 0);
  1589. std::vector<std::string> debugProperties;
  1590. const char *debugProp =
  1591. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1592. if (debugProp)
  1593. {
  1594. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1595. }
  1596. bool debugIncludes = !this->DebugIncludesDone
  1597. && std::find(debugProperties.begin(),
  1598. debugProperties.end(),
  1599. "INCLUDE_DIRECTORIES")
  1600. != debugProperties.end();
  1601. if (this->Makefile->IsGeneratingBuildSystem())
  1602. {
  1603. this->DebugIncludesDone = true;
  1604. }
  1605. processIncludeDirectories(this,
  1606. this->Internal->IncludeDirectoriesEntries,
  1607. includes,
  1608. uniqueIncludes,
  1609. &dagChecker,
  1610. config,
  1611. debugIncludes);
  1612. std::string configString = config ? config : "";
  1613. if (!this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString])
  1614. {
  1615. for (std::vector<cmValueWithOrigin>::const_iterator
  1616. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  1617. end = this->Internal->LinkImplementationPropertyEntries.end();
  1618. it != end; ++it)
  1619. {
  1620. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  1621. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  1622. {
  1623. continue;
  1624. }
  1625. {
  1626. cmGeneratorExpression ge(lfbt);
  1627. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1628. ge.Parse(it->Value);
  1629. std::string result = cge->Evaluate(this->Makefile, config,
  1630. false, this, 0, 0);
  1631. if (!this->Makefile->FindTargetToUse(result))
  1632. {
  1633. continue;
  1634. }
  1635. }
  1636. std::string includeGenex = "$<TARGET_PROPERTY:" +
  1637. it->Value + ",INTERFACE_INCLUDE_DIRECTORIES>";
  1638. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  1639. {
  1640. // Because it->Value is a generator expression, ensure that it
  1641. // evaluates to the non-empty string before being used in the
  1642. // TARGET_PROPERTY expression.
  1643. includeGenex = "$<$<BOOL:" + it->Value + ">:" + includeGenex + ">";
  1644. }
  1645. cmGeneratorExpression ge(it->Backtrace);
  1646. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  1647. includeGenex);
  1648. this->Internal
  1649. ->CachedLinkInterfaceIncludeDirectoriesEntries[configString].push_back(
  1650. new cmTargetInternals::TargetPropertyEntry(cge,
  1651. it->Value));
  1652. }
  1653. if(this->Makefile->IsOn("APPLE"))
  1654. {
  1655. LinkImplementation const* impl = this->GetLinkImplementation(config,
  1656. this);
  1657. for(std::vector<std::string>::const_iterator
  1658. it = impl->Libraries.begin();
  1659. it != impl->Libraries.end(); ++it)
  1660. {
  1661. std::string libDir = cmSystemTools::CollapseFullPath(it->c_str());
  1662. static cmsys::RegularExpression
  1663. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  1664. if(!frameworkCheck.find(libDir))
  1665. {
  1666. continue;
  1667. }
  1668. libDir = frameworkCheck.match(1);
  1669. cmGeneratorExpression ge(lfbt);
  1670. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1671. ge.Parse(libDir.c_str());
  1672. this->Internal
  1673. ->CachedLinkInterfaceIncludeDirectoriesEntries[configString]
  1674. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1675. }
  1676. }
  1677. }
  1678. processIncludeDirectories(this,
  1679. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries[configString],
  1680. includes,
  1681. uniqueIncludes,
  1682. &dagChecker,
  1683. config,
  1684. debugIncludes);
  1685. if (!this->Makefile->IsGeneratingBuildSystem())
  1686. {
  1687. deleteAndClear(
  1688. this->Internal->CachedLinkInterfaceIncludeDirectoriesEntries);
  1689. }
  1690. else
  1691. {
  1692. this->Internal->CacheLinkInterfaceIncludeDirectoriesDone[configString]
  1693. = true;
  1694. }
  1695. return includes;
  1696. }
  1697. //----------------------------------------------------------------------------
  1698. static void processCompileOptionsInternal(cmTarget const* tgt,
  1699. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1700. std::vector<std::string> &options,
  1701. std::set<std::string> &uniqueOptions,
  1702. cmGeneratorExpressionDAGChecker *dagChecker,
  1703. const char *config, bool debugOptions, const char *logName)
  1704. {
  1705. cmMakefile *mf = tgt->GetMakefile();
  1706. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1707. it = entries.begin(), end = entries.end(); it != end; ++it)
  1708. {
  1709. bool cacheOptions = false;
  1710. std::vector<std::string> entryOptions = (*it)->CachedEntries;
  1711. if(entryOptions.empty())
  1712. {
  1713. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1714. config,
  1715. false,
  1716. tgt,
  1717. dagChecker),
  1718. entryOptions);
  1719. if (mf->IsGeneratingBuildSystem()
  1720. && !(*it)->ge->GetHadContextSensitiveCondition())
  1721. {
  1722. cacheOptions = true;
  1723. }
  1724. }
  1725. std::string usedOptions;
  1726. for(std::vector<std::string>::iterator
  1727. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  1728. {
  1729. std::string opt = *li;
  1730. if(uniqueOptions.insert(opt).second)
  1731. {
  1732. options.push_back(opt);
  1733. if (debugOptions)
  1734. {
  1735. usedOptions += " * " + opt + "\n";
  1736. }
  1737. }
  1738. }
  1739. if (cacheOptions)
  1740. {
  1741. (*it)->CachedEntries = entryOptions;
  1742. }
  1743. if (!usedOptions.empty())
  1744. {
  1745. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1746. std::string("Used compile ") + logName
  1747. + std::string(" for target ")
  1748. + tgt->GetName() + ":\n"
  1749. + usedOptions, (*it)->ge->GetBacktrace());
  1750. }
  1751. }
  1752. }
  1753. //----------------------------------------------------------------------------
  1754. static void processCompileOptions(cmTarget const* tgt,
  1755. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1756. std::vector<std::string> &options,
  1757. std::set<std::string> &uniqueOptions,
  1758. cmGeneratorExpressionDAGChecker *dagChecker,
  1759. const char *config, bool debugOptions)
  1760. {
  1761. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  1762. dagChecker, config, debugOptions, "options");
  1763. }
  1764. //----------------------------------------------------------------------------
  1765. void cmTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1766. const char *config) const
  1767. {
  1768. const char *prop
  1769. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1770. config);
  1771. if (!prop)
  1772. {
  1773. return;
  1774. }
  1775. cmListFileBacktrace lfbt;
  1776. cmGeneratorExpression ge(lfbt);
  1777. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1778. this->GetName(),
  1779. "AUTOUIC_OPTIONS", 0, 0);
  1780. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1781. ->Evaluate(this->Makefile,
  1782. config,
  1783. false,
  1784. this,
  1785. &dagChecker),
  1786. result);
  1787. }
  1788. //----------------------------------------------------------------------------
  1789. void cmTarget::GetCompileOptions(std::vector<std::string> &result,
  1790. const char *config) const
  1791. {
  1792. std::set<std::string> uniqueOptions;
  1793. cmListFileBacktrace lfbt;
  1794. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1795. this->GetName(),
  1796. "COMPILE_OPTIONS", 0, 0);
  1797. std::vector<std::string> debugProperties;
  1798. const char *debugProp =
  1799. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1800. if (debugProp)
  1801. {
  1802. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1803. }
  1804. bool debugOptions = !this->DebugCompileOptionsDone
  1805. && std::find(debugProperties.begin(),
  1806. debugProperties.end(),
  1807. "COMPILE_OPTIONS")
  1808. != debugProperties.end();
  1809. if (this->Makefile->IsGeneratingBuildSystem())
  1810. {
  1811. this->DebugCompileOptionsDone = true;
  1812. }
  1813. processCompileOptions(this,
  1814. this->Internal->CompileOptionsEntries,
  1815. result,
  1816. uniqueOptions,
  1817. &dagChecker,
  1818. config,
  1819. debugOptions);
  1820. std::string configString = config ? config : "";
  1821. if (!this->Internal->CacheLinkInterfaceCompileOptionsDone[configString])
  1822. {
  1823. for (std::vector<cmValueWithOrigin>::const_iterator
  1824. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  1825. end = this->Internal->LinkImplementationPropertyEntries.end();
  1826. it != end; ++it)
  1827. {
  1828. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  1829. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  1830. {
  1831. continue;
  1832. }
  1833. {
  1834. cmGeneratorExpression ge(lfbt);
  1835. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1836. ge.Parse(it->Value);
  1837. std::string targetResult = cge->Evaluate(this->Makefile, config,
  1838. false, this, 0, 0);
  1839. if (!this->Makefile->FindTargetToUse(targetResult))
  1840. {
  1841. continue;
  1842. }
  1843. }
  1844. std::string optionGenex = "$<TARGET_PROPERTY:" +
  1845. it->Value + ",INTERFACE_COMPILE_OPTIONS>";
  1846. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  1847. {
  1848. // Because it->Value is a generator expression, ensure that it
  1849. // evaluates to the non-empty string before being used in the
  1850. // TARGET_PROPERTY expression.
  1851. optionGenex = "$<$<BOOL:" + it->Value + ">:" + optionGenex + ">";
  1852. }
  1853. cmGeneratorExpression ge(it->Backtrace);
  1854. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  1855. optionGenex);
  1856. this->Internal
  1857. ->CachedLinkInterfaceCompileOptionsEntries[configString].push_back(
  1858. new cmTargetInternals::TargetPropertyEntry(cge,
  1859. it->Value));
  1860. }
  1861. }
  1862. processCompileOptions(this,
  1863. this->Internal->CachedLinkInterfaceCompileOptionsEntries[configString],
  1864. result,
  1865. uniqueOptions,
  1866. &dagChecker,
  1867. config,
  1868. debugOptions);
  1869. if (!this->Makefile->IsGeneratingBuildSystem())
  1870. {
  1871. deleteAndClear(this->Internal->CachedLinkInterfaceCompileOptionsEntries);
  1872. }
  1873. else
  1874. {
  1875. this->Internal->CacheLinkInterfaceCompileOptionsDone[configString] = true;
  1876. }
  1877. }
  1878. //----------------------------------------------------------------------------
  1879. static void processCompileDefinitions(cmTarget const* tgt,
  1880. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1881. std::vector<std::string> &options,
  1882. std::set<std::string> &uniqueOptions,
  1883. cmGeneratorExpressionDAGChecker *dagChecker,
  1884. const char *config, bool debugOptions)
  1885. {
  1886. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  1887. dagChecker, config, debugOptions,
  1888. "definitions");
  1889. }
  1890. //----------------------------------------------------------------------------
  1891. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  1892. const char *config) const
  1893. {
  1894. std::set<std::string> uniqueOptions;
  1895. cmListFileBacktrace lfbt;
  1896. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  1897. this->GetName(),
  1898. "COMPILE_DEFINITIONS", 0, 0);
  1899. std::vector<std::string> debugProperties;
  1900. const char *debugProp =
  1901. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1902. if (debugProp)
  1903. {
  1904. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1905. }
  1906. bool debugDefines = !this->DebugCompileDefinitionsDone
  1907. && std::find(debugProperties.begin(),
  1908. debugProperties.end(),
  1909. "COMPILE_DEFINITIONS")
  1910. != debugProperties.end();
  1911. if (this->Makefile->IsGeneratingBuildSystem())
  1912. {
  1913. this->DebugCompileDefinitionsDone = true;
  1914. }
  1915. processCompileDefinitions(this,
  1916. this->Internal->CompileDefinitionsEntries,
  1917. list,
  1918. uniqueOptions,
  1919. &dagChecker,
  1920. config,
  1921. debugDefines);
  1922. std::string configString = config ? config : "";
  1923. if (!this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString])
  1924. {
  1925. for (std::vector<cmValueWithOrigin>::const_iterator
  1926. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  1927. end = this->Internal->LinkImplementationPropertyEntries.end();
  1928. it != end; ++it)
  1929. {
  1930. if (!cmGeneratorExpression::IsValidTargetName(it->Value)
  1931. && cmGeneratorExpression::Find(it->Value) == std::string::npos)
  1932. {
  1933. continue;
  1934. }
  1935. {
  1936. cmGeneratorExpression ge(lfbt);
  1937. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1938. ge.Parse(it->Value);
  1939. std::string targetResult = cge->Evaluate(this->Makefile, config,
  1940. false, this, 0, 0);
  1941. if (!this->Makefile->FindTargetToUse(targetResult))
  1942. {
  1943. continue;
  1944. }
  1945. }
  1946. std::string defsGenex = "$<TARGET_PROPERTY:" +
  1947. it->Value + ",INTERFACE_COMPILE_DEFINITIONS>";
  1948. if (cmGeneratorExpression::Find(it->Value) != std::string::npos)
  1949. {
  1950. // Because it->Value is a generator expression, ensure that it
  1951. // evaluates to the non-empty string before being used in the
  1952. // TARGET_PROPERTY expression.
  1953. defsGenex = "$<$<BOOL:" + it->Value + ">:" + defsGenex + ">";
  1954. }
  1955. cmGeneratorExpression ge(it->Backtrace);
  1956. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(
  1957. defsGenex);
  1958. this->Internal
  1959. ->CachedLinkInterfaceCompileDefinitionsEntries[configString].push_back(
  1960. new cmTargetInternals::TargetPropertyEntry(cge,
  1961. it->Value));
  1962. }
  1963. if (config)
  1964. {
  1965. std::string configPropName = "COMPILE_DEFINITIONS_"
  1966. + cmSystemTools::UpperCase(config);
  1967. const char *configProp = this->GetProperty(configPropName.c_str());
  1968. if (configProp)
  1969. {
  1970. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  1971. {
  1972. case cmPolicies::WARN:
  1973. {
  1974. cmOStringStream e;
  1975. e << this->Makefile->GetCMakeInstance()->GetPolicies()
  1976. ->GetPolicyWarning(cmPolicies::CMP0043);
  1977. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  1978. e.str().c_str());
  1979. }
  1980. case cmPolicies::OLD:
  1981. {
  1982. cmGeneratorExpression ge(lfbt);
  1983. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1984. ge.Parse(configProp);
  1985. this->Internal
  1986. ->CachedLinkInterfaceCompileDefinitionsEntries[configString]
  1987. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1988. }
  1989. break;
  1990. case cmPolicies::NEW:
  1991. case cmPolicies::REQUIRED_ALWAYS:
  1992. case cmPolicies::REQUIRED_IF_USED:
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. }
  1998. processCompileDefinitions(this,
  1999. this->Internal->CachedLinkInterfaceCompileDefinitionsEntries[configString],
  2000. list,
  2001. uniqueOptions,
  2002. &dagChecker,
  2003. config,
  2004. debugDefines);
  2005. if (!this->Makefile->IsGeneratingBuildSystem())
  2006. {
  2007. deleteAndClear(this->Internal
  2008. ->CachedLinkInterfaceCompileDefinitionsEntries);
  2009. }
  2010. else
  2011. {
  2012. this->Internal->CacheLinkInterfaceCompileDefinitionsDone[configString]
  2013. = true;
  2014. }
  2015. }
  2016. //----------------------------------------------------------------------------
  2017. void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop)
  2018. {
  2019. // Wipe out maps caching information affected by this property.
  2020. if(this->IsImported() && cmHasLiteralPrefix(prop, "IMPORTED"))
  2021. {
  2022. this->Internal->ImportInfoMap.clear();
  2023. }
  2024. if(!this->IsImported() && cmHasLiteralPrefix(prop, "LINK_INTERFACE_"))
  2025. {
  2026. this->ClearLinkMaps();
  2027. }
  2028. }
  2029. //----------------------------------------------------------------------------
  2030. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2031. const std::string& prop, const char* value, cmMakefile* context,
  2032. bool imported)
  2033. {
  2034. // Look for link-type keywords in the value.
  2035. static cmsys::RegularExpression
  2036. keys("(^|;)(debug|optimized|general)(;|$)");
  2037. if(!keys.find(value))
  2038. {
  2039. return;
  2040. }
  2041. // Support imported and non-imported versions of the property.
  2042. const char* base = (imported?
  2043. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2044. "LINK_INTERFACE_LIBRARIES");
  2045. // Report an error.
  2046. cmOStringStream e;
  2047. e << "Property " << prop << " may not contain link-type keyword \""
  2048. << keys.match(2) << "\". "
  2049. << "The " << base << " property has a per-configuration "
  2050. << "version called " << base << "_<CONFIG> which may be "
  2051. << "used to specify per-configuration rules.";
  2052. if(!imported)
  2053. {
  2054. e << " "
  2055. << "Alternatively, an IMPORTED library may be created, configured "
  2056. << "with a per-configuration location, and then named in the "
  2057. << "property value. "
  2058. << "See the add_library command's IMPORTED mode for details."
  2059. << "\n"
  2060. << "If you have a list of libraries that already contains the "
  2061. << "keyword, use the target_link_libraries command with its "
  2062. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2063. << "The command automatically recognizes link-type keywords and sets "
  2064. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2065. << "properties accordingly.";
  2066. }
  2067. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2068. }
  2069. //----------------------------------------------------------------------------
  2070. static void cmTargetCheckINTERFACE_LINK_LIBRARIES(const char* value,
  2071. cmMakefile* context)
  2072. {
  2073. // Look for link-type keywords in the value.
  2074. static cmsys::RegularExpression
  2075. keys("(^|;)(debug|optimized|general)(;|$)");
  2076. if(!keys.find(value))
  2077. {
  2078. return;
  2079. }
  2080. // Report an error.
  2081. cmOStringStream e;
  2082. e << "Property INTERFACE_LINK_LIBRARIES may not contain link-type "
  2083. "keyword \"" << keys.match(2) << "\". The INTERFACE_LINK_LIBRARIES "
  2084. "property may contain configuration-sensitive generator-expressions "
  2085. "which may be used to specify per-configuration rules.";
  2086. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2087. }
  2088. //----------------------------------------------------------------------------
  2089. void cmTarget::CheckProperty(const std::string& prop,
  2090. cmMakefile* context) const
  2091. {
  2092. // Certain properties need checking.
  2093. if(cmHasLiteralPrefix(prop, "LINK_INTERFACE_LIBRARIES"))
  2094. {
  2095. if(const char* value = this->GetProperty(prop))
  2096. {
  2097. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2098. }
  2099. }
  2100. if(cmHasLiteralPrefix(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2101. {
  2102. if(const char* value = this->GetProperty(prop))
  2103. {
  2104. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2105. }
  2106. }
  2107. if(cmHasLiteralPrefix(prop, "INTERFACE_LINK_LIBRARIES"))
  2108. {
  2109. if(const char* value = this->GetProperty(prop))
  2110. {
  2111. cmTargetCheckINTERFACE_LINK_LIBRARIES(value, context);
  2112. }
  2113. }
  2114. }
  2115. //----------------------------------------------------------------------------
  2116. void cmTarget::MarkAsImported()
  2117. {
  2118. this->IsImportedTarget = true;
  2119. }
  2120. //----------------------------------------------------------------------------
  2121. bool cmTarget::HaveWellDefinedOutputFiles() const
  2122. {
  2123. return
  2124. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2125. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2126. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2127. this->GetType() == cmTarget::EXECUTABLE;
  2128. }
  2129. //----------------------------------------------------------------------------
  2130. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config) const
  2131. {
  2132. // There is no output information for imported targets.
  2133. if(this->IsImported())
  2134. {
  2135. return 0;
  2136. }
  2137. // Only libraries and executables have well-defined output files.
  2138. if(!this->HaveWellDefinedOutputFiles())
  2139. {
  2140. std::string msg = "cmTarget::GetOutputInfo called for ";
  2141. msg += this->GetName();
  2142. msg += " which has type ";
  2143. msg += cmTarget::GetTargetTypeName(this->GetType());
  2144. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2145. abort();
  2146. return 0;
  2147. }
  2148. // Lookup/compute/cache the output information for this configuration.
  2149. std::string config_upper;
  2150. if(config && *config)
  2151. {
  2152. config_upper = cmSystemTools::UpperCase(config);
  2153. }
  2154. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2155. OutputInfoMapType::const_iterator i =
  2156. this->Internal->OutputInfoMap.find(config_upper);
  2157. if(i == this->Internal->OutputInfoMap.end())
  2158. {
  2159. OutputInfo info;
  2160. this->ComputeOutputDir(config, false, info.OutDir);
  2161. this->ComputeOutputDir(config, true, info.ImpDir);
  2162. if(!this->ComputePDBOutputDir("PDB", config, info.PdbDir))
  2163. {
  2164. info.PdbDir = info.OutDir;
  2165. }
  2166. OutputInfoMapType::value_type entry(config_upper, info);
  2167. i = this->Internal->OutputInfoMap.insert(entry).first;
  2168. }
  2169. return &i->second;
  2170. }
  2171. //----------------------------------------------------------------------------
  2172. cmTarget::CompileInfo const* cmTarget::GetCompileInfo(const char* config) const
  2173. {
  2174. // There is no compile information for imported targets.
  2175. if(this->IsImported())
  2176. {
  2177. return 0;
  2178. }
  2179. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  2180. {
  2181. std::string msg = "cmTarget::GetCompileInfo called for ";
  2182. msg += this->GetName();
  2183. msg += " which has type ";
  2184. msg += cmTarget::GetTargetTypeName(this->GetType());
  2185. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2186. abort();
  2187. return 0;
  2188. }
  2189. // Lookup/compute/cache the compile information for this configuration.
  2190. std::string config_upper;
  2191. if(config && *config)
  2192. {
  2193. config_upper = cmSystemTools::UpperCase(config);
  2194. }
  2195. typedef cmTargetInternals::CompileInfoMapType CompileInfoMapType;
  2196. CompileInfoMapType::const_iterator i =
  2197. this->Internal->CompileInfoMap.find(config_upper);
  2198. if(i == this->Internal->CompileInfoMap.end())
  2199. {
  2200. CompileInfo info;
  2201. this->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  2202. CompileInfoMapType::value_type entry(config_upper, info);
  2203. i = this->Internal->CompileInfoMap.insert(entry).first;
  2204. }
  2205. return &i->second;
  2206. }
  2207. //----------------------------------------------------------------------------
  2208. std::string cmTarget::GetDirectory(const char* config, bool implib) const
  2209. {
  2210. if (this->IsImported())
  2211. {
  2212. // Return the directory from which the target is imported.
  2213. return
  2214. cmSystemTools::GetFilenamePath(
  2215. this->ImportedGetFullPath(config, implib));
  2216. }
  2217. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2218. {
  2219. // Return the directory in which the target will be built.
  2220. return implib? info->ImpDir : info->OutDir;
  2221. }
  2222. return "";
  2223. }
  2224. //----------------------------------------------------------------------------
  2225. std::string cmTarget::GetPDBDirectory(const char* config) const
  2226. {
  2227. if(OutputInfo const* info = this->GetOutputInfo(config))
  2228. {
  2229. // Return the directory in which the target will be built.
  2230. return info->PdbDir;
  2231. }
  2232. return "";
  2233. }
  2234. //----------------------------------------------------------------------------
  2235. std::string cmTarget::GetCompilePDBDirectory(const char* config) const
  2236. {
  2237. if(CompileInfo const* info = this->GetCompileInfo(config))
  2238. {
  2239. return info->CompilePdbDir;
  2240. }
  2241. return "";
  2242. }
  2243. //----------------------------------------------------------------------------
  2244. const char* cmTarget::GetLocation(const char* config) const
  2245. {
  2246. if (this->IsImported())
  2247. {
  2248. return this->ImportedGetLocation(config);
  2249. }
  2250. else
  2251. {
  2252. return this->NormalGetLocation(config);
  2253. }
  2254. }
  2255. //----------------------------------------------------------------------------
  2256. const char* cmTarget::ImportedGetLocation(const char* config) const
  2257. {
  2258. static std::string location;
  2259. location = this->ImportedGetFullPath(config, false);
  2260. return location.c_str();
  2261. }
  2262. //----------------------------------------------------------------------------
  2263. const char* cmTarget::NormalGetLocation(const char* config) const
  2264. {
  2265. static std::string location;
  2266. // Handle the configuration-specific case first.
  2267. if(config)
  2268. {
  2269. location = this->GetFullPath(config, false);
  2270. return location.c_str();
  2271. }
  2272. // Now handle the deprecated build-time configuration location.
  2273. location = this->GetDirectory();
  2274. if(!location.empty())
  2275. {
  2276. location += "/";
  2277. }
  2278. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2279. if(cfgid && strcmp(cfgid, ".") != 0)
  2280. {
  2281. location += "/";
  2282. location += cfgid;
  2283. location += "/";
  2284. }
  2285. if(this->IsAppBundleOnApple())
  2286. {
  2287. std::string macdir = this->BuildMacContentDirectory("", config, false);
  2288. if(!macdir.empty())
  2289. {
  2290. location += "/";
  2291. location += macdir;
  2292. }
  2293. }
  2294. location += "/";
  2295. location += this->GetFullName(config, false);
  2296. return location.c_str();
  2297. }
  2298. //----------------------------------------------------------------------------
  2299. void cmTarget::GetTargetVersion(int& major, int& minor) const
  2300. {
  2301. int patch;
  2302. this->GetTargetVersion(false, major, minor, patch);
  2303. }
  2304. //----------------------------------------------------------------------------
  2305. void cmTarget::GetTargetVersion(bool soversion,
  2306. int& major, int& minor, int& patch) const
  2307. {
  2308. // Set the default values.
  2309. major = 0;
  2310. minor = 0;
  2311. patch = 0;
  2312. assert(this->GetType() != INTERFACE_LIBRARY);
  2313. // Look for a VERSION or SOVERSION property.
  2314. const char* prop = soversion? "SOVERSION" : "VERSION";
  2315. if(const char* version = this->GetProperty(prop))
  2316. {
  2317. // Try to parse the version number and store the results that were
  2318. // successfully parsed.
  2319. int parsed_major;
  2320. int parsed_minor;
  2321. int parsed_patch;
  2322. switch(sscanf(version, "%d.%d.%d",
  2323. &parsed_major, &parsed_minor, &parsed_patch))
  2324. {
  2325. case 3: patch = parsed_patch; // no break!
  2326. case 2: minor = parsed_minor; // no break!
  2327. case 1: major = parsed_major; // no break!
  2328. default: break;
  2329. }
  2330. }
  2331. }
  2332. //----------------------------------------------------------------------------
  2333. const char* cmTarget::GetFeature(const char* feature, const char* config) const
  2334. {
  2335. if(config && *config)
  2336. {
  2337. std::string featureConfig = feature;
  2338. featureConfig += "_";
  2339. featureConfig += cmSystemTools::UpperCase(config);
  2340. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2341. {
  2342. return value;
  2343. }
  2344. }
  2345. if(const char* value = this->GetProperty(feature))
  2346. {
  2347. return value;
  2348. }
  2349. return this->Makefile->GetFeature(feature, config);
  2350. }
  2351. //----------------------------------------------------------------------------
  2352. const char *cmTarget::GetProperty(const std::string& prop) const
  2353. {
  2354. return this->GetProperty(prop, cmProperty::TARGET);
  2355. }
  2356. //----------------------------------------------------------------------------
  2357. bool cmTarget::HandleLocationPropertyPolicy() const
  2358. {
  2359. if (this->IsImported())
  2360. {
  2361. return true;
  2362. }
  2363. const char *modal = 0;
  2364. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  2365. switch (this->Makefile->GetPolicyStatus(cmPolicies::CMP0026))
  2366. {
  2367. case cmPolicies::WARN:
  2368. modal = "should";
  2369. case cmPolicies::OLD:
  2370. break;
  2371. case cmPolicies::REQUIRED_ALWAYS:
  2372. case cmPolicies::REQUIRED_IF_USED:
  2373. case cmPolicies::NEW:
  2374. modal = "may";
  2375. messageType = cmake::FATAL_ERROR;
  2376. }
  2377. if (modal)
  2378. {
  2379. cmOStringStream e;
  2380. e << (this->Makefile->GetPolicies()
  2381. ->GetPolicyWarning(cmPolicies::CMP0026)) << "\n";
  2382. e << "The LOCATION property " << modal << " not be read from target \""
  2383. << this->GetName() << "\". Use the target name directly with "
  2384. "add_custom_command, or use the generator expression $<TARGET_FILE>, "
  2385. "as appropriate.\n";
  2386. this->Makefile->IssueMessage(messageType, e.str().c_str());
  2387. }
  2388. return messageType != cmake::FATAL_ERROR;
  2389. }
  2390. //----------------------------------------------------------------------------
  2391. const char *cmTarget::GetProperty(const std::string& prop,
  2392. cmProperty::ScopeType scope) const
  2393. {
  2394. if (this->GetType() == INTERFACE_LIBRARY
  2395. && !whiteListedInterfaceProperty(prop))
  2396. {
  2397. cmOStringStream e;
  2398. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  2399. "The property \"" << prop << "\" is not allowed.";
  2400. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str());
  2401. return 0;
  2402. }
  2403. if (prop == "NAME")
  2404. {
  2405. return this->GetName();
  2406. }
  2407. // Watch for special "computed" properties that are dependent on
  2408. // other properties or variables. Always recompute them.
  2409. if(this->GetType() == cmTarget::EXECUTABLE ||
  2410. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2411. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2412. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2413. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2414. {
  2415. if(prop == "LOCATION")
  2416. {
  2417. if (!this->HandleLocationPropertyPolicy())
  2418. {
  2419. return 0;
  2420. }
  2421. // Set the LOCATION property of the target.
  2422. //
  2423. // For an imported target this is the location of an arbitrary
  2424. // available configuration.
  2425. //
  2426. // For a non-imported target this is deprecated because it
  2427. // cannot take into account the per-configuration name of the
  2428. // target because the configuration type may not be known at
  2429. // CMake time.
  2430. this->Properties.SetProperty("LOCATION", this->GetLocation(0),
  2431. cmProperty::TARGET);
  2432. }
  2433. // Support "LOCATION_<CONFIG>".
  2434. if(cmHasLiteralPrefix(prop, "LOCATION_"))
  2435. {
  2436. if (!this->HandleLocationPropertyPolicy())
  2437. {
  2438. return 0;
  2439. }
  2440. const char* configName = prop.c_str() + 9;
  2441. this->Properties.SetProperty(prop,
  2442. this->GetLocation(configName),
  2443. cmProperty::TARGET);
  2444. }
  2445. }
  2446. if(prop == "INCLUDE_DIRECTORIES")
  2447. {
  2448. static std::string output;
  2449. output = "";
  2450. std::string sep;
  2451. typedef cmTargetInternals::TargetPropertyEntry
  2452. TargetPropertyEntry;
  2453. for (std::vector<TargetPropertyEntry*>::const_iterator
  2454. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2455. end = this->Internal->IncludeDirectoriesEntries.end();
  2456. it != end; ++it)
  2457. {
  2458. output += sep;
  2459. output += (*it)->ge->GetInput();
  2460. sep = ";";
  2461. }
  2462. return output.c_str();
  2463. }
  2464. if(prop == "COMPILE_OPTIONS")
  2465. {
  2466. static std::string output;
  2467. output = "";
  2468. std::string sep;
  2469. typedef cmTargetInternals::TargetPropertyEntry
  2470. TargetPropertyEntry;
  2471. for (std::vector<TargetPropertyEntry*>::const_iterator
  2472. it = this->Internal->CompileOptionsEntries.begin(),
  2473. end = this->Internal->CompileOptionsEntries.end();
  2474. it != end; ++it)
  2475. {
  2476. output += sep;
  2477. output += (*it)->ge->GetInput();
  2478. sep = ";";
  2479. }
  2480. return output.c_str();
  2481. }
  2482. if(prop == "COMPILE_DEFINITIONS")
  2483. {
  2484. static std::string output;
  2485. output = "";
  2486. std::string sep;
  2487. typedef cmTargetInternals::TargetPropertyEntry
  2488. TargetPropertyEntry;
  2489. for (std::vector<TargetPropertyEntry*>::const_iterator
  2490. it = this->Internal->CompileDefinitionsEntries.begin(),
  2491. end = this->Internal->CompileDefinitionsEntries.end();
  2492. it != end; ++it)
  2493. {
  2494. output += sep;
  2495. output += (*it)->ge->GetInput();
  2496. sep = ";";
  2497. }
  2498. return output.c_str();
  2499. }
  2500. if(prop == "LINK_LIBRARIES")
  2501. {
  2502. static std::string output;
  2503. output = "";
  2504. std::string sep;
  2505. for (std::vector<cmValueWithOrigin>::const_iterator
  2506. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  2507. end = this->Internal->LinkImplementationPropertyEntries.end();
  2508. it != end; ++it)
  2509. {
  2510. output += sep;
  2511. output += it->Value;
  2512. sep = ";";
  2513. }
  2514. return output.c_str();
  2515. }
  2516. if (prop == "IMPORTED")
  2517. {
  2518. return this->IsImported()?"TRUE":"FALSE";
  2519. }
  2520. if(prop == "SOURCES")
  2521. {
  2522. cmOStringStream ss;
  2523. const char* sep = "";
  2524. for(std::vector<cmSourceFile*>::const_iterator
  2525. i = this->SourceFiles.begin();
  2526. i != this->SourceFiles.end(); ++i)
  2527. {
  2528. // Separate from the previous list entries.
  2529. ss << sep;
  2530. sep = ";";
  2531. // Construct what is known about this source file location.
  2532. cmSourceFileLocation const& location = (*i)->GetLocation();
  2533. std::string sname = location.GetDirectory();
  2534. if(!sname.empty())
  2535. {
  2536. sname += "/";
  2537. }
  2538. sname += location.GetName();
  2539. // Append this list entry.
  2540. ss << sname;
  2541. }
  2542. this->Properties.SetProperty("SOURCES", ss.str().c_str(),
  2543. cmProperty::TARGET);
  2544. }
  2545. // the type property returns what type the target is
  2546. if (prop == "TYPE")
  2547. {
  2548. return cmTarget::GetTargetTypeName(this->GetType());
  2549. }
  2550. bool chain = false;
  2551. const char *retVal =
  2552. this->Properties.GetPropertyValue(prop, scope, chain);
  2553. if (chain)
  2554. {
  2555. return this->Makefile->GetProperty(prop,scope);
  2556. }
  2557. return retVal;
  2558. }
  2559. //----------------------------------------------------------------------------
  2560. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  2561. {
  2562. return cmSystemTools::IsOn(this->GetProperty(prop));
  2563. }
  2564. //----------------------------------------------------------------------------
  2565. class cmTargetCollectLinkLanguages
  2566. {
  2567. public:
  2568. cmTargetCollectLinkLanguages(cmTarget const* target, const char* config,
  2569. std::set<cmStdString>& languages,
  2570. cmTarget const* head):
  2571. Config(config), Languages(languages), HeadTarget(head),
  2572. Makefile(target->GetMakefile()), Target(target)
  2573. { this->Visited.insert(target); }
  2574. void Visit(const std::string& name)
  2575. {
  2576. cmTarget *target = this->Makefile->FindTargetToUse(name);
  2577. if(!target)
  2578. {
  2579. if(name.find("::") != std::string::npos)
  2580. {
  2581. bool noMessage = false;
  2582. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2583. cmOStringStream e;
  2584. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  2585. {
  2586. case cmPolicies::WARN:
  2587. {
  2588. e << (this->Makefile->GetPolicies()
  2589. ->GetPolicyWarning(cmPolicies::CMP0028)) << "\n";
  2590. messageType = cmake::AUTHOR_WARNING;
  2591. }
  2592. break;
  2593. case cmPolicies::OLD:
  2594. noMessage = true;
  2595. case cmPolicies::REQUIRED_IF_USED:
  2596. case cmPolicies::REQUIRED_ALWAYS:
  2597. case cmPolicies::NEW:
  2598. // Issue the fatal message.
  2599. break;
  2600. }
  2601. if(!noMessage)
  2602. {
  2603. e << "Target \"" << this->Target->GetName()
  2604. << "\" links to target \"" << name
  2605. << "\" but the target was not found. Perhaps a find_package() "
  2606. "call is missing for an IMPORTED target, or an ALIAS target is "
  2607. "missing?";
  2608. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  2609. e.str(),
  2610. this->Target->GetBacktrace());
  2611. }
  2612. }
  2613. return;
  2614. }
  2615. if(!this->Visited.insert(target).second)
  2616. {
  2617. return;
  2618. }
  2619. cmTarget::LinkInterface const* iface =
  2620. target->GetLinkInterface(this->Config, this->HeadTarget);
  2621. if(!iface) { return; }
  2622. for(std::vector<std::string>::const_iterator
  2623. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2624. {
  2625. this->Languages.insert(*li);
  2626. }
  2627. for(std::vector<std::string>::const_iterator
  2628. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2629. {
  2630. this->Visit(*li);
  2631. }
  2632. }
  2633. private:
  2634. const char* Config;
  2635. std::set<cmStdString>& Languages;
  2636. cmTarget const* HeadTarget;
  2637. cmMakefile* Makefile;
  2638. const cmTarget* Target;
  2639. std::set<cmTarget const*> Visited;
  2640. };
  2641. //----------------------------------------------------------------------------
  2642. const char* cmTarget::GetLinkerLanguage(const char* config,
  2643. cmTarget const* head) const
  2644. {
  2645. cmTarget const* headTarget = head ? head : this;
  2646. const char* lang = this->GetLinkClosure(config, headTarget)
  2647. ->LinkerLanguage.c_str();
  2648. return *lang? lang : 0;
  2649. }
  2650. //----------------------------------------------------------------------------
  2651. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
  2652. cmTarget const* head) const
  2653. {
  2654. TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
  2655. cmTargetInternals::LinkClosureMapType::iterator
  2656. i = this->Internal->LinkClosureMap.find(key);
  2657. if(i == this->Internal->LinkClosureMap.end())
  2658. {
  2659. LinkClosure lc;
  2660. this->ComputeLinkClosure(config, lc, head);
  2661. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  2662. i = this->Internal->LinkClosureMap.insert(entry).first;
  2663. }
  2664. return &i->second;
  2665. }
  2666. //----------------------------------------------------------------------------
  2667. class cmTargetSelectLinker
  2668. {
  2669. int Preference;
  2670. cmTarget const* Target;
  2671. cmMakefile* Makefile;
  2672. cmGlobalGenerator* GG;
  2673. std::set<cmStdString> Preferred;
  2674. public:
  2675. cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
  2676. {
  2677. this->Makefile = this->Target->GetMakefile();
  2678. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  2679. }
  2680. void Consider(const char* lang)
  2681. {
  2682. int preference = this->GG->GetLinkerPreference(lang);
  2683. if(preference > this->Preference)
  2684. {
  2685. this->Preference = preference;
  2686. this->Preferred.clear();
  2687. }
  2688. if(preference == this->Preference)
  2689. {
  2690. this->Preferred.insert(lang);
  2691. }
  2692. }
  2693. std::string Choose()
  2694. {
  2695. if(this->Preferred.empty())
  2696. {
  2697. return "";
  2698. }
  2699. else if(this->Preferred.size() > 1)
  2700. {
  2701. cmOStringStream e;
  2702. e << "Target " << this->Target->GetName()
  2703. << " contains multiple languages with the highest linker preference"
  2704. << " (" << this->Preference << "):\n";
  2705. for(std::set<cmStdString>::const_iterator
  2706. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  2707. {
  2708. e << " " << *li << "\n";
  2709. }
  2710. e << "Set the LINKER_LANGUAGE property for this target.";
  2711. cmake* cm = this->Makefile->GetCMakeInstance();
  2712. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  2713. this->Target->GetBacktrace());
  2714. }
  2715. return *this->Preferred.begin();
  2716. }
  2717. };
  2718. //----------------------------------------------------------------------------
  2719. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
  2720. cmTarget const* head) const
  2721. {
  2722. // Get languages built in this target.
  2723. std::set<cmStdString> languages;
  2724. LinkImplementation const* impl = this->GetLinkImplementation(config, head);
  2725. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2726. li != impl->Languages.end(); ++li)
  2727. {
  2728. languages.insert(*li);
  2729. }
  2730. // Add interface languages from linked targets.
  2731. cmTargetCollectLinkLanguages cll(this, config, languages, head);
  2732. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  2733. li != impl->Libraries.end(); ++li)
  2734. {
  2735. cll.Visit(*li);
  2736. }
  2737. // Store the transitive closure of languages.
  2738. for(std::set<cmStdString>::const_iterator li = languages.begin();
  2739. li != languages.end(); ++li)
  2740. {
  2741. lc.Languages.push_back(*li);
  2742. }
  2743. // Choose the language whose linker should be used.
  2744. if(this->GetProperty("HAS_CXX"))
  2745. {
  2746. lc.LinkerLanguage = "CXX";
  2747. }
  2748. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  2749. {
  2750. lc.LinkerLanguage = linkerLang;
  2751. }
  2752. else
  2753. {
  2754. // Find the language with the highest preference value.
  2755. cmTargetSelectLinker tsl(this);
  2756. // First select from the languages compiled directly in this target.
  2757. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  2758. li != impl->Languages.end(); ++li)
  2759. {
  2760. tsl.Consider(li->c_str());
  2761. }
  2762. // Now consider languages that propagate from linked targets.
  2763. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  2764. sit != languages.end(); ++sit)
  2765. {
  2766. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  2767. if(this->Makefile->IsOn(propagates.c_str()))
  2768. {
  2769. tsl.Consider(sit->c_str());
  2770. }
  2771. }
  2772. lc.LinkerLanguage = tsl.Choose();
  2773. }
  2774. }
  2775. //----------------------------------------------------------------------------
  2776. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  2777. {
  2778. switch(this->GetType())
  2779. {
  2780. case cmTarget::STATIC_LIBRARY:
  2781. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  2782. case cmTarget::SHARED_LIBRARY:
  2783. return (implib
  2784. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2785. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  2786. case cmTarget::MODULE_LIBRARY:
  2787. return (implib
  2788. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2789. : "CMAKE_SHARED_MODULE_SUFFIX");
  2790. case cmTarget::EXECUTABLE:
  2791. return (implib
  2792. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  2793. : "CMAKE_EXECUTABLE_SUFFIX");
  2794. default:
  2795. break;
  2796. }
  2797. return "";
  2798. }
  2799. //----------------------------------------------------------------------------
  2800. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  2801. {
  2802. switch(this->GetType())
  2803. {
  2804. case cmTarget::STATIC_LIBRARY:
  2805. return "CMAKE_STATIC_LIBRARY_PREFIX";
  2806. case cmTarget::SHARED_LIBRARY:
  2807. return (implib
  2808. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2809. : "CMAKE_SHARED_LIBRARY_PREFIX");
  2810. case cmTarget::MODULE_LIBRARY:
  2811. return (implib
  2812. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  2813. : "CMAKE_SHARED_MODULE_PREFIX");
  2814. case cmTarget::EXECUTABLE:
  2815. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  2816. default:
  2817. break;
  2818. }
  2819. return "";
  2820. }
  2821. //----------------------------------------------------------------------------
  2822. std::string cmTarget::GetPDBName(const char* config) const
  2823. {
  2824. std::string prefix;
  2825. std::string base;
  2826. std::string suffix;
  2827. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2828. std::vector<std::string> props;
  2829. std::string configUpper =
  2830. cmSystemTools::UpperCase(config? config : "");
  2831. if(!configUpper.empty())
  2832. {
  2833. // PDB_NAME_<CONFIG>
  2834. props.push_back("PDB_NAME_" + configUpper);
  2835. }
  2836. // PDB_NAME
  2837. props.push_back("PDB_NAME");
  2838. for(std::vector<std::string>::const_iterator i = props.begin();
  2839. i != props.end(); ++i)
  2840. {
  2841. if(const char* outName = this->GetProperty(i->c_str()))
  2842. {
  2843. base = outName;
  2844. break;
  2845. }
  2846. }
  2847. return prefix+base+".pdb";
  2848. }
  2849. //----------------------------------------------------------------------------
  2850. std::string cmTarget::GetCompilePDBName(const char* config) const
  2851. {
  2852. std::string prefix;
  2853. std::string base;
  2854. std::string suffix;
  2855. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2856. // Check for a per-configuration output directory target property.
  2857. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  2858. std::string configProp = "COMPILE_PDB_NAME_";
  2859. configProp += configUpper;
  2860. const char* config_name = this->GetProperty(configProp.c_str());
  2861. if(config_name && *config_name)
  2862. {
  2863. return prefix + config_name + ".pdb";
  2864. }
  2865. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  2866. if(name && *name)
  2867. {
  2868. return prefix + name + ".pdb";
  2869. }
  2870. return "";
  2871. }
  2872. //----------------------------------------------------------------------------
  2873. std::string cmTarget::GetCompilePDBPath(const char* config) const
  2874. {
  2875. std::string dir = this->GetCompilePDBDirectory(config);
  2876. std::string name = this->GetCompilePDBName(config);
  2877. if(dir.empty() && !name.empty())
  2878. {
  2879. dir = this->GetPDBDirectory(config);
  2880. }
  2881. if(!dir.empty())
  2882. {
  2883. dir += "/";
  2884. }
  2885. return dir + name;
  2886. }
  2887. //----------------------------------------------------------------------------
  2888. bool cmTarget::HasSOName(const char* config) const
  2889. {
  2890. // soname is supported only for shared libraries and modules,
  2891. // and then only when the platform supports an soname flag.
  2892. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  2893. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  2894. !this->GetPropertyAsBool("NO_SONAME") &&
  2895. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
  2896. this)));
  2897. }
  2898. //----------------------------------------------------------------------------
  2899. std::string cmTarget::GetSOName(const char* config) const
  2900. {
  2901. if(this->IsImported())
  2902. {
  2903. // Lookup the imported soname.
  2904. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  2905. {
  2906. if(info->NoSOName)
  2907. {
  2908. // The imported library has no builtin soname so the name
  2909. // searched at runtime will be just the filename.
  2910. return cmSystemTools::GetFilenameName(info->Location);
  2911. }
  2912. else
  2913. {
  2914. // Use the soname given if any.
  2915. if(info->SOName.find("@rpath/") == 0)
  2916. {
  2917. return info->SOName.substr(6);
  2918. }
  2919. return info->SOName;
  2920. }
  2921. }
  2922. else
  2923. {
  2924. return "";
  2925. }
  2926. }
  2927. else
  2928. {
  2929. // Compute the soname that will be built.
  2930. std::string name;
  2931. std::string soName;
  2932. std::string realName;
  2933. std::string impName;
  2934. std::string pdbName;
  2935. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2936. return soName;
  2937. }
  2938. }
  2939. //----------------------------------------------------------------------------
  2940. bool cmTarget::HasMacOSXRpathInstallNameDir(const char* config) const
  2941. {
  2942. bool install_name_is_rpath = false;
  2943. bool macosx_rpath = false;
  2944. if(!this->IsImportedTarget)
  2945. {
  2946. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  2947. {
  2948. return false;
  2949. }
  2950. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  2951. bool use_install_name =
  2952. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  2953. if(install_name && use_install_name &&
  2954. std::string(install_name) == "@rpath")
  2955. {
  2956. install_name_is_rpath = true;
  2957. }
  2958. else if(install_name && use_install_name)
  2959. {
  2960. return false;
  2961. }
  2962. if(!install_name_is_rpath)
  2963. {
  2964. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  2965. }
  2966. }
  2967. else
  2968. {
  2969. // Lookup the imported soname.
  2970. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  2971. {
  2972. if(!info->NoSOName && !info->SOName.empty())
  2973. {
  2974. if(info->SOName.find("@rpath/") == 0)
  2975. {
  2976. install_name_is_rpath = true;
  2977. }
  2978. }
  2979. else
  2980. {
  2981. std::string install_name;
  2982. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  2983. if(install_name.find("@rpath") != std::string::npos)
  2984. {
  2985. install_name_is_rpath = true;
  2986. }
  2987. }
  2988. }
  2989. }
  2990. if(!install_name_is_rpath && !macosx_rpath)
  2991. {
  2992. return false;
  2993. }
  2994. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  2995. {
  2996. cmOStringStream w;
  2997. w << "Attempting to use";
  2998. if(macosx_rpath)
  2999. {
  3000. w << " MACOSX_RPATH";
  3001. }
  3002. else
  3003. {
  3004. w << " @rpath";
  3005. }
  3006. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  3007. w << " This could be because you are using a Mac OS X version";
  3008. w << " less than 10.5 or because CMake's platform configuration is";
  3009. w << " corrupt.";
  3010. cmake* cm = this->Makefile->GetCMakeInstance();
  3011. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  3012. }
  3013. return true;
  3014. }
  3015. //----------------------------------------------------------------------------
  3016. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3017. {
  3018. // we can't do rpaths when unsupported
  3019. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3020. {
  3021. return false;
  3022. }
  3023. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3024. if(macosx_rpath_str)
  3025. {
  3026. return this->GetPropertyAsBool("MACOSX_RPATH");
  3027. }
  3028. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3029. if(cmp0042 == cmPolicies::WARN)
  3030. {
  3031. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3032. AddCMP0042WarnTarget(this->GetName());
  3033. }
  3034. if(cmp0042 == cmPolicies::NEW)
  3035. {
  3036. return true;
  3037. }
  3038. return false;
  3039. }
  3040. //----------------------------------------------------------------------------
  3041. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config) const
  3042. {
  3043. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3044. {
  3045. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3046. {
  3047. return info->NoSOName;
  3048. }
  3049. }
  3050. return false;
  3051. }
  3052. //----------------------------------------------------------------------------
  3053. std::string cmTarget::NormalGetRealName(const char* config) const
  3054. {
  3055. // This should not be called for imported targets.
  3056. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3057. // enforcement of the limited imported target API.
  3058. if(this->IsImported())
  3059. {
  3060. std::string msg = "NormalGetRealName called on imported target: ";
  3061. msg += this->GetName();
  3062. this->GetMakefile()->
  3063. IssueMessage(cmake::INTERNAL_ERROR,
  3064. msg.c_str());
  3065. }
  3066. if(this->GetType() == cmTarget::EXECUTABLE)
  3067. {
  3068. // Compute the real name that will be built.
  3069. std::string name;
  3070. std::string realName;
  3071. std::string impName;
  3072. std::string pdbName;
  3073. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3074. return realName;
  3075. }
  3076. else
  3077. {
  3078. // Compute the real name that will be built.
  3079. std::string name;
  3080. std::string soName;
  3081. std::string realName;
  3082. std::string impName;
  3083. std::string pdbName;
  3084. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3085. return realName;
  3086. }
  3087. }
  3088. //----------------------------------------------------------------------------
  3089. std::string cmTarget::GetFullName(const char* config, bool implib) const
  3090. {
  3091. if(this->IsImported())
  3092. {
  3093. return this->GetFullNameImported(config, implib);
  3094. }
  3095. else
  3096. {
  3097. return this->GetFullNameInternal(config, implib);
  3098. }
  3099. }
  3100. //----------------------------------------------------------------------------
  3101. std::string
  3102. cmTarget::GetFullNameImported(const char* config, bool implib) const
  3103. {
  3104. return cmSystemTools::GetFilenameName(
  3105. this->ImportedGetFullPath(config, implib));
  3106. }
  3107. //----------------------------------------------------------------------------
  3108. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3109. std::string& suffix, const char* config,
  3110. bool implib) const
  3111. {
  3112. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3113. }
  3114. //----------------------------------------------------------------------------
  3115. std::string cmTarget::GetFullPath(const char* config, bool implib,
  3116. bool realname) const
  3117. {
  3118. if(this->IsImported())
  3119. {
  3120. return this->ImportedGetFullPath(config, implib);
  3121. }
  3122. else
  3123. {
  3124. return this->NormalGetFullPath(config, implib, realname);
  3125. }
  3126. }
  3127. //----------------------------------------------------------------------------
  3128. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  3129. bool realname) const
  3130. {
  3131. std::string fpath = this->GetDirectory(config, implib);
  3132. fpath += "/";
  3133. if(this->IsAppBundleOnApple())
  3134. {
  3135. fpath = this->BuildMacContentDirectory(fpath, config, false);
  3136. fpath += "/";
  3137. }
  3138. // Add the full name of the target.
  3139. if(implib)
  3140. {
  3141. fpath += this->GetFullName(config, true);
  3142. }
  3143. else if(realname)
  3144. {
  3145. fpath += this->NormalGetRealName(config);
  3146. }
  3147. else
  3148. {
  3149. fpath += this->GetFullName(config, false);
  3150. }
  3151. return fpath;
  3152. }
  3153. //----------------------------------------------------------------------------
  3154. std::string
  3155. cmTarget::ImportedGetFullPath(const char* config, bool implib) const
  3156. {
  3157. std::string result;
  3158. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3159. {
  3160. result = implib? info->ImportLibrary : info->Location;
  3161. }
  3162. if(result.empty())
  3163. {
  3164. result = this->GetName();
  3165. result += "-NOTFOUND";
  3166. }
  3167. return result;
  3168. }
  3169. //----------------------------------------------------------------------------
  3170. std::string
  3171. cmTarget::GetFullNameInternal(const char* config, bool implib) const
  3172. {
  3173. std::string prefix;
  3174. std::string base;
  3175. std::string suffix;
  3176. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3177. return prefix+base+suffix;
  3178. }
  3179. //----------------------------------------------------------------------------
  3180. void cmTarget::GetFullNameInternal(const char* config,
  3181. bool implib,
  3182. std::string& outPrefix,
  3183. std::string& outBase,
  3184. std::string& outSuffix) const
  3185. {
  3186. // Use just the target name for non-main target types.
  3187. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3188. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3189. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3190. this->GetType() != cmTarget::EXECUTABLE)
  3191. {
  3192. outPrefix = "";
  3193. outBase = this->GetName();
  3194. outSuffix = "";
  3195. return;
  3196. }
  3197. // Return an empty name for the import library if this platform
  3198. // does not support import libraries.
  3199. if(implib &&
  3200. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3201. {
  3202. outPrefix = "";
  3203. outBase = "";
  3204. outSuffix = "";
  3205. return;
  3206. }
  3207. // The implib option is only allowed for shared libraries, module
  3208. // libraries, and executables.
  3209. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3210. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3211. this->GetType() != cmTarget::EXECUTABLE)
  3212. {
  3213. implib = false;
  3214. }
  3215. // Compute the full name for main target types.
  3216. const char* targetPrefix = (implib
  3217. ? this->GetProperty("IMPORT_PREFIX")
  3218. : this->GetProperty("PREFIX"));
  3219. const char* targetSuffix = (implib
  3220. ? this->GetProperty("IMPORT_SUFFIX")
  3221. : this->GetProperty("SUFFIX"));
  3222. const char* configPostfix = 0;
  3223. if(config && *config)
  3224. {
  3225. std::string configProp = cmSystemTools::UpperCase(config);
  3226. configProp += "_POSTFIX";
  3227. configPostfix = this->GetProperty(configProp.c_str());
  3228. // Mac application bundles and frameworks have no postfix.
  3229. if(configPostfix &&
  3230. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3231. {
  3232. configPostfix = 0;
  3233. }
  3234. }
  3235. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3236. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3237. // Check for language-specific default prefix and suffix.
  3238. if(const char* ll = this->GetLinkerLanguage(config, this))
  3239. {
  3240. if(!targetSuffix && suffixVar && *suffixVar)
  3241. {
  3242. std::string langSuff = suffixVar + std::string("_") + ll;
  3243. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  3244. }
  3245. if(!targetPrefix && prefixVar && *prefixVar)
  3246. {
  3247. std::string langPrefix = prefixVar + std::string("_") + ll;
  3248. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  3249. }
  3250. }
  3251. // if there is no prefix on the target use the cmake definition
  3252. if(!targetPrefix && prefixVar)
  3253. {
  3254. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3255. }
  3256. // if there is no suffix on the target use the cmake definition
  3257. if(!targetSuffix && suffixVar)
  3258. {
  3259. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3260. }
  3261. // frameworks have directory prefix but no suffix
  3262. std::string fw_prefix;
  3263. if(this->IsFrameworkOnApple())
  3264. {
  3265. fw_prefix = this->GetOutputName(config, false);
  3266. fw_prefix += ".framework/";
  3267. targetPrefix = fw_prefix.c_str();
  3268. targetSuffix = 0;
  3269. }
  3270. if(this->IsCFBundleOnApple())
  3271. {
  3272. fw_prefix = this->GetOutputName(config, false);
  3273. fw_prefix += ".";
  3274. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  3275. if (!ext)
  3276. {
  3277. ext = "bundle";
  3278. }
  3279. fw_prefix += ext;
  3280. fw_prefix += "/Contents/MacOS/";
  3281. targetPrefix = fw_prefix.c_str();
  3282. targetSuffix = 0;
  3283. }
  3284. // Begin the final name with the prefix.
  3285. outPrefix = targetPrefix?targetPrefix:"";
  3286. // Append the target name or property-specified name.
  3287. outBase += this->GetOutputName(config, implib);
  3288. // Append the per-configuration postfix.
  3289. outBase += configPostfix?configPostfix:"";
  3290. // Name shared libraries with their version number on some platforms.
  3291. if(const char* soversion = this->GetProperty("SOVERSION"))
  3292. {
  3293. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3294. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3295. {
  3296. outBase += "-";
  3297. outBase += soversion;
  3298. }
  3299. }
  3300. // Append the suffix.
  3301. outSuffix = targetSuffix?targetSuffix:"";
  3302. }
  3303. //----------------------------------------------------------------------------
  3304. void cmTarget::GetLibraryNames(std::string& name,
  3305. std::string& soName,
  3306. std::string& realName,
  3307. std::string& impName,
  3308. std::string& pdbName,
  3309. const char* config) const
  3310. {
  3311. // This should not be called for imported targets.
  3312. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3313. // enforcement of the limited imported target API.
  3314. if(this->IsImported())
  3315. {
  3316. std::string msg = "GetLibraryNames called on imported target: ";
  3317. msg += this->GetName();
  3318. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3319. msg.c_str());
  3320. return;
  3321. }
  3322. assert(this->GetType() != INTERFACE_LIBRARY);
  3323. // Check for library version properties.
  3324. const char* version = this->GetProperty("VERSION");
  3325. const char* soversion = this->GetProperty("SOVERSION");
  3326. if(!this->HasSOName(config) ||
  3327. this->IsFrameworkOnApple())
  3328. {
  3329. // Versioning is supported only for shared libraries and modules,
  3330. // and then only when the platform supports an soname flag.
  3331. version = 0;
  3332. soversion = 0;
  3333. }
  3334. if(version && !soversion)
  3335. {
  3336. // The soversion must be set if the library version is set. Use
  3337. // the library version as the soversion.
  3338. soversion = version;
  3339. }
  3340. if(!version && soversion)
  3341. {
  3342. // Use the soversion as the library version.
  3343. version = soversion;
  3344. }
  3345. // Get the components of the library name.
  3346. std::string prefix;
  3347. std::string base;
  3348. std::string suffix;
  3349. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3350. // The library name.
  3351. name = prefix+base+suffix;
  3352. if(this->IsFrameworkOnApple())
  3353. {
  3354. realName = prefix;
  3355. realName += "Versions/";
  3356. realName += this->GetFrameworkVersion();
  3357. realName += "/";
  3358. realName += base;
  3359. soName = realName;
  3360. }
  3361. else
  3362. {
  3363. // The library's soname.
  3364. this->ComputeVersionedName(soName, prefix, base, suffix,
  3365. name, soversion);
  3366. // The library's real name on disk.
  3367. this->ComputeVersionedName(realName, prefix, base, suffix,
  3368. name, version);
  3369. }
  3370. // The import library name.
  3371. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3372. this->GetType() == cmTarget::MODULE_LIBRARY)
  3373. {
  3374. impName = this->GetFullNameInternal(config, true);
  3375. }
  3376. else
  3377. {
  3378. impName = "";
  3379. }
  3380. // The program database file name.
  3381. pdbName = this->GetPDBName(config);
  3382. }
  3383. //----------------------------------------------------------------------------
  3384. void cmTarget::ComputeVersionedName(std::string& vName,
  3385. std::string const& prefix,
  3386. std::string const& base,
  3387. std::string const& suffix,
  3388. std::string const& name,
  3389. const char* version) const
  3390. {
  3391. vName = this->IsApple? (prefix+base) : name;
  3392. if(version)
  3393. {
  3394. vName += ".";
  3395. vName += version;
  3396. }
  3397. vName += this->IsApple? suffix : std::string();
  3398. }
  3399. //----------------------------------------------------------------------------
  3400. void cmTarget::GetExecutableNames(std::string& name,
  3401. std::string& realName,
  3402. std::string& impName,
  3403. std::string& pdbName,
  3404. const char* config) const
  3405. {
  3406. // This should not be called for imported targets.
  3407. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3408. // enforcement of the limited imported target API.
  3409. if(this->IsImported())
  3410. {
  3411. std::string msg =
  3412. "GetExecutableNames called on imported target: ";
  3413. msg += this->GetName();
  3414. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3415. }
  3416. // This versioning is supported only for executables and then only
  3417. // when the platform supports symbolic links.
  3418. #if defined(_WIN32) && !defined(__CYGWIN__)
  3419. const char* version = 0;
  3420. #else
  3421. // Check for executable version properties.
  3422. const char* version = this->GetProperty("VERSION");
  3423. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3424. {
  3425. version = 0;
  3426. }
  3427. #endif
  3428. // Get the components of the executable name.
  3429. std::string prefix;
  3430. std::string base;
  3431. std::string suffix;
  3432. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3433. // The executable name.
  3434. name = prefix+base+suffix;
  3435. // The executable's real name on disk.
  3436. #if defined(__CYGWIN__)
  3437. realName = prefix+base;
  3438. #else
  3439. realName = name;
  3440. #endif
  3441. if(version)
  3442. {
  3443. realName += "-";
  3444. realName += version;
  3445. }
  3446. #if defined(__CYGWIN__)
  3447. realName += suffix;
  3448. #endif
  3449. // The import library name.
  3450. impName = this->GetFullNameInternal(config, true);
  3451. // The program database file name.
  3452. pdbName = this->GetPDBName(config);
  3453. }
  3454. //----------------------------------------------------------------------------
  3455. bool cmTarget::HasImplibGNUtoMS() const
  3456. {
  3457. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3458. }
  3459. //----------------------------------------------------------------------------
  3460. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3461. std::string& out, const char* newExt) const
  3462. {
  3463. if(this->HasImplibGNUtoMS() &&
  3464. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3465. {
  3466. out = gnuName.substr(0, gnuName.size()-6);
  3467. out += newExt? newExt : ".lib";
  3468. return true;
  3469. }
  3470. return false;
  3471. }
  3472. //----------------------------------------------------------------------------
  3473. void cmTarget::SetPropertyDefault(const std::string& property,
  3474. const char* default_value)
  3475. {
  3476. // Compute the name of the variable holding the default value.
  3477. std::string var = "CMAKE_";
  3478. var += property;
  3479. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3480. {
  3481. this->SetProperty(property, value);
  3482. }
  3483. else if(default_value)
  3484. {
  3485. this->SetProperty(property, default_value);
  3486. }
  3487. }
  3488. //----------------------------------------------------------------------------
  3489. bool cmTarget::HaveBuildTreeRPATH(const char *config) const
  3490. {
  3491. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3492. {
  3493. return false;
  3494. }
  3495. std::vector<std::string> libs;
  3496. this->GetDirectLinkLibraries(config, libs, this);
  3497. return !libs.empty();
  3498. }
  3499. //----------------------------------------------------------------------------
  3500. bool cmTarget::HaveInstallTreeRPATH() const
  3501. {
  3502. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3503. return (install_rpath && *install_rpath) &&
  3504. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3505. }
  3506. //----------------------------------------------------------------------------
  3507. bool cmTarget::NeedRelinkBeforeInstall(const char* config) const
  3508. {
  3509. // Only executables and shared libraries can have an rpath and may
  3510. // need relinking.
  3511. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3512. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3513. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3514. {
  3515. return false;
  3516. }
  3517. // If there is no install location this target will not be installed
  3518. // and therefore does not need relinking.
  3519. if(!this->GetHaveInstallRule())
  3520. {
  3521. return false;
  3522. }
  3523. // If skipping all rpaths completely then no relinking is needed.
  3524. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3525. {
  3526. return false;
  3527. }
  3528. // If building with the install-tree rpath no relinking is needed.
  3529. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3530. {
  3531. return false;
  3532. }
  3533. // If chrpath is going to be used no relinking is needed.
  3534. if(this->IsChrpathUsed(config))
  3535. {
  3536. return false;
  3537. }
  3538. // Check for rpath support on this platform.
  3539. if(const char* ll = this->GetLinkerLanguage(config, this))
  3540. {
  3541. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3542. flagVar += ll;
  3543. flagVar += "_FLAG";
  3544. if(!this->Makefile->IsSet(flagVar.c_str()))
  3545. {
  3546. // There is no rpath support on this platform so nothing needs
  3547. // relinking.
  3548. return false;
  3549. }
  3550. }
  3551. else
  3552. {
  3553. // No linker language is known. This error will be reported by
  3554. // other code.
  3555. return false;
  3556. }
  3557. // If either a build or install tree rpath is set then the rpath
  3558. // will likely change between the build tree and install tree and
  3559. // this target must be relinked.
  3560. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  3561. }
  3562. //----------------------------------------------------------------------------
  3563. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config) const
  3564. {
  3565. // If building directly for installation then the build tree install_name
  3566. // is the same as the install tree.
  3567. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3568. {
  3569. return GetInstallNameDirForInstallTree();
  3570. }
  3571. // Use the build tree directory for the target.
  3572. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3573. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3574. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3575. {
  3576. std::string dir;
  3577. bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3578. if(macosx_rpath)
  3579. {
  3580. dir = "@rpath";
  3581. }
  3582. else
  3583. {
  3584. dir = this->GetDirectory(config);
  3585. }
  3586. dir += "/";
  3587. return dir;
  3588. }
  3589. else
  3590. {
  3591. return "";
  3592. }
  3593. }
  3594. //----------------------------------------------------------------------------
  3595. std::string cmTarget::GetInstallNameDirForInstallTree() const
  3596. {
  3597. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3598. {
  3599. std::string dir;
  3600. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3601. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3602. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  3603. {
  3604. if(install_name_dir && *install_name_dir)
  3605. {
  3606. dir = install_name_dir;
  3607. dir += "/";
  3608. }
  3609. }
  3610. if(!install_name_dir)
  3611. {
  3612. if(this->MacOSXRpathInstallNameDirDefault())
  3613. {
  3614. dir = "@rpath/";
  3615. }
  3616. }
  3617. return dir;
  3618. }
  3619. else
  3620. {
  3621. return "";
  3622. }
  3623. }
  3624. //----------------------------------------------------------------------------
  3625. const char* cmTarget::GetOutputTargetType(bool implib) const
  3626. {
  3627. switch(this->GetType())
  3628. {
  3629. case cmTarget::SHARED_LIBRARY:
  3630. if(this->DLLPlatform)
  3631. {
  3632. if(implib)
  3633. {
  3634. // A DLL import library is treated as an archive target.
  3635. return "ARCHIVE";
  3636. }
  3637. else
  3638. {
  3639. // A DLL shared library is treated as a runtime target.
  3640. return "RUNTIME";
  3641. }
  3642. }
  3643. else
  3644. {
  3645. // For non-DLL platforms shared libraries are treated as
  3646. // library targets.
  3647. return "LIBRARY";
  3648. }
  3649. case cmTarget::STATIC_LIBRARY:
  3650. // Static libraries are always treated as archive targets.
  3651. return "ARCHIVE";
  3652. case cmTarget::MODULE_LIBRARY:
  3653. if(implib)
  3654. {
  3655. // Module libraries are always treated as library targets.
  3656. return "ARCHIVE";
  3657. }
  3658. else
  3659. {
  3660. // Module import libraries are treated as archive targets.
  3661. return "LIBRARY";
  3662. }
  3663. case cmTarget::EXECUTABLE:
  3664. if(implib)
  3665. {
  3666. // Executable import libraries are treated as archive targets.
  3667. return "ARCHIVE";
  3668. }
  3669. else
  3670. {
  3671. // Executables are always treated as runtime targets.
  3672. return "RUNTIME";
  3673. }
  3674. default:
  3675. break;
  3676. }
  3677. return "";
  3678. }
  3679. //----------------------------------------------------------------------------
  3680. bool cmTarget::ComputeOutputDir(const char* config,
  3681. bool implib, std::string& out) const
  3682. {
  3683. bool usesDefaultOutputDir = false;
  3684. // Look for a target property defining the target output directory
  3685. // based on the target type.
  3686. std::string targetTypeName = this->GetOutputTargetType(implib);
  3687. const char* propertyName = 0;
  3688. std::string propertyNameStr = targetTypeName;
  3689. if(!propertyNameStr.empty())
  3690. {
  3691. propertyNameStr += "_OUTPUT_DIRECTORY";
  3692. propertyName = propertyNameStr.c_str();
  3693. }
  3694. // Check for a per-configuration output directory target property.
  3695. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3696. const char* configProp = 0;
  3697. std::string configPropStr = targetTypeName;
  3698. if(!configPropStr.empty())
  3699. {
  3700. configPropStr += "_OUTPUT_DIRECTORY_";
  3701. configPropStr += configUpper;
  3702. configProp = configPropStr.c_str();
  3703. }
  3704. // Select an output directory.
  3705. if(const char* config_outdir = this->GetProperty(configProp))
  3706. {
  3707. // Use the user-specified per-configuration output directory.
  3708. out = config_outdir;
  3709. // Skip per-configuration subdirectory.
  3710. config = 0;
  3711. }
  3712. else if(const char* outdir = this->GetProperty(propertyName))
  3713. {
  3714. // Use the user-specified output directory.
  3715. out = outdir;
  3716. }
  3717. else if(this->GetType() == cmTarget::EXECUTABLE)
  3718. {
  3719. // Lookup the output path for executables.
  3720. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3721. }
  3722. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3723. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3724. this->GetType() == cmTarget::MODULE_LIBRARY)
  3725. {
  3726. // Lookup the output path for libraries.
  3727. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3728. }
  3729. if(out.empty())
  3730. {
  3731. // Default to the current output directory.
  3732. usesDefaultOutputDir = true;
  3733. out = ".";
  3734. }
  3735. // Convert the output path to a full path in case it is
  3736. // specified as a relative path. Treat a relative path as
  3737. // relative to the current output directory for this makefile.
  3738. out = (cmSystemTools::CollapseFullPath
  3739. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3740. // The generator may add the configuration's subdirectory.
  3741. if(config && *config)
  3742. {
  3743. const char *platforms = this->Makefile->GetDefinition(
  3744. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3745. std::string suffix =
  3746. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3747. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3748. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  3749. }
  3750. return usesDefaultOutputDir;
  3751. }
  3752. //----------------------------------------------------------------------------
  3753. bool cmTarget::ComputePDBOutputDir(const char* kind, const char* config,
  3754. std::string& out) const
  3755. {
  3756. // Look for a target property defining the target output directory
  3757. // based on the target type.
  3758. const char* propertyName = 0;
  3759. std::string propertyNameStr = kind;
  3760. if(!propertyNameStr.empty())
  3761. {
  3762. propertyNameStr += "_OUTPUT_DIRECTORY";
  3763. propertyName = propertyNameStr.c_str();
  3764. }
  3765. // Check for a per-configuration output directory target property.
  3766. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3767. const char* configProp = 0;
  3768. std::string configPropStr = kind;
  3769. if(!configPropStr.empty())
  3770. {
  3771. configPropStr += "_OUTPUT_DIRECTORY_";
  3772. configPropStr += configUpper;
  3773. configProp = configPropStr.c_str();
  3774. }
  3775. // Select an output directory.
  3776. if(const char* config_outdir = this->GetProperty(configProp))
  3777. {
  3778. // Use the user-specified per-configuration output directory.
  3779. out = config_outdir;
  3780. // Skip per-configuration subdirectory.
  3781. config = 0;
  3782. }
  3783. else if(const char* outdir = this->GetProperty(propertyName))
  3784. {
  3785. // Use the user-specified output directory.
  3786. out = outdir;
  3787. }
  3788. if(out.empty())
  3789. {
  3790. return false;
  3791. }
  3792. // Convert the output path to a full path in case it is
  3793. // specified as a relative path. Treat a relative path as
  3794. // relative to the current output directory for this makefile.
  3795. out = (cmSystemTools::CollapseFullPath
  3796. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3797. // The generator may add the configuration's subdirectory.
  3798. if(config && *config)
  3799. {
  3800. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3801. AppendDirectoryForConfig("/", config, "", out);
  3802. }
  3803. return true;
  3804. }
  3805. //----------------------------------------------------------------------------
  3806. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib) const
  3807. {
  3808. std::string dir;
  3809. return this->ComputeOutputDir(config, implib, dir);
  3810. }
  3811. //----------------------------------------------------------------------------
  3812. std::string cmTarget::GetOutputName(const char* config, bool implib) const
  3813. {
  3814. std::vector<std::string> props;
  3815. std::string type = this->GetOutputTargetType(implib);
  3816. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3817. if(!type.empty() && !configUpper.empty())
  3818. {
  3819. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  3820. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  3821. }
  3822. if(!type.empty())
  3823. {
  3824. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  3825. props.push_back(type + "_OUTPUT_NAME");
  3826. }
  3827. if(!configUpper.empty())
  3828. {
  3829. // OUTPUT_NAME_<CONFIG>
  3830. props.push_back("OUTPUT_NAME_" + configUpper);
  3831. // <CONFIG>_OUTPUT_NAME
  3832. props.push_back(configUpper + "_OUTPUT_NAME");
  3833. }
  3834. // OUTPUT_NAME
  3835. props.push_back("OUTPUT_NAME");
  3836. for(std::vector<std::string>::const_iterator i = props.begin();
  3837. i != props.end(); ++i)
  3838. {
  3839. if(const char* outName = this->GetProperty(i->c_str()))
  3840. {
  3841. return outName;
  3842. }
  3843. }
  3844. return this->GetName();
  3845. }
  3846. //----------------------------------------------------------------------------
  3847. std::string cmTarget::GetFrameworkVersion() const
  3848. {
  3849. assert(this->GetType() != INTERFACE_LIBRARY);
  3850. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  3851. {
  3852. return fversion;
  3853. }
  3854. else if(const char* tversion = this->GetProperty("VERSION"))
  3855. {
  3856. return tversion;
  3857. }
  3858. else
  3859. {
  3860. return "A";
  3861. }
  3862. }
  3863. //----------------------------------------------------------------------------
  3864. const char* cmTarget::GetExportMacro() const
  3865. {
  3866. // Define the symbol for targets that export symbols.
  3867. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3868. this->GetType() == cmTarget::MODULE_LIBRARY ||
  3869. this->IsExecutableWithExports())
  3870. {
  3871. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  3872. {
  3873. this->ExportMacro = custom_export_name;
  3874. }
  3875. else
  3876. {
  3877. std::string in = this->GetName();
  3878. in += "_EXPORTS";
  3879. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  3880. }
  3881. return this->ExportMacro.c_str();
  3882. }
  3883. else
  3884. {
  3885. return 0;
  3886. }
  3887. }
  3888. //----------------------------------------------------------------------------
  3889. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  3890. {
  3891. return this->LinkImplicitNullProperties.find(p)
  3892. != this->LinkImplicitNullProperties.end();
  3893. }
  3894. //----------------------------------------------------------------------------
  3895. template<typename PropertyType>
  3896. PropertyType getTypedProperty(cmTarget const* tgt, const char *prop,
  3897. PropertyType *);
  3898. //----------------------------------------------------------------------------
  3899. template<>
  3900. bool getTypedProperty<bool>(cmTarget const* tgt, const char *prop, bool *)
  3901. {
  3902. return tgt->GetPropertyAsBool(prop);
  3903. }
  3904. //----------------------------------------------------------------------------
  3905. template<>
  3906. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  3907. const char *prop,
  3908. const char **)
  3909. {
  3910. return tgt->GetProperty(prop);
  3911. }
  3912. enum CompatibleType
  3913. {
  3914. BoolType,
  3915. StringType,
  3916. NumberMinType,
  3917. NumberMaxType
  3918. };
  3919. //----------------------------------------------------------------------------
  3920. template<typename PropertyType>
  3921. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3922. PropertyType rhs,
  3923. CompatibleType t);
  3924. //----------------------------------------------------------------------------
  3925. template<>
  3926. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  3927. {
  3928. return std::make_pair(lhs == rhs, lhs);
  3929. }
  3930. //----------------------------------------------------------------------------
  3931. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  3932. const char *rhs)
  3933. {
  3934. const bool b = strcmp(lhs, rhs) == 0;
  3935. return std::make_pair(b, b ? lhs : 0);
  3936. }
  3937. #if defined(_MSC_VER) && _MSC_VER <= 1200
  3938. template<typename T> const T&
  3939. cmMaximum(const T& l, const T& r) {return l > r ? l : r;}
  3940. template<typename T> const T&
  3941. cmMinimum(const T& l, const T& r) {return l < r ? l : r;}
  3942. #else
  3943. #define cmMinimum std::min
  3944. #define cmMaximum std::max
  3945. #endif
  3946. //----------------------------------------------------------------------------
  3947. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  3948. const char *rhs,
  3949. CompatibleType t)
  3950. {
  3951. char *pEnd;
  3952. #if defined(_MSC_VER)
  3953. static const char* const null_ptr = 0;
  3954. #else
  3955. # define null_ptr 0
  3956. #endif
  3957. long lnum = strtol(lhs, &pEnd, 0);
  3958. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  3959. {
  3960. return std::pair<bool, const char*>(false, null_ptr);
  3961. }
  3962. long rnum = strtol(rhs, &pEnd, 0);
  3963. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  3964. {
  3965. return std::pair<bool, const char*>(false, null_ptr);
  3966. }
  3967. #if !defined(_MSC_VER)
  3968. #undef null_ptr
  3969. #endif
  3970. if (t == NumberMaxType)
  3971. {
  3972. return std::make_pair(true, cmMaximum(lnum, rnum) == lnum ? lhs : rhs);
  3973. }
  3974. else
  3975. {
  3976. return std::make_pair(true, cmMinimum(lnum, rnum) == lnum ? lhs : rhs);
  3977. }
  3978. }
  3979. //----------------------------------------------------------------------------
  3980. template<>
  3981. std::pair<bool, const char*> consistentProperty(const char *lhs,
  3982. const char *rhs,
  3983. CompatibleType t)
  3984. {
  3985. if (!lhs && !rhs)
  3986. {
  3987. return std::make_pair(true, lhs);
  3988. }
  3989. if (!lhs)
  3990. {
  3991. return std::make_pair(true, rhs);
  3992. }
  3993. if (!rhs)
  3994. {
  3995. return std::make_pair(true, lhs);
  3996. }
  3997. #if defined(_MSC_VER)
  3998. static const char* const null_ptr = 0;
  3999. #else
  4000. # define null_ptr 0
  4001. #endif
  4002. switch(t)
  4003. {
  4004. case BoolType:
  4005. assert(!"consistentProperty for strings called with BoolType");
  4006. return std::pair<bool, const char*>(false, null_ptr);
  4007. case StringType:
  4008. return consistentStringProperty(lhs, rhs);
  4009. case NumberMinType:
  4010. case NumberMaxType:
  4011. return consistentNumberProperty(lhs, rhs, t);
  4012. }
  4013. assert(!"Unreachable!");
  4014. return std::pair<bool, const char*>(false, null_ptr);
  4015. #if !defined(_MSC_VER)
  4016. #undef null_ptr
  4017. #endif
  4018. }
  4019. template<typename PropertyType>
  4020. PropertyType impliedValue(PropertyType);
  4021. template<>
  4022. bool impliedValue<bool>(bool)
  4023. {
  4024. return false;
  4025. }
  4026. template<>
  4027. const char* impliedValue<const char*>(const char*)
  4028. {
  4029. return "";
  4030. }
  4031. template<typename PropertyType>
  4032. std::string valueAsString(PropertyType);
  4033. template<>
  4034. std::string valueAsString<bool>(bool value)
  4035. {
  4036. return value ? "TRUE" : "FALSE";
  4037. }
  4038. template<>
  4039. std::string valueAsString<const char*>(const char* value)
  4040. {
  4041. return value ? value : "(unset)";
  4042. }
  4043. //----------------------------------------------------------------------------
  4044. void
  4045. cmTarget::ReportPropertyOrigin(const std::string &p,
  4046. const std::string &result,
  4047. const std::string &report,
  4048. const std::string &compatibilityType) const
  4049. {
  4050. std::vector<std::string> debugProperties;
  4051. const char *debugProp =
  4052. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4053. if (debugProp)
  4054. {
  4055. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4056. }
  4057. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4058. && std::find(debugProperties.begin(),
  4059. debugProperties.end(),
  4060. p)
  4061. != debugProperties.end();
  4062. if (this->Makefile->IsGeneratingBuildSystem())
  4063. {
  4064. this->DebugCompatiblePropertiesDone[p] = true;
  4065. }
  4066. if (!debugOrigin)
  4067. {
  4068. return;
  4069. }
  4070. std::string areport = compatibilityType;
  4071. areport += std::string(" of property \"") + p + "\" for target \"";
  4072. areport += std::string(this->GetName());
  4073. areport += "\" (result: \"";
  4074. areport += result;
  4075. areport += "\"):\n" + report;
  4076. cmListFileBacktrace lfbt;
  4077. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport, lfbt);
  4078. }
  4079. //----------------------------------------------------------------------------
  4080. std::string compatibilityType(CompatibleType t)
  4081. {
  4082. switch(t)
  4083. {
  4084. case BoolType:
  4085. return "Boolean compatibility";
  4086. case StringType:
  4087. return "String compatibility";
  4088. case NumberMaxType:
  4089. return "Numeric maximum compatibility";
  4090. case NumberMinType:
  4091. return "Numeric minimum compatibility";
  4092. }
  4093. assert(!"Unreachable!");
  4094. return "";
  4095. }
  4096. //----------------------------------------------------------------------------
  4097. std::string compatibilityAgree(CompatibleType t, bool dominant)
  4098. {
  4099. switch(t)
  4100. {
  4101. case BoolType:
  4102. case StringType:
  4103. return dominant ? "(Disagree)\n" : "(Agree)\n";
  4104. case NumberMaxType:
  4105. case NumberMinType:
  4106. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  4107. }
  4108. assert(!"Unreachable!");
  4109. return "";
  4110. }
  4111. //----------------------------------------------------------------------------
  4112. template<typename PropertyType>
  4113. PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
  4114. const std::string &p,
  4115. const char *config,
  4116. const char *defaultValue,
  4117. CompatibleType t,
  4118. PropertyType *)
  4119. {
  4120. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
  4121. 0);
  4122. const bool explicitlySet = tgt->GetProperties()
  4123. .find(p.c_str())
  4124. != tgt->GetProperties().end();
  4125. const bool impliedByUse =
  4126. tgt->IsNullImpliedByLinkLibraries(p);
  4127. assert((impliedByUse ^ explicitlySet)
  4128. || (!impliedByUse && !explicitlySet));
  4129. std::vector<cmTarget*> deps;
  4130. tgt->GetTransitiveTargetClosure(config, tgt, deps);
  4131. if(deps.empty())
  4132. {
  4133. return propContent;
  4134. }
  4135. bool propInitialized = explicitlySet;
  4136. std::string report = " * Target \"";
  4137. report += tgt->GetName();
  4138. if (explicitlySet)
  4139. {
  4140. report += "\" has property content \"";
  4141. report += valueAsString<PropertyType>(propContent);
  4142. report += "\"\n";
  4143. }
  4144. else if (impliedByUse)
  4145. {
  4146. report += "\" property is implied by use.\n";
  4147. }
  4148. else
  4149. {
  4150. report += "\" property not set.\n";
  4151. }
  4152. for(std::vector<cmTarget*>::const_iterator li =
  4153. deps.begin();
  4154. li != deps.end(); ++li)
  4155. {
  4156. // An error should be reported if one dependency
  4157. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4158. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4159. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4160. // with a dependency.
  4161. cmTarget const* theTarget = *li;
  4162. const bool ifaceIsSet = theTarget->GetProperties()
  4163. .find("INTERFACE_" + p)
  4164. != theTarget->GetProperties().end();
  4165. PropertyType ifacePropContent =
  4166. getTypedProperty<PropertyType>(theTarget,
  4167. ("INTERFACE_" + p).c_str(), 0);
  4168. std::string reportEntry;
  4169. if (ifaceIsSet)
  4170. {
  4171. reportEntry += " * Target \"";
  4172. reportEntry += theTarget->GetName();
  4173. reportEntry += "\" property value \"";
  4174. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4175. reportEntry += "\" ";
  4176. }
  4177. if (explicitlySet)
  4178. {
  4179. if (ifaceIsSet)
  4180. {
  4181. std::pair<bool, PropertyType> consistent =
  4182. consistentProperty(propContent,
  4183. ifacePropContent, t);
  4184. report += reportEntry;
  4185. report += compatibilityAgree(t, propContent != consistent.second);
  4186. if (!consistent.first)
  4187. {
  4188. cmOStringStream e;
  4189. e << "Property " << p << " on target \""
  4190. << tgt->GetName() << "\" does\nnot match the "
  4191. "INTERFACE_" << p << " property requirement\nof "
  4192. "dependency \"" << theTarget->GetName() << "\".\n";
  4193. cmSystemTools::Error(e.str().c_str());
  4194. break;
  4195. }
  4196. else
  4197. {
  4198. propContent = consistent.second;
  4199. continue;
  4200. }
  4201. }
  4202. else
  4203. {
  4204. // Explicitly set on target and not set in iface. Can't disagree.
  4205. continue;
  4206. }
  4207. }
  4208. else if (impliedByUse)
  4209. {
  4210. propContent = impliedValue<PropertyType>(propContent);
  4211. if (ifaceIsSet)
  4212. {
  4213. std::pair<bool, PropertyType> consistent =
  4214. consistentProperty(propContent,
  4215. ifacePropContent, t);
  4216. report += reportEntry;
  4217. report += compatibilityAgree(t, propContent != consistent.second);
  4218. if (!consistent.first)
  4219. {
  4220. cmOStringStream e;
  4221. e << "Property " << p << " on target \""
  4222. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4223. << " because it was used to determine the link libraries\n"
  4224. "already. The INTERFACE_" << p << " property on\ndependency \""
  4225. << theTarget->GetName() << "\" is in conflict.\n";
  4226. cmSystemTools::Error(e.str().c_str());
  4227. break;
  4228. }
  4229. else
  4230. {
  4231. propContent = consistent.second;
  4232. continue;
  4233. }
  4234. }
  4235. else
  4236. {
  4237. // Implicitly set on target and not set in iface. Can't disagree.
  4238. continue;
  4239. }
  4240. }
  4241. else
  4242. {
  4243. if (ifaceIsSet)
  4244. {
  4245. if (propInitialized)
  4246. {
  4247. std::pair<bool, PropertyType> consistent =
  4248. consistentProperty(propContent,
  4249. ifacePropContent, t);
  4250. report += reportEntry;
  4251. report += compatibilityAgree(t, propContent != consistent.second);
  4252. if (!consistent.first)
  4253. {
  4254. cmOStringStream e;
  4255. e << "The INTERFACE_" << p << " property of \""
  4256. << theTarget->GetName() << "\" does\nnot agree with the value "
  4257. "of " << p << " already determined\nfor \""
  4258. << tgt->GetName() << "\".\n";
  4259. cmSystemTools::Error(e.str().c_str());
  4260. break;
  4261. }
  4262. else
  4263. {
  4264. propContent = consistent.second;
  4265. continue;
  4266. }
  4267. }
  4268. else
  4269. {
  4270. report += reportEntry + "(Interface set)\n";
  4271. propContent = ifacePropContent;
  4272. propInitialized = true;
  4273. }
  4274. }
  4275. else
  4276. {
  4277. // Not set. Nothing to agree on.
  4278. continue;
  4279. }
  4280. }
  4281. }
  4282. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4283. report, compatibilityType(t));
  4284. return propContent;
  4285. }
  4286. //----------------------------------------------------------------------------
  4287. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4288. const char *config) const
  4289. {
  4290. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4291. BoolType, 0);
  4292. }
  4293. //----------------------------------------------------------------------------
  4294. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4295. const std::string &p,
  4296. const char *config) const
  4297. {
  4298. return checkInterfacePropertyCompatibility<const char *>(this,
  4299. p,
  4300. config,
  4301. "empty",
  4302. StringType, 0);
  4303. }
  4304. //----------------------------------------------------------------------------
  4305. const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
  4306. const std::string &p,
  4307. const char *config) const
  4308. {
  4309. return checkInterfacePropertyCompatibility<const char *>(this,
  4310. p,
  4311. config,
  4312. "empty",
  4313. NumberMinType, 0);
  4314. }
  4315. //----------------------------------------------------------------------------
  4316. const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4317. const std::string &p,
  4318. const char *config) const
  4319. {
  4320. return checkInterfacePropertyCompatibility<const char *>(this,
  4321. p,
  4322. config,
  4323. "empty",
  4324. NumberMaxType, 0);
  4325. }
  4326. //----------------------------------------------------------------------------
  4327. bool isLinkDependentProperty(cmTarget const* tgt, const std::string &p,
  4328. const std::string& interfaceProperty,
  4329. const char *config)
  4330. {
  4331. std::vector<cmTarget*> deps;
  4332. tgt->GetTransitiveTargetClosure(config, tgt, deps);
  4333. if(deps.empty())
  4334. {
  4335. return false;
  4336. }
  4337. for(std::vector<cmTarget*>::const_iterator li =
  4338. deps.begin();
  4339. li != deps.end(); ++li)
  4340. {
  4341. const char *prop = (*li)->GetProperty(interfaceProperty);
  4342. if (!prop)
  4343. {
  4344. continue;
  4345. }
  4346. std::vector<std::string> props;
  4347. cmSystemTools::ExpandListArgument(prop, props);
  4348. for(std::vector<std::string>::iterator pi = props.begin();
  4349. pi != props.end(); ++pi)
  4350. {
  4351. if (*pi == p)
  4352. {
  4353. return true;
  4354. }
  4355. }
  4356. }
  4357. return false;
  4358. }
  4359. //----------------------------------------------------------------------------
  4360. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4361. const char *config) const
  4362. {
  4363. if (this->TargetTypeValue == OBJECT_LIBRARY
  4364. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4365. {
  4366. return false;
  4367. }
  4368. return (p == "POSITION_INDEPENDENT_CODE") ||
  4369. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
  4370. config);
  4371. }
  4372. //----------------------------------------------------------------------------
  4373. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4374. const char *config) const
  4375. {
  4376. if (this->TargetTypeValue == OBJECT_LIBRARY
  4377. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4378. {
  4379. return false;
  4380. }
  4381. return (p == "AUTOUIC_OPTIONS") ||
  4382. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
  4383. config);
  4384. }
  4385. //----------------------------------------------------------------------------
  4386. bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  4387. const char *config) const
  4388. {
  4389. if (this->TargetTypeValue == OBJECT_LIBRARY
  4390. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4391. {
  4392. return false;
  4393. }
  4394. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  4395. config);
  4396. }
  4397. //----------------------------------------------------------------------------
  4398. bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  4399. const char *config) const
  4400. {
  4401. if (this->TargetTypeValue == OBJECT_LIBRARY
  4402. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4403. {
  4404. return false;
  4405. }
  4406. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  4407. config);
  4408. }
  4409. //----------------------------------------------------------------------------
  4410. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  4411. {
  4412. for(std::vector<cmSourceFile*>::const_iterator
  4413. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  4414. {
  4415. if(const char* lang = (*i)->GetLanguage())
  4416. {
  4417. languages.insert(lang);
  4418. }
  4419. }
  4420. }
  4421. //----------------------------------------------------------------------------
  4422. bool cmTarget::IsChrpathUsed(const char* config) const
  4423. {
  4424. // Only certain target types have an rpath.
  4425. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4426. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4427. this->GetType() == cmTarget::EXECUTABLE))
  4428. {
  4429. return false;
  4430. }
  4431. // If the target will not be installed we do not need to change its
  4432. // rpath.
  4433. if(!this->GetHaveInstallRule())
  4434. {
  4435. return false;
  4436. }
  4437. // Skip chrpath if skipping rpath altogether.
  4438. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4439. {
  4440. return false;
  4441. }
  4442. // Skip chrpath if it does not need to be changed at install time.
  4443. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4444. {
  4445. return false;
  4446. }
  4447. // Allow the user to disable builtin chrpath explicitly.
  4448. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4449. {
  4450. return false;
  4451. }
  4452. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4453. {
  4454. return true;
  4455. }
  4456. #if defined(CMAKE_USE_ELF_PARSER)
  4457. // Enable if the rpath flag uses a separator and the target uses ELF
  4458. // binaries.
  4459. if(const char* ll = this->GetLinkerLanguage(config, this))
  4460. {
  4461. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4462. sepVar += ll;
  4463. sepVar += "_FLAG_SEP";
  4464. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  4465. if(sep && *sep)
  4466. {
  4467. // TODO: Add ELF check to ABI detection and get rid of
  4468. // CMAKE_EXECUTABLE_FORMAT.
  4469. if(const char* fmt =
  4470. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4471. {
  4472. return strcmp(fmt, "ELF") == 0;
  4473. }
  4474. }
  4475. }
  4476. #endif
  4477. static_cast<void>(config);
  4478. return false;
  4479. }
  4480. //----------------------------------------------------------------------------
  4481. cmTarget::ImportInfo const*
  4482. cmTarget::GetImportInfo(const char* config, cmTarget const* headTarget) const
  4483. {
  4484. // There is no imported information for non-imported targets.
  4485. if(!this->IsImported())
  4486. {
  4487. return 0;
  4488. }
  4489. // Lookup/compute/cache the import information for this
  4490. // configuration.
  4491. std::string config_upper;
  4492. if(config && *config)
  4493. {
  4494. config_upper = cmSystemTools::UpperCase(config);
  4495. }
  4496. else
  4497. {
  4498. config_upper = "NOCONFIG";
  4499. }
  4500. TargetConfigPair key(headTarget, config_upper);
  4501. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4502. ImportInfoMapType::const_iterator i =
  4503. this->Internal->ImportInfoMap.find(key);
  4504. if(i == this->Internal->ImportInfoMap.end())
  4505. {
  4506. ImportInfo info;
  4507. this->ComputeImportInfo(config_upper, info, headTarget);
  4508. ImportInfoMapType::value_type entry(key, info);
  4509. i = this->Internal->ImportInfoMap.insert(entry).first;
  4510. }
  4511. if(this->GetType() == INTERFACE_LIBRARY)
  4512. {
  4513. return &i->second;
  4514. }
  4515. // If the location is empty then the target is not available for
  4516. // this configuration.
  4517. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4518. {
  4519. return 0;
  4520. }
  4521. // Return the import information.
  4522. return &i->second;
  4523. }
  4524. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4525. const char** loc,
  4526. const char** imp,
  4527. std::string& suffix) const
  4528. {
  4529. if (this->GetType() == INTERFACE_LIBRARY)
  4530. {
  4531. // This method attempts to find a config-specific LOCATION for the
  4532. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  4533. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  4534. // and valid response.
  4535. return true;
  4536. }
  4537. // Track the configuration-specific property suffix.
  4538. suffix = "_";
  4539. suffix += desired_config;
  4540. std::vector<std::string> mappedConfigs;
  4541. {
  4542. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  4543. mapProp += desired_config;
  4544. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  4545. {
  4546. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  4547. }
  4548. }
  4549. // If we needed to find one of the mapped configurations but did not
  4550. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  4551. // library or an executable with exports.
  4552. bool allowImp = this->HasImportLibrary();
  4553. // If a mapping was found, check its configurations.
  4554. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  4555. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  4556. {
  4557. // Look for this configuration.
  4558. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  4559. std::string locProp = "IMPORTED_LOCATION_";
  4560. locProp += mcUpper;
  4561. *loc = this->GetProperty(locProp.c_str());
  4562. if(allowImp)
  4563. {
  4564. std::string impProp = "IMPORTED_IMPLIB_";
  4565. impProp += mcUpper;
  4566. *imp = this->GetProperty(impProp.c_str());
  4567. }
  4568. // If it was found, use it for all properties below.
  4569. if(*loc || *imp)
  4570. {
  4571. suffix = "_";
  4572. suffix += mcUpper;
  4573. }
  4574. }
  4575. // If we needed to find one of the mapped configurations but did not
  4576. // then the target is not found. The project does not want any
  4577. // other configuration.
  4578. if(!mappedConfigs.empty() && !*loc && !*imp)
  4579. {
  4580. return false;
  4581. }
  4582. // If we have not yet found it then there are no mapped
  4583. // configurations. Look for an exact-match.
  4584. if(!*loc && !*imp)
  4585. {
  4586. std::string locProp = "IMPORTED_LOCATION";
  4587. locProp += suffix;
  4588. *loc = this->GetProperty(locProp.c_str());
  4589. if(allowImp)
  4590. {
  4591. std::string impProp = "IMPORTED_IMPLIB";
  4592. impProp += suffix;
  4593. *imp = this->GetProperty(impProp.c_str());
  4594. }
  4595. }
  4596. // If we have not yet found it then there are no mapped
  4597. // configurations and no exact match.
  4598. if(!*loc && !*imp)
  4599. {
  4600. // The suffix computed above is not useful.
  4601. suffix = "";
  4602. // Look for a configuration-less location. This may be set by
  4603. // manually-written code.
  4604. *loc = this->GetProperty("IMPORTED_LOCATION");
  4605. if(allowImp)
  4606. {
  4607. *imp = this->GetProperty("IMPORTED_IMPLIB");
  4608. }
  4609. }
  4610. // If we have not yet found it then the project is willing to try
  4611. // any available configuration.
  4612. if(!*loc && !*imp)
  4613. {
  4614. std::vector<std::string> availableConfigs;
  4615. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  4616. {
  4617. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  4618. }
  4619. for(std::vector<std::string>::const_iterator
  4620. aci = availableConfigs.begin();
  4621. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  4622. {
  4623. suffix = "_";
  4624. suffix += cmSystemTools::UpperCase(*aci);
  4625. std::string locProp = "IMPORTED_LOCATION";
  4626. locProp += suffix;
  4627. *loc = this->GetProperty(locProp.c_str());
  4628. if(allowImp)
  4629. {
  4630. std::string impProp = "IMPORTED_IMPLIB";
  4631. impProp += suffix;
  4632. *imp = this->GetProperty(impProp.c_str());
  4633. }
  4634. }
  4635. }
  4636. // If we have not yet found it then the target is not available.
  4637. if(!*loc && !*imp)
  4638. {
  4639. return false;
  4640. }
  4641. return true;
  4642. }
  4643. //----------------------------------------------------------------------------
  4644. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  4645. ImportInfo& info,
  4646. cmTarget const* headTarget) const
  4647. {
  4648. // This method finds information about an imported target from its
  4649. // properties. The "IMPORTED_" namespace is reserved for properties
  4650. // defined by the project exporting the target.
  4651. // Initialize members.
  4652. info.NoSOName = false;
  4653. const char* loc = 0;
  4654. const char* imp = 0;
  4655. std::string suffix;
  4656. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  4657. {
  4658. return;
  4659. }
  4660. // Get the link interface.
  4661. {
  4662. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  4663. const char *propertyLibs = this->GetProperty(linkProp.c_str());
  4664. if (this->GetType() != INTERFACE_LIBRARY)
  4665. {
  4666. if(!propertyLibs)
  4667. {
  4668. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4669. linkProp += suffix;
  4670. propertyLibs = this->GetProperty(linkProp.c_str());
  4671. }
  4672. if(!propertyLibs)
  4673. {
  4674. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4675. propertyLibs = this->GetProperty(linkProp.c_str());
  4676. }
  4677. }
  4678. if(propertyLibs)
  4679. {
  4680. cmListFileBacktrace lfbt;
  4681. cmGeneratorExpression ge(lfbt);
  4682. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  4683. this->GetName(),
  4684. linkProp, 0, 0);
  4685. cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
  4686. ->Evaluate(this->Makefile,
  4687. desired_config.c_str(),
  4688. false,
  4689. headTarget,
  4690. this,
  4691. &dagChecker),
  4692. info.LinkInterface.Libraries);
  4693. }
  4694. }
  4695. if(this->GetType() == INTERFACE_LIBRARY)
  4696. {
  4697. return;
  4698. }
  4699. // A provided configuration has been chosen. Load the
  4700. // configuration's properties.
  4701. // Get the location.
  4702. if(loc)
  4703. {
  4704. info.Location = loc;
  4705. }
  4706. else
  4707. {
  4708. std::string impProp = "IMPORTED_LOCATION";
  4709. impProp += suffix;
  4710. if(const char* config_location = this->GetProperty(impProp.c_str()))
  4711. {
  4712. info.Location = config_location;
  4713. }
  4714. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  4715. {
  4716. info.Location = location;
  4717. }
  4718. }
  4719. // Get the soname.
  4720. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4721. {
  4722. std::string soProp = "IMPORTED_SONAME";
  4723. soProp += suffix;
  4724. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  4725. {
  4726. info.SOName = config_soname;
  4727. }
  4728. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  4729. {
  4730. info.SOName = soname;
  4731. }
  4732. }
  4733. // Get the "no-soname" mark.
  4734. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4735. {
  4736. std::string soProp = "IMPORTED_NO_SONAME";
  4737. soProp += suffix;
  4738. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  4739. {
  4740. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4741. }
  4742. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4743. {
  4744. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4745. }
  4746. }
  4747. // Get the import library.
  4748. if(imp)
  4749. {
  4750. info.ImportLibrary = imp;
  4751. }
  4752. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4753. this->IsExecutableWithExports())
  4754. {
  4755. std::string impProp = "IMPORTED_IMPLIB";
  4756. impProp += suffix;
  4757. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  4758. {
  4759. info.ImportLibrary = config_implib;
  4760. }
  4761. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4762. {
  4763. info.ImportLibrary = implib;
  4764. }
  4765. }
  4766. // Get the link dependencies.
  4767. {
  4768. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4769. linkProp += suffix;
  4770. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4771. {
  4772. cmSystemTools::ExpandListArgument(config_libs,
  4773. info.LinkInterface.SharedDeps);
  4774. }
  4775. else if(const char* libs =
  4776. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4777. {
  4778. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  4779. }
  4780. }
  4781. // Get the link languages.
  4782. if(this->LinkLanguagePropagatesToDependents())
  4783. {
  4784. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4785. linkProp += suffix;
  4786. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4787. {
  4788. cmSystemTools::ExpandListArgument(config_libs,
  4789. info.LinkInterface.Languages);
  4790. }
  4791. else if(const char* libs =
  4792. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4793. {
  4794. cmSystemTools::ExpandListArgument(libs,
  4795. info.LinkInterface.Languages);
  4796. }
  4797. }
  4798. // Get the cyclic repetition count.
  4799. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4800. {
  4801. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4802. linkProp += suffix;
  4803. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  4804. {
  4805. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  4806. }
  4807. else if(const char* reps =
  4808. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4809. {
  4810. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  4811. }
  4812. }
  4813. }
  4814. //----------------------------------------------------------------------------
  4815. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
  4816. cmTarget const* head) const
  4817. {
  4818. // Imported targets have their own link interface.
  4819. if(this->IsImported())
  4820. {
  4821. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  4822. {
  4823. return &info->LinkInterface;
  4824. }
  4825. return 0;
  4826. }
  4827. // Link interfaces are not supported for executables that do not
  4828. // export symbols.
  4829. if(this->GetType() == cmTarget::EXECUTABLE &&
  4830. !this->IsExecutableWithExports())
  4831. {
  4832. return 0;
  4833. }
  4834. // Lookup any existing link interface for this configuration.
  4835. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4836. cmTargetInternals::LinkInterfaceMapType::iterator
  4837. i = this->Internal->LinkInterfaceMap.find(key);
  4838. if(i == this->Internal->LinkInterfaceMap.end())
  4839. {
  4840. // Compute the link interface for this configuration.
  4841. cmTargetInternals::OptionalLinkInterface iface;
  4842. iface.ExplicitLibraries =
  4843. this->ComputeLinkInterfaceLibraries(config, iface, head, iface.Exists);
  4844. if (iface.Exists)
  4845. {
  4846. this->Internal->ComputeLinkInterface(this, config, iface,
  4847. head, iface.ExplicitLibraries);
  4848. }
  4849. // Store the information for this configuration.
  4850. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  4851. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  4852. }
  4853. else if(!i->second.Complete && i->second.Exists)
  4854. {
  4855. this->Internal->ComputeLinkInterface(this, config, i->second, head,
  4856. i->second.ExplicitLibraries);
  4857. }
  4858. return i->second.Exists ? &i->second : 0;
  4859. }
  4860. //----------------------------------------------------------------------------
  4861. cmTarget::LinkInterface const*
  4862. cmTarget::GetLinkInterfaceLibraries(const char* config,
  4863. cmTarget const* head) const
  4864. {
  4865. // Imported targets have their own link interface.
  4866. if(this->IsImported())
  4867. {
  4868. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  4869. {
  4870. return &info->LinkInterface;
  4871. }
  4872. return 0;
  4873. }
  4874. // Link interfaces are not supported for executables that do not
  4875. // export symbols.
  4876. if(this->GetType() == cmTarget::EXECUTABLE &&
  4877. !this->IsExecutableWithExports())
  4878. {
  4879. return 0;
  4880. }
  4881. // Lookup any existing link interface for this configuration.
  4882. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4883. cmTargetInternals::LinkInterfaceMapType::iterator
  4884. i = this->Internal->LinkInterfaceMap.find(key);
  4885. if(i == this->Internal->LinkInterfaceMap.end())
  4886. {
  4887. // Compute the link interface for this configuration.
  4888. cmTargetInternals::OptionalLinkInterface iface;
  4889. iface.ExplicitLibraries = this->ComputeLinkInterfaceLibraries(config,
  4890. iface,
  4891. head,
  4892. iface.Exists);
  4893. // Store the information for this configuration.
  4894. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  4895. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  4896. }
  4897. return i->second.Exists ? &i->second : 0;
  4898. }
  4899. //----------------------------------------------------------------------------
  4900. void processILibs(const char* config,
  4901. cmTarget const* headTarget,
  4902. std::string const& name,
  4903. std::vector<cmTarget*>& tgts, std::set<cmTarget*>& emitted)
  4904. {
  4905. if (cmTarget* tgt = headTarget->GetMakefile()
  4906. ->FindTargetToUse(name.c_str()))
  4907. {
  4908. if (emitted.insert(tgt).second)
  4909. {
  4910. tgts.push_back(tgt);
  4911. std::vector<std::string> ilibs;
  4912. cmTarget::LinkInterface const* iface =
  4913. tgt->GetLinkInterfaceLibraries(config, headTarget);
  4914. if (iface)
  4915. {
  4916. for(std::vector<std::string>::const_iterator
  4917. it = iface->Libraries.begin();
  4918. it != iface->Libraries.end(); ++it)
  4919. {
  4920. processILibs(config, headTarget, *it, tgts, emitted);
  4921. }
  4922. }
  4923. }
  4924. }
  4925. }
  4926. //----------------------------------------------------------------------------
  4927. void cmTarget::GetTransitiveTargetClosure(const char* config,
  4928. cmTarget const* headTarget,
  4929. std::vector<cmTarget*> &tgts) const
  4930. {
  4931. std::set<cmTarget*> emitted;
  4932. cmTarget::LinkImplementation const* impl
  4933. = this->GetLinkImplementationLibraries(config, headTarget);
  4934. for(std::vector<std::string>::const_iterator it = impl->Libraries.begin();
  4935. it != impl->Libraries.end(); ++it)
  4936. {
  4937. processILibs(config, headTarget, *it, tgts, emitted);
  4938. }
  4939. }
  4940. //----------------------------------------------------------------------------
  4941. void cmTarget::GetTransitivePropertyTargets(const char* config,
  4942. cmTarget const* headTarget,
  4943. std::vector<cmTarget*> &tgts) const
  4944. {
  4945. cmTarget::LinkInterface const* iface
  4946. = this->GetLinkInterfaceLibraries(config, headTarget);
  4947. if (!iface)
  4948. {
  4949. return;
  4950. }
  4951. if(this->GetType() != STATIC_LIBRARY
  4952. || this->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4953. || this->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4954. {
  4955. for(std::vector<std::string>::const_iterator it = iface->Libraries.begin();
  4956. it != iface->Libraries.end(); ++it)
  4957. {
  4958. if (cmTarget* tgt = headTarget->GetMakefile()
  4959. ->FindTargetToUse(it->c_str()))
  4960. {
  4961. tgts.push_back(tgt);
  4962. }
  4963. }
  4964. return;
  4965. }
  4966. const char* linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4967. const char* interfaceLibs = this->GetProperty(linkIfaceProp);
  4968. if (!interfaceLibs)
  4969. {
  4970. return;
  4971. }
  4972. // The interface libraries have been explicitly set.
  4973. cmListFileBacktrace lfbt;
  4974. cmGeneratorExpression ge(lfbt);
  4975. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  4976. linkIfaceProp, 0, 0);
  4977. dagChecker.SetTransitivePropertiesOnly();
  4978. std::vector<std::string> libs;
  4979. cmSystemTools::ExpandListArgument(ge.Parse(interfaceLibs)->Evaluate(
  4980. this->Makefile,
  4981. config,
  4982. false,
  4983. headTarget,
  4984. this, &dagChecker), libs);
  4985. for(std::vector<std::string>::const_iterator it = libs.begin();
  4986. it != libs.end(); ++it)
  4987. {
  4988. if (cmTarget* tgt = headTarget->GetMakefile()
  4989. ->FindTargetToUse(it->c_str()))
  4990. {
  4991. tgts.push_back(tgt);
  4992. }
  4993. }
  4994. }
  4995. //----------------------------------------------------------------------------
  4996. const char* cmTarget::ComputeLinkInterfaceLibraries(const char* config,
  4997. LinkInterface& iface,
  4998. cmTarget const* headTarget,
  4999. bool &exists) const
  5000. {
  5001. // Construct the property name suffix for this configuration.
  5002. std::string suffix = "_";
  5003. if(config && *config)
  5004. {
  5005. suffix += cmSystemTools::UpperCase(config);
  5006. }
  5007. else
  5008. {
  5009. suffix += "NOCONFIG";
  5010. }
  5011. // An explicit list of interface libraries may be set for shared
  5012. // libraries and executables that export symbols.
  5013. const char* explicitLibraries = 0;
  5014. std::string linkIfaceProp;
  5015. if(this->PolicyStatusCMP0022 != cmPolicies::OLD &&
  5016. this->PolicyStatusCMP0022 != cmPolicies::WARN)
  5017. {
  5018. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  5019. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5020. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  5021. }
  5022. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5023. this->IsExecutableWithExports())
  5024. {
  5025. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  5026. // shared lib or executable.
  5027. // Lookup the per-configuration property.
  5028. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5029. linkIfaceProp += suffix;
  5030. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  5031. // If not set, try the generic property.
  5032. if(!explicitLibraries)
  5033. {
  5034. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5035. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  5036. }
  5037. }
  5038. if(explicitLibraries && this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5039. !this->Internal->PolicyWarnedCMP0022)
  5040. {
  5041. // Compare the explicitly set old link interface properties to the
  5042. // preferred new link interface property one and warn if different.
  5043. const char* newExplicitLibraries =
  5044. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  5045. if (newExplicitLibraries
  5046. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  5047. {
  5048. cmOStringStream w;
  5049. w <<
  5050. (this->Makefile->GetPolicies()
  5051. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5052. "Target \"" << this->GetName() << "\" has an "
  5053. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  5054. linkIfaceProp << " properties."
  5055. "\n"
  5056. "INTERFACE_LINK_LIBRARIES:\n"
  5057. " " << newExplicitLibraries << "\n" <<
  5058. linkIfaceProp << ":\n"
  5059. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  5060. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5061. this->Internal->PolicyWarnedCMP0022 = true;
  5062. }
  5063. }
  5064. // There is no implicit link interface for executables or modules
  5065. // so if none was explicitly set then there is no link interface.
  5066. if(!explicitLibraries &&
  5067. (this->GetType() == cmTarget::EXECUTABLE ||
  5068. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  5069. {
  5070. exists = false;
  5071. return 0;
  5072. }
  5073. exists = true;
  5074. if(explicitLibraries)
  5075. {
  5076. // The interface libraries have been explicitly set.
  5077. cmListFileBacktrace lfbt;
  5078. cmGeneratorExpression ge(lfbt);
  5079. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5080. linkIfaceProp, 0, 0);
  5081. cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
  5082. this->Makefile,
  5083. config,
  5084. false,
  5085. headTarget,
  5086. this, &dagChecker), iface.Libraries);
  5087. }
  5088. else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
  5089. || this->PolicyStatusCMP0022 == cmPolicies::OLD)
  5090. // If CMP0022 is NEW then the plain tll signature sets the
  5091. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  5092. // cleared the property explicitly and we should not fall back
  5093. // to the link implementation.
  5094. {
  5095. // The link implementation is the default link interface.
  5096. LinkImplementation const* impl =
  5097. this->GetLinkImplementationLibraries(config, headTarget);
  5098. iface.Libraries = impl->Libraries;
  5099. if(this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5100. !this->Internal->PolicyWarnedCMP0022)
  5101. {
  5102. // Compare the link implementation fallback link interface to the
  5103. // preferred new link interface property and warn if different.
  5104. cmListFileBacktrace lfbt;
  5105. cmGeneratorExpression ge(lfbt);
  5106. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  5107. "INTERFACE_LINK_LIBRARIES", 0, 0);
  5108. std::vector<std::string> ifaceLibs;
  5109. const char* newExplicitLibraries =
  5110. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  5111. cmSystemTools::ExpandListArgument(
  5112. ge.Parse(newExplicitLibraries)->Evaluate(this->Makefile,
  5113. config,
  5114. false,
  5115. headTarget,
  5116. this, &dagChecker),
  5117. ifaceLibs);
  5118. if (ifaceLibs != impl->Libraries)
  5119. {
  5120. std::string oldLibraries;
  5121. std::string newLibraries;
  5122. const char *sep = "";
  5123. for(std::vector<std::string>::const_iterator it
  5124. = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
  5125. {
  5126. oldLibraries += sep;
  5127. oldLibraries += *it;
  5128. sep = ";";
  5129. }
  5130. sep = "";
  5131. for(std::vector<std::string>::const_iterator it
  5132. = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
  5133. {
  5134. newLibraries += sep;
  5135. newLibraries += *it;
  5136. sep = ";";
  5137. }
  5138. if(oldLibraries.empty())
  5139. { oldLibraries = "(empty)"; }
  5140. if(newLibraries.empty())
  5141. { newLibraries = "(empty)"; }
  5142. cmOStringStream w;
  5143. w <<
  5144. (this->Makefile->GetPolicies()
  5145. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5146. "Target \"" << this->GetName() << "\" has an "
  5147. "INTERFACE_LINK_LIBRARIES property. "
  5148. "This should be preferred as the source of the link interface "
  5149. "for this library but because CMP0022 is not set CMake is "
  5150. "ignoring the property and using the link implementation "
  5151. "as the link interface instead."
  5152. "\n"
  5153. "INTERFACE_LINK_LIBRARIES:\n"
  5154. " " << newLibraries << "\n"
  5155. "Link implementation:\n"
  5156. " " << oldLibraries << "\n";
  5157. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5158. this->Internal->PolicyWarnedCMP0022 = true;
  5159. }
  5160. }
  5161. }
  5162. return explicitLibraries;
  5163. }
  5164. //----------------------------------------------------------------------------
  5165. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  5166. const char* config,
  5167. OptionalLinkInterface& iface,
  5168. cmTarget const* headTarget,
  5169. const char* explicitLibraries) const
  5170. {
  5171. if(explicitLibraries)
  5172. {
  5173. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  5174. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  5175. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  5176. {
  5177. // Shared libraries may have runtime implementation dependencies
  5178. // on other shared libraries that are not in the interface.
  5179. std::set<cmStdString> emitted;
  5180. for(std::vector<std::string>::const_iterator
  5181. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5182. {
  5183. emitted.insert(*li);
  5184. }
  5185. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  5186. {
  5187. cmTarget::LinkImplementation const* impl =
  5188. thisTarget->GetLinkImplementation(config, headTarget);
  5189. for(std::vector<std::string>::const_iterator
  5190. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5191. {
  5192. if(emitted.insert(*li).second)
  5193. {
  5194. if(cmTarget* tgt = thisTarget->Makefile->FindTargetToUse(*li))
  5195. {
  5196. // This is a runtime dependency on another shared library.
  5197. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  5198. {
  5199. iface.SharedDeps.push_back(*li);
  5200. }
  5201. }
  5202. else
  5203. {
  5204. // TODO: Recognize shared library file names. Perhaps this
  5205. // should be moved to cmComputeLinkInformation, but that creates
  5206. // a chicken-and-egg problem since this list is needed for its
  5207. // construction.
  5208. }
  5209. }
  5210. }
  5211. if(thisTarget->LinkLanguagePropagatesToDependents())
  5212. {
  5213. // Targets using this archive need its language runtime libraries.
  5214. iface.Languages = impl->Languages;
  5215. }
  5216. }
  5217. }
  5218. }
  5219. else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
  5220. || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
  5221. {
  5222. // The link implementation is the default link interface.
  5223. cmTarget::LinkImplementation const*
  5224. impl = thisTarget->GetLinkImplementation(config, headTarget);
  5225. iface.ImplementationIsInterface = true;
  5226. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5227. if(thisTarget->LinkLanguagePropagatesToDependents())
  5228. {
  5229. // Targets using this archive need its language runtime libraries.
  5230. iface.Languages = impl->Languages;
  5231. }
  5232. }
  5233. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  5234. {
  5235. // Construct the property name suffix for this configuration.
  5236. std::string suffix = "_";
  5237. if(config && *config)
  5238. {
  5239. suffix += cmSystemTools::UpperCase(config);
  5240. }
  5241. else
  5242. {
  5243. suffix += "NOCONFIG";
  5244. }
  5245. // How many repetitions are needed if this library has cyclic
  5246. // dependencies?
  5247. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5248. propName += suffix;
  5249. if(const char* config_reps = thisTarget->GetProperty(propName.c_str()))
  5250. {
  5251. sscanf(config_reps, "%u", &iface.Multiplicity);
  5252. }
  5253. else if(const char* reps =
  5254. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5255. {
  5256. sscanf(reps, "%u", &iface.Multiplicity);
  5257. }
  5258. }
  5259. iface.Complete = true;
  5260. }
  5261. //----------------------------------------------------------------------------
  5262. cmTarget::LinkImplementation const*
  5263. cmTarget::GetLinkImplementation(const char* config, cmTarget const* head) const
  5264. {
  5265. // There is no link implementation for imported targets.
  5266. if(this->IsImported())
  5267. {
  5268. return 0;
  5269. }
  5270. // Lookup any existing link implementation for this configuration.
  5271. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  5272. cmTargetInternals::LinkImplMapType::iterator
  5273. i = this->Internal->LinkImplMap.find(key);
  5274. if(i == this->Internal->LinkImplMap.end())
  5275. {
  5276. // Compute the link implementation for this configuration.
  5277. LinkImplementation impl;
  5278. this->ComputeLinkImplementation(config, impl, head);
  5279. this->ComputeLinkImplementationLanguages(impl);
  5280. // Store the information for this configuration.
  5281. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  5282. i = this->Internal->LinkImplMap.insert(entry).first;
  5283. }
  5284. else if (i->second.Languages.empty())
  5285. {
  5286. this->ComputeLinkImplementationLanguages(i->second);
  5287. }
  5288. return &i->second;
  5289. }
  5290. //----------------------------------------------------------------------------
  5291. cmTarget::LinkImplementation const*
  5292. cmTarget::GetLinkImplementationLibraries(const char* config,
  5293. cmTarget const* head) const
  5294. {
  5295. // There is no link implementation for imported targets.
  5296. if(this->IsImported())
  5297. {
  5298. return 0;
  5299. }
  5300. // Lookup any existing link implementation for this configuration.
  5301. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  5302. cmTargetInternals::LinkImplMapType::iterator
  5303. i = this->Internal->LinkImplMap.find(key);
  5304. if(i == this->Internal->LinkImplMap.end())
  5305. {
  5306. // Compute the link implementation for this configuration.
  5307. LinkImplementation impl;
  5308. this->ComputeLinkImplementation(config, impl, head);
  5309. // Store the information for this configuration.
  5310. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  5311. i = this->Internal->LinkImplMap.insert(entry).first;
  5312. }
  5313. return &i->second;
  5314. }
  5315. //----------------------------------------------------------------------------
  5316. void cmTarget::ComputeLinkImplementation(const char* config,
  5317. LinkImplementation& impl,
  5318. cmTarget const* head) const
  5319. {
  5320. // Collect libraries directly linked in this configuration.
  5321. std::vector<std::string> llibs;
  5322. this->GetDirectLinkLibraries(config, llibs, head);
  5323. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5324. li != llibs.end(); ++li)
  5325. {
  5326. // Skip entries that resolve to the target itself or are empty.
  5327. std::string item = this->CheckCMP0004(*li);
  5328. if(item == this->GetName() || item.empty())
  5329. {
  5330. if(item == this->GetName())
  5331. {
  5332. bool noMessage = false;
  5333. cmake::MessageType messageType = cmake::FATAL_ERROR;
  5334. cmOStringStream e;
  5335. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0038))
  5336. {
  5337. case cmPolicies::WARN:
  5338. {
  5339. e << (this->Makefile->GetPolicies()
  5340. ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
  5341. messageType = cmake::AUTHOR_WARNING;
  5342. }
  5343. break;
  5344. case cmPolicies::OLD:
  5345. noMessage = true;
  5346. case cmPolicies::REQUIRED_IF_USED:
  5347. case cmPolicies::REQUIRED_ALWAYS:
  5348. case cmPolicies::NEW:
  5349. // Issue the fatal message.
  5350. break;
  5351. }
  5352. if(!noMessage)
  5353. {
  5354. e << "Target \"" << this->GetName() << "\" links to itself.";
  5355. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  5356. e.str(),
  5357. this->GetBacktrace());
  5358. if (messageType == cmake::FATAL_ERROR)
  5359. {
  5360. return;
  5361. }
  5362. }
  5363. }
  5364. continue;
  5365. }
  5366. // The entry is meant for this configuration.
  5367. impl.Libraries.push_back(item);
  5368. }
  5369. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  5370. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  5371. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5372. li != oldllibs.end(); ++li)
  5373. {
  5374. if(li->second != cmTarget::GENERAL && li->second != linkType)
  5375. {
  5376. std::string item = this->CheckCMP0004(li->first);
  5377. if(item == this->GetName() || item.empty())
  5378. {
  5379. continue;
  5380. }
  5381. // Support OLD behavior for CMP0003.
  5382. impl.WrongConfigLibraries.push_back(item);
  5383. }
  5384. }
  5385. }
  5386. //----------------------------------------------------------------------------
  5387. void
  5388. cmTarget::ComputeLinkImplementationLanguages(LinkImplementation& impl) const
  5389. {
  5390. // This target needs runtime libraries for its source languages.
  5391. std::set<cmStdString> languages;
  5392. // Get languages used in our source files.
  5393. this->GetLanguages(languages);
  5394. // Get languages used in object library sources.
  5395. for(std::vector<std::string>::const_iterator
  5396. i = this->ObjectLibraries.begin();
  5397. i != this->ObjectLibraries.end(); ++i)
  5398. {
  5399. if(cmTarget* objLib = this->Makefile->FindTargetToUse(*i))
  5400. {
  5401. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  5402. {
  5403. objLib->GetLanguages(languages);
  5404. }
  5405. }
  5406. }
  5407. // Copy the set of langauges to the link implementation.
  5408. for(std::set<cmStdString>::iterator li = languages.begin();
  5409. li != languages.end(); ++li)
  5410. {
  5411. impl.Languages.push_back(*li);
  5412. }
  5413. }
  5414. //----------------------------------------------------------------------------
  5415. std::string cmTarget::CheckCMP0004(std::string const& item) const
  5416. {
  5417. // Strip whitespace off the library names because we used to do this
  5418. // in case variables were expanded at generate time. We no longer
  5419. // do the expansion but users link to libraries like " ${VAR} ".
  5420. std::string lib = item;
  5421. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5422. if(pos != lib.npos)
  5423. {
  5424. lib = lib.substr(pos, lib.npos);
  5425. }
  5426. pos = lib.find_last_not_of(" \t\r\n");
  5427. if(pos != lib.npos)
  5428. {
  5429. lib = lib.substr(0, pos+1);
  5430. }
  5431. if(lib != item)
  5432. {
  5433. cmake* cm = this->Makefile->GetCMakeInstance();
  5434. switch(this->PolicyStatusCMP0004)
  5435. {
  5436. case cmPolicies::WARN:
  5437. {
  5438. cmOStringStream w;
  5439. w << (this->Makefile->GetPolicies()
  5440. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  5441. << "Target \"" << this->GetName() << "\" links to item \""
  5442. << item << "\" which has leading or trailing whitespace.";
  5443. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5444. this->GetBacktrace());
  5445. }
  5446. case cmPolicies::OLD:
  5447. break;
  5448. case cmPolicies::NEW:
  5449. {
  5450. cmOStringStream e;
  5451. e << "Target \"" << this->GetName() << "\" links to item \""
  5452. << item << "\" which has leading or trailing whitespace. "
  5453. << "This is now an error according to policy CMP0004.";
  5454. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5455. }
  5456. break;
  5457. case cmPolicies::REQUIRED_IF_USED:
  5458. case cmPolicies::REQUIRED_ALWAYS:
  5459. {
  5460. cmOStringStream e;
  5461. e << (this->Makefile->GetPolicies()
  5462. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  5463. << "Target \"" << this->GetName() << "\" links to item \""
  5464. << item << "\" which has leading or trailing whitespace.";
  5465. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5466. }
  5467. break;
  5468. }
  5469. }
  5470. return lib;
  5471. }
  5472. template<typename PropertyType>
  5473. PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5474. const std::string& prop,
  5475. const char *config,
  5476. CompatibleType,
  5477. PropertyType *);
  5478. template<>
  5479. bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5480. const std::string& prop,
  5481. const char *config,
  5482. CompatibleType, bool *)
  5483. {
  5484. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5485. }
  5486. template<>
  5487. const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
  5488. const std::string& prop,
  5489. const char *config,
  5490. CompatibleType t,
  5491. const char **)
  5492. {
  5493. switch(t)
  5494. {
  5495. case BoolType:
  5496. assert(!"String compatibility check function called for boolean");
  5497. return 0;
  5498. case StringType:
  5499. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5500. case NumberMinType:
  5501. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  5502. case NumberMaxType:
  5503. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  5504. }
  5505. assert(!"Unreachable!");
  5506. return 0;
  5507. }
  5508. //----------------------------------------------------------------------------
  5509. template<typename PropertyType>
  5510. void checkPropertyConsistency(cmTarget const* depender,
  5511. cmTarget const* dependee,
  5512. const cmStdString& propName,
  5513. std::set<cmStdString> &emitted,
  5514. const char *config,
  5515. CompatibleType t,
  5516. PropertyType *)
  5517. {
  5518. const char *prop = dependee->GetProperty(propName);
  5519. if (!prop)
  5520. {
  5521. return;
  5522. }
  5523. std::vector<std::string> props;
  5524. cmSystemTools::ExpandListArgument(prop, props);
  5525. std::string pdir =
  5526. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  5527. pdir += "/Help/prop_tgt/";
  5528. for(std::vector<std::string>::iterator pi = props.begin();
  5529. pi != props.end(); ++pi)
  5530. {
  5531. std::string pname = cmSystemTools::HelpFileName(*pi);
  5532. std::string pfile = pdir + pname + ".rst";
  5533. if(cmSystemTools::FileExists(pfile.c_str(), true))
  5534. {
  5535. cmOStringStream e;
  5536. e << "Target \"" << dependee->GetName() << "\" has property \""
  5537. << *pi << "\" listed in its " << propName << " property. "
  5538. "This is not allowed. Only user-defined properties may appear "
  5539. "listed in the " << propName << " property.";
  5540. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  5541. return;
  5542. }
  5543. if(emitted.insert(*pi).second)
  5544. {
  5545. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  5546. t, 0);
  5547. if (cmSystemTools::GetErrorOccuredFlag())
  5548. {
  5549. return;
  5550. }
  5551. }
  5552. }
  5553. }
  5554. static cmStdString intersect(const std::set<cmStdString> &s1,
  5555. const std::set<cmStdString> &s2)
  5556. {
  5557. std::set<cmStdString> intersect;
  5558. std::set_intersection(s1.begin(),s1.end(),
  5559. s2.begin(),s2.end(),
  5560. std::inserter(intersect,intersect.begin()));
  5561. if (!intersect.empty())
  5562. {
  5563. return *intersect.begin();
  5564. }
  5565. return "";
  5566. }
  5567. static cmStdString intersect(const std::set<cmStdString> &s1,
  5568. const std::set<cmStdString> &s2,
  5569. const std::set<cmStdString> &s3)
  5570. {
  5571. cmStdString result;
  5572. result = intersect(s1, s2);
  5573. if (!result.empty())
  5574. return result;
  5575. result = intersect(s1, s3);
  5576. if (!result.empty())
  5577. return result;
  5578. return intersect(s2, s3);
  5579. }
  5580. static cmStdString intersect(const std::set<cmStdString> &s1,
  5581. const std::set<cmStdString> &s2,
  5582. const std::set<cmStdString> &s3,
  5583. const std::set<cmStdString> &s4)
  5584. {
  5585. cmStdString result;
  5586. result = intersect(s1, s2);
  5587. if (!result.empty())
  5588. return result;
  5589. result = intersect(s1, s3);
  5590. if (!result.empty())
  5591. return result;
  5592. result = intersect(s1, s4);
  5593. if (!result.empty())
  5594. return result;
  5595. return intersect(s2, s3, s4);
  5596. }
  5597. //----------------------------------------------------------------------------
  5598. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  5599. const char* config) const
  5600. {
  5601. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  5602. std::set<cmStdString> emittedBools;
  5603. std::set<cmStdString> emittedStrings;
  5604. std::set<cmStdString> emittedMinNumbers;
  5605. std::set<cmStdString> emittedMaxNumbers;
  5606. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  5607. deps.begin();
  5608. li != deps.end(); ++li)
  5609. {
  5610. if (!li->Target)
  5611. {
  5612. continue;
  5613. }
  5614. checkPropertyConsistency<bool>(this, li->Target,
  5615. std::string("COMPATIBLE_INTERFACE_BOOL"),
  5616. emittedBools, config, BoolType, 0);
  5617. if (cmSystemTools::GetErrorOccuredFlag())
  5618. {
  5619. return;
  5620. }
  5621. checkPropertyConsistency<const char *>(this, li->Target,
  5622. std::string("COMPATIBLE_INTERFACE_STRING"),
  5623. emittedStrings, config,
  5624. StringType, 0);
  5625. if (cmSystemTools::GetErrorOccuredFlag())
  5626. {
  5627. return;
  5628. }
  5629. checkPropertyConsistency<const char *>(this, li->Target,
  5630. std::string("COMPATIBLE_INTERFACE_NUMBER_MIN"),
  5631. emittedMinNumbers, config,
  5632. NumberMinType, 0);
  5633. if (cmSystemTools::GetErrorOccuredFlag())
  5634. {
  5635. return;
  5636. }
  5637. checkPropertyConsistency<const char *>(this, li->Target,
  5638. std::string("COMPATIBLE_INTERFACE_NUMBER_MAX"),
  5639. emittedMaxNumbers, config,
  5640. NumberMaxType, 0);
  5641. if (cmSystemTools::GetErrorOccuredFlag())
  5642. {
  5643. return;
  5644. }
  5645. }
  5646. std::string prop = intersect(emittedBools,
  5647. emittedStrings,
  5648. emittedMinNumbers,
  5649. emittedMaxNumbers);
  5650. if (!prop.empty())
  5651. {
  5652. std::set<std::string> props;
  5653. std::set<cmStdString>::const_iterator i = emittedBools.find(prop);
  5654. if (i != emittedBools.end())
  5655. {
  5656. props.insert("COMPATIBLE_INTERFACE_BOOL");
  5657. }
  5658. i = emittedStrings.find(prop);
  5659. if (i != emittedStrings.end())
  5660. {
  5661. props.insert("COMPATIBLE_INTERFACE_STRING");
  5662. }
  5663. i = emittedMinNumbers.find(prop);
  5664. if (i != emittedMinNumbers.end())
  5665. {
  5666. props.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  5667. }
  5668. i = emittedMaxNumbers.find(prop);
  5669. if (i != emittedMaxNumbers.end())
  5670. {
  5671. props.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  5672. }
  5673. std::string propsString = *props.begin();
  5674. props.erase(props.begin());
  5675. while (props.size() > 1)
  5676. {
  5677. propsString += ", " + *props.begin();
  5678. props.erase(props.begin());
  5679. }
  5680. if (props.size() == 1)
  5681. {
  5682. propsString += " and the " + *props.begin();
  5683. }
  5684. cmOStringStream e;
  5685. e << "Property \"" << prop << "\" appears in both the "
  5686. << propsString <<
  5687. " property in the dependencies of target \"" << this->GetName() <<
  5688. "\". This is not allowed. A property may only require compatibility "
  5689. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  5690. "string interpretation, but not a mixture.";
  5691. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  5692. }
  5693. }
  5694. //----------------------------------------------------------------------------
  5695. cmComputeLinkInformation*
  5696. cmTarget::GetLinkInformation(const char* config, cmTarget const* head) const
  5697. {
  5698. cmTarget const* headTarget = head ? head : this;
  5699. // Lookup any existing information for this configuration.
  5700. TargetConfigPair key(headTarget,
  5701. cmSystemTools::UpperCase(config?config:""));
  5702. cmTargetLinkInformationMap::iterator
  5703. i = this->LinkInformation.find(key);
  5704. if(i == this->LinkInformation.end())
  5705. {
  5706. // Compute information for this configuration.
  5707. cmComputeLinkInformation* info =
  5708. new cmComputeLinkInformation(this, config, headTarget);
  5709. if(!info || !info->Compute())
  5710. {
  5711. delete info;
  5712. info = 0;
  5713. }
  5714. // Store the information for this configuration.
  5715. cmTargetLinkInformationMap::value_type entry(key, info);
  5716. i = this->LinkInformation.insert(entry).first;
  5717. if (info)
  5718. {
  5719. this->CheckPropertyCompatibility(info, config);
  5720. }
  5721. }
  5722. return i->second;
  5723. }
  5724. //----------------------------------------------------------------------------
  5725. std::string cmTarget::GetFrameworkDirectory(const char* config,
  5726. bool rootDir) const
  5727. {
  5728. std::string fpath;
  5729. fpath += this->GetOutputName(config, false);
  5730. fpath += ".framework";
  5731. if(!rootDir)
  5732. {
  5733. fpath += "/Versions/";
  5734. fpath += this->GetFrameworkVersion();
  5735. }
  5736. return fpath;
  5737. }
  5738. //----------------------------------------------------------------------------
  5739. std::string cmTarget::GetCFBundleDirectory(const char* config,
  5740. bool contentOnly) const
  5741. {
  5742. std::string fpath;
  5743. fpath += this->GetOutputName(config, false);
  5744. fpath += ".";
  5745. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  5746. if (!ext)
  5747. {
  5748. ext = "bundle";
  5749. }
  5750. fpath += ext;
  5751. fpath += "/Contents";
  5752. if(!contentOnly)
  5753. fpath += "/MacOS";
  5754. return fpath;
  5755. }
  5756. //----------------------------------------------------------------------------
  5757. std::string cmTarget::GetAppBundleDirectory(const char* config,
  5758. bool contentOnly) const
  5759. {
  5760. std::string fpath = this->GetFullName(config, false);
  5761. fpath += ".app/Contents";
  5762. if(!contentOnly)
  5763. fpath += "/MacOS";
  5764. return fpath;
  5765. }
  5766. //----------------------------------------------------------------------------
  5767. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  5768. const char* config,
  5769. bool contentOnly) const
  5770. {
  5771. std::string fpath = base;
  5772. if(this->IsAppBundleOnApple())
  5773. {
  5774. fpath += this->GetAppBundleDirectory(config, contentOnly);
  5775. }
  5776. if(this->IsFrameworkOnApple())
  5777. {
  5778. fpath += this->GetFrameworkDirectory(config, contentOnly);
  5779. }
  5780. if(this->IsCFBundleOnApple())
  5781. {
  5782. fpath += this->GetCFBundleDirectory(config, contentOnly);
  5783. }
  5784. return fpath;
  5785. }
  5786. //----------------------------------------------------------------------------
  5787. std::string cmTarget::GetMacContentDirectory(const char* config,
  5788. bool implib) const
  5789. {
  5790. // Start with the output directory for the target.
  5791. std::string fpath = this->GetDirectory(config, implib);
  5792. fpath += "/";
  5793. bool contentOnly = true;
  5794. if(this->IsFrameworkOnApple())
  5795. {
  5796. // additional files with a framework go into the version specific
  5797. // directory
  5798. contentOnly = false;
  5799. }
  5800. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  5801. return fpath;
  5802. }
  5803. //----------------------------------------------------------------------------
  5804. cmTargetLinkInformationMap
  5805. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  5806. {
  5807. // Ideally cmTarget instances should never be copied. However until
  5808. // we can make a sweep to remove that, this copy constructor avoids
  5809. // allowing the resources (LinkInformation) from getting copied. In
  5810. // the worst case this will lead to extra cmComputeLinkInformation
  5811. // instances. We also enforce in debug mode that the map be emptied
  5812. // when copied.
  5813. static_cast<void>(r);
  5814. assert(r.empty());
  5815. }
  5816. //----------------------------------------------------------------------------
  5817. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  5818. {
  5819. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  5820. {
  5821. delete i->second;
  5822. }
  5823. }
  5824. //----------------------------------------------------------------------------
  5825. cmTargetInternalPointer::cmTargetInternalPointer()
  5826. {
  5827. this->Pointer = new cmTargetInternals;
  5828. }
  5829. //----------------------------------------------------------------------------
  5830. cmTargetInternalPointer
  5831. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  5832. {
  5833. // Ideally cmTarget instances should never be copied. However until
  5834. // we can make a sweep to remove that, this copy constructor avoids
  5835. // allowing the resources (Internals) to be copied.
  5836. this->Pointer = new cmTargetInternals(*r.Pointer);
  5837. }
  5838. //----------------------------------------------------------------------------
  5839. cmTargetInternalPointer::~cmTargetInternalPointer()
  5840. {
  5841. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  5842. deleteAndClear(this->Pointer->CompileOptionsEntries);
  5843. deleteAndClear(this->Pointer->CompileDefinitionsEntries);
  5844. delete this->Pointer;
  5845. }
  5846. //----------------------------------------------------------------------------
  5847. cmTargetInternalPointer&
  5848. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  5849. {
  5850. if(this == &r) { return *this; } // avoid warning on HP about self check
  5851. // Ideally cmTarget instances should never be copied. However until
  5852. // we can make a sweep to remove that, this copy constructor avoids
  5853. // allowing the resources (Internals) to be copied.
  5854. cmTargetInternals* oldPointer = this->Pointer;
  5855. this->Pointer = new cmTargetInternals(*r.Pointer);
  5856. delete oldPointer;
  5857. return *this;
  5858. }