cmTarget.cxx 222 KB

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