cmTarget.cxx 232 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202
  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. static std::string output;
  2983. output = "";
  2984. std::string sep;
  2985. typedef cmTargetInternals::TargetPropertyEntry
  2986. TargetPropertyEntry;
  2987. for (std::vector<TargetPropertyEntry*>::const_iterator
  2988. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2989. end = this->Internal->IncludeDirectoriesEntries.end();
  2990. it != end; ++it)
  2991. {
  2992. output += sep;
  2993. output += (*it)->ge->GetInput();
  2994. sep = ";";
  2995. }
  2996. return output.c_str();
  2997. }
  2998. if(prop == "COMPILE_OPTIONS")
  2999. {
  3000. static std::string output;
  3001. output = "";
  3002. std::string sep;
  3003. typedef cmTargetInternals::TargetPropertyEntry
  3004. TargetPropertyEntry;
  3005. for (std::vector<TargetPropertyEntry*>::const_iterator
  3006. it = this->Internal->CompileOptionsEntries.begin(),
  3007. end = this->Internal->CompileOptionsEntries.end();
  3008. it != end; ++it)
  3009. {
  3010. output += sep;
  3011. output += (*it)->ge->GetInput();
  3012. sep = ";";
  3013. }
  3014. return output.c_str();
  3015. }
  3016. if(prop == "COMPILE_FEATURES")
  3017. {
  3018. static std::string output;
  3019. output = "";
  3020. std::string sep;
  3021. typedef cmTargetInternals::TargetPropertyEntry
  3022. TargetPropertyEntry;
  3023. for (std::vector<TargetPropertyEntry*>::const_iterator
  3024. it = this->Internal->CompileFeaturesEntries.begin(),
  3025. end = this->Internal->CompileFeaturesEntries.end();
  3026. it != end; ++it)
  3027. {
  3028. output += sep;
  3029. output += (*it)->ge->GetInput();
  3030. sep = ";";
  3031. }
  3032. return output.c_str();
  3033. }
  3034. if(prop == "COMPILE_DEFINITIONS")
  3035. {
  3036. static std::string output;
  3037. output = "";
  3038. std::string sep;
  3039. typedef cmTargetInternals::TargetPropertyEntry
  3040. TargetPropertyEntry;
  3041. for (std::vector<TargetPropertyEntry*>::const_iterator
  3042. it = this->Internal->CompileDefinitionsEntries.begin(),
  3043. end = this->Internal->CompileDefinitionsEntries.end();
  3044. it != end; ++it)
  3045. {
  3046. output += sep;
  3047. output += (*it)->ge->GetInput();
  3048. sep = ";";
  3049. }
  3050. return output.c_str();
  3051. }
  3052. if(prop == "LINK_LIBRARIES")
  3053. {
  3054. static std::string output;
  3055. output = "";
  3056. std::string sep;
  3057. for (std::vector<cmValueWithOrigin>::const_iterator
  3058. it = this->Internal->LinkImplementationPropertyEntries.begin(),
  3059. end = this->Internal->LinkImplementationPropertyEntries.end();
  3060. it != end; ++it)
  3061. {
  3062. output += sep;
  3063. output += it->Value;
  3064. sep = ";";
  3065. }
  3066. return output.c_str();
  3067. }
  3068. if (prop == "IMPORTED")
  3069. {
  3070. return this->IsImported()?"TRUE":"FALSE";
  3071. }
  3072. if(prop == "SOURCES")
  3073. {
  3074. cmOStringStream ss;
  3075. const char* sep = "";
  3076. typedef cmTargetInternals::TargetPropertyEntry
  3077. TargetPropertyEntry;
  3078. for(std::vector<TargetPropertyEntry*>::const_iterator
  3079. i = this->Internal->SourceEntries.begin();
  3080. i != this->Internal->SourceEntries.end(); ++i)
  3081. {
  3082. std::string entry = (*i)->ge->GetInput();
  3083. std::vector<std::string> files;
  3084. cmSystemTools::ExpandListArgument(entry, files);
  3085. for (std::vector<std::string>::const_iterator
  3086. li = files.begin(); li != files.end(); ++li)
  3087. {
  3088. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  3089. (*li)[li->size() - 1] == '>')
  3090. {
  3091. std::string objLibName = li->substr(17, li->size()-18);
  3092. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  3093. {
  3094. ss << sep;
  3095. sep = ";";
  3096. ss << *li;
  3097. continue;
  3098. }
  3099. bool addContent = false;
  3100. bool noMessage = true;
  3101. cmOStringStream e;
  3102. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  3103. switch(context->GetPolicyStatus(cmPolicies::CMP0051))
  3104. {
  3105. case cmPolicies::WARN:
  3106. e << (this->Makefile->GetPolicies()
  3107. ->GetPolicyWarning(cmPolicies::CMP0051)) << "\n";
  3108. noMessage = false;
  3109. case cmPolicies::OLD:
  3110. break;
  3111. case cmPolicies::REQUIRED_ALWAYS:
  3112. case cmPolicies::REQUIRED_IF_USED:
  3113. case cmPolicies::NEW:
  3114. addContent = true;
  3115. }
  3116. if (!noMessage)
  3117. {
  3118. e << "Target \"" << this->Name << "\" contains $<TARGET_OBJECTS> "
  3119. "generator expression in its sources list. This content was not "
  3120. "previously part of the SOURCES property when that property was "
  3121. "read at configure time. Code reading that property needs to be "
  3122. "adapted to ignore the generator expression using the "
  3123. "string(GENEX_STRIP) command.";
  3124. context->IssueMessage(messageType, e.str());
  3125. }
  3126. if (addContent)
  3127. {
  3128. ss << sep;
  3129. sep = ";";
  3130. ss << *li;
  3131. }
  3132. }
  3133. else if (cmGeneratorExpression::Find(*li) == std::string::npos)
  3134. {
  3135. ss << sep;
  3136. sep = ";";
  3137. ss << *li;
  3138. }
  3139. else
  3140. {
  3141. cmSourceFile *sf = this->Makefile->GetOrCreateSource(*li);
  3142. // Construct what is known about this source file location.
  3143. cmSourceFileLocation const& location = sf->GetLocation();
  3144. std::string sname = location.GetDirectory();
  3145. if(!sname.empty())
  3146. {
  3147. sname += "/";
  3148. }
  3149. sname += location.GetName();
  3150. ss << sep;
  3151. sep = ";";
  3152. // Append this list entry.
  3153. ss << sname;
  3154. }
  3155. }
  3156. }
  3157. this->Properties.SetProperty("SOURCES", ss.str().c_str(),
  3158. cmProperty::TARGET);
  3159. }
  3160. // the type property returns what type the target is
  3161. if (prop == "TYPE")
  3162. {
  3163. return cmTarget::GetTargetTypeName(this->GetType());
  3164. }
  3165. bool chain = false;
  3166. const char *retVal =
  3167. this->Properties.GetPropertyValue(prop, cmProperty::TARGET, chain);
  3168. if (chain)
  3169. {
  3170. return this->Makefile->GetProperty(prop, cmProperty::TARGET);
  3171. }
  3172. return retVal;
  3173. }
  3174. //----------------------------------------------------------------------------
  3175. bool cmTarget::GetPropertyAsBool(const std::string& prop) const
  3176. {
  3177. return cmSystemTools::IsOn(this->GetProperty(prop));
  3178. }
  3179. //----------------------------------------------------------------------------
  3180. class cmTargetCollectLinkLanguages
  3181. {
  3182. public:
  3183. cmTargetCollectLinkLanguages(cmTarget const* target,
  3184. const std::string& config,
  3185. std::set<std::string>& languages,
  3186. cmTarget const* head):
  3187. Config(config), Languages(languages), HeadTarget(head),
  3188. Makefile(target->GetMakefile()), Target(target)
  3189. { this->Visited.insert(target); }
  3190. void Visit(cmLinkItem const& item)
  3191. {
  3192. if(!item.Target)
  3193. {
  3194. if(item.find("::") != std::string::npos)
  3195. {
  3196. bool noMessage = false;
  3197. cmake::MessageType messageType = cmake::FATAL_ERROR;
  3198. cmOStringStream e;
  3199. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  3200. {
  3201. case cmPolicies::WARN:
  3202. {
  3203. e << (this->Makefile->GetPolicies()
  3204. ->GetPolicyWarning(cmPolicies::CMP0028)) << "\n";
  3205. messageType = cmake::AUTHOR_WARNING;
  3206. }
  3207. break;
  3208. case cmPolicies::OLD:
  3209. noMessage = true;
  3210. case cmPolicies::REQUIRED_IF_USED:
  3211. case cmPolicies::REQUIRED_ALWAYS:
  3212. case cmPolicies::NEW:
  3213. // Issue the fatal message.
  3214. break;
  3215. }
  3216. if(!noMessage)
  3217. {
  3218. e << "Target \"" << this->Target->GetName()
  3219. << "\" links to target \"" << item
  3220. << "\" but the target was not found. Perhaps a find_package() "
  3221. "call is missing for an IMPORTED target, or an ALIAS target is "
  3222. "missing?";
  3223. this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
  3224. e.str(),
  3225. this->Target->GetBacktrace());
  3226. }
  3227. }
  3228. return;
  3229. }
  3230. if(!this->Visited.insert(item.Target).second)
  3231. {
  3232. return;
  3233. }
  3234. cmTarget::LinkInterface const* iface =
  3235. item.Target->GetLinkInterface(this->Config, this->HeadTarget);
  3236. if(!iface) { return; }
  3237. for(std::vector<std::string>::const_iterator
  3238. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  3239. {
  3240. this->Languages.insert(*li);
  3241. }
  3242. for(std::vector<cmLinkItem>::const_iterator
  3243. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  3244. {
  3245. this->Visit(*li);
  3246. }
  3247. }
  3248. private:
  3249. std::string Config;
  3250. std::set<std::string>& Languages;
  3251. cmTarget const* HeadTarget;
  3252. cmMakefile* Makefile;
  3253. const cmTarget* Target;
  3254. std::set<cmTarget const*> Visited;
  3255. };
  3256. //----------------------------------------------------------------------------
  3257. std::string cmTarget::GetLinkerLanguage(const std::string& config) const
  3258. {
  3259. return this->GetLinkClosure(config)->LinkerLanguage;
  3260. }
  3261. //----------------------------------------------------------------------------
  3262. cmTarget::LinkClosure const*
  3263. cmTarget::GetLinkClosure(const std::string& config) const
  3264. {
  3265. std::string key(cmSystemTools::UpperCase(config));
  3266. cmTargetInternals::LinkClosureMapType::iterator
  3267. i = this->Internal->LinkClosureMap.find(key);
  3268. if(i == this->Internal->LinkClosureMap.end())
  3269. {
  3270. LinkClosure lc;
  3271. this->ComputeLinkClosure(config, lc);
  3272. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  3273. i = this->Internal->LinkClosureMap.insert(entry).first;
  3274. }
  3275. return &i->second;
  3276. }
  3277. //----------------------------------------------------------------------------
  3278. class cmTargetSelectLinker
  3279. {
  3280. int Preference;
  3281. cmTarget const* Target;
  3282. cmMakefile* Makefile;
  3283. cmGlobalGenerator* GG;
  3284. std::set<std::string> Preferred;
  3285. public:
  3286. cmTargetSelectLinker(cmTarget const* target): Preference(0), Target(target)
  3287. {
  3288. this->Makefile = this->Target->GetMakefile();
  3289. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  3290. }
  3291. void Consider(const std::string& lang)
  3292. {
  3293. int preference = this->GG->GetLinkerPreference(lang);
  3294. if(preference > this->Preference)
  3295. {
  3296. this->Preference = preference;
  3297. this->Preferred.clear();
  3298. }
  3299. if(preference == this->Preference)
  3300. {
  3301. this->Preferred.insert(lang);
  3302. }
  3303. }
  3304. std::string Choose()
  3305. {
  3306. if(this->Preferred.empty())
  3307. {
  3308. return "";
  3309. }
  3310. else if(this->Preferred.size() > 1)
  3311. {
  3312. cmOStringStream e;
  3313. e << "Target " << this->Target->GetName()
  3314. << " contains multiple languages with the highest linker preference"
  3315. << " (" << this->Preference << "):\n";
  3316. for(std::set<std::string>::const_iterator
  3317. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3318. {
  3319. e << " " << *li << "\n";
  3320. }
  3321. e << "Set the LINKER_LANGUAGE property for this target.";
  3322. cmake* cm = this->Makefile->GetCMakeInstance();
  3323. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3324. this->Target->GetBacktrace());
  3325. }
  3326. return *this->Preferred.begin();
  3327. }
  3328. };
  3329. //----------------------------------------------------------------------------
  3330. void cmTarget::ComputeLinkClosure(const std::string& config,
  3331. LinkClosure& lc) const
  3332. {
  3333. // Get languages built in this target.
  3334. std::set<std::string> languages;
  3335. LinkImplementation const* impl = this->GetLinkImplementation(config);
  3336. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3337. li != impl->Languages.end(); ++li)
  3338. {
  3339. languages.insert(*li);
  3340. }
  3341. // Add interface languages from linked targets.
  3342. cmTargetCollectLinkLanguages cll(this, config, languages, this);
  3343. for(std::vector<cmLinkItem>::const_iterator li = impl->Libraries.begin();
  3344. li != impl->Libraries.end(); ++li)
  3345. {
  3346. cll.Visit(*li);
  3347. }
  3348. // Store the transitive closure of languages.
  3349. for(std::set<std::string>::const_iterator li = languages.begin();
  3350. li != languages.end(); ++li)
  3351. {
  3352. lc.Languages.push_back(*li);
  3353. }
  3354. // Choose the language whose linker should be used.
  3355. if(this->GetProperty("HAS_CXX"))
  3356. {
  3357. lc.LinkerLanguage = "CXX";
  3358. }
  3359. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3360. {
  3361. lc.LinkerLanguage = linkerLang;
  3362. }
  3363. else
  3364. {
  3365. // Find the language with the highest preference value.
  3366. cmTargetSelectLinker tsl(this);
  3367. // First select from the languages compiled directly in this target.
  3368. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3369. li != impl->Languages.end(); ++li)
  3370. {
  3371. tsl.Consider(*li);
  3372. }
  3373. // Now consider languages that propagate from linked targets.
  3374. for(std::set<std::string>::const_iterator sit = languages.begin();
  3375. sit != languages.end(); ++sit)
  3376. {
  3377. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3378. if(this->Makefile->IsOn(propagates))
  3379. {
  3380. tsl.Consider(*sit);
  3381. }
  3382. }
  3383. lc.LinkerLanguage = tsl.Choose();
  3384. }
  3385. }
  3386. //----------------------------------------------------------------------------
  3387. void cmTarget::ExpandLinkItems(std::string const& prop,
  3388. std::string const& value,
  3389. std::string const& config,
  3390. cmTarget const* headTarget,
  3391. bool usage_requirements_only,
  3392. std::vector<cmLinkItem>& items) const
  3393. {
  3394. cmGeneratorExpression ge;
  3395. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3396. if(usage_requirements_only)
  3397. {
  3398. dagChecker.SetTransitivePropertiesOnly();
  3399. }
  3400. std::vector<std::string> libs;
  3401. cmSystemTools::ExpandListArgument(ge.Parse(value)->Evaluate(
  3402. this->Makefile,
  3403. config,
  3404. false,
  3405. headTarget,
  3406. this, &dagChecker), libs);
  3407. this->LookupLinkItems(libs, items);
  3408. }
  3409. //----------------------------------------------------------------------------
  3410. void cmTarget::LookupLinkItems(std::vector<std::string> const& names,
  3411. std::vector<cmLinkItem>& items) const
  3412. {
  3413. for(std::vector<std::string>::const_iterator i = names.begin();
  3414. i != names.end(); ++i)
  3415. {
  3416. std::string name = this->CheckCMP0004(*i);
  3417. if(name == this->GetName() || name.empty())
  3418. {
  3419. continue;
  3420. }
  3421. items.push_back(cmLinkItem(name, this->FindTargetToLink(name)));
  3422. }
  3423. }
  3424. //----------------------------------------------------------------------------
  3425. const char* cmTarget::GetSuffixVariableInternal(bool implib) const
  3426. {
  3427. switch(this->GetType())
  3428. {
  3429. case cmTarget::STATIC_LIBRARY:
  3430. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3431. case cmTarget::SHARED_LIBRARY:
  3432. return (implib
  3433. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3434. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3435. case cmTarget::MODULE_LIBRARY:
  3436. return (implib
  3437. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3438. : "CMAKE_SHARED_MODULE_SUFFIX");
  3439. case cmTarget::EXECUTABLE:
  3440. return (implib
  3441. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3442. : "CMAKE_EXECUTABLE_SUFFIX");
  3443. default:
  3444. break;
  3445. }
  3446. return "";
  3447. }
  3448. //----------------------------------------------------------------------------
  3449. const char* cmTarget::GetPrefixVariableInternal(bool implib) const
  3450. {
  3451. switch(this->GetType())
  3452. {
  3453. case cmTarget::STATIC_LIBRARY:
  3454. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3455. case cmTarget::SHARED_LIBRARY:
  3456. return (implib
  3457. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3458. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3459. case cmTarget::MODULE_LIBRARY:
  3460. return (implib
  3461. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3462. : "CMAKE_SHARED_MODULE_PREFIX");
  3463. case cmTarget::EXECUTABLE:
  3464. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  3465. default:
  3466. break;
  3467. }
  3468. return "";
  3469. }
  3470. //----------------------------------------------------------------------------
  3471. std::string cmTarget::GetPDBName(const std::string& config) const
  3472. {
  3473. std::string prefix;
  3474. std::string base;
  3475. std::string suffix;
  3476. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3477. std::vector<std::string> props;
  3478. std::string configUpper = cmSystemTools::UpperCase(config);
  3479. if(!configUpper.empty())
  3480. {
  3481. // PDB_NAME_<CONFIG>
  3482. props.push_back("PDB_NAME_" + configUpper);
  3483. }
  3484. // PDB_NAME
  3485. props.push_back("PDB_NAME");
  3486. for(std::vector<std::string>::const_iterator i = props.begin();
  3487. i != props.end(); ++i)
  3488. {
  3489. if(const char* outName = this->GetProperty(*i))
  3490. {
  3491. base = outName;
  3492. break;
  3493. }
  3494. }
  3495. return prefix+base+".pdb";
  3496. }
  3497. //----------------------------------------------------------------------------
  3498. std::string cmTarget::GetCompilePDBName(const std::string& config) const
  3499. {
  3500. std::string prefix;
  3501. std::string base;
  3502. std::string suffix;
  3503. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3504. // Check for a per-configuration output directory target property.
  3505. std::string configUpper = cmSystemTools::UpperCase(config);
  3506. std::string configProp = "COMPILE_PDB_NAME_";
  3507. configProp += configUpper;
  3508. const char* config_name = this->GetProperty(configProp);
  3509. if(config_name && *config_name)
  3510. {
  3511. return prefix + config_name + ".pdb";
  3512. }
  3513. const char* name = this->GetProperty("COMPILE_PDB_NAME");
  3514. if(name && *name)
  3515. {
  3516. return prefix + name + ".pdb";
  3517. }
  3518. return "";
  3519. }
  3520. //----------------------------------------------------------------------------
  3521. std::string cmTarget::GetCompilePDBPath(const std::string& config) const
  3522. {
  3523. std::string dir = this->GetCompilePDBDirectory(config);
  3524. std::string name = this->GetCompilePDBName(config);
  3525. if(dir.empty() && !name.empty())
  3526. {
  3527. dir = this->GetPDBDirectory(config);
  3528. }
  3529. if(!dir.empty())
  3530. {
  3531. dir += "/";
  3532. }
  3533. return dir + name;
  3534. }
  3535. //----------------------------------------------------------------------------
  3536. bool cmTarget::HasSOName(const std::string& config) const
  3537. {
  3538. // soname is supported only for shared libraries and modules,
  3539. // and then only when the platform supports an soname flag.
  3540. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3541. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3542. !this->GetPropertyAsBool("NO_SONAME") &&
  3543. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  3544. }
  3545. //----------------------------------------------------------------------------
  3546. std::string cmTarget::GetSOName(const std::string& config) const
  3547. {
  3548. if(this->IsImported())
  3549. {
  3550. // Lookup the imported soname.
  3551. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3552. {
  3553. if(info->NoSOName)
  3554. {
  3555. // The imported library has no builtin soname so the name
  3556. // searched at runtime will be just the filename.
  3557. return cmSystemTools::GetFilenameName(info->Location);
  3558. }
  3559. else
  3560. {
  3561. // Use the soname given if any.
  3562. if(info->SOName.find("@rpath/") == 0)
  3563. {
  3564. return info->SOName.substr(6);
  3565. }
  3566. return info->SOName;
  3567. }
  3568. }
  3569. else
  3570. {
  3571. return "";
  3572. }
  3573. }
  3574. else
  3575. {
  3576. // Compute the soname that will be built.
  3577. std::string name;
  3578. std::string soName;
  3579. std::string realName;
  3580. std::string impName;
  3581. std::string pdbName;
  3582. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3583. return soName;
  3584. }
  3585. }
  3586. //----------------------------------------------------------------------------
  3587. bool cmTarget::HasMacOSXRpathInstallNameDir(const std::string& config) const
  3588. {
  3589. bool install_name_is_rpath = false;
  3590. bool macosx_rpath = false;
  3591. if(!this->IsImportedTarget)
  3592. {
  3593. if(this->GetType() != cmTarget::SHARED_LIBRARY)
  3594. {
  3595. return false;
  3596. }
  3597. const char* install_name = this->GetProperty("INSTALL_NAME_DIR");
  3598. bool use_install_name =
  3599. this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH");
  3600. if(install_name && use_install_name &&
  3601. std::string(install_name) == "@rpath")
  3602. {
  3603. install_name_is_rpath = true;
  3604. }
  3605. else if(install_name && use_install_name)
  3606. {
  3607. return false;
  3608. }
  3609. if(!install_name_is_rpath)
  3610. {
  3611. macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  3612. }
  3613. }
  3614. else
  3615. {
  3616. // Lookup the imported soname.
  3617. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3618. {
  3619. if(!info->NoSOName && !info->SOName.empty())
  3620. {
  3621. if(info->SOName.find("@rpath/") == 0)
  3622. {
  3623. install_name_is_rpath = true;
  3624. }
  3625. }
  3626. else
  3627. {
  3628. std::string install_name;
  3629. cmSystemTools::GuessLibraryInstallName(info->Location, install_name);
  3630. if(install_name.find("@rpath") != std::string::npos)
  3631. {
  3632. install_name_is_rpath = true;
  3633. }
  3634. }
  3635. }
  3636. }
  3637. if(!install_name_is_rpath && !macosx_rpath)
  3638. {
  3639. return false;
  3640. }
  3641. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3642. {
  3643. cmOStringStream w;
  3644. w << "Attempting to use";
  3645. if(macosx_rpath)
  3646. {
  3647. w << " MACOSX_RPATH";
  3648. }
  3649. else
  3650. {
  3651. w << " @rpath";
  3652. }
  3653. w << " without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being set.";
  3654. w << " This could be because you are using a Mac OS X version";
  3655. w << " less than 10.5 or because CMake's platform configuration is";
  3656. w << " corrupt.";
  3657. cmake* cm = this->Makefile->GetCMakeInstance();
  3658. cm->IssueMessage(cmake::FATAL_ERROR, w.str(), this->GetBacktrace());
  3659. }
  3660. return true;
  3661. }
  3662. //----------------------------------------------------------------------------
  3663. bool cmTarget::MacOSXRpathInstallNameDirDefault() const
  3664. {
  3665. // we can't do rpaths when unsupported
  3666. if(!this->Makefile->IsSet("CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG"))
  3667. {
  3668. return false;
  3669. }
  3670. const char* macosx_rpath_str = this->GetProperty("MACOSX_RPATH");
  3671. if(macosx_rpath_str)
  3672. {
  3673. return this->GetPropertyAsBool("MACOSX_RPATH");
  3674. }
  3675. cmPolicies::PolicyStatus cmp0042 = this->GetPolicyStatusCMP0042();
  3676. if(cmp0042 == cmPolicies::WARN)
  3677. {
  3678. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3679. AddCMP0042WarnTarget(this->GetName());
  3680. }
  3681. if(cmp0042 == cmPolicies::NEW)
  3682. {
  3683. return true;
  3684. }
  3685. return false;
  3686. }
  3687. //----------------------------------------------------------------------------
  3688. bool cmTarget::IsImportedSharedLibWithoutSOName(
  3689. const std::string& config) const
  3690. {
  3691. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3692. {
  3693. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3694. {
  3695. return info->NoSOName;
  3696. }
  3697. }
  3698. return false;
  3699. }
  3700. //----------------------------------------------------------------------------
  3701. std::string cmTarget::NormalGetRealName(const std::string& config) const
  3702. {
  3703. // This should not be called for imported targets.
  3704. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3705. // enforcement of the limited imported target API.
  3706. if(this->IsImported())
  3707. {
  3708. std::string msg = "NormalGetRealName called on imported target: ";
  3709. msg += this->GetName();
  3710. this->GetMakefile()->
  3711. IssueMessage(cmake::INTERNAL_ERROR,
  3712. msg);
  3713. }
  3714. if(this->GetType() == cmTarget::EXECUTABLE)
  3715. {
  3716. // Compute the real name that will be built.
  3717. std::string name;
  3718. std::string realName;
  3719. std::string impName;
  3720. std::string pdbName;
  3721. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3722. return realName;
  3723. }
  3724. else
  3725. {
  3726. // Compute the real name that will be built.
  3727. std::string name;
  3728. std::string soName;
  3729. std::string realName;
  3730. std::string impName;
  3731. std::string pdbName;
  3732. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3733. return realName;
  3734. }
  3735. }
  3736. //----------------------------------------------------------------------------
  3737. std::string cmTarget::GetFullName(const std::string& config,
  3738. bool implib) const
  3739. {
  3740. if(this->IsImported())
  3741. {
  3742. return this->GetFullNameImported(config, implib);
  3743. }
  3744. else
  3745. {
  3746. return this->GetFullNameInternal(config, implib);
  3747. }
  3748. }
  3749. //----------------------------------------------------------------------------
  3750. std::string
  3751. cmTarget::GetFullNameImported(const std::string& config, bool implib) const
  3752. {
  3753. return cmSystemTools::GetFilenameName(
  3754. this->ImportedGetFullPath(config, implib));
  3755. }
  3756. //----------------------------------------------------------------------------
  3757. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3758. std::string& suffix,
  3759. const std::string& config,
  3760. bool implib) const
  3761. {
  3762. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3763. }
  3764. //----------------------------------------------------------------------------
  3765. std::string cmTarget::GetFullPath(const std::string& config, bool implib,
  3766. bool realname) const
  3767. {
  3768. if(this->IsImported())
  3769. {
  3770. return this->ImportedGetFullPath(config, implib);
  3771. }
  3772. else
  3773. {
  3774. return this->NormalGetFullPath(config, implib, realname);
  3775. }
  3776. }
  3777. //----------------------------------------------------------------------------
  3778. std::string cmTarget::NormalGetFullPath(const std::string& config,
  3779. bool implib, bool realname) const
  3780. {
  3781. std::string fpath = this->GetDirectory(config, implib);
  3782. fpath += "/";
  3783. if(this->IsAppBundleOnApple())
  3784. {
  3785. fpath = this->BuildMacContentDirectory(fpath, config, false);
  3786. fpath += "/";
  3787. }
  3788. // Add the full name of the target.
  3789. if(implib)
  3790. {
  3791. fpath += this->GetFullName(config, true);
  3792. }
  3793. else if(realname)
  3794. {
  3795. fpath += this->NormalGetRealName(config);
  3796. }
  3797. else
  3798. {
  3799. fpath += this->GetFullName(config, false);
  3800. }
  3801. return fpath;
  3802. }
  3803. //----------------------------------------------------------------------------
  3804. std::string
  3805. cmTarget::ImportedGetFullPath(const std::string& config, bool implib) const
  3806. {
  3807. std::string result;
  3808. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  3809. {
  3810. result = implib? info->ImportLibrary : info->Location;
  3811. }
  3812. if(result.empty())
  3813. {
  3814. result = this->GetName();
  3815. result += "-NOTFOUND";
  3816. }
  3817. return result;
  3818. }
  3819. //----------------------------------------------------------------------------
  3820. std::string
  3821. cmTarget::GetFullNameInternal(const std::string& config, bool implib) const
  3822. {
  3823. std::string prefix;
  3824. std::string base;
  3825. std::string suffix;
  3826. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3827. return prefix+base+suffix;
  3828. }
  3829. //----------------------------------------------------------------------------
  3830. void cmTarget::GetFullNameInternal(const std::string& config,
  3831. bool implib,
  3832. std::string& outPrefix,
  3833. std::string& outBase,
  3834. std::string& outSuffix) const
  3835. {
  3836. // Use just the target name for non-main target types.
  3837. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3838. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3839. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3840. this->GetType() != cmTarget::EXECUTABLE)
  3841. {
  3842. outPrefix = "";
  3843. outBase = this->GetName();
  3844. outSuffix = "";
  3845. return;
  3846. }
  3847. // Return an empty name for the import library if this platform
  3848. // does not support import libraries.
  3849. if(implib &&
  3850. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3851. {
  3852. outPrefix = "";
  3853. outBase = "";
  3854. outSuffix = "";
  3855. return;
  3856. }
  3857. // The implib option is only allowed for shared libraries, module
  3858. // libraries, and executables.
  3859. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3860. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3861. this->GetType() != cmTarget::EXECUTABLE)
  3862. {
  3863. implib = false;
  3864. }
  3865. // Compute the full name for main target types.
  3866. const char* targetPrefix = (implib
  3867. ? this->GetProperty("IMPORT_PREFIX")
  3868. : this->GetProperty("PREFIX"));
  3869. const char* targetSuffix = (implib
  3870. ? this->GetProperty("IMPORT_SUFFIX")
  3871. : this->GetProperty("SUFFIX"));
  3872. const char* configPostfix = 0;
  3873. if(!config.empty())
  3874. {
  3875. std::string configProp = cmSystemTools::UpperCase(config);
  3876. configProp += "_POSTFIX";
  3877. configPostfix = this->GetProperty(configProp);
  3878. // Mac application bundles and frameworks have no postfix.
  3879. if(configPostfix &&
  3880. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3881. {
  3882. configPostfix = 0;
  3883. }
  3884. }
  3885. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3886. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3887. // Check for language-specific default prefix and suffix.
  3888. std::string ll = this->GetLinkerLanguage(config);
  3889. if(!ll.empty())
  3890. {
  3891. if(!targetSuffix && suffixVar && *suffixVar)
  3892. {
  3893. std::string langSuff = suffixVar + std::string("_") + ll;
  3894. targetSuffix = this->Makefile->GetDefinition(langSuff);
  3895. }
  3896. if(!targetPrefix && prefixVar && *prefixVar)
  3897. {
  3898. std::string langPrefix = prefixVar + std::string("_") + ll;
  3899. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  3900. }
  3901. }
  3902. // if there is no prefix on the target use the cmake definition
  3903. if(!targetPrefix && prefixVar)
  3904. {
  3905. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3906. }
  3907. // if there is no suffix on the target use the cmake definition
  3908. if(!targetSuffix && suffixVar)
  3909. {
  3910. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3911. }
  3912. // frameworks have directory prefix but no suffix
  3913. std::string fw_prefix;
  3914. if(this->IsFrameworkOnApple())
  3915. {
  3916. fw_prefix = this->GetOutputName(config, false);
  3917. fw_prefix += ".framework/";
  3918. targetPrefix = fw_prefix.c_str();
  3919. targetSuffix = 0;
  3920. }
  3921. if(this->IsCFBundleOnApple())
  3922. {
  3923. fw_prefix = this->GetOutputName(config, false);
  3924. fw_prefix += ".";
  3925. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  3926. if (!ext)
  3927. {
  3928. ext = "bundle";
  3929. }
  3930. fw_prefix += ext;
  3931. fw_prefix += "/Contents/MacOS/";
  3932. targetPrefix = fw_prefix.c_str();
  3933. targetSuffix = 0;
  3934. }
  3935. // Begin the final name with the prefix.
  3936. outPrefix = targetPrefix?targetPrefix:"";
  3937. // Append the target name or property-specified name.
  3938. outBase += this->GetOutputName(config, implib);
  3939. // Append the per-configuration postfix.
  3940. outBase += configPostfix?configPostfix:"";
  3941. // Name shared libraries with their version number on some platforms.
  3942. if(const char* soversion = this->GetProperty("SOVERSION"))
  3943. {
  3944. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3945. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3946. {
  3947. outBase += "-";
  3948. outBase += soversion;
  3949. }
  3950. }
  3951. // Append the suffix.
  3952. outSuffix = targetSuffix?targetSuffix:"";
  3953. }
  3954. //----------------------------------------------------------------------------
  3955. void cmTarget::GetLibraryNames(std::string& name,
  3956. std::string& soName,
  3957. std::string& realName,
  3958. std::string& impName,
  3959. std::string& pdbName,
  3960. const std::string& config) const
  3961. {
  3962. // This should not be called for imported targets.
  3963. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3964. // enforcement of the limited imported target API.
  3965. if(this->IsImported())
  3966. {
  3967. std::string msg = "GetLibraryNames called on imported target: ";
  3968. msg += this->GetName();
  3969. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3970. msg);
  3971. return;
  3972. }
  3973. assert(this->GetType() != INTERFACE_LIBRARY);
  3974. // Check for library version properties.
  3975. const char* version = this->GetProperty("VERSION");
  3976. const char* soversion = this->GetProperty("SOVERSION");
  3977. if(!this->HasSOName(config) ||
  3978. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  3979. this->IsFrameworkOnApple())
  3980. {
  3981. // Versioning is supported only for shared libraries and modules,
  3982. // and then only when the platform supports an soname flag.
  3983. version = 0;
  3984. soversion = 0;
  3985. }
  3986. if(version && !soversion)
  3987. {
  3988. // The soversion must be set if the library version is set. Use
  3989. // the library version as the soversion.
  3990. soversion = version;
  3991. }
  3992. if(!version && soversion)
  3993. {
  3994. // Use the soversion as the library version.
  3995. version = soversion;
  3996. }
  3997. // Get the components of the library name.
  3998. std::string prefix;
  3999. std::string base;
  4000. std::string suffix;
  4001. this->GetFullNameInternal(config, false, prefix, base, suffix);
  4002. // The library name.
  4003. name = prefix+base+suffix;
  4004. if(this->IsFrameworkOnApple())
  4005. {
  4006. realName = prefix;
  4007. realName += "Versions/";
  4008. realName += this->GetFrameworkVersion();
  4009. realName += "/";
  4010. realName += base;
  4011. soName = realName;
  4012. }
  4013. else
  4014. {
  4015. // The library's soname.
  4016. this->ComputeVersionedName(soName, prefix, base, suffix,
  4017. name, soversion);
  4018. // The library's real name on disk.
  4019. this->ComputeVersionedName(realName, prefix, base, suffix,
  4020. name, version);
  4021. }
  4022. // The import library name.
  4023. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4024. this->GetType() == cmTarget::MODULE_LIBRARY)
  4025. {
  4026. impName = this->GetFullNameInternal(config, true);
  4027. }
  4028. else
  4029. {
  4030. impName = "";
  4031. }
  4032. // The program database file name.
  4033. pdbName = this->GetPDBName(config);
  4034. }
  4035. //----------------------------------------------------------------------------
  4036. void cmTarget::ComputeVersionedName(std::string& vName,
  4037. std::string const& prefix,
  4038. std::string const& base,
  4039. std::string const& suffix,
  4040. std::string const& name,
  4041. const char* version) const
  4042. {
  4043. vName = this->IsApple? (prefix+base) : name;
  4044. if(version)
  4045. {
  4046. vName += ".";
  4047. vName += version;
  4048. }
  4049. vName += this->IsApple? suffix : std::string();
  4050. }
  4051. //----------------------------------------------------------------------------
  4052. void cmTarget::GetExecutableNames(std::string& name,
  4053. std::string& realName,
  4054. std::string& impName,
  4055. std::string& pdbName,
  4056. const std::string& config) const
  4057. {
  4058. // This should not be called for imported targets.
  4059. // TODO: Split cmTarget into a class hierarchy to get compile-time
  4060. // enforcement of the limited imported target API.
  4061. if(this->IsImported())
  4062. {
  4063. std::string msg =
  4064. "GetExecutableNames called on imported target: ";
  4065. msg += this->GetName();
  4066. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  4067. }
  4068. // This versioning is supported only for executables and then only
  4069. // when the platform supports symbolic links.
  4070. #if defined(_WIN32) && !defined(__CYGWIN__)
  4071. const char* version = 0;
  4072. #else
  4073. // Check for executable version properties.
  4074. const char* version = this->GetProperty("VERSION");
  4075. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  4076. {
  4077. version = 0;
  4078. }
  4079. #endif
  4080. // Get the components of the executable name.
  4081. std::string prefix;
  4082. std::string base;
  4083. std::string suffix;
  4084. this->GetFullNameInternal(config, false, prefix, base, suffix);
  4085. // The executable name.
  4086. name = prefix+base+suffix;
  4087. // The executable's real name on disk.
  4088. #if defined(__CYGWIN__)
  4089. realName = prefix+base;
  4090. #else
  4091. realName = name;
  4092. #endif
  4093. if(version)
  4094. {
  4095. realName += "-";
  4096. realName += version;
  4097. }
  4098. #if defined(__CYGWIN__)
  4099. realName += suffix;
  4100. #endif
  4101. // The import library name.
  4102. impName = this->GetFullNameInternal(config, true);
  4103. // The program database file name.
  4104. pdbName = this->GetPDBName(config);
  4105. }
  4106. //----------------------------------------------------------------------------
  4107. bool cmTarget::HasImplibGNUtoMS() const
  4108. {
  4109. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  4110. }
  4111. //----------------------------------------------------------------------------
  4112. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  4113. std::string& out, const char* newExt) const
  4114. {
  4115. if(this->HasImplibGNUtoMS() &&
  4116. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  4117. {
  4118. out = gnuName.substr(0, gnuName.size()-6);
  4119. out += newExt? newExt : ".lib";
  4120. return true;
  4121. }
  4122. return false;
  4123. }
  4124. //----------------------------------------------------------------------------
  4125. void cmTarget::SetPropertyDefault(const std::string& property,
  4126. const char* default_value)
  4127. {
  4128. // Compute the name of the variable holding the default value.
  4129. std::string var = "CMAKE_";
  4130. var += property;
  4131. if(const char* value = this->Makefile->GetDefinition(var))
  4132. {
  4133. this->SetProperty(property, value);
  4134. }
  4135. else if(default_value)
  4136. {
  4137. this->SetProperty(property, default_value);
  4138. }
  4139. }
  4140. //----------------------------------------------------------------------------
  4141. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  4142. {
  4143. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  4144. {
  4145. return false;
  4146. }
  4147. if(LinkImplementation const* impl =
  4148. this->GetLinkImplementationLibraries(config))
  4149. {
  4150. return !impl->Libraries.empty();
  4151. }
  4152. return false;
  4153. }
  4154. //----------------------------------------------------------------------------
  4155. bool cmTarget::HaveInstallTreeRPATH() const
  4156. {
  4157. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  4158. return (install_rpath && *install_rpath) &&
  4159. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  4160. }
  4161. //----------------------------------------------------------------------------
  4162. bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
  4163. {
  4164. // Only executables and shared libraries can have an rpath and may
  4165. // need relinking.
  4166. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  4167. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  4168. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  4169. {
  4170. return false;
  4171. }
  4172. // If there is no install location this target will not be installed
  4173. // and therefore does not need relinking.
  4174. if(!this->GetHaveInstallRule())
  4175. {
  4176. return false;
  4177. }
  4178. // If skipping all rpaths completely then no relinking is needed.
  4179. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4180. {
  4181. return false;
  4182. }
  4183. // If building with the install-tree rpath no relinking is needed.
  4184. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4185. {
  4186. return false;
  4187. }
  4188. // If chrpath is going to be used no relinking is needed.
  4189. if(this->IsChrpathUsed(config))
  4190. {
  4191. return false;
  4192. }
  4193. // Check for rpath support on this platform.
  4194. std::string ll = this->GetLinkerLanguage(config);
  4195. if(!ll.empty())
  4196. {
  4197. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4198. flagVar += ll;
  4199. flagVar += "_FLAG";
  4200. if(!this->Makefile->IsSet(flagVar))
  4201. {
  4202. // There is no rpath support on this platform so nothing needs
  4203. // relinking.
  4204. return false;
  4205. }
  4206. }
  4207. else
  4208. {
  4209. // No linker language is known. This error will be reported by
  4210. // other code.
  4211. return false;
  4212. }
  4213. // If either a build or install tree rpath is set then the rpath
  4214. // will likely change between the build tree and install tree and
  4215. // this target must be relinked.
  4216. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  4217. }
  4218. //----------------------------------------------------------------------------
  4219. std::string cmTarget::GetInstallNameDirForBuildTree(
  4220. const std::string& config) const
  4221. {
  4222. // If building directly for installation then the build tree install_name
  4223. // is the same as the install tree.
  4224. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4225. {
  4226. return GetInstallNameDirForInstallTree();
  4227. }
  4228. // Use the build tree directory for the target.
  4229. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  4230. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4231. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  4232. {
  4233. std::string dir;
  4234. bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  4235. if(macosx_rpath)
  4236. {
  4237. dir = "@rpath";
  4238. }
  4239. else
  4240. {
  4241. dir = this->GetDirectory(config);
  4242. }
  4243. dir += "/";
  4244. return dir;
  4245. }
  4246. else
  4247. {
  4248. return "";
  4249. }
  4250. }
  4251. //----------------------------------------------------------------------------
  4252. std::string cmTarget::GetInstallNameDirForInstallTree() const
  4253. {
  4254. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4255. {
  4256. std::string dir;
  4257. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  4258. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4259. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  4260. {
  4261. if(install_name_dir && *install_name_dir)
  4262. {
  4263. dir = install_name_dir;
  4264. dir += "/";
  4265. }
  4266. }
  4267. if(!install_name_dir)
  4268. {
  4269. if(this->MacOSXRpathInstallNameDirDefault())
  4270. {
  4271. dir = "@rpath/";
  4272. }
  4273. }
  4274. return dir;
  4275. }
  4276. else
  4277. {
  4278. return "";
  4279. }
  4280. }
  4281. //----------------------------------------------------------------------------
  4282. const char* cmTarget::GetOutputTargetType(bool implib) const
  4283. {
  4284. switch(this->GetType())
  4285. {
  4286. case cmTarget::SHARED_LIBRARY:
  4287. if(this->DLLPlatform)
  4288. {
  4289. if(implib)
  4290. {
  4291. // A DLL import library is treated as an archive target.
  4292. return "ARCHIVE";
  4293. }
  4294. else
  4295. {
  4296. // A DLL shared library is treated as a runtime target.
  4297. return "RUNTIME";
  4298. }
  4299. }
  4300. else
  4301. {
  4302. // For non-DLL platforms shared libraries are treated as
  4303. // library targets.
  4304. return "LIBRARY";
  4305. }
  4306. case cmTarget::STATIC_LIBRARY:
  4307. // Static libraries are always treated as archive targets.
  4308. return "ARCHIVE";
  4309. case cmTarget::MODULE_LIBRARY:
  4310. if(implib)
  4311. {
  4312. // Module libraries are always treated as library targets.
  4313. return "ARCHIVE";
  4314. }
  4315. else
  4316. {
  4317. // Module import libraries are treated as archive targets.
  4318. return "LIBRARY";
  4319. }
  4320. case cmTarget::EXECUTABLE:
  4321. if(implib)
  4322. {
  4323. // Executable import libraries are treated as archive targets.
  4324. return "ARCHIVE";
  4325. }
  4326. else
  4327. {
  4328. // Executables are always treated as runtime targets.
  4329. return "RUNTIME";
  4330. }
  4331. default:
  4332. break;
  4333. }
  4334. return "";
  4335. }
  4336. //----------------------------------------------------------------------------
  4337. bool cmTarget::ComputeOutputDir(const std::string& config,
  4338. bool implib, std::string& out) const
  4339. {
  4340. bool usesDefaultOutputDir = false;
  4341. std::string conf = config;
  4342. // Look for a target property defining the target output directory
  4343. // based on the target type.
  4344. std::string targetTypeName = this->GetOutputTargetType(implib);
  4345. const char* propertyName = 0;
  4346. std::string propertyNameStr = targetTypeName;
  4347. if(!propertyNameStr.empty())
  4348. {
  4349. propertyNameStr += "_OUTPUT_DIRECTORY";
  4350. propertyName = propertyNameStr.c_str();
  4351. }
  4352. // Check for a per-configuration output directory target property.
  4353. std::string configUpper = cmSystemTools::UpperCase(conf);
  4354. const char* configProp = 0;
  4355. std::string configPropStr = targetTypeName;
  4356. if(!configPropStr.empty())
  4357. {
  4358. configPropStr += "_OUTPUT_DIRECTORY_";
  4359. configPropStr += configUpper;
  4360. configProp = configPropStr.c_str();
  4361. }
  4362. // Select an output directory.
  4363. if(const char* config_outdir = this->GetProperty(configProp))
  4364. {
  4365. // Use the user-specified per-configuration output directory.
  4366. out = config_outdir;
  4367. // Skip per-configuration subdirectory.
  4368. conf = "";
  4369. }
  4370. else if(const char* outdir = this->GetProperty(propertyName))
  4371. {
  4372. // Use the user-specified output directory.
  4373. out = outdir;
  4374. }
  4375. else if(this->GetType() == cmTarget::EXECUTABLE)
  4376. {
  4377. // Lookup the output path for executables.
  4378. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4379. }
  4380. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  4381. this->GetType() == cmTarget::SHARED_LIBRARY ||
  4382. this->GetType() == cmTarget::MODULE_LIBRARY)
  4383. {
  4384. // Lookup the output path for libraries.
  4385. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4386. }
  4387. if(out.empty())
  4388. {
  4389. // Default to the current output directory.
  4390. usesDefaultOutputDir = true;
  4391. out = ".";
  4392. }
  4393. // Convert the output path to a full path in case it is
  4394. // specified as a relative path. Treat a relative path as
  4395. // relative to the current output directory for this makefile.
  4396. out = (cmSystemTools::CollapseFullPath
  4397. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4398. // The generator may add the configuration's subdirectory.
  4399. if(!conf.empty())
  4400. {
  4401. const char *platforms = this->Makefile->GetDefinition(
  4402. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  4403. std::string suffix =
  4404. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  4405. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4406. AppendDirectoryForConfig("/", conf, suffix, out);
  4407. }
  4408. return usesDefaultOutputDir;
  4409. }
  4410. //----------------------------------------------------------------------------
  4411. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  4412. const std::string& config,
  4413. std::string& out) const
  4414. {
  4415. // Look for a target property defining the target output directory
  4416. // based on the target type.
  4417. const char* propertyName = 0;
  4418. std::string propertyNameStr = kind;
  4419. if(!propertyNameStr.empty())
  4420. {
  4421. propertyNameStr += "_OUTPUT_DIRECTORY";
  4422. propertyName = propertyNameStr.c_str();
  4423. }
  4424. std::string conf = config;
  4425. // Check for a per-configuration output directory target property.
  4426. std::string configUpper = cmSystemTools::UpperCase(conf);
  4427. const char* configProp = 0;
  4428. std::string configPropStr = kind;
  4429. if(!configPropStr.empty())
  4430. {
  4431. configPropStr += "_OUTPUT_DIRECTORY_";
  4432. configPropStr += configUpper;
  4433. configProp = configPropStr.c_str();
  4434. }
  4435. // Select an output directory.
  4436. if(const char* config_outdir = this->GetProperty(configProp))
  4437. {
  4438. // Use the user-specified per-configuration output directory.
  4439. out = config_outdir;
  4440. // Skip per-configuration subdirectory.
  4441. conf = "";
  4442. }
  4443. else if(const char* outdir = this->GetProperty(propertyName))
  4444. {
  4445. // Use the user-specified output directory.
  4446. out = outdir;
  4447. }
  4448. if(out.empty())
  4449. {
  4450. return false;
  4451. }
  4452. // Convert the output path to a full path in case it is
  4453. // specified as a relative path. Treat a relative path as
  4454. // relative to the current output directory for this makefile.
  4455. out = (cmSystemTools::CollapseFullPath
  4456. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4457. // The generator may add the configuration's subdirectory.
  4458. if(!conf.empty())
  4459. {
  4460. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4461. AppendDirectoryForConfig("/", conf, "", out);
  4462. }
  4463. return true;
  4464. }
  4465. //----------------------------------------------------------------------------
  4466. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  4467. bool implib) const
  4468. {
  4469. std::string dir;
  4470. return this->ComputeOutputDir(config, implib, dir);
  4471. }
  4472. //----------------------------------------------------------------------------
  4473. std::string cmTarget::GetOutputName(const std::string& config,
  4474. bool implib) const
  4475. {
  4476. std::vector<std::string> props;
  4477. std::string type = this->GetOutputTargetType(implib);
  4478. std::string configUpper = cmSystemTools::UpperCase(config);
  4479. if(!type.empty() && !configUpper.empty())
  4480. {
  4481. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4482. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4483. }
  4484. if(!type.empty())
  4485. {
  4486. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4487. props.push_back(type + "_OUTPUT_NAME");
  4488. }
  4489. if(!configUpper.empty())
  4490. {
  4491. // OUTPUT_NAME_<CONFIG>
  4492. props.push_back("OUTPUT_NAME_" + configUpper);
  4493. // <CONFIG>_OUTPUT_NAME
  4494. props.push_back(configUpper + "_OUTPUT_NAME");
  4495. }
  4496. // OUTPUT_NAME
  4497. props.push_back("OUTPUT_NAME");
  4498. for(std::vector<std::string>::const_iterator i = props.begin();
  4499. i != props.end(); ++i)
  4500. {
  4501. if(const char* outName = this->GetProperty(*i))
  4502. {
  4503. return outName;
  4504. }
  4505. }
  4506. return this->GetName();
  4507. }
  4508. //----------------------------------------------------------------------------
  4509. std::string cmTarget::GetFrameworkVersion() const
  4510. {
  4511. assert(this->GetType() != INTERFACE_LIBRARY);
  4512. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4513. {
  4514. return fversion;
  4515. }
  4516. else if(const char* tversion = this->GetProperty("VERSION"))
  4517. {
  4518. return tversion;
  4519. }
  4520. else
  4521. {
  4522. return "A";
  4523. }
  4524. }
  4525. //----------------------------------------------------------------------------
  4526. const char* cmTarget::GetExportMacro() const
  4527. {
  4528. // Define the symbol for targets that export symbols.
  4529. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4530. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4531. this->IsExecutableWithExports())
  4532. {
  4533. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4534. {
  4535. this->ExportMacro = custom_export_name;
  4536. }
  4537. else
  4538. {
  4539. std::string in = this->GetName();
  4540. in += "_EXPORTS";
  4541. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4542. }
  4543. return this->ExportMacro.c_str();
  4544. }
  4545. else
  4546. {
  4547. return 0;
  4548. }
  4549. }
  4550. //----------------------------------------------------------------------------
  4551. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  4552. {
  4553. return this->LinkImplicitNullProperties.find(p)
  4554. != this->LinkImplicitNullProperties.end();
  4555. }
  4556. //----------------------------------------------------------------------------
  4557. template<typename PropertyType>
  4558. PropertyType getTypedProperty(cmTarget const* tgt, const char *prop,
  4559. PropertyType *);
  4560. //----------------------------------------------------------------------------
  4561. template<>
  4562. bool getTypedProperty<bool>(cmTarget const* tgt, const char *prop, bool *)
  4563. {
  4564. return tgt->GetPropertyAsBool(prop);
  4565. }
  4566. //----------------------------------------------------------------------------
  4567. template<>
  4568. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  4569. const char *prop,
  4570. const char **)
  4571. {
  4572. return tgt->GetProperty(prop);
  4573. }
  4574. enum CompatibleType
  4575. {
  4576. BoolType,
  4577. StringType,
  4578. NumberMinType,
  4579. NumberMaxType
  4580. };
  4581. //----------------------------------------------------------------------------
  4582. template<typename PropertyType>
  4583. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  4584. PropertyType rhs,
  4585. CompatibleType t);
  4586. //----------------------------------------------------------------------------
  4587. template<>
  4588. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  4589. {
  4590. return std::make_pair(lhs == rhs, lhs);
  4591. }
  4592. //----------------------------------------------------------------------------
  4593. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  4594. const char *rhs)
  4595. {
  4596. const bool b = strcmp(lhs, rhs) == 0;
  4597. return std::make_pair(b, b ? lhs : 0);
  4598. }
  4599. #if defined(_MSC_VER) && _MSC_VER <= 1200
  4600. template<typename T> const T&
  4601. cmMaximum(const T& l, const T& r) {return l > r ? l : r;}
  4602. template<typename T> const T&
  4603. cmMinimum(const T& l, const T& r) {return l < r ? l : r;}
  4604. #else
  4605. #define cmMinimum std::min
  4606. #define cmMaximum std::max
  4607. #endif
  4608. //----------------------------------------------------------------------------
  4609. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  4610. const char *rhs,
  4611. CompatibleType t)
  4612. {
  4613. char *pEnd;
  4614. #if defined(_MSC_VER)
  4615. static const char* const null_ptr = 0;
  4616. #else
  4617. # define null_ptr 0
  4618. #endif
  4619. long lnum = strtol(lhs, &pEnd, 0);
  4620. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  4621. {
  4622. return std::pair<bool, const char*>(false, null_ptr);
  4623. }
  4624. long rnum = strtol(rhs, &pEnd, 0);
  4625. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  4626. {
  4627. return std::pair<bool, const char*>(false, null_ptr);
  4628. }
  4629. #if !defined(_MSC_VER)
  4630. #undef null_ptr
  4631. #endif
  4632. if (t == NumberMaxType)
  4633. {
  4634. return std::make_pair(true, cmMaximum(lnum, rnum) == lnum ? lhs : rhs);
  4635. }
  4636. else
  4637. {
  4638. return std::make_pair(true, cmMinimum(lnum, rnum) == lnum ? lhs : rhs);
  4639. }
  4640. }
  4641. //----------------------------------------------------------------------------
  4642. template<>
  4643. std::pair<bool, const char*> consistentProperty(const char *lhs,
  4644. const char *rhs,
  4645. CompatibleType t)
  4646. {
  4647. if (!lhs && !rhs)
  4648. {
  4649. return std::make_pair(true, lhs);
  4650. }
  4651. if (!lhs)
  4652. {
  4653. return std::make_pair(true, rhs);
  4654. }
  4655. if (!rhs)
  4656. {
  4657. return std::make_pair(true, lhs);
  4658. }
  4659. #if defined(_MSC_VER)
  4660. static const char* const null_ptr = 0;
  4661. #else
  4662. # define null_ptr 0
  4663. #endif
  4664. switch(t)
  4665. {
  4666. case BoolType:
  4667. assert(!"consistentProperty for strings called with BoolType");
  4668. return std::pair<bool, const char*>(false, null_ptr);
  4669. case StringType:
  4670. return consistentStringProperty(lhs, rhs);
  4671. case NumberMinType:
  4672. case NumberMaxType:
  4673. return consistentNumberProperty(lhs, rhs, t);
  4674. }
  4675. assert(!"Unreachable!");
  4676. return std::pair<bool, const char*>(false, null_ptr);
  4677. #if !defined(_MSC_VER)
  4678. #undef null_ptr
  4679. #endif
  4680. }
  4681. template<typename PropertyType>
  4682. PropertyType impliedValue(PropertyType);
  4683. template<>
  4684. bool impliedValue<bool>(bool)
  4685. {
  4686. return false;
  4687. }
  4688. template<>
  4689. const char* impliedValue<const char*>(const char*)
  4690. {
  4691. return "";
  4692. }
  4693. template<typename PropertyType>
  4694. std::string valueAsString(PropertyType);
  4695. template<>
  4696. std::string valueAsString<bool>(bool value)
  4697. {
  4698. return value ? "TRUE" : "FALSE";
  4699. }
  4700. template<>
  4701. std::string valueAsString<const char*>(const char* value)
  4702. {
  4703. return value ? value : "(unset)";
  4704. }
  4705. //----------------------------------------------------------------------------
  4706. void
  4707. cmTarget::ReportPropertyOrigin(const std::string &p,
  4708. const std::string &result,
  4709. const std::string &report,
  4710. const std::string &compatibilityType) const
  4711. {
  4712. std::vector<std::string> debugProperties;
  4713. const char *debugProp =
  4714. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4715. if (debugProp)
  4716. {
  4717. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4718. }
  4719. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4720. && std::find(debugProperties.begin(),
  4721. debugProperties.end(),
  4722. p)
  4723. != debugProperties.end();
  4724. if (this->Makefile->IsGeneratingBuildSystem())
  4725. {
  4726. this->DebugCompatiblePropertiesDone[p] = true;
  4727. }
  4728. if (!debugOrigin)
  4729. {
  4730. return;
  4731. }
  4732. std::string areport = compatibilityType;
  4733. areport += std::string(" of property \"") + p + "\" for target \"";
  4734. areport += std::string(this->GetName());
  4735. areport += "\" (result: \"";
  4736. areport += result;
  4737. areport += "\"):\n" + report;
  4738. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  4739. }
  4740. //----------------------------------------------------------------------------
  4741. std::string compatibilityType(CompatibleType t)
  4742. {
  4743. switch(t)
  4744. {
  4745. case BoolType:
  4746. return "Boolean compatibility";
  4747. case StringType:
  4748. return "String compatibility";
  4749. case NumberMaxType:
  4750. return "Numeric maximum compatibility";
  4751. case NumberMinType:
  4752. return "Numeric minimum compatibility";
  4753. }
  4754. assert(!"Unreachable!");
  4755. return "";
  4756. }
  4757. //----------------------------------------------------------------------------
  4758. std::string compatibilityAgree(CompatibleType t, bool dominant)
  4759. {
  4760. switch(t)
  4761. {
  4762. case BoolType:
  4763. case StringType:
  4764. return dominant ? "(Disagree)\n" : "(Agree)\n";
  4765. case NumberMaxType:
  4766. case NumberMinType:
  4767. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  4768. }
  4769. assert(!"Unreachable!");
  4770. return "";
  4771. }
  4772. //----------------------------------------------------------------------------
  4773. template<typename PropertyType>
  4774. PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
  4775. const std::string &p,
  4776. const std::string& config,
  4777. const char *defaultValue,
  4778. CompatibleType t,
  4779. PropertyType *)
  4780. {
  4781. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
  4782. 0);
  4783. const bool explicitlySet = tgt->GetProperties()
  4784. .find(p)
  4785. != tgt->GetProperties().end();
  4786. const bool impliedByUse =
  4787. tgt->IsNullImpliedByLinkLibraries(p);
  4788. assert((impliedByUse ^ explicitlySet)
  4789. || (!impliedByUse && !explicitlySet));
  4790. std::vector<cmTarget const*> const& deps =
  4791. tgt->GetLinkImplementationClosure(config);
  4792. if(deps.empty())
  4793. {
  4794. return propContent;
  4795. }
  4796. bool propInitialized = explicitlySet;
  4797. std::string report = " * Target \"";
  4798. report += tgt->GetName();
  4799. if (explicitlySet)
  4800. {
  4801. report += "\" has property content \"";
  4802. report += valueAsString<PropertyType>(propContent);
  4803. report += "\"\n";
  4804. }
  4805. else if (impliedByUse)
  4806. {
  4807. report += "\" property is implied by use.\n";
  4808. }
  4809. else
  4810. {
  4811. report += "\" property not set.\n";
  4812. }
  4813. for(std::vector<cmTarget const*>::const_iterator li =
  4814. deps.begin();
  4815. li != deps.end(); ++li)
  4816. {
  4817. // An error should be reported if one dependency
  4818. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4819. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4820. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4821. // with a dependency.
  4822. cmTarget const* theTarget = *li;
  4823. const bool ifaceIsSet = theTarget->GetProperties()
  4824. .find("INTERFACE_" + p)
  4825. != theTarget->GetProperties().end();
  4826. PropertyType ifacePropContent =
  4827. getTypedProperty<PropertyType>(theTarget,
  4828. ("INTERFACE_" + p).c_str(), 0);
  4829. std::string reportEntry;
  4830. if (ifaceIsSet)
  4831. {
  4832. reportEntry += " * Target \"";
  4833. reportEntry += theTarget->GetName();
  4834. reportEntry += "\" property value \"";
  4835. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4836. reportEntry += "\" ";
  4837. }
  4838. if (explicitlySet)
  4839. {
  4840. if (ifaceIsSet)
  4841. {
  4842. std::pair<bool, PropertyType> consistent =
  4843. consistentProperty(propContent,
  4844. ifacePropContent, t);
  4845. report += reportEntry;
  4846. report += compatibilityAgree(t, propContent != consistent.second);
  4847. if (!consistent.first)
  4848. {
  4849. cmOStringStream e;
  4850. e << "Property " << p << " on target \""
  4851. << tgt->GetName() << "\" does\nnot match the "
  4852. "INTERFACE_" << p << " property requirement\nof "
  4853. "dependency \"" << theTarget->GetName() << "\".\n";
  4854. cmSystemTools::Error(e.str().c_str());
  4855. break;
  4856. }
  4857. else
  4858. {
  4859. propContent = consistent.second;
  4860. continue;
  4861. }
  4862. }
  4863. else
  4864. {
  4865. // Explicitly set on target and not set in iface. Can't disagree.
  4866. continue;
  4867. }
  4868. }
  4869. else if (impliedByUse)
  4870. {
  4871. propContent = impliedValue<PropertyType>(propContent);
  4872. if (ifaceIsSet)
  4873. {
  4874. std::pair<bool, PropertyType> consistent =
  4875. consistentProperty(propContent,
  4876. ifacePropContent, t);
  4877. report += reportEntry;
  4878. report += compatibilityAgree(t, propContent != consistent.second);
  4879. if (!consistent.first)
  4880. {
  4881. cmOStringStream e;
  4882. e << "Property " << p << " on target \""
  4883. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4884. << " because it was used to determine the link libraries\n"
  4885. "already. The INTERFACE_" << p << " property on\ndependency \""
  4886. << theTarget->GetName() << "\" is in conflict.\n";
  4887. cmSystemTools::Error(e.str().c_str());
  4888. break;
  4889. }
  4890. else
  4891. {
  4892. propContent = consistent.second;
  4893. continue;
  4894. }
  4895. }
  4896. else
  4897. {
  4898. // Implicitly set on target and not set in iface. Can't disagree.
  4899. continue;
  4900. }
  4901. }
  4902. else
  4903. {
  4904. if (ifaceIsSet)
  4905. {
  4906. if (propInitialized)
  4907. {
  4908. std::pair<bool, PropertyType> consistent =
  4909. consistentProperty(propContent,
  4910. ifacePropContent, t);
  4911. report += reportEntry;
  4912. report += compatibilityAgree(t, propContent != consistent.second);
  4913. if (!consistent.first)
  4914. {
  4915. cmOStringStream e;
  4916. e << "The INTERFACE_" << p << " property of \""
  4917. << theTarget->GetName() << "\" does\nnot agree with the value "
  4918. "of " << p << " already determined\nfor \""
  4919. << tgt->GetName() << "\".\n";
  4920. cmSystemTools::Error(e.str().c_str());
  4921. break;
  4922. }
  4923. else
  4924. {
  4925. propContent = consistent.second;
  4926. continue;
  4927. }
  4928. }
  4929. else
  4930. {
  4931. report += reportEntry + "(Interface set)\n";
  4932. propContent = ifacePropContent;
  4933. propInitialized = true;
  4934. }
  4935. }
  4936. else
  4937. {
  4938. // Not set. Nothing to agree on.
  4939. continue;
  4940. }
  4941. }
  4942. }
  4943. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4944. report, compatibilityType(t));
  4945. return propContent;
  4946. }
  4947. //----------------------------------------------------------------------------
  4948. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4949. const std::string& config) const
  4950. {
  4951. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4952. BoolType, 0);
  4953. }
  4954. //----------------------------------------------------------------------------
  4955. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4956. const std::string &p,
  4957. const std::string& config) const
  4958. {
  4959. return checkInterfacePropertyCompatibility<const char *>(this,
  4960. p,
  4961. config,
  4962. "empty",
  4963. StringType, 0);
  4964. }
  4965. //----------------------------------------------------------------------------
  4966. const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
  4967. const std::string &p,
  4968. const std::string& config) const
  4969. {
  4970. return checkInterfacePropertyCompatibility<const char *>(this,
  4971. p,
  4972. config,
  4973. "empty",
  4974. NumberMinType, 0);
  4975. }
  4976. //----------------------------------------------------------------------------
  4977. const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4978. const std::string &p,
  4979. const std::string& config) const
  4980. {
  4981. return checkInterfacePropertyCompatibility<const char *>(this,
  4982. p,
  4983. config,
  4984. "empty",
  4985. NumberMaxType, 0);
  4986. }
  4987. //----------------------------------------------------------------------------
  4988. bool isLinkDependentProperty(cmTarget const* tgt, const std::string &p,
  4989. const std::string& interfaceProperty,
  4990. const std::string& config)
  4991. {
  4992. std::vector<cmTarget const*> const& deps =
  4993. tgt->GetLinkImplementationClosure(config);
  4994. if(deps.empty())
  4995. {
  4996. return false;
  4997. }
  4998. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  4999. li != deps.end(); ++li)
  5000. {
  5001. const char *prop = (*li)->GetProperty(interfaceProperty);
  5002. if (!prop)
  5003. {
  5004. continue;
  5005. }
  5006. std::vector<std::string> props;
  5007. cmSystemTools::ExpandListArgument(prop, props);
  5008. for(std::vector<std::string>::iterator pi = props.begin();
  5009. pi != props.end(); ++pi)
  5010. {
  5011. if (*pi == p)
  5012. {
  5013. return true;
  5014. }
  5015. }
  5016. }
  5017. return false;
  5018. }
  5019. //----------------------------------------------------------------------------
  5020. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  5021. const std::string& config) const
  5022. {
  5023. if (this->TargetTypeValue == OBJECT_LIBRARY
  5024. || this->TargetTypeValue == INTERFACE_LIBRARY)
  5025. {
  5026. return false;
  5027. }
  5028. return (p == "POSITION_INDEPENDENT_CODE") ||
  5029. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
  5030. config);
  5031. }
  5032. //----------------------------------------------------------------------------
  5033. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  5034. const std::string& config) const
  5035. {
  5036. if (this->TargetTypeValue == OBJECT_LIBRARY
  5037. || this->TargetTypeValue == INTERFACE_LIBRARY)
  5038. {
  5039. return false;
  5040. }
  5041. return (p == "AUTOUIC_OPTIONS") ||
  5042. isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
  5043. config);
  5044. }
  5045. //----------------------------------------------------------------------------
  5046. bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  5047. const std::string& config) const
  5048. {
  5049. if (this->TargetTypeValue == OBJECT_LIBRARY
  5050. || this->TargetTypeValue == INTERFACE_LIBRARY)
  5051. {
  5052. return false;
  5053. }
  5054. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MIN",
  5055. config);
  5056. }
  5057. //----------------------------------------------------------------------------
  5058. bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  5059. const std::string& config) const
  5060. {
  5061. if (this->TargetTypeValue == OBJECT_LIBRARY
  5062. || this->TargetTypeValue == INTERFACE_LIBRARY)
  5063. {
  5064. return false;
  5065. }
  5066. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_NUMBER_MAX",
  5067. config);
  5068. }
  5069. //----------------------------------------------------------------------------
  5070. void
  5071. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  5072. {
  5073. // At configure-time, this method can be called as part of getting the
  5074. // LOCATION property or to export() a file to be include()d. However
  5075. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  5076. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  5077. // behavior of CMP0024 and CMP0026 only.
  5078. typedef cmTargetInternals::TargetPropertyEntry
  5079. TargetPropertyEntry;
  5080. for(std::vector<TargetPropertyEntry*>::const_iterator
  5081. i = this->Internal->SourceEntries.begin();
  5082. i != this->Internal->SourceEntries.end(); ++i)
  5083. {
  5084. std::string entry = (*i)->ge->GetInput();
  5085. std::vector<std::string> files;
  5086. cmSystemTools::ExpandListArgument(entry, files);
  5087. for (std::vector<std::string>::const_iterator
  5088. li = files.begin(); li != files.end(); ++li)
  5089. {
  5090. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  5091. (*li)[li->size() - 1] == '>')
  5092. {
  5093. std::string objLibName = li->substr(17, li->size()-18);
  5094. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  5095. {
  5096. continue;
  5097. }
  5098. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName.c_str());
  5099. if(objLib)
  5100. {
  5101. objlibs.push_back(objLib);
  5102. }
  5103. }
  5104. }
  5105. }
  5106. }
  5107. //----------------------------------------------------------------------------
  5108. void cmTarget::GetLanguages(std::set<std::string>& languages,
  5109. const std::string& config,
  5110. cmTarget const* head) const
  5111. {
  5112. std::vector<cmSourceFile*> sourceFiles;
  5113. this->GetSourceFiles(sourceFiles, config, head);
  5114. for(std::vector<cmSourceFile*>::const_iterator
  5115. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  5116. {
  5117. const std::string& lang = (*i)->GetLanguage();
  5118. if(!lang.empty())
  5119. {
  5120. languages.insert(lang);
  5121. }
  5122. }
  5123. std::vector<cmTarget*> objectLibraries;
  5124. std::vector<cmSourceFile const*> externalObjects;
  5125. if (this->Makefile->GetGeneratorTargets().empty())
  5126. {
  5127. this->GetObjectLibrariesCMP0026(objectLibraries);
  5128. }
  5129. else
  5130. {
  5131. cmGeneratorTarget* gt = this->Makefile->GetLocalGenerator()
  5132. ->GetGlobalGenerator()
  5133. ->GetGeneratorTarget(this);
  5134. gt->GetExternalObjects(externalObjects, config);
  5135. for(std::vector<cmSourceFile const*>::const_iterator
  5136. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  5137. {
  5138. std::string objLib = (*i)->GetObjectLibrary();
  5139. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  5140. {
  5141. objectLibraries.push_back(tgt);
  5142. }
  5143. }
  5144. }
  5145. for(std::vector<cmTarget*>::const_iterator
  5146. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  5147. {
  5148. (*i)->GetLanguages(languages, config, head);
  5149. }
  5150. }
  5151. //----------------------------------------------------------------------------
  5152. bool cmTarget::IsChrpathUsed(const std::string& config) const
  5153. {
  5154. // Only certain target types have an rpath.
  5155. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5156. this->GetType() == cmTarget::MODULE_LIBRARY ||
  5157. this->GetType() == cmTarget::EXECUTABLE))
  5158. {
  5159. return false;
  5160. }
  5161. // If the target will not be installed we do not need to change its
  5162. // rpath.
  5163. if(!this->GetHaveInstallRule())
  5164. {
  5165. return false;
  5166. }
  5167. // Skip chrpath if skipping rpath altogether.
  5168. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  5169. {
  5170. return false;
  5171. }
  5172. // Skip chrpath if it does not need to be changed at install time.
  5173. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  5174. {
  5175. return false;
  5176. }
  5177. // Allow the user to disable builtin chrpath explicitly.
  5178. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  5179. {
  5180. return false;
  5181. }
  5182. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  5183. {
  5184. return true;
  5185. }
  5186. #if defined(CMAKE_USE_ELF_PARSER)
  5187. // Enable if the rpath flag uses a separator and the target uses ELF
  5188. // binaries.
  5189. std::string ll = this->GetLinkerLanguage(config);
  5190. if(!ll.empty())
  5191. {
  5192. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  5193. sepVar += ll;
  5194. sepVar += "_FLAG_SEP";
  5195. const char* sep = this->Makefile->GetDefinition(sepVar);
  5196. if(sep && *sep)
  5197. {
  5198. // TODO: Add ELF check to ABI detection and get rid of
  5199. // CMAKE_EXECUTABLE_FORMAT.
  5200. if(const char* fmt =
  5201. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  5202. {
  5203. return strcmp(fmt, "ELF") == 0;
  5204. }
  5205. }
  5206. }
  5207. #endif
  5208. static_cast<void>(config);
  5209. return false;
  5210. }
  5211. //----------------------------------------------------------------------------
  5212. cmTarget::ImportInfo const*
  5213. cmTarget::GetImportInfo(const std::string& config) const
  5214. {
  5215. // There is no imported information for non-imported targets.
  5216. if(!this->IsImported())
  5217. {
  5218. return 0;
  5219. }
  5220. // Lookup/compute/cache the import information for this
  5221. // configuration.
  5222. std::string config_upper;
  5223. if(!config.empty())
  5224. {
  5225. config_upper = cmSystemTools::UpperCase(config);
  5226. }
  5227. else
  5228. {
  5229. config_upper = "NOCONFIG";
  5230. }
  5231. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  5232. ImportInfoMapType::const_iterator i =
  5233. this->Internal->ImportInfoMap.find(config_upper);
  5234. if(i == this->Internal->ImportInfoMap.end())
  5235. {
  5236. ImportInfo info;
  5237. this->ComputeImportInfo(config_upper, info);
  5238. ImportInfoMapType::value_type entry(config_upper, info);
  5239. i = this->Internal->ImportInfoMap.insert(entry).first;
  5240. }
  5241. if(this->GetType() == INTERFACE_LIBRARY)
  5242. {
  5243. return &i->second;
  5244. }
  5245. // If the location is empty then the target is not available for
  5246. // this configuration.
  5247. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  5248. {
  5249. return 0;
  5250. }
  5251. // Return the import information.
  5252. return &i->second;
  5253. }
  5254. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  5255. const char** loc,
  5256. const char** imp,
  5257. std::string& suffix) const
  5258. {
  5259. if (this->GetType() == INTERFACE_LIBRARY)
  5260. {
  5261. // This method attempts to find a config-specific LOCATION for the
  5262. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  5263. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  5264. // and valid response.
  5265. return true;
  5266. }
  5267. // Track the configuration-specific property suffix.
  5268. suffix = "_";
  5269. suffix += desired_config;
  5270. std::vector<std::string> mappedConfigs;
  5271. {
  5272. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  5273. mapProp += desired_config;
  5274. if(const char* mapValue = this->GetProperty(mapProp))
  5275. {
  5276. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  5277. }
  5278. }
  5279. // If we needed to find one of the mapped configurations but did not
  5280. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  5281. // library or an executable with exports.
  5282. bool allowImp = this->HasImportLibrary();
  5283. // If a mapping was found, check its configurations.
  5284. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  5285. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  5286. {
  5287. // Look for this configuration.
  5288. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  5289. std::string locProp = "IMPORTED_LOCATION_";
  5290. locProp += mcUpper;
  5291. *loc = this->GetProperty(locProp);
  5292. if(allowImp)
  5293. {
  5294. std::string impProp = "IMPORTED_IMPLIB_";
  5295. impProp += mcUpper;
  5296. *imp = this->GetProperty(impProp);
  5297. }
  5298. // If it was found, use it for all properties below.
  5299. if(*loc || *imp)
  5300. {
  5301. suffix = "_";
  5302. suffix += mcUpper;
  5303. }
  5304. }
  5305. // If we needed to find one of the mapped configurations but did not
  5306. // then the target is not found. The project does not want any
  5307. // other configuration.
  5308. if(!mappedConfigs.empty() && !*loc && !*imp)
  5309. {
  5310. return false;
  5311. }
  5312. // If we have not yet found it then there are no mapped
  5313. // configurations. Look for an exact-match.
  5314. if(!*loc && !*imp)
  5315. {
  5316. std::string locProp = "IMPORTED_LOCATION";
  5317. locProp += suffix;
  5318. *loc = this->GetProperty(locProp);
  5319. if(allowImp)
  5320. {
  5321. std::string impProp = "IMPORTED_IMPLIB";
  5322. impProp += suffix;
  5323. *imp = this->GetProperty(impProp);
  5324. }
  5325. }
  5326. // If we have not yet found it then there are no mapped
  5327. // configurations and no exact match.
  5328. if(!*loc && !*imp)
  5329. {
  5330. // The suffix computed above is not useful.
  5331. suffix = "";
  5332. // Look for a configuration-less location. This may be set by
  5333. // manually-written code.
  5334. *loc = this->GetProperty("IMPORTED_LOCATION");
  5335. if(allowImp)
  5336. {
  5337. *imp = this->GetProperty("IMPORTED_IMPLIB");
  5338. }
  5339. }
  5340. // If we have not yet found it then the project is willing to try
  5341. // any available configuration.
  5342. if(!*loc && !*imp)
  5343. {
  5344. std::vector<std::string> availableConfigs;
  5345. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  5346. {
  5347. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  5348. }
  5349. for(std::vector<std::string>::const_iterator
  5350. aci = availableConfigs.begin();
  5351. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  5352. {
  5353. suffix = "_";
  5354. suffix += cmSystemTools::UpperCase(*aci);
  5355. std::string locProp = "IMPORTED_LOCATION";
  5356. locProp += suffix;
  5357. *loc = this->GetProperty(locProp);
  5358. if(allowImp)
  5359. {
  5360. std::string impProp = "IMPORTED_IMPLIB";
  5361. impProp += suffix;
  5362. *imp = this->GetProperty(impProp);
  5363. }
  5364. }
  5365. }
  5366. // If we have not yet found it then the target is not available.
  5367. if(!*loc && !*imp)
  5368. {
  5369. return false;
  5370. }
  5371. return true;
  5372. }
  5373. //----------------------------------------------------------------------------
  5374. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  5375. ImportInfo& info) const
  5376. {
  5377. // This method finds information about an imported target from its
  5378. // properties. The "IMPORTED_" namespace is reserved for properties
  5379. // defined by the project exporting the target.
  5380. // Initialize members.
  5381. info.NoSOName = false;
  5382. const char* loc = 0;
  5383. const char* imp = 0;
  5384. std::string suffix;
  5385. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  5386. {
  5387. return;
  5388. }
  5389. // Get the link interface.
  5390. {
  5391. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  5392. const char *propertyLibs = this->GetProperty(linkProp);
  5393. if (this->GetType() != INTERFACE_LIBRARY)
  5394. {
  5395. if(!propertyLibs)
  5396. {
  5397. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5398. linkProp += suffix;
  5399. propertyLibs = this->GetProperty(linkProp);
  5400. }
  5401. if(!propertyLibs)
  5402. {
  5403. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5404. propertyLibs = this->GetProperty(linkProp);
  5405. }
  5406. }
  5407. if(propertyLibs)
  5408. {
  5409. info.LibrariesProp = linkProp;
  5410. info.Libraries = propertyLibs;
  5411. }
  5412. }
  5413. if(this->GetType() == INTERFACE_LIBRARY)
  5414. {
  5415. return;
  5416. }
  5417. // A provided configuration has been chosen. Load the
  5418. // configuration's properties.
  5419. // Get the location.
  5420. if(loc)
  5421. {
  5422. info.Location = loc;
  5423. }
  5424. else
  5425. {
  5426. std::string impProp = "IMPORTED_LOCATION";
  5427. impProp += suffix;
  5428. if(const char* config_location = this->GetProperty(impProp))
  5429. {
  5430. info.Location = config_location;
  5431. }
  5432. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  5433. {
  5434. info.Location = location;
  5435. }
  5436. }
  5437. // Get the soname.
  5438. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5439. {
  5440. std::string soProp = "IMPORTED_SONAME";
  5441. soProp += suffix;
  5442. if(const char* config_soname = this->GetProperty(soProp))
  5443. {
  5444. info.SOName = config_soname;
  5445. }
  5446. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  5447. {
  5448. info.SOName = soname;
  5449. }
  5450. }
  5451. // Get the "no-soname" mark.
  5452. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5453. {
  5454. std::string soProp = "IMPORTED_NO_SONAME";
  5455. soProp += suffix;
  5456. if(const char* config_no_soname = this->GetProperty(soProp))
  5457. {
  5458. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  5459. }
  5460. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  5461. {
  5462. info.NoSOName = cmSystemTools::IsOn(no_soname);
  5463. }
  5464. }
  5465. // Get the import library.
  5466. if(imp)
  5467. {
  5468. info.ImportLibrary = imp;
  5469. }
  5470. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5471. this->IsExecutableWithExports())
  5472. {
  5473. std::string impProp = "IMPORTED_IMPLIB";
  5474. impProp += suffix;
  5475. if(const char* config_implib = this->GetProperty(impProp))
  5476. {
  5477. info.ImportLibrary = config_implib;
  5478. }
  5479. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  5480. {
  5481. info.ImportLibrary = implib;
  5482. }
  5483. }
  5484. // Get the link dependencies.
  5485. {
  5486. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5487. linkProp += suffix;
  5488. if(const char* config_libs = this->GetProperty(linkProp))
  5489. {
  5490. info.SharedDeps = config_libs;
  5491. }
  5492. else if(const char* libs =
  5493. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  5494. {
  5495. info.SharedDeps = libs;
  5496. }
  5497. }
  5498. // Get the link languages.
  5499. if(this->LinkLanguagePropagatesToDependents())
  5500. {
  5501. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5502. linkProp += suffix;
  5503. if(const char* config_libs = this->GetProperty(linkProp))
  5504. {
  5505. info.Languages = config_libs;
  5506. }
  5507. else if(const char* libs =
  5508. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  5509. {
  5510. info.Languages = libs;
  5511. }
  5512. }
  5513. // Get the cyclic repetition count.
  5514. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5515. {
  5516. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5517. linkProp += suffix;
  5518. if(const char* config_reps = this->GetProperty(linkProp))
  5519. {
  5520. sscanf(config_reps, "%u", &info.Multiplicity);
  5521. }
  5522. else if(const char* reps =
  5523. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  5524. {
  5525. sscanf(reps, "%u", &info.Multiplicity);
  5526. }
  5527. }
  5528. }
  5529. //----------------------------------------------------------------------------
  5530. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  5531. const std::string& config,
  5532. cmTarget const* head) const
  5533. {
  5534. // Imported targets have their own link interface.
  5535. if(this->IsImported())
  5536. {
  5537. return this->GetImportLinkInterface(config, head, false);
  5538. }
  5539. // Link interfaces are not supported for executables that do not
  5540. // export symbols.
  5541. if(this->GetType() == cmTarget::EXECUTABLE &&
  5542. !this->IsExecutableWithExports())
  5543. {
  5544. return 0;
  5545. }
  5546. // Lookup any existing link interface for this configuration.
  5547. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5548. cmTargetInternals::LinkInterfaceMapType::iterator
  5549. i = this->Internal->LinkInterfaceMap.find(key);
  5550. if(i == this->Internal->LinkInterfaceMap.end())
  5551. {
  5552. // Compute the link interface for this configuration.
  5553. cmTargetInternals::OptionalLinkInterface iface;
  5554. iface.ExplicitLibraries =
  5555. this->ComputeLinkInterfaceLibraries(config, iface, head, false,
  5556. iface.Exists);
  5557. if (iface.Exists)
  5558. {
  5559. this->Internal->ComputeLinkInterface(this, config, iface,
  5560. head, iface.ExplicitLibraries);
  5561. }
  5562. // Store the information for this configuration.
  5563. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  5564. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  5565. }
  5566. else if(!i->second.Complete && i->second.Exists)
  5567. {
  5568. this->Internal->ComputeLinkInterface(this, config, i->second, head,
  5569. i->second.ExplicitLibraries);
  5570. }
  5571. return i->second.Exists ? &i->second : 0;
  5572. }
  5573. //----------------------------------------------------------------------------
  5574. cmTarget::LinkInterface const*
  5575. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  5576. cmTarget const* head,
  5577. bool usage_requirements_only) const
  5578. {
  5579. // Imported targets have their own link interface.
  5580. if(this->IsImported())
  5581. {
  5582. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  5583. }
  5584. // Link interfaces are not supported for executables that do not
  5585. // export symbols.
  5586. if(this->GetType() == cmTarget::EXECUTABLE &&
  5587. !this->IsExecutableWithExports())
  5588. {
  5589. return 0;
  5590. }
  5591. // Lookup any existing link interface for this configuration.
  5592. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  5593. cmTargetInternals::LinkInterfaceMapType& lim =
  5594. (usage_requirements_only ?
  5595. this->Internal->LinkInterfaceUsageRequirementsOnlyMap :
  5596. this->Internal->LinkInterfaceMap);
  5597. cmTargetInternals::LinkInterfaceMapType::iterator i = lim.find(key);
  5598. if(i == lim.end())
  5599. {
  5600. // Compute the link interface for this configuration.
  5601. cmTargetInternals::OptionalLinkInterface iface;
  5602. iface.ExplicitLibraries =
  5603. this->ComputeLinkInterfaceLibraries(config, iface, head,
  5604. usage_requirements_only,
  5605. iface.Exists);
  5606. // Store the information for this configuration.
  5607. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  5608. i = lim.insert(entry).first;
  5609. }
  5610. return i->second.Exists ? &i->second : 0;
  5611. }
  5612. //----------------------------------------------------------------------------
  5613. cmTarget::LinkInterface const*
  5614. cmTarget::GetImportLinkInterface(const std::string& config,
  5615. cmTarget const* headTarget,
  5616. bool usage_requirements_only) const
  5617. {
  5618. cmTarget::ImportInfo const* info = this->GetImportInfo(config);
  5619. if(!info)
  5620. {
  5621. return 0;
  5622. }
  5623. TargetConfigPair key(headTarget, cmSystemTools::UpperCase(config));
  5624. cmTargetInternals::ImportLinkInterfaceMapType& lim =
  5625. (usage_requirements_only ?
  5626. this->Internal->ImportLinkInterfaceUsageRequirementsOnlyMap :
  5627. this->Internal->ImportLinkInterfaceMap);
  5628. cmTargetInternals::ImportLinkInterfaceMapType::iterator i = lim.find(key);
  5629. if(i == lim.end())
  5630. {
  5631. LinkInterface iface;
  5632. iface.Multiplicity = info->Multiplicity;
  5633. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  5634. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  5635. headTarget, usage_requirements_only,
  5636. iface.Libraries);
  5637. {
  5638. std::vector<std::string> deps;
  5639. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  5640. this->LookupLinkItems(deps, iface.SharedDeps);
  5641. }
  5642. cmTargetInternals::ImportLinkInterfaceMapType::value_type
  5643. entry(key, iface);
  5644. i = lim.insert(entry).first;
  5645. }
  5646. return &i->second;
  5647. }
  5648. //----------------------------------------------------------------------------
  5649. void processILibs(const std::string& config,
  5650. cmTarget const* headTarget,
  5651. cmLinkItem const& item,
  5652. std::vector<cmTarget const*>& tgts,
  5653. std::set<cmTarget const*>& emitted)
  5654. {
  5655. if (item.Target && emitted.insert(item.Target).second)
  5656. {
  5657. tgts.push_back(item.Target);
  5658. if(cmTarget::LinkInterface const* iface =
  5659. item.Target->GetLinkInterfaceLibraries(config, headTarget, false))
  5660. {
  5661. for(std::vector<cmLinkItem>::const_iterator
  5662. it = iface->Libraries.begin();
  5663. it != iface->Libraries.end(); ++it)
  5664. {
  5665. processILibs(config, headTarget, *it, tgts, emitted);
  5666. }
  5667. }
  5668. }
  5669. }
  5670. //----------------------------------------------------------------------------
  5671. std::vector<cmTarget const*> const&
  5672. cmTarget::GetLinkImplementationClosure(const std::string& config) const
  5673. {
  5674. std::vector<cmTarget const*>& tgts =
  5675. this->Internal->CachedLinkImplementationClosure[config];
  5676. if(!this->Internal->CacheLinkImplementationClosureDone[config])
  5677. {
  5678. this->Internal->CacheLinkImplementationClosureDone[config] = true;
  5679. std::set<cmTarget const*> emitted;
  5680. cmTarget::LinkImplementation const* impl
  5681. = this->GetLinkImplementationLibraries(config);
  5682. for(std::vector<cmLinkItem>::const_iterator it = impl->Libraries.begin();
  5683. it != impl->Libraries.end(); ++it)
  5684. {
  5685. processILibs(config, this, *it, tgts , emitted);
  5686. }
  5687. }
  5688. return tgts;
  5689. }
  5690. //----------------------------------------------------------------------------
  5691. void cmTarget::GetTransitivePropertyTargets(const std::string& config,
  5692. cmTarget const* headTarget,
  5693. std::vector<cmTarget const*> &tgts) const
  5694. {
  5695. // The $<LINK_ONLY> expression may be in a link interface to specify private
  5696. // link dependencies that are otherwise excluded from usage requirements.
  5697. // Currently $<LINK_ONLY> is internal to CMake and only ever added by
  5698. // target_link_libraries for PRIVATE dependencies of STATIC libraries in
  5699. // INTERFACE_LINK_LIBRARIES which is used under CMP0022 NEW behavior.
  5700. bool usage_requirements_only =
  5701. this->GetType() == STATIC_LIBRARY &&
  5702. this->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
  5703. this->GetPolicyStatusCMP0022() != cmPolicies::OLD;
  5704. if(cmTarget::LinkInterface const* iface =
  5705. this->GetLinkInterfaceLibraries(config, headTarget,
  5706. usage_requirements_only))
  5707. {
  5708. for(std::vector<cmLinkItem>::const_iterator it = iface->Libraries.begin();
  5709. it != iface->Libraries.end(); ++it)
  5710. {
  5711. if (it->Target)
  5712. {
  5713. tgts.push_back(it->Target);
  5714. }
  5715. }
  5716. }
  5717. }
  5718. //----------------------------------------------------------------------------
  5719. const char* cmTarget::ComputeLinkInterfaceLibraries(const std::string& config,
  5720. LinkInterface& iface,
  5721. cmTarget const* headTarget,
  5722. bool usage_requirements_only,
  5723. bool &exists) const
  5724. {
  5725. // Construct the property name suffix for this configuration.
  5726. std::string suffix = "_";
  5727. if(!config.empty())
  5728. {
  5729. suffix += cmSystemTools::UpperCase(config);
  5730. }
  5731. else
  5732. {
  5733. suffix += "NOCONFIG";
  5734. }
  5735. // An explicit list of interface libraries may be set for shared
  5736. // libraries and executables that export symbols.
  5737. const char* explicitLibraries = 0;
  5738. std::string linkIfaceProp;
  5739. if(this->PolicyStatusCMP0022 != cmPolicies::OLD &&
  5740. this->PolicyStatusCMP0022 != cmPolicies::WARN)
  5741. {
  5742. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  5743. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5744. explicitLibraries = this->GetProperty(linkIfaceProp);
  5745. }
  5746. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5747. this->IsExecutableWithExports())
  5748. {
  5749. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  5750. // shared lib or executable.
  5751. // Lookup the per-configuration property.
  5752. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5753. linkIfaceProp += suffix;
  5754. explicitLibraries = this->GetProperty(linkIfaceProp);
  5755. // If not set, try the generic property.
  5756. if(!explicitLibraries)
  5757. {
  5758. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5759. explicitLibraries = this->GetProperty(linkIfaceProp);
  5760. }
  5761. }
  5762. if(explicitLibraries && this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5763. !this->Internal->PolicyWarnedCMP0022)
  5764. {
  5765. // Compare the explicitly set old link interface properties to the
  5766. // preferred new link interface property one and warn if different.
  5767. const char* newExplicitLibraries =
  5768. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  5769. if (newExplicitLibraries
  5770. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  5771. {
  5772. cmOStringStream w;
  5773. w <<
  5774. (this->Makefile->GetPolicies()
  5775. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5776. "Target \"" << this->GetName() << "\" has an "
  5777. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  5778. linkIfaceProp << " properties."
  5779. "\n"
  5780. "INTERFACE_LINK_LIBRARIES:\n"
  5781. " " << newExplicitLibraries << "\n" <<
  5782. linkIfaceProp << ":\n"
  5783. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  5784. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5785. this->Internal->PolicyWarnedCMP0022 = true;
  5786. }
  5787. }
  5788. // There is no implicit link interface for executables or modules
  5789. // so if none was explicitly set then there is no link interface.
  5790. if(!explicitLibraries &&
  5791. (this->GetType() == cmTarget::EXECUTABLE ||
  5792. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  5793. {
  5794. exists = false;
  5795. return 0;
  5796. }
  5797. exists = true;
  5798. if(explicitLibraries)
  5799. {
  5800. // The interface libraries have been explicitly set.
  5801. this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
  5802. headTarget, usage_requirements_only,
  5803. iface.Libraries);
  5804. }
  5805. else if (this->PolicyStatusCMP0022 == cmPolicies::WARN
  5806. || this->PolicyStatusCMP0022 == cmPolicies::OLD)
  5807. // If CMP0022 is NEW then the plain tll signature sets the
  5808. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  5809. // cleared the property explicitly and we should not fall back
  5810. // to the link implementation.
  5811. {
  5812. // The link implementation is the default link interface.
  5813. LinkImplementation const* impl =
  5814. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  5815. iface.Libraries = impl->Libraries;
  5816. if(this->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5817. !this->Internal->PolicyWarnedCMP0022 && !usage_requirements_only)
  5818. {
  5819. // Compare the link implementation fallback link interface to the
  5820. // preferred new link interface property and warn if different.
  5821. std::vector<cmLinkItem> ifaceLibs;
  5822. std::string newProp = "INTERFACE_LINK_LIBRARIES";
  5823. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  5824. {
  5825. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  5826. headTarget, usage_requirements_only,
  5827. ifaceLibs);
  5828. }
  5829. if (ifaceLibs != impl->Libraries)
  5830. {
  5831. std::string oldLibraries;
  5832. std::string newLibraries;
  5833. const char *sep = "";
  5834. for(std::vector<cmLinkItem>::const_iterator it
  5835. = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
  5836. {
  5837. oldLibraries += sep;
  5838. oldLibraries += *it;
  5839. sep = ";";
  5840. }
  5841. sep = "";
  5842. for(std::vector<cmLinkItem>::const_iterator it
  5843. = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
  5844. {
  5845. newLibraries += sep;
  5846. newLibraries += *it;
  5847. sep = ";";
  5848. }
  5849. if(oldLibraries.empty())
  5850. { oldLibraries = "(empty)"; }
  5851. if(newLibraries.empty())
  5852. { newLibraries = "(empty)"; }
  5853. cmOStringStream w;
  5854. w <<
  5855. (this->Makefile->GetPolicies()
  5856. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5857. "Target \"" << this->GetName() << "\" has an "
  5858. "INTERFACE_LINK_LIBRARIES property. "
  5859. "This should be preferred as the source of the link interface "
  5860. "for this library but because CMP0022 is not set CMake is "
  5861. "ignoring the property and using the link implementation "
  5862. "as the link interface instead."
  5863. "\n"
  5864. "INTERFACE_LINK_LIBRARIES:\n"
  5865. " " << newLibraries << "\n"
  5866. "Link implementation:\n"
  5867. " " << oldLibraries << "\n";
  5868. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5869. this->Internal->PolicyWarnedCMP0022 = true;
  5870. }
  5871. }
  5872. }
  5873. return explicitLibraries;
  5874. }
  5875. //----------------------------------------------------------------------------
  5876. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  5877. const std::string& config,
  5878. OptionalLinkInterface& iface,
  5879. cmTarget const* headTarget,
  5880. const char* explicitLibraries) const
  5881. {
  5882. if(explicitLibraries)
  5883. {
  5884. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  5885. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  5886. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  5887. {
  5888. // Shared libraries may have runtime implementation dependencies
  5889. // on other shared libraries that are not in the interface.
  5890. std::set<std::string> emitted;
  5891. for(std::vector<cmLinkItem>::const_iterator
  5892. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5893. {
  5894. emitted.insert(*li);
  5895. }
  5896. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  5897. {
  5898. cmTarget::LinkImplementation const* impl =
  5899. thisTarget->GetLinkImplementation(config);
  5900. for(std::vector<cmLinkItem>::const_iterator
  5901. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5902. {
  5903. if(emitted.insert(*li).second)
  5904. {
  5905. if(li->Target)
  5906. {
  5907. // This is a runtime dependency on another shared library.
  5908. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  5909. {
  5910. iface.SharedDeps.push_back(*li);
  5911. }
  5912. }
  5913. else
  5914. {
  5915. // TODO: Recognize shared library file names. Perhaps this
  5916. // should be moved to cmComputeLinkInformation, but that creates
  5917. // a chicken-and-egg problem since this list is needed for its
  5918. // construction.
  5919. }
  5920. }
  5921. }
  5922. }
  5923. }
  5924. }
  5925. else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
  5926. || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
  5927. {
  5928. // The link implementation is the default link interface.
  5929. cmTarget::LinkImplementation const*
  5930. impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
  5931. headTarget);
  5932. iface.ImplementationIsInterface = true;
  5933. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5934. }
  5935. if(thisTarget->LinkLanguagePropagatesToDependents())
  5936. {
  5937. // Targets using this archive need its language runtime libraries.
  5938. if(cmTarget::LinkImplementation const* impl =
  5939. thisTarget->GetLinkImplementation(config))
  5940. {
  5941. iface.Languages = impl->Languages;
  5942. }
  5943. }
  5944. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  5945. {
  5946. // Construct the property name suffix for this configuration.
  5947. std::string suffix = "_";
  5948. if(!config.empty())
  5949. {
  5950. suffix += cmSystemTools::UpperCase(config);
  5951. }
  5952. else
  5953. {
  5954. suffix += "NOCONFIG";
  5955. }
  5956. // How many repetitions are needed if this library has cyclic
  5957. // dependencies?
  5958. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5959. propName += suffix;
  5960. if(const char* config_reps = thisTarget->GetProperty(propName))
  5961. {
  5962. sscanf(config_reps, "%u", &iface.Multiplicity);
  5963. }
  5964. else if(const char* reps =
  5965. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5966. {
  5967. sscanf(reps, "%u", &iface.Multiplicity);
  5968. }
  5969. }
  5970. iface.Complete = true;
  5971. }
  5972. //----------------------------------------------------------------------------
  5973. cmTarget::LinkImplementation const*
  5974. cmTarget::GetLinkImplementation(const std::string& config) const
  5975. {
  5976. // There is no link implementation for imported targets.
  5977. if(this->IsImported())
  5978. {
  5979. return 0;
  5980. }
  5981. // Populate the link implementation for this configuration.
  5982. TargetConfigPair key(this, cmSystemTools::UpperCase(config));
  5983. cmTargetInternals::OptionalLinkImplementation&
  5984. impl = this->Internal->LinkImplMap[key];
  5985. if(!impl.LibrariesDone)
  5986. {
  5987. impl.LibrariesDone = true;
  5988. this->ComputeLinkImplementation(config, impl, this);
  5989. }
  5990. if(!impl.LanguagesDone)
  5991. {
  5992. impl.LanguagesDone = true;
  5993. this->ComputeLinkImplementationLanguages(config, impl, this);
  5994. }
  5995. return &impl;
  5996. }
  5997. //----------------------------------------------------------------------------
  5998. cmTarget::LinkImplementation const*
  5999. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  6000. {
  6001. return this->GetLinkImplementationLibrariesInternal(config, this);
  6002. }
  6003. //----------------------------------------------------------------------------
  6004. cmTarget::LinkImplementation const*
  6005. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  6006. cmTarget const* head) const
  6007. {
  6008. // There is no link implementation for imported targets.
  6009. if(this->IsImported())
  6010. {
  6011. return 0;
  6012. }
  6013. // Populate the link implementation libraries for this configuration.
  6014. TargetConfigPair key(head, cmSystemTools::UpperCase(config));
  6015. cmTargetInternals::OptionalLinkImplementation&
  6016. impl = this->Internal->LinkImplMap[key];
  6017. if(!impl.LibrariesDone)
  6018. {
  6019. impl.LibrariesDone = true;
  6020. this->ComputeLinkImplementation(config, impl, head);
  6021. }
  6022. return &impl;
  6023. }
  6024. //----------------------------------------------------------------------------
  6025. void cmTarget::ComputeLinkImplementation(const std::string& config,
  6026. LinkImplementation& impl,
  6027. cmTarget const* head) const
  6028. {
  6029. // Collect libraries directly linked in this configuration.
  6030. for (std::vector<cmValueWithOrigin>::const_iterator
  6031. le = this->Internal->LinkImplementationPropertyEntries.begin(),
  6032. end = this->Internal->LinkImplementationPropertyEntries.end();
  6033. le != end; ++le)
  6034. {
  6035. std::vector<std::string> llibs;
  6036. cmGeneratorExpressionDAGChecker dagChecker(
  6037. this->GetName(),
  6038. "LINK_LIBRARIES", 0, 0);
  6039. cmGeneratorExpression ge(&le->Backtrace);
  6040. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  6041. ge.Parse(le->Value);
  6042. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  6043. config,
  6044. false,
  6045. head,
  6046. &dagChecker),
  6047. llibs);
  6048. for(std::vector<std::string>::const_iterator li = llibs.begin();
  6049. li != llibs.end(); ++li)
  6050. {
  6051. // Skip entries that resolve to the target itself or are empty.
  6052. std::string name = this->CheckCMP0004(*li);
  6053. if(name == this->GetName() || name.empty())
  6054. {
  6055. if(name == this->GetName())
  6056. {
  6057. bool noMessage = false;
  6058. cmake::MessageType messageType = cmake::FATAL_ERROR;
  6059. cmOStringStream e;
  6060. switch(this->GetPolicyStatusCMP0038())
  6061. {
  6062. case cmPolicies::WARN:
  6063. {
  6064. e << (this->Makefile->GetPolicies()
  6065. ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
  6066. messageType = cmake::AUTHOR_WARNING;
  6067. }
  6068. break;
  6069. case cmPolicies::OLD:
  6070. noMessage = true;
  6071. case cmPolicies::REQUIRED_IF_USED:
  6072. case cmPolicies::REQUIRED_ALWAYS:
  6073. case cmPolicies::NEW:
  6074. // Issue the fatal message.
  6075. break;
  6076. }
  6077. if(!noMessage)
  6078. {
  6079. e << "Target \"" << this->GetName() << "\" links to itself.";
  6080. this->Makefile->GetCMakeInstance()->IssueMessage(
  6081. messageType, e.str(), this->GetBacktrace());
  6082. if (messageType == cmake::FATAL_ERROR)
  6083. {
  6084. return;
  6085. }
  6086. }
  6087. }
  6088. continue;
  6089. }
  6090. // The entry is meant for this configuration.
  6091. impl.Libraries.push_back(
  6092. cmLinkItem(name, this->FindTargetToLink(name)));
  6093. }
  6094. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  6095. for (std::set<std::string>::const_iterator it = seenProps.begin();
  6096. it != seenProps.end(); ++it)
  6097. {
  6098. if (!this->GetProperty(*it))
  6099. {
  6100. this->LinkImplicitNullProperties.insert(*it);
  6101. }
  6102. }
  6103. cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards);
  6104. }
  6105. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  6106. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  6107. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  6108. li != oldllibs.end(); ++li)
  6109. {
  6110. if(li->second != cmTarget::GENERAL && li->second != linkType)
  6111. {
  6112. std::string name = this->CheckCMP0004(li->first);
  6113. if(name == this->GetName() || name.empty())
  6114. {
  6115. continue;
  6116. }
  6117. // Support OLD behavior for CMP0003.
  6118. impl.WrongConfigLibraries.push_back(
  6119. cmLinkItem(name, this->FindTargetToLink(name)));
  6120. }
  6121. }
  6122. }
  6123. //----------------------------------------------------------------------------
  6124. void
  6125. cmTarget::ComputeLinkImplementationLanguages(const std::string& config,
  6126. LinkImplementation& impl,
  6127. cmTarget const* head) const
  6128. {
  6129. // This target needs runtime libraries for its source languages.
  6130. std::set<std::string> languages;
  6131. // Get languages used in our source files.
  6132. this->GetLanguages(languages, config, head);
  6133. // Copy the set of langauges to the link implementation.
  6134. for(std::set<std::string>::iterator li = languages.begin();
  6135. li != languages.end(); ++li)
  6136. {
  6137. impl.Languages.push_back(*li);
  6138. }
  6139. }
  6140. //----------------------------------------------------------------------------
  6141. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  6142. {
  6143. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  6144. // Skip targets that will not really be linked. This is probably a
  6145. // name conflict between an external library and an executable
  6146. // within the project.
  6147. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  6148. !tgt->IsExecutableWithExports())
  6149. {
  6150. tgt = 0;
  6151. }
  6152. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  6153. {
  6154. cmOStringStream e;
  6155. e << "Target \"" << this->GetName() << "\" links to "
  6156. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  6157. "allowed. "
  6158. "One may link only to STATIC or SHARED libraries, or to executables "
  6159. "with the ENABLE_EXPORTS property set.";
  6160. cmake* cm = this->Makefile->GetCMakeInstance();
  6161. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  6162. tgt = 0;
  6163. }
  6164. // Return the target found, if any.
  6165. return tgt;
  6166. }
  6167. //----------------------------------------------------------------------------
  6168. std::string cmTarget::CheckCMP0004(std::string const& item) const
  6169. {
  6170. // Strip whitespace off the library names because we used to do this
  6171. // in case variables were expanded at generate time. We no longer
  6172. // do the expansion but users link to libraries like " ${VAR} ".
  6173. std::string lib = item;
  6174. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  6175. if(pos != lib.npos)
  6176. {
  6177. lib = lib.substr(pos, lib.npos);
  6178. }
  6179. pos = lib.find_last_not_of(" \t\r\n");
  6180. if(pos != lib.npos)
  6181. {
  6182. lib = lib.substr(0, pos+1);
  6183. }
  6184. if(lib != item)
  6185. {
  6186. cmake* cm = this->Makefile->GetCMakeInstance();
  6187. switch(this->PolicyStatusCMP0004)
  6188. {
  6189. case cmPolicies::WARN:
  6190. {
  6191. cmOStringStream w;
  6192. w << (this->Makefile->GetPolicies()
  6193. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  6194. << "Target \"" << this->GetName() << "\" links to item \""
  6195. << item << "\" which has leading or trailing whitespace.";
  6196. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  6197. this->GetBacktrace());
  6198. }
  6199. case cmPolicies::OLD:
  6200. break;
  6201. case cmPolicies::NEW:
  6202. {
  6203. cmOStringStream e;
  6204. e << "Target \"" << this->GetName() << "\" links to item \""
  6205. << item << "\" which has leading or trailing whitespace. "
  6206. << "This is now an error according to policy CMP0004.";
  6207. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  6208. }
  6209. break;
  6210. case cmPolicies::REQUIRED_IF_USED:
  6211. case cmPolicies::REQUIRED_ALWAYS:
  6212. {
  6213. cmOStringStream e;
  6214. e << (this->Makefile->GetPolicies()
  6215. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  6216. << "Target \"" << this->GetName() << "\" links to item \""
  6217. << item << "\" which has leading or trailing whitespace.";
  6218. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  6219. }
  6220. break;
  6221. }
  6222. }
  6223. return lib;
  6224. }
  6225. template<typename PropertyType>
  6226. PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6227. const std::string& prop,
  6228. const std::string& config,
  6229. CompatibleType,
  6230. PropertyType *);
  6231. template<>
  6232. bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6233. const std::string& prop,
  6234. const std::string& config,
  6235. CompatibleType, bool *)
  6236. {
  6237. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  6238. }
  6239. template<>
  6240. const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6241. const std::string& prop,
  6242. const std::string& config,
  6243. CompatibleType t,
  6244. const char **)
  6245. {
  6246. switch(t)
  6247. {
  6248. case BoolType:
  6249. assert(!"String compatibility check function called for boolean");
  6250. return 0;
  6251. case StringType:
  6252. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  6253. case NumberMinType:
  6254. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  6255. case NumberMaxType:
  6256. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  6257. }
  6258. assert(!"Unreachable!");
  6259. return 0;
  6260. }
  6261. //----------------------------------------------------------------------------
  6262. template<typename PropertyType>
  6263. void checkPropertyConsistency(cmTarget const* depender,
  6264. cmTarget const* dependee,
  6265. const std::string& propName,
  6266. std::set<std::string> &emitted,
  6267. const std::string& config,
  6268. CompatibleType t,
  6269. PropertyType *)
  6270. {
  6271. const char *prop = dependee->GetProperty(propName);
  6272. if (!prop)
  6273. {
  6274. return;
  6275. }
  6276. std::vector<std::string> props;
  6277. cmSystemTools::ExpandListArgument(prop, props);
  6278. std::string pdir =
  6279. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  6280. pdir += "/Help/prop_tgt/";
  6281. for(std::vector<std::string>::iterator pi = props.begin();
  6282. pi != props.end(); ++pi)
  6283. {
  6284. std::string pname = cmSystemTools::HelpFileName(*pi);
  6285. std::string pfile = pdir + pname + ".rst";
  6286. if(cmSystemTools::FileExists(pfile.c_str(), true))
  6287. {
  6288. cmOStringStream e;
  6289. e << "Target \"" << dependee->GetName() << "\" has property \""
  6290. << *pi << "\" listed in its " << propName << " property. "
  6291. "This is not allowed. Only user-defined properties may appear "
  6292. "listed in the " << propName << " property.";
  6293. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  6294. return;
  6295. }
  6296. if(emitted.insert(*pi).second)
  6297. {
  6298. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  6299. t, 0);
  6300. if (cmSystemTools::GetErrorOccuredFlag())
  6301. {
  6302. return;
  6303. }
  6304. }
  6305. }
  6306. }
  6307. static std::string intersect(const std::set<std::string> &s1,
  6308. const std::set<std::string> &s2)
  6309. {
  6310. std::set<std::string> intersect;
  6311. std::set_intersection(s1.begin(),s1.end(),
  6312. s2.begin(),s2.end(),
  6313. std::inserter(intersect,intersect.begin()));
  6314. if (!intersect.empty())
  6315. {
  6316. return *intersect.begin();
  6317. }
  6318. return "";
  6319. }
  6320. static std::string intersect(const std::set<std::string> &s1,
  6321. const std::set<std::string> &s2,
  6322. const std::set<std::string> &s3)
  6323. {
  6324. std::string result;
  6325. result = intersect(s1, s2);
  6326. if (!result.empty())
  6327. return result;
  6328. result = intersect(s1, s3);
  6329. if (!result.empty())
  6330. return result;
  6331. return intersect(s2, s3);
  6332. }
  6333. static std::string intersect(const std::set<std::string> &s1,
  6334. const std::set<std::string> &s2,
  6335. const std::set<std::string> &s3,
  6336. const std::set<std::string> &s4)
  6337. {
  6338. std::string result;
  6339. result = intersect(s1, s2);
  6340. if (!result.empty())
  6341. return result;
  6342. result = intersect(s1, s3);
  6343. if (!result.empty())
  6344. return result;
  6345. result = intersect(s1, s4);
  6346. if (!result.empty())
  6347. return result;
  6348. return intersect(s2, s3, s4);
  6349. }
  6350. //----------------------------------------------------------------------------
  6351. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  6352. const std::string& config) const
  6353. {
  6354. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  6355. std::set<std::string> emittedBools;
  6356. std::set<std::string> emittedStrings;
  6357. std::set<std::string> emittedMinNumbers;
  6358. std::set<std::string> emittedMaxNumbers;
  6359. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  6360. deps.begin();
  6361. li != deps.end(); ++li)
  6362. {
  6363. if (!li->Target)
  6364. {
  6365. continue;
  6366. }
  6367. checkPropertyConsistency<bool>(this, li->Target,
  6368. std::string("COMPATIBLE_INTERFACE_BOOL"),
  6369. emittedBools, config, BoolType, 0);
  6370. if (cmSystemTools::GetErrorOccuredFlag())
  6371. {
  6372. return;
  6373. }
  6374. checkPropertyConsistency<const char *>(this, li->Target,
  6375. std::string("COMPATIBLE_INTERFACE_STRING"),
  6376. emittedStrings, config,
  6377. StringType, 0);
  6378. if (cmSystemTools::GetErrorOccuredFlag())
  6379. {
  6380. return;
  6381. }
  6382. checkPropertyConsistency<const char *>(this, li->Target,
  6383. std::string("COMPATIBLE_INTERFACE_NUMBER_MIN"),
  6384. emittedMinNumbers, config,
  6385. NumberMinType, 0);
  6386. if (cmSystemTools::GetErrorOccuredFlag())
  6387. {
  6388. return;
  6389. }
  6390. checkPropertyConsistency<const char *>(this, li->Target,
  6391. std::string("COMPATIBLE_INTERFACE_NUMBER_MAX"),
  6392. emittedMaxNumbers, config,
  6393. NumberMaxType, 0);
  6394. if (cmSystemTools::GetErrorOccuredFlag())
  6395. {
  6396. return;
  6397. }
  6398. }
  6399. std::string prop = intersect(emittedBools,
  6400. emittedStrings,
  6401. emittedMinNumbers,
  6402. emittedMaxNumbers);
  6403. if (!prop.empty())
  6404. {
  6405. std::set<std::string> props;
  6406. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  6407. if (i != emittedBools.end())
  6408. {
  6409. props.insert("COMPATIBLE_INTERFACE_BOOL");
  6410. }
  6411. i = emittedStrings.find(prop);
  6412. if (i != emittedStrings.end())
  6413. {
  6414. props.insert("COMPATIBLE_INTERFACE_STRING");
  6415. }
  6416. i = emittedMinNumbers.find(prop);
  6417. if (i != emittedMinNumbers.end())
  6418. {
  6419. props.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  6420. }
  6421. i = emittedMaxNumbers.find(prop);
  6422. if (i != emittedMaxNumbers.end())
  6423. {
  6424. props.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  6425. }
  6426. std::string propsString = *props.begin();
  6427. props.erase(props.begin());
  6428. while (props.size() > 1)
  6429. {
  6430. propsString += ", " + *props.begin();
  6431. props.erase(props.begin());
  6432. }
  6433. if (props.size() == 1)
  6434. {
  6435. propsString += " and the " + *props.begin();
  6436. }
  6437. cmOStringStream e;
  6438. e << "Property \"" << prop << "\" appears in both the "
  6439. << propsString <<
  6440. " property in the dependencies of target \"" << this->GetName() <<
  6441. "\". This is not allowed. A property may only require compatibility "
  6442. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  6443. "string interpretation, but not a mixture.";
  6444. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  6445. }
  6446. }
  6447. //----------------------------------------------------------------------------
  6448. cmComputeLinkInformation*
  6449. cmTarget::GetLinkInformation(const std::string& config) const
  6450. {
  6451. // Lookup any existing information for this configuration.
  6452. std::string key(cmSystemTools::UpperCase(config));
  6453. cmTargetLinkInformationMap::iterator
  6454. i = this->LinkInformation.find(key);
  6455. if(i == this->LinkInformation.end())
  6456. {
  6457. // Compute information for this configuration.
  6458. cmComputeLinkInformation* info =
  6459. new cmComputeLinkInformation(this, config);
  6460. if(!info || !info->Compute())
  6461. {
  6462. delete info;
  6463. info = 0;
  6464. }
  6465. // Store the information for this configuration.
  6466. cmTargetLinkInformationMap::value_type entry(key, info);
  6467. i = this->LinkInformation.insert(entry).first;
  6468. if (info)
  6469. {
  6470. this->CheckPropertyCompatibility(info, config);
  6471. }
  6472. }
  6473. return i->second;
  6474. }
  6475. //----------------------------------------------------------------------------
  6476. std::string cmTarget::GetFrameworkDirectory(const std::string& config,
  6477. bool rootDir) const
  6478. {
  6479. std::string fpath;
  6480. fpath += this->GetOutputName(config, false);
  6481. fpath += ".framework";
  6482. if(!rootDir)
  6483. {
  6484. fpath += "/Versions/";
  6485. fpath += this->GetFrameworkVersion();
  6486. }
  6487. return fpath;
  6488. }
  6489. //----------------------------------------------------------------------------
  6490. std::string cmTarget::GetCFBundleDirectory(const std::string& config,
  6491. bool contentOnly) const
  6492. {
  6493. std::string fpath;
  6494. fpath += this->GetOutputName(config, false);
  6495. fpath += ".";
  6496. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  6497. if (!ext)
  6498. {
  6499. ext = "bundle";
  6500. }
  6501. fpath += ext;
  6502. fpath += "/Contents";
  6503. if(!contentOnly)
  6504. fpath += "/MacOS";
  6505. return fpath;
  6506. }
  6507. //----------------------------------------------------------------------------
  6508. std::string cmTarget::GetAppBundleDirectory(const std::string& config,
  6509. bool contentOnly) const
  6510. {
  6511. std::string fpath = this->GetFullName(config, false);
  6512. fpath += ".app/Contents";
  6513. if(!contentOnly)
  6514. fpath += "/MacOS";
  6515. return fpath;
  6516. }
  6517. //----------------------------------------------------------------------------
  6518. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  6519. const std::string& config,
  6520. bool contentOnly) const
  6521. {
  6522. std::string fpath = base;
  6523. if(this->IsAppBundleOnApple())
  6524. {
  6525. fpath += this->GetAppBundleDirectory(config, contentOnly);
  6526. }
  6527. if(this->IsFrameworkOnApple())
  6528. {
  6529. fpath += this->GetFrameworkDirectory(config, contentOnly);
  6530. }
  6531. if(this->IsCFBundleOnApple())
  6532. {
  6533. fpath += this->GetCFBundleDirectory(config, contentOnly);
  6534. }
  6535. return fpath;
  6536. }
  6537. //----------------------------------------------------------------------------
  6538. std::string cmTarget::GetMacContentDirectory(const std::string& config,
  6539. bool implib) const
  6540. {
  6541. // Start with the output directory for the target.
  6542. std::string fpath = this->GetDirectory(config, implib);
  6543. fpath += "/";
  6544. bool contentOnly = true;
  6545. if(this->IsFrameworkOnApple())
  6546. {
  6547. // additional files with a framework go into the version specific
  6548. // directory
  6549. contentOnly = false;
  6550. }
  6551. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  6552. return fpath;
  6553. }
  6554. //----------------------------------------------------------------------------
  6555. cmTargetLinkInformationMap
  6556. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  6557. {
  6558. // Ideally cmTarget instances should never be copied. However until
  6559. // we can make a sweep to remove that, this copy constructor avoids
  6560. // allowing the resources (LinkInformation) from getting copied. In
  6561. // the worst case this will lead to extra cmComputeLinkInformation
  6562. // instances. We also enforce in debug mode that the map be emptied
  6563. // when copied.
  6564. static_cast<void>(r);
  6565. assert(r.empty());
  6566. }
  6567. //----------------------------------------------------------------------------
  6568. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  6569. {
  6570. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  6571. {
  6572. delete i->second;
  6573. }
  6574. }
  6575. //----------------------------------------------------------------------------
  6576. cmTargetInternalPointer::cmTargetInternalPointer()
  6577. {
  6578. this->Pointer = new cmTargetInternals;
  6579. }
  6580. //----------------------------------------------------------------------------
  6581. cmTargetInternalPointer
  6582. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  6583. {
  6584. // Ideally cmTarget instances should never be copied. However until
  6585. // we can make a sweep to remove that, this copy constructor avoids
  6586. // allowing the resources (Internals) to be copied.
  6587. this->Pointer = new cmTargetInternals(*r.Pointer);
  6588. }
  6589. //----------------------------------------------------------------------------
  6590. cmTargetInternalPointer::~cmTargetInternalPointer()
  6591. {
  6592. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  6593. deleteAndClear(this->Pointer->CompileOptionsEntries);
  6594. deleteAndClear(this->Pointer->CompileFeaturesEntries);
  6595. deleteAndClear(this->Pointer->CompileDefinitionsEntries);
  6596. deleteAndClear(this->Pointer->SourceEntries);
  6597. delete this->Pointer;
  6598. }
  6599. //----------------------------------------------------------------------------
  6600. cmTargetInternalPointer&
  6601. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  6602. {
  6603. if(this == &r) { return *this; } // avoid warning on HP about self check
  6604. // Ideally cmTarget instances should never be copied. However until
  6605. // we can make a sweep to remove that, this copy constructor avoids
  6606. // allowing the resources (Internals) to be copied.
  6607. cmTargetInternals* oldPointer = this->Pointer;
  6608. this->Pointer = new cmTargetInternals(*r.Pointer);
  6609. delete oldPointer;
  6610. return *this;
  6611. }