cmTarget.cxx 220 KB

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