cmTarget.cxx 232 KB

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