cmTarget.cxx 213 KB

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