cmTarget.cxx 211 KB

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