cmTarget.cxx 220 KB

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