cmTarget.cxx 224 KB

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