cmTarget.cxx 215 KB

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