cmTarget.cxx 225 KB

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