cmTarget.cxx 224 KB

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