1
0

cmTarget.cxx 231 KB

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