cmTarget.cxx 223 KB

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