cmTarget.cxx 223 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980
  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. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  206. it = entries.begin(),
  207. end = entries.end();
  208. it != end; ++it)
  209. {
  210. delete *it;
  211. }
  212. entries.clear();
  213. }
  214. //----------------------------------------------------------------------------
  215. cmTargetInternals::~cmTargetInternals()
  216. {
  217. }
  218. //----------------------------------------------------------------------------
  219. cmTarget::cmTarget()
  220. {
  221. #define INITIALIZE_TARGET_POLICY_MEMBER(POLICY) \
  222. this->PolicyStatus ## POLICY = cmPolicies::WARN;
  223. CM_FOR_EACH_TARGET_POLICY(INITIALIZE_TARGET_POLICY_MEMBER)
  224. #undef INITIALIZE_TARGET_POLICY_MEMBER
  225. this->Makefile = 0;
  226. #if defined(_WIN32) && !defined(__CYGWIN__)
  227. this->LinkLibrariesForVS6Analyzed = false;
  228. #endif
  229. this->HaveInstallRule = false;
  230. this->DLLPlatform = false;
  231. this->IsAndroid = false;
  232. this->IsApple = false;
  233. this->IsImportedTarget = false;
  234. this->BuildInterfaceIncludesAppended = false;
  235. this->DebugIncludesDone = false;
  236. this->DebugCompileOptionsDone = false;
  237. this->DebugCompileFeaturesDone = false;
  238. this->DebugCompileDefinitionsDone = false;
  239. this->DebugSourcesDone = false;
  240. this->LinkImplementationLanguageIsContextDependent = true;
  241. }
  242. //----------------------------------------------------------------------------
  243. void cmTarget::DefineProperties(cmake *cm)
  244. {
  245. cm->DefineProperty
  246. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  247. "", "", true);
  248. cm->DefineProperty
  249. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  250. "", "", true);
  251. cm->DefineProperty
  252. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  253. "", "", true);
  254. }
  255. void cmTarget::SetType(TargetType type, const std::string& name)
  256. {
  257. this->Name = name;
  258. // only add dependency information for library targets
  259. this->TargetTypeValue = type;
  260. if(this->TargetTypeValue >= STATIC_LIBRARY
  261. && this->TargetTypeValue <= MODULE_LIBRARY)
  262. {
  263. this->RecordDependencies = true;
  264. }
  265. else
  266. {
  267. this->RecordDependencies = false;
  268. }
  269. }
  270. //----------------------------------------------------------------------------
  271. void cmTarget::SetMakefile(cmMakefile* mf)
  272. {
  273. // Set our makefile.
  274. this->Makefile = mf;
  275. // set the cmake instance of the properties
  276. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  277. // Check whether this is a DLL platform.
  278. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  279. this->Makefile->IsOn("CYGWIN") ||
  280. this->Makefile->IsOn("MINGW"));
  281. // Check whether we are targeting an Android platform.
  282. this->IsAndroid =
  283. strcmp(this->Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME"),
  284. "Android") == 0;
  285. // Check whether we are targeting an Apple platform.
  286. this->IsApple = this->Makefile->IsOn("APPLE");
  287. // Setup default property values.
  288. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  289. {
  290. this->SetPropertyDefault("ANDROID_API", 0);
  291. this->SetPropertyDefault("INSTALL_NAME_DIR", 0);
  292. this->SetPropertyDefault("INSTALL_RPATH", "");
  293. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  294. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  295. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  296. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  297. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  298. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  299. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  300. this->SetPropertyDefault("COMPILE_PDB_OUTPUT_DIRECTORY", 0);
  301. this->SetPropertyDefault("Fortran_FORMAT", 0);
  302. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  303. this->SetPropertyDefault("GNUtoMS", 0);
  304. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  305. this->SetPropertyDefault("AUTOMOC", 0);
  306. this->SetPropertyDefault("AUTOUIC", 0);
  307. this->SetPropertyDefault("AUTORCC", 0);
  308. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  309. this->SetPropertyDefault("AUTOUIC_OPTIONS", 0);
  310. this->SetPropertyDefault("AUTORCC_OPTIONS", 0);
  311. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  312. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  313. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  314. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  315. this->SetPropertyDefault("MACOSX_RPATH", 0);
  316. this->SetPropertyDefault("NO_SYSTEM_FROM_IMPORTED", 0);
  317. this->SetPropertyDefault("C_STANDARD", 0);
  318. this->SetPropertyDefault("C_STANDARD_REQUIRED", 0);
  319. this->SetPropertyDefault("C_EXTENSIONS", 0);
  320. this->SetPropertyDefault("CXX_STANDARD", 0);
  321. this->SetPropertyDefault("CXX_STANDARD_REQUIRED", 0);
  322. this->SetPropertyDefault("CXX_EXTENSIONS", 0);
  323. }
  324. // Collect the set of configuration types.
  325. std::vector<std::string> configNames;
  326. mf->GetConfigurations(configNames);
  327. // Setup per-configuration property default values.
  328. if (this->GetType() != UTILITY)
  329. {
  330. const char* configProps[] = {
  331. "ARCHIVE_OUTPUT_DIRECTORY_",
  332. "LIBRARY_OUTPUT_DIRECTORY_",
  333. "RUNTIME_OUTPUT_DIRECTORY_",
  334. "PDB_OUTPUT_DIRECTORY_",
  335. "COMPILE_PDB_OUTPUT_DIRECTORY_",
  336. "MAP_IMPORTED_CONFIG_",
  337. 0};
  338. for(std::vector<std::string>::iterator ci = configNames.begin();
  339. ci != configNames.end(); ++ci)
  340. {
  341. std::string configUpper = cmSystemTools::UpperCase(*ci);
  342. for(const char** p = configProps; *p; ++p)
  343. {
  344. if (this->TargetTypeValue == INTERFACE_LIBRARY
  345. && strcmp(*p, "MAP_IMPORTED_CONFIG_") != 0)
  346. {
  347. continue;
  348. }
  349. std::string property = *p;
  350. property += configUpper;
  351. this->SetPropertyDefault(property, 0);
  352. }
  353. // Initialize per-configuration name postfix property from the
  354. // variable only for non-executable targets. This preserves
  355. // compatibility with previous CMake versions in which executables
  356. // did not support this variable. Projects may still specify the
  357. // property directly.
  358. if(this->TargetTypeValue != cmTarget::EXECUTABLE
  359. && this->TargetTypeValue != cmTarget::INTERFACE_LIBRARY)
  360. {
  361. std::string property = cmSystemTools::UpperCase(*ci);
  362. property += "_POSTFIX";
  363. this->SetPropertyDefault(property, 0);
  364. }
  365. }
  366. }
  367. // Save the backtrace of target construction.
  368. this->Internal->Backtrace = this->Makefile->GetBacktrace();
  369. if (!this->IsImported())
  370. {
  371. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  372. // of the same directory property:
  373. const std::vector<cmValueWithOrigin> parentIncludes =
  374. this->Makefile->GetIncludeDirectoriesEntries();
  375. for (std::vector<cmValueWithOrigin>::const_iterator it
  376. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  377. {
  378. this->InsertInclude(*it);
  379. }
  380. const std::set<std::string> parentSystemIncludes =
  381. this->Makefile->GetSystemIncludeDirectories();
  382. for (std::set<std::string>::const_iterator it
  383. = parentSystemIncludes.begin();
  384. it != parentSystemIncludes.end(); ++it)
  385. {
  386. this->SystemIncludeDirectories.insert(*it);
  387. }
  388. const std::vector<cmValueWithOrigin> parentOptions =
  389. this->Makefile->GetCompileOptionsEntries();
  390. for (std::vector<cmValueWithOrigin>::const_iterator it
  391. = parentOptions.begin(); it != parentOptions.end(); ++it)
  392. {
  393. this->InsertCompileOption(*it);
  394. }
  395. }
  396. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  397. {
  398. this->SetPropertyDefault("C_VISIBILITY_PRESET", 0);
  399. this->SetPropertyDefault("CXX_VISIBILITY_PRESET", 0);
  400. this->SetPropertyDefault("VISIBILITY_INLINES_HIDDEN", 0);
  401. }
  402. if(this->TargetTypeValue == cmTarget::EXECUTABLE)
  403. {
  404. this->SetPropertyDefault("ANDROID_GUI", 0);
  405. }
  406. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  407. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  408. {
  409. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  410. }
  411. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  412. {
  413. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  414. }
  415. // Record current policies for later use.
  416. #define CAPTURE_TARGET_POLICY(POLICY) \
  417. this->PolicyStatus ## POLICY = \
  418. this->Makefile->GetPolicyStatus(cmPolicies::POLICY);
  419. CM_FOR_EACH_TARGET_POLICY(CAPTURE_TARGET_POLICY)
  420. #undef CAPTURE_TARGET_POLICY
  421. if (this->TargetTypeValue == INTERFACE_LIBRARY)
  422. {
  423. // This policy is checked in a few conditions. The properties relevant
  424. // to the policy are always ignored for INTERFACE_LIBRARY targets,
  425. // so ensure that the conditions don't lead to nonsense.
  426. this->PolicyStatusCMP0022 = cmPolicies::NEW;
  427. }
  428. if (this->GetType() != INTERFACE_LIBRARY && this->GetType() != UTILITY)
  429. {
  430. this->SetPropertyDefault("JOB_POOL_COMPILE", 0);
  431. this->SetPropertyDefault("JOB_POOL_LINK", 0);
  432. }
  433. }
  434. //----------------------------------------------------------------------------
  435. void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile)
  436. {
  437. if(this->Utilities.insert(u).second && makefile)
  438. {
  439. UtilityBacktraces.insert(std::make_pair(u, makefile->GetBacktrace()));
  440. }
  441. }
  442. //----------------------------------------------------------------------------
  443. cmListFileBacktrace const* cmTarget::GetUtilityBacktrace(
  444. const std::string& u) const
  445. {
  446. std::map<std::string, cmListFileBacktrace>::const_iterator i =
  447. this->UtilityBacktraces.find(u);
  448. if(i == this->UtilityBacktraces.end()) return 0;
  449. return &i->second;
  450. }
  451. //----------------------------------------------------------------------------
  452. std::set<cmLinkItem> const& cmTarget::GetUtilityItems() const
  453. {
  454. if(!this->Internal->UtilityItemsDone)
  455. {
  456. this->Internal->UtilityItemsDone = true;
  457. for(std::set<std::string>::const_iterator i = this->Utilities.begin();
  458. i != this->Utilities.end(); ++i)
  459. {
  460. this->Internal->UtilityItems.insert(
  461. cmLinkItem(*i, this->Makefile->FindTargetToUse(*i)));
  462. }
  463. }
  464. return this->Internal->UtilityItems;
  465. }
  466. //----------------------------------------------------------------------------
  467. void cmTarget::FinishConfigure()
  468. {
  469. // Erase any cached link information that might have been comptued
  470. // on-demand during the configuration. This ensures that build
  471. // system generation uses up-to-date information even if other cache
  472. // invalidation code in this source file is buggy.
  473. this->ClearLinkMaps();
  474. #if defined(_WIN32) && !defined(__CYGWIN__)
  475. // Do old-style link dependency analysis only for CM_USE_OLD_VS6.
  476. if(this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->IsForVS6())
  477. {
  478. this->AnalyzeLibDependenciesForVS6(*this->Makefile);
  479. }
  480. #endif
  481. }
  482. //----------------------------------------------------------------------------
  483. void cmTarget::ClearLinkMaps()
  484. {
  485. this->LinkImplementationLanguageIsContextDependent = true;
  486. this->Internal->LinkImplMap.clear();
  487. this->Internal->LinkInterfaceMap.clear();
  488. this->Internal->LinkInterfaceUsageRequirementsOnlyMap.clear();
  489. this->Internal->LinkClosureMap.clear();
  490. for (cmTargetLinkInformationMap::const_iterator it
  491. = this->LinkInformation.begin();
  492. it != this->LinkInformation.end(); ++it)
  493. {
  494. delete it->second;
  495. }
  496. this->LinkInformation.clear();
  497. }
  498. //----------------------------------------------------------------------------
  499. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  500. {
  501. return this->Internal->Backtrace;
  502. }
  503. //----------------------------------------------------------------------------
  504. std::string cmTarget::GetSupportDirectory() const
  505. {
  506. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  507. dir += cmake::GetCMakeFilesDirectory();
  508. dir += "/";
  509. dir += this->Name;
  510. #if defined(__VMS)
  511. dir += "_dir";
  512. #else
  513. dir += ".dir";
  514. #endif
  515. return dir;
  516. }
  517. //----------------------------------------------------------------------------
  518. bool cmTarget::IsExecutableWithExports() const
  519. {
  520. return (this->GetType() == cmTarget::EXECUTABLE &&
  521. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  522. }
  523. //----------------------------------------------------------------------------
  524. bool cmTarget::IsLinkable() const
  525. {
  526. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  527. this->GetType() == cmTarget::SHARED_LIBRARY ||
  528. this->GetType() == cmTarget::MODULE_LIBRARY ||
  529. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  530. this->GetType() == cmTarget::INTERFACE_LIBRARY ||
  531. this->IsExecutableWithExports());
  532. }
  533. //----------------------------------------------------------------------------
  534. bool cmTarget::HasImportLibrary() const
  535. {
  536. return (this->DLLPlatform &&
  537. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  538. this->IsExecutableWithExports()));
  539. }
  540. //----------------------------------------------------------------------------
  541. bool cmTarget::IsFrameworkOnApple() const
  542. {
  543. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  544. this->Makefile->IsOn("APPLE") &&
  545. this->GetPropertyAsBool("FRAMEWORK"));
  546. }
  547. //----------------------------------------------------------------------------
  548. bool cmTarget::IsAppBundleOnApple() const
  549. {
  550. return (this->GetType() == cmTarget::EXECUTABLE &&
  551. this->Makefile->IsOn("APPLE") &&
  552. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  553. }
  554. //----------------------------------------------------------------------------
  555. bool cmTarget::IsCFBundleOnApple() const
  556. {
  557. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  558. this->Makefile->IsOn("APPLE") &&
  559. this->GetPropertyAsBool("BUNDLE"));
  560. }
  561. //----------------------------------------------------------------------------
  562. bool cmTarget::IsBundleOnApple() const
  563. {
  564. return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
  565. this->IsCFBundleOnApple();
  566. }
  567. //----------------------------------------------------------------------------
  568. static bool processSources(cmTarget const* tgt,
  569. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  570. std::vector<std::string> &srcs,
  571. UNORDERED_SET<std::string> &uniqueSrcs,
  572. cmGeneratorExpressionDAGChecker *dagChecker,
  573. std::string const& config, bool debugSources)
  574. {
  575. cmMakefile *mf = tgt->GetMakefile();
  576. bool contextDependent = false;
  577. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  578. it = entries.begin(), end = entries.end(); it != end; ++it)
  579. {
  580. std::vector<std::string> entrySources;
  581. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  582. config,
  583. false,
  584. tgt,
  585. tgt,
  586. dagChecker),
  587. entrySources);
  588. if ((*it)->ge->GetHadContextSensitiveCondition())
  589. {
  590. contextDependent = true;
  591. }
  592. for(std::vector<std::string>::iterator i = entrySources.begin();
  593. i != entrySources.end(); ++i)
  594. {
  595. std::string& src = *i;
  596. cmSourceFile* sf = mf->GetOrCreateSource(src);
  597. std::string e;
  598. src = sf->GetFullPath(&e);
  599. if(src.empty())
  600. {
  601. if(!e.empty())
  602. {
  603. cmake* cm = mf->GetCMakeInstance();
  604. cm->IssueMessage(cmake::FATAL_ERROR, e,
  605. tgt->GetBacktrace());
  606. }
  607. return contextDependent;
  608. }
  609. }
  610. std::string usedSources;
  611. for(std::vector<std::string>::iterator
  612. li = entrySources.begin(); li != entrySources.end(); ++li)
  613. {
  614. std::string src = *li;
  615. if(uniqueSrcs.insert(src).second)
  616. {
  617. srcs.push_back(src);
  618. if (debugSources)
  619. {
  620. usedSources += " * " + src + "\n";
  621. }
  622. }
  623. }
  624. if (!usedSources.empty())
  625. {
  626. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  627. std::string("Used sources for target ")
  628. + tgt->GetName() + ":\n"
  629. + usedSources, (*it)->ge->GetBacktrace());
  630. }
  631. }
  632. return contextDependent;
  633. }
  634. //----------------------------------------------------------------------------
  635. void cmTarget::GetSourceFiles(std::vector<std::string> &files,
  636. const std::string& config) const
  637. {
  638. assert(this->GetType() != INTERFACE_LIBRARY);
  639. if (this->Makefile->GetGeneratorTargets().empty())
  640. {
  641. // At configure-time, this method can be called as part of getting the
  642. // LOCATION property or to export() a file to be include()d. However
  643. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  644. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  645. // behavior of CMP0024 and CMP0026 only.
  646. typedef cmTargetInternals::TargetPropertyEntry
  647. TargetPropertyEntry;
  648. for(std::vector<TargetPropertyEntry*>::const_iterator
  649. i = this->Internal->SourceEntries.begin();
  650. i != this->Internal->SourceEntries.end(); ++i)
  651. {
  652. std::string entry = (*i)->ge->GetInput();
  653. std::vector<std::string> items;
  654. cmSystemTools::ExpandListArgument(entry, items);
  655. for (std::vector<std::string>::const_iterator
  656. li = items.begin(); li != items.end(); ++li)
  657. {
  658. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  659. (*li)[li->size() - 1] == '>')
  660. {
  661. continue;
  662. }
  663. files.push_back(*li);
  664. }
  665. }
  666. return;
  667. }
  668. std::vector<std::string> debugProperties;
  669. const char *debugProp =
  670. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  671. if (debugProp)
  672. {
  673. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  674. }
  675. bool debugSources = !this->DebugSourcesDone
  676. && std::find(debugProperties.begin(),
  677. debugProperties.end(),
  678. "SOURCES")
  679. != debugProperties.end();
  680. if (this->Makefile->IsGeneratingBuildSystem())
  681. {
  682. this->DebugSourcesDone = true;
  683. }
  684. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  685. "SOURCES", 0, 0);
  686. UNORDERED_SET<std::string> uniqueSrcs;
  687. bool contextDependentDirectSources = processSources(this,
  688. this->Internal->SourceEntries,
  689. files,
  690. uniqueSrcs,
  691. &dagChecker,
  692. config,
  693. debugSources);
  694. std::vector<cmTargetInternals::TargetPropertyEntry*>
  695. linkInterfaceSourcesEntries;
  696. this->Internal->AddInterfaceEntries(
  697. this, config, "INTERFACE_SOURCES",
  698. linkInterfaceSourcesEntries);
  699. std::vector<std::string>::size_type numFilesBefore = files.size();
  700. bool contextDependentInterfaceSources = processSources(this,
  701. linkInterfaceSourcesEntries,
  702. files,
  703. uniqueSrcs,
  704. &dagChecker,
  705. config,
  706. debugSources);
  707. if (!contextDependentDirectSources
  708. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  709. {
  710. this->LinkImplementationLanguageIsContextDependent = false;
  711. }
  712. deleteAndClear(linkInterfaceSourcesEntries);
  713. }
  714. //----------------------------------------------------------------------------
  715. bool
  716. cmTarget::GetConfigCommonSourceFiles(std::vector<cmSourceFile*>& files) const
  717. {
  718. std::vector<std::string> configs;
  719. this->Makefile->GetConfigurations(configs);
  720. if (configs.empty())
  721. {
  722. configs.push_back("");
  723. }
  724. std::vector<std::string>::const_iterator it = configs.begin();
  725. const std::string& firstConfig = *it;
  726. this->GetSourceFiles(files, firstConfig);
  727. for ( ; it != configs.end(); ++it)
  728. {
  729. std::vector<cmSourceFile*> configFiles;
  730. this->GetSourceFiles(configFiles, *it);
  731. if (configFiles != files)
  732. {
  733. std::string firstConfigFiles;
  734. const char* sep = "";
  735. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  736. fi != files.end(); ++fi)
  737. {
  738. firstConfigFiles += sep;
  739. firstConfigFiles += (*fi)->GetFullPath();
  740. sep = "\n ";
  741. }
  742. std::string thisConfigFiles;
  743. sep = "";
  744. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  745. fi != configFiles.end(); ++fi)
  746. {
  747. thisConfigFiles += sep;
  748. thisConfigFiles += (*fi)->GetFullPath();
  749. sep = "\n ";
  750. }
  751. cmOStringStream e;
  752. e << "Target \"" << this->Name << "\" has source files which vary by "
  753. "configuration. This is not supported by the \""
  754. << this->Makefile->GetLocalGenerator()
  755. ->GetGlobalGenerator()->GetName()
  756. << "\" generator.\n"
  757. "Config \"" << firstConfig << "\":\n"
  758. " " << firstConfigFiles << "\n"
  759. "Config \"" << *it << "\":\n"
  760. " " << thisConfigFiles << "\n";
  761. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  762. return false;
  763. }
  764. }
  765. return true;
  766. }
  767. //----------------------------------------------------------------------------
  768. void cmTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  769. const std::string& config) const
  770. {
  771. // Lookup any existing link implementation for this configuration.
  772. std::string key = cmSystemTools::UpperCase(config);
  773. if(!this->LinkImplementationLanguageIsContextDependent)
  774. {
  775. files = this->Internal->SourceFilesMap.begin()->second;
  776. return;
  777. }
  778. cmTargetInternals::SourceFilesMapType::iterator
  779. it = this->Internal->SourceFilesMap.find(key);
  780. if(it != this->Internal->SourceFilesMap.end())
  781. {
  782. files = it->second;
  783. }
  784. else
  785. {
  786. std::vector<std::string> srcs;
  787. this->GetSourceFiles(srcs, config);
  788. std::set<cmSourceFile*> emitted;
  789. for(std::vector<std::string>::const_iterator i = srcs.begin();
  790. i != srcs.end(); ++i)
  791. {
  792. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  793. if (emitted.insert(sf).second)
  794. {
  795. files.push_back(sf);
  796. }
  797. }
  798. this->Internal->SourceFilesMap[key] = files;
  799. }
  800. }
  801. //----------------------------------------------------------------------------
  802. void cmTarget::AddTracedSources(std::vector<std::string> const& srcs)
  803. {
  804. std::string srcFiles;
  805. const char* sep = "";
  806. for(std::vector<std::string>::const_iterator i = srcs.begin();
  807. i != srcs.end(); ++i)
  808. {
  809. std::string filename = *i;
  810. srcFiles += sep;
  811. srcFiles += filename;
  812. sep = ";";
  813. }
  814. if (!srcFiles.empty())
  815. {
  816. this->Internal->SourceFilesMap.clear();
  817. this->LinkImplementationLanguageIsContextDependent = true;
  818. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  819. cmGeneratorExpression ge(&lfbt);
  820. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  821. cge->SetEvaluateForBuildsystem(true);
  822. this->Internal->SourceEntries.push_back(
  823. new cmTargetInternals::TargetPropertyEntry(cge));
  824. }
  825. }
  826. //----------------------------------------------------------------------------
  827. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  828. {
  829. std::string srcFiles;
  830. const char* sep = "";
  831. for(std::vector<std::string>::const_iterator i = srcs.begin();
  832. i != srcs.end(); ++i)
  833. {
  834. std::string filename = *i;
  835. const char* src = filename.c_str();
  836. if(!(src[0] == '$' && src[1] == '<'))
  837. {
  838. if(!filename.empty())
  839. {
  840. filename = this->ProcessSourceItemCMP0049(filename);
  841. if(filename.empty())
  842. {
  843. return;
  844. }
  845. }
  846. this->Makefile->GetOrCreateSource(filename);
  847. }
  848. srcFiles += sep;
  849. srcFiles += filename;
  850. sep = ";";
  851. }
  852. if (!srcFiles.empty())
  853. {
  854. this->Internal->SourceFilesMap.clear();
  855. this->LinkImplementationLanguageIsContextDependent = true;
  856. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  857. cmGeneratorExpression ge(&lfbt);
  858. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  859. cge->SetEvaluateForBuildsystem(true);
  860. this->Internal->SourceEntries.push_back(
  861. new cmTargetInternals::TargetPropertyEntry(cge));
  862. }
  863. }
  864. //----------------------------------------------------------------------------
  865. std::string cmTarget::ProcessSourceItemCMP0049(const std::string& s)
  866. {
  867. std::string src = s;
  868. // For backwards compatibility replace varibles in source names.
  869. // This should eventually be removed.
  870. this->Makefile->ExpandVariablesInString(src);
  871. if (src != s)
  872. {
  873. cmOStringStream e;
  874. bool noMessage = false;
  875. cmake::MessageType messageType = cmake::AUTHOR_WARNING;
  876. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0049))
  877. {
  878. case cmPolicies::WARN:
  879. e << (this->Makefile->GetPolicies()
  880. ->GetPolicyWarning(cmPolicies::CMP0049)) << "\n";
  881. break;
  882. case cmPolicies::OLD:
  883. noMessage = true;
  884. break;
  885. case cmPolicies::REQUIRED_ALWAYS:
  886. case cmPolicies::REQUIRED_IF_USED:
  887. case cmPolicies::NEW:
  888. messageType = cmake::FATAL_ERROR;
  889. }
  890. if (!noMessage)
  891. {
  892. e << "Legacy variable expansion in source file \""
  893. << s << "\" expanded to \"" << src << "\" in target \""
  894. << this->GetName() << "\". This behavior will be removed in a "
  895. "future version of CMake.";
  896. this->Makefile->IssueMessage(messageType, e.str());
  897. if (messageType == cmake::FATAL_ERROR)
  898. {
  899. return "";
  900. }
  901. }
  902. }
  903. return src;
  904. }
  905. //----------------------------------------------------------------------------
  906. cmSourceFile* cmTarget::AddSourceCMP0049(const std::string& s)
  907. {
  908. std::string src = this->ProcessSourceItemCMP0049(s);
  909. if(!s.empty() && src.empty())
  910. {
  911. return 0;
  912. }
  913. return this->AddSource(src);
  914. }
  915. //----------------------------------------------------------------------------
  916. struct CreateLocation
  917. {
  918. cmMakefile const* Makefile;
  919. CreateLocation(cmMakefile const* mf)
  920. : Makefile(mf)
  921. {
  922. }
  923. cmSourceFileLocation operator()(const std::string& filename)
  924. {
  925. return cmSourceFileLocation(this->Makefile, filename);
  926. }
  927. };
  928. //----------------------------------------------------------------------------
  929. struct LocationMatcher
  930. {
  931. const cmSourceFileLocation& Needle;
  932. LocationMatcher(const cmSourceFileLocation& needle)
  933. : Needle(needle)
  934. {
  935. }
  936. bool operator()(cmSourceFileLocation &loc)
  937. {
  938. return loc.Matches(this->Needle);
  939. }
  940. };
  941. //----------------------------------------------------------------------------
  942. struct TargetPropertyEntryFinder
  943. {
  944. private:
  945. const cmSourceFileLocation& Needle;
  946. public:
  947. TargetPropertyEntryFinder(const cmSourceFileLocation& needle)
  948. : Needle(needle)
  949. {
  950. }
  951. bool operator()(cmTargetInternals::TargetPropertyEntry* entry)
  952. {
  953. std::vector<std::string> files;
  954. cmSystemTools::ExpandListArgument(entry->ge->GetInput(), files);
  955. std::vector<cmSourceFileLocation> locations(files.size());
  956. std::transform(files.begin(), files.end(), locations.begin(),
  957. CreateLocation(this->Needle.GetMakefile()));
  958. return std::find_if(locations.begin(), locations.end(),
  959. LocationMatcher(this->Needle)) != locations.end();
  960. }
  961. };
  962. //----------------------------------------------------------------------------
  963. cmSourceFile* cmTarget::AddSource(const std::string& src)
  964. {
  965. cmSourceFileLocation sfl(this->Makefile, src);
  966. if (std::find_if(this->Internal->SourceEntries.begin(),
  967. this->Internal->SourceEntries.end(),
  968. TargetPropertyEntryFinder(sfl))
  969. == this->Internal->SourceEntries.end())
  970. {
  971. this->Internal->SourceFilesMap.clear();
  972. this->LinkImplementationLanguageIsContextDependent = true;
  973. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  974. cmGeneratorExpression ge(&lfbt);
  975. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  976. cge->SetEvaluateForBuildsystem(true);
  977. this->Internal->SourceEntries.push_back(
  978. new cmTargetInternals::TargetPropertyEntry(cge));
  979. }
  980. if (cmGeneratorExpression::Find(src) != std::string::npos)
  981. {
  982. return 0;
  983. }
  984. return this->Makefile->GetOrCreateSource(src);
  985. }
  986. //----------------------------------------------------------------------------
  987. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  988. const std::string& selfname,
  989. const LinkLibraryVectorType& libs )
  990. {
  991. // Only add on libraries we haven't added on before.
  992. // Assumption: the global link libraries could only grow, never shrink
  993. LinkLibraryVectorType::const_iterator i = libs.begin();
  994. i += this->PrevLinkedLibraries.size();
  995. for( ; i != libs.end(); ++i )
  996. {
  997. // This is equivalent to the target_link_libraries plain signature.
  998. this->AddLinkLibrary( mf, selfname, i->first, i->second );
  999. this->AppendProperty("INTERFACE_LINK_LIBRARIES",
  1000. this->GetDebugGeneratorExpressions(i->first, i->second).c_str());
  1001. }
  1002. this->PrevLinkedLibraries = libs;
  1003. }
  1004. //----------------------------------------------------------------------------
  1005. void cmTarget::AddLinkDirectory(const std::string& d)
  1006. {
  1007. // Make sure we don't add unnecessary search directories.
  1008. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1009. {
  1010. this->LinkDirectories.push_back(d);
  1011. }
  1012. }
  1013. //----------------------------------------------------------------------------
  1014. const std::vector<std::string>& cmTarget::GetLinkDirectories() const
  1015. {
  1016. return this->LinkDirectories;
  1017. }
  1018. //----------------------------------------------------------------------------
  1019. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(
  1020. const std::string& config) const
  1021. {
  1022. // No configuration is always optimized.
  1023. if(config.empty())
  1024. {
  1025. return cmTarget::OPTIMIZED;
  1026. }
  1027. // Get the list of configurations considered to be DEBUG.
  1028. std::vector<std::string> const& debugConfigs =
  1029. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1030. // Check if any entry in the list matches this configuration.
  1031. std::string configUpper = cmSystemTools::UpperCase(config);
  1032. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  1033. i != debugConfigs.end(); ++i)
  1034. {
  1035. if(*i == configUpper)
  1036. {
  1037. return cmTarget::DEBUG;
  1038. }
  1039. }
  1040. // The current configuration is not a debug configuration.
  1041. return cmTarget::OPTIMIZED;
  1042. }
  1043. //----------------------------------------------------------------------------
  1044. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1045. const std::string& target )
  1046. {
  1047. // Clear the dependencies. The cache variable must exist iff we are
  1048. // recording dependency information for this target.
  1049. std::string depname = target;
  1050. depname += "_LIB_DEPENDS";
  1051. if (this->RecordDependencies)
  1052. {
  1053. mf.AddCacheDefinition(depname, "",
  1054. "Dependencies for target", cmCacheManager::STATIC);
  1055. }
  1056. else
  1057. {
  1058. if (mf.GetDefinition( depname ))
  1059. {
  1060. std::string message = "Target ";
  1061. message += target;
  1062. message += " has dependency information when it shouldn't.\n";
  1063. message += "Your cache is probably stale. Please remove the entry\n ";
  1064. message += depname;
  1065. message += "\nfrom the cache.";
  1066. cmSystemTools::Error( message.c_str() );
  1067. }
  1068. }
  1069. }
  1070. //----------------------------------------------------------------------------
  1071. bool cmTarget::NameResolvesToFramework(const std::string& libname) const
  1072. {
  1073. return this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  1074. NameResolvesToFramework(libname);
  1075. }
  1076. //----------------------------------------------------------------------------
  1077. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  1078. cmTarget::LinkLibraryType llt) const
  1079. {
  1080. if (llt == GENERAL)
  1081. {
  1082. return value;
  1083. }
  1084. // Get the list of configurations considered to be DEBUG.
  1085. std::vector<std::string> const& debugConfigs =
  1086. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1087. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  1088. if (debugConfigs.size() > 1)
  1089. {
  1090. for(std::vector<std::string>::const_iterator
  1091. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  1092. {
  1093. configString += ",$<CONFIG:" + *li + ">";
  1094. }
  1095. configString = "$<OR:" + configString + ">";
  1096. }
  1097. if (llt == OPTIMIZED)
  1098. {
  1099. configString = "$<NOT:" + configString + ">";
  1100. }
  1101. return "$<" + configString + ":" + value + ">";
  1102. }
  1103. //----------------------------------------------------------------------------
  1104. static std::string targetNameGenex(const std::string& lib)
  1105. {
  1106. return "$<TARGET_NAME:" + lib + ">";
  1107. }
  1108. //----------------------------------------------------------------------------
  1109. bool cmTarget::PushTLLCommandTrace(TLLSignature signature)
  1110. {
  1111. bool ret = true;
  1112. if (!this->TLLCommands.empty())
  1113. {
  1114. if (this->TLLCommands.back().first != signature)
  1115. {
  1116. ret = false;
  1117. }
  1118. }
  1119. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1120. this->TLLCommands.push_back(std::make_pair(signature, lfbt));
  1121. return ret;
  1122. }
  1123. //----------------------------------------------------------------------------
  1124. void cmTarget::GetTllSignatureTraces(cmOStringStream &s,
  1125. TLLSignature sig) const
  1126. {
  1127. std::vector<cmListFileBacktrace> sigs;
  1128. typedef std::vector<std::pair<TLLSignature, cmListFileBacktrace> > Container;
  1129. for(Container::const_iterator it = this->TLLCommands.begin();
  1130. it != this->TLLCommands.end(); ++it)
  1131. {
  1132. if (it->first == sig)
  1133. {
  1134. sigs.push_back(it->second);
  1135. }
  1136. }
  1137. if (!sigs.empty())
  1138. {
  1139. const char *sigString
  1140. = (sig == cmTarget::KeywordTLLSignature ? "keyword"
  1141. : "plain");
  1142. s << "The uses of the " << sigString << " signature are here:\n";
  1143. UNORDERED_SET<std::string> emitted;
  1144. for(std::vector<cmListFileBacktrace>::iterator it = sigs.begin();
  1145. it != sigs.end(); ++it)
  1146. {
  1147. it->MakeRelative();
  1148. cmListFileBacktrace::const_iterator i = it->begin();
  1149. if(i != it->end())
  1150. {
  1151. cmListFileContext const& lfc = *i;
  1152. cmOStringStream line;
  1153. line << " * " << (lfc.Line? "": " in ") << lfc << std::endl;
  1154. if (emitted.insert(line.str()).second)
  1155. {
  1156. s << line.str();
  1157. }
  1158. ++i;
  1159. }
  1160. }
  1161. }
  1162. }
  1163. //----------------------------------------------------------------------------
  1164. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  1165. const std::string& target,
  1166. const std::string& lib,
  1167. LinkLibraryType llt)
  1168. {
  1169. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  1170. {
  1171. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  1172. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  1173. ? targetNameGenex(lib)
  1174. : lib;
  1175. this->AppendProperty("LINK_LIBRARIES",
  1176. this->GetDebugGeneratorExpressions(libName,
  1177. llt).c_str());
  1178. }
  1179. if (cmGeneratorExpression::Find(lib) != std::string::npos
  1180. || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
  1181. || (target == lib ))
  1182. {
  1183. return;
  1184. }
  1185. cmTarget::LibraryID tmp;
  1186. tmp.first = lib;
  1187. tmp.second = llt;
  1188. #if defined(_WIN32) && !defined(__CYGWIN__)
  1189. this->LinkLibrariesForVS6.push_back( tmp );
  1190. #endif
  1191. this->OriginalLinkLibraries.push_back(tmp);
  1192. this->ClearLinkMaps();
  1193. // Add the explicit dependency information for this target. This is
  1194. // simply a set of libraries separated by ";". There should always
  1195. // be a trailing ";". These library names are not canonical, in that
  1196. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  1197. // We shouldn't remove duplicates here because external libraries
  1198. // may be purposefully duplicated to handle recursive dependencies,
  1199. // and we removing one instance will break the link line. Duplicates
  1200. // will be appropriately eliminated at emit time.
  1201. if(this->RecordDependencies)
  1202. {
  1203. std::string targetEntry = target;
  1204. targetEntry += "_LIB_DEPENDS";
  1205. std::string dependencies;
  1206. const char* old_val = mf.GetDefinition( targetEntry );
  1207. if( old_val )
  1208. {
  1209. dependencies += old_val;
  1210. }
  1211. switch (llt)
  1212. {
  1213. case cmTarget::GENERAL:
  1214. dependencies += "general";
  1215. break;
  1216. case cmTarget::DEBUG:
  1217. dependencies += "debug";
  1218. break;
  1219. case cmTarget::OPTIMIZED:
  1220. dependencies += "optimized";
  1221. break;
  1222. }
  1223. dependencies += ";";
  1224. dependencies += lib;
  1225. dependencies += ";";
  1226. mf.AddCacheDefinition( targetEntry, dependencies.c_str(),
  1227. "Dependencies for the target",
  1228. cmCacheManager::STATIC );
  1229. }
  1230. }
  1231. //----------------------------------------------------------------------------
  1232. void
  1233. cmTarget::AddSystemIncludeDirectories(const std::set<std::string> &incs)
  1234. {
  1235. for(std::set<std::string>::const_iterator li = incs.begin();
  1236. li != incs.end(); ++li)
  1237. {
  1238. this->SystemIncludeDirectories.insert(*li);
  1239. }
  1240. }
  1241. //----------------------------------------------------------------------------
  1242. void
  1243. cmTarget::AddSystemIncludeDirectories(const std::vector<std::string> &incs)
  1244. {
  1245. for(std::vector<std::string>::const_iterator li = incs.begin();
  1246. li != incs.end(); ++li)
  1247. {
  1248. this->SystemIncludeDirectories.insert(*li);
  1249. }
  1250. }
  1251. #if defined(_WIN32) && !defined(__CYGWIN__)
  1252. //----------------------------------------------------------------------------
  1253. void
  1254. cmTarget::AnalyzeLibDependenciesForVS6( const cmMakefile& mf )
  1255. {
  1256. // There are two key parts of the dependency analysis: (1)
  1257. // determining the libraries in the link line, and (2) constructing
  1258. // the dependency graph for those libraries.
  1259. //
  1260. // The latter is done using the cache entries that record the
  1261. // dependencies of each library.
  1262. //
  1263. // The former is a more thorny issue, since it is not clear how to
  1264. // determine if two libraries listed on the link line refer to the a
  1265. // single library or not. For example, consider the link "libraries"
  1266. // /usr/lib/libtiff.so -ltiff
  1267. // Is this one library or two? The solution implemented here is the
  1268. // simplest (and probably the only practical) one: two libraries are
  1269. // the same if their "link strings" are identical. Thus, the two
  1270. // libraries above are considered distinct. This also means that for
  1271. // dependency analysis to be effective, the CMake user must specify
  1272. // libraries build by his project without using any linker flags or
  1273. // file extensions. That is,
  1274. // LINK_LIBRARIES( One Two )
  1275. // instead of
  1276. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  1277. // The former is probably what most users would do, but it never
  1278. // hurts to document the assumptions. :-) Therefore, in the analysis
  1279. // code, the "canonical name" of a library is simply its name as
  1280. // given to a LINK_LIBRARIES command.
  1281. //
  1282. // Also, we will leave the original link line intact; we will just add any
  1283. // dependencies that were missing.
  1284. //
  1285. // There is a problem with recursive external libraries
  1286. // (i.e. libraries with no dependency information that are
  1287. // recursively dependent). We must make sure that the we emit one of
  1288. // the libraries twice to satisfy the recursion, but we shouldn't
  1289. // emit it more times than necessary. In particular, we must make
  1290. // sure that handling this improbable case doesn't cost us when
  1291. // dealing with the common case of non-recursive libraries. The
  1292. // solution is to assume that the recursion is satisfied at one node
  1293. // of the dependency tree. To illustrate, assume libA and libB are
  1294. // extrenal and mutually dependent. Suppose libX depends on
  1295. // libA, and libY on libA and libX. Then
  1296. // TARGET_LINK_LIBRARIES( Y X A B A )
  1297. // TARGET_LINK_LIBRARIES( X A B A )
  1298. // TARGET_LINK_LIBRARIES( Exec Y )
  1299. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  1300. // specify the dependencies, since the mutual dependency of A and B
  1301. // is resolved *every time libA is specified*.
  1302. //
  1303. // Something like
  1304. // TARGET_LINK_LIBRARIES( Y X A B A )
  1305. // TARGET_LINK_LIBRARIES( X A B )
  1306. // TARGET_LINK_LIBRARIES( Exec Y )
  1307. // would result in "-lY -lX -lA -lB", and the mutual dependency
  1308. // information is lost. This is because in some case (Y), the mutual
  1309. // dependency of A and B is listed, while in another other case (X),
  1310. // it is not. Depending on which line actually emits A, the mutual
  1311. // dependency may or may not be on the final link line. We can't
  1312. // handle this pathalogical case cleanly without emitting extra
  1313. // libraries for the normal cases. Besides, the dependency
  1314. // information for X is wrong anyway: if we build an executable
  1315. // depending on X alone, we would not have the mutual dependency on
  1316. // A and B resolved.
  1317. //
  1318. // IMPROVEMENTS:
  1319. // -- The current algorithm will not always pick the "optimal" link line
  1320. // when recursive dependencies are present. It will instead break the
  1321. // cycles at an aribtrary point. The majority of projects won't have
  1322. // cyclic dependencies, so this is probably not a big deal. Note that
  1323. // the link line is always correct, just not necessary optimal.
  1324. {
  1325. // Expand variables in link library names. This is for backwards
  1326. // compatibility with very early CMake versions and should
  1327. // eventually be removed. This code was moved here from the end of
  1328. // old source list processing code which was called just before this
  1329. // method.
  1330. for(LinkLibraryVectorType::iterator p = this->LinkLibrariesForVS6.begin();
  1331. p != this->LinkLibrariesForVS6.end(); ++p)
  1332. {
  1333. this->Makefile->ExpandVariablesInString(p->first, true, true);
  1334. }
  1335. }
  1336. // The dependency map.
  1337. DependencyMap dep_map;
  1338. // 1. Build the dependency graph
  1339. //
  1340. for(LinkLibraryVectorType::reverse_iterator lib
  1341. = this->LinkLibrariesForVS6.rbegin();
  1342. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1343. {
  1344. this->GatherDependenciesForVS6( mf, *lib, dep_map);
  1345. }
  1346. // 2. Remove any dependencies that are already satisfied in the original
  1347. // link line.
  1348. //
  1349. for(LinkLibraryVectorType::iterator lib = this->LinkLibrariesForVS6.begin();
  1350. lib != this->LinkLibrariesForVS6.end(); ++lib)
  1351. {
  1352. for( LinkLibraryVectorType::iterator lib2 = lib;
  1353. lib2 != this->LinkLibrariesForVS6.end(); ++lib2)
  1354. {
  1355. this->DeleteDependencyForVS6( dep_map, *lib, *lib2);
  1356. }
  1357. }
  1358. // 3. Create the new link line by simply emitting any dependencies that are
  1359. // missing. Start from the back and keep adding.
  1360. //
  1361. std::set<DependencyMap::key_type> done, visited;
  1362. std::vector<DependencyMap::key_type> newLinkLibrariesForVS6;
  1363. for(LinkLibraryVectorType::reverse_iterator lib =
  1364. this->LinkLibrariesForVS6.rbegin();
  1365. lib != this->LinkLibrariesForVS6.rend(); ++lib)
  1366. {
  1367. // skip zero size library entries, this may happen
  1368. // if a variable expands to nothing.
  1369. if (lib->first.size() != 0)
  1370. {
  1371. this->EmitForVS6( *lib, dep_map, done, visited, newLinkLibrariesForVS6 );
  1372. }
  1373. }
  1374. // 4. Add the new libraries to the link line.
  1375. //
  1376. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  1377. newLinkLibrariesForVS6.rbegin();
  1378. k != newLinkLibrariesForVS6.rend(); ++k )
  1379. {
  1380. // get the llt from the dep_map
  1381. this->LinkLibrariesForVS6.push_back( std::make_pair(k->first,k->second) );
  1382. }
  1383. this->LinkLibrariesForVS6Analyzed = true;
  1384. }
  1385. //----------------------------------------------------------------------------
  1386. void cmTarget::InsertDependencyForVS6( DependencyMap& depMap,
  1387. const LibraryID& lib,
  1388. const LibraryID& dep)
  1389. {
  1390. depMap[lib].push_back(dep);
  1391. }
  1392. //----------------------------------------------------------------------------
  1393. void cmTarget::DeleteDependencyForVS6( DependencyMap& depMap,
  1394. const LibraryID& lib,
  1395. const LibraryID& dep)
  1396. {
  1397. // Make sure there is an entry in the map for lib. If so, delete all
  1398. // dependencies to dep. There may be repeated entries because of
  1399. // external libraries that are specified multiple times.
  1400. DependencyMap::iterator map_itr = depMap.find( lib );
  1401. if( map_itr != depMap.end() )
  1402. {
  1403. DependencyList& depList = map_itr->second;
  1404. DependencyList::iterator itr;
  1405. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  1406. depList.end() )
  1407. {
  1408. depList.erase( itr );
  1409. }
  1410. }
  1411. }
  1412. //----------------------------------------------------------------------------
  1413. void cmTarget::EmitForVS6(const LibraryID lib,
  1414. const DependencyMap& dep_map,
  1415. std::set<LibraryID>& emitted,
  1416. std::set<LibraryID>& visited,
  1417. DependencyList& link_line )
  1418. {
  1419. // It's already been emitted
  1420. if( emitted.find(lib) != emitted.end() )
  1421. {
  1422. return;
  1423. }
  1424. // Emit the dependencies only if this library node hasn't been
  1425. // visited before. If it has, then we have a cycle. The recursion
  1426. // that got us here should take care of everything.
  1427. if( visited.insert(lib).second )
  1428. {
  1429. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  1430. {
  1431. const DependencyList& dep_on = dep_map.find( lib )->second;
  1432. DependencyList::const_reverse_iterator i;
  1433. // To cater for recursive external libraries, we must emit
  1434. // duplicates on this link line *unless* they were emitted by
  1435. // some other node, in which case we assume that the recursion
  1436. // was resolved then. We making the simplifying assumption that
  1437. // any duplicates on a single link line are on purpose, and must
  1438. // be preserved.
  1439. // This variable will keep track of the libraries that were
  1440. // emitted directly from the current node, and not from a
  1441. // recursive call. This way, if we come across a library that
  1442. // has already been emitted, we repeat it iff it has been
  1443. // emitted here.
  1444. std::set<DependencyMap::key_type> emitted_here;
  1445. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  1446. {
  1447. if( emitted_here.find(*i) != emitted_here.end() )
  1448. {
  1449. // a repeat. Must emit.
  1450. emitted.insert(*i);
  1451. link_line.push_back( *i );
  1452. }
  1453. else
  1454. {
  1455. // Emit only if no-one else has
  1456. if( emitted.find(*i) == emitted.end() )
  1457. {
  1458. // emit dependencies
  1459. this->EmitForVS6( *i, dep_map, emitted, visited, link_line );
  1460. // emit self
  1461. emitted.insert(*i);
  1462. emitted_here.insert(*i);
  1463. link_line.push_back( *i );
  1464. }
  1465. }
  1466. }
  1467. }
  1468. }
  1469. }
  1470. //----------------------------------------------------------------------------
  1471. void cmTarget::GatherDependenciesForVS6( const cmMakefile& mf,
  1472. const LibraryID& lib,
  1473. DependencyMap& dep_map)
  1474. {
  1475. // If the library is already in the dependency map, then it has
  1476. // already been fully processed.
  1477. if( dep_map.find(lib) != dep_map.end() )
  1478. {
  1479. return;
  1480. }
  1481. const char* deps = mf.GetDefinition( lib.first+"_LIB_DEPENDS" );
  1482. if( deps && strcmp(deps,"") != 0 )
  1483. {
  1484. // Make sure this library is in the map, even if it has an empty
  1485. // set of dependencies. This distinguishes the case of explicitly
  1486. // no dependencies with that of unspecified dependencies.
  1487. dep_map[lib];
  1488. // Parse the dependency information, which is a set of
  1489. // type, library pairs separated by ";". There is always a trailing ";".
  1490. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  1491. std::string depline = deps;
  1492. std::string::size_type start = 0;
  1493. std::string::size_type end;
  1494. end = depline.find( ";", start );
  1495. while( end != std::string::npos )
  1496. {
  1497. std::string l = depline.substr( start, end-start );
  1498. if( l.size() != 0 )
  1499. {
  1500. if (l == "debug")
  1501. {
  1502. llt = cmTarget::DEBUG;
  1503. }
  1504. else if (l == "optimized")
  1505. {
  1506. llt = cmTarget::OPTIMIZED;
  1507. }
  1508. else if (l == "general")
  1509. {
  1510. llt = cmTarget::GENERAL;
  1511. }
  1512. else
  1513. {
  1514. LibraryID lib2(l,llt);
  1515. this->InsertDependencyForVS6( dep_map, lib, lib2);
  1516. this->GatherDependenciesForVS6( mf, lib2, dep_map);
  1517. llt = cmTarget::GENERAL;
  1518. }
  1519. }
  1520. start = end+1; // skip the ;
  1521. end = depline.find( ";", start );
  1522. }
  1523. // cannot depend on itself
  1524. this->DeleteDependencyForVS6( dep_map, lib, lib);
  1525. }
  1526. }
  1527. #endif
  1528. //----------------------------------------------------------------------------
  1529. static bool whiteListedInterfaceProperty(const std::string& prop)
  1530. {
  1531. if(cmHasLiteralPrefix(prop, "INTERFACE_"))
  1532. {
  1533. return true;
  1534. }
  1535. static UNORDERED_SET<std::string> builtIns;
  1536. if (builtIns.empty())
  1537. {
  1538. builtIns.insert("COMPATIBLE_INTERFACE_BOOL");
  1539. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MAX");
  1540. builtIns.insert("COMPATIBLE_INTERFACE_NUMBER_MIN");
  1541. builtIns.insert("COMPATIBLE_INTERFACE_STRING");
  1542. builtIns.insert("EXPORT_NAME");
  1543. builtIns.insert("IMPORTED");
  1544. builtIns.insert("NAME");
  1545. builtIns.insert("TYPE");
  1546. }
  1547. if (builtIns.count(prop))
  1548. {
  1549. return true;
  1550. }
  1551. if (cmHasLiteralPrefix(prop, "MAP_IMPORTED_CONFIG_"))
  1552. {
  1553. return true;
  1554. }
  1555. return false;
  1556. }
  1557. //----------------------------------------------------------------------------
  1558. void cmTarget::SetProperty(const std::string& prop, const char* value)
  1559. {
  1560. if (this->GetType() == INTERFACE_LIBRARY
  1561. && !whiteListedInterfaceProperty(prop))
  1562. {
  1563. cmOStringStream e;
  1564. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1565. "The property \"" << prop << "\" is not allowed.";
  1566. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1567. return;
  1568. }
  1569. else if (prop == "NAME")
  1570. {
  1571. cmOStringStream e;
  1572. e << "NAME property is read-only\n";
  1573. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1574. return;
  1575. }
  1576. else if(prop == "INCLUDE_DIRECTORIES")
  1577. {
  1578. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1579. cmGeneratorExpression ge(&lfbt);
  1580. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  1581. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1582. this->Internal->IncludeDirectoriesEntries.push_back(
  1583. new cmTargetInternals::TargetPropertyEntry(cge));
  1584. }
  1585. else if(prop == "COMPILE_OPTIONS")
  1586. {
  1587. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1588. cmGeneratorExpression ge(&lfbt);
  1589. deleteAndClear(this->Internal->CompileOptionsEntries);
  1590. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1591. this->Internal->CompileOptionsEntries.push_back(
  1592. new cmTargetInternals::TargetPropertyEntry(cge));
  1593. }
  1594. else if(prop == "COMPILE_FEATURES")
  1595. {
  1596. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1597. cmGeneratorExpression ge(&lfbt);
  1598. deleteAndClear(this->Internal->CompileFeaturesEntries);
  1599. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1600. this->Internal->CompileFeaturesEntries.push_back(
  1601. new cmTargetInternals::TargetPropertyEntry(cge));
  1602. }
  1603. else if(prop == "COMPILE_DEFINITIONS")
  1604. {
  1605. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1606. cmGeneratorExpression ge(&lfbt);
  1607. deleteAndClear(this->Internal->CompileDefinitionsEntries);
  1608. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1609. this->Internal->CompileDefinitionsEntries.push_back(
  1610. new cmTargetInternals::TargetPropertyEntry(cge));
  1611. }
  1612. else if(prop == "EXPORT_NAME" && this->IsImported())
  1613. {
  1614. cmOStringStream e;
  1615. e << "EXPORT_NAME property can't be set on imported targets (\""
  1616. << this->Name << "\")\n";
  1617. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1618. }
  1619. else if (prop == "LINK_LIBRARIES")
  1620. {
  1621. this->Internal->LinkImplementationPropertyEntries.clear();
  1622. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1623. cmValueWithOrigin entry(value, lfbt);
  1624. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1625. }
  1626. else if (prop == "SOURCES")
  1627. {
  1628. if(this->IsImported())
  1629. {
  1630. cmOStringStream e;
  1631. e << "SOURCES property can't be set on imported targets (\""
  1632. << this->Name << "\")\n";
  1633. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1634. return;
  1635. }
  1636. this->Internal->SourceFilesMap.clear();
  1637. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1638. cmGeneratorExpression ge(&lfbt);
  1639. this->Internal->SourceEntries.clear();
  1640. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1641. this->Internal->SourceEntries.push_back(
  1642. new cmTargetInternals::TargetPropertyEntry(cge));
  1643. }
  1644. else
  1645. {
  1646. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  1647. this->MaybeInvalidatePropertyCache(prop);
  1648. }
  1649. }
  1650. //----------------------------------------------------------------------------
  1651. void cmTarget::AppendProperty(const std::string& prop, const char* value,
  1652. bool asString)
  1653. {
  1654. if (this->GetType() == INTERFACE_LIBRARY
  1655. && !whiteListedInterfaceProperty(prop))
  1656. {
  1657. cmOStringStream e;
  1658. e << "INTERFACE_LIBRARY targets may only have whitelisted properties. "
  1659. "The property \"" << prop << "\" is not allowed.";
  1660. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1661. return;
  1662. }
  1663. else if (prop == "NAME")
  1664. {
  1665. cmOStringStream e;
  1666. e << "NAME property is read-only\n";
  1667. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1668. return;
  1669. }
  1670. else if(prop == "INCLUDE_DIRECTORIES")
  1671. {
  1672. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1673. cmGeneratorExpression ge(&lfbt);
  1674. this->Internal->IncludeDirectoriesEntries.push_back(
  1675. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1676. }
  1677. else if(prop == "COMPILE_OPTIONS")
  1678. {
  1679. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1680. cmGeneratorExpression ge(&lfbt);
  1681. this->Internal->CompileOptionsEntries.push_back(
  1682. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1683. }
  1684. else if(prop == "COMPILE_FEATURES")
  1685. {
  1686. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1687. cmGeneratorExpression ge(&lfbt);
  1688. this->Internal->CompileFeaturesEntries.push_back(
  1689. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1690. }
  1691. else if(prop == "COMPILE_DEFINITIONS")
  1692. {
  1693. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1694. cmGeneratorExpression ge(&lfbt);
  1695. this->Internal->CompileDefinitionsEntries.push_back(
  1696. new cmTargetInternals::TargetPropertyEntry(ge.Parse(value)));
  1697. }
  1698. else if(prop == "EXPORT_NAME" && this->IsImported())
  1699. {
  1700. cmOStringStream e;
  1701. e << "EXPORT_NAME property can't be set on imported targets (\""
  1702. << this->Name << "\")\n";
  1703. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1704. }
  1705. else if (prop == "LINK_LIBRARIES")
  1706. {
  1707. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1708. cmValueWithOrigin entry(value, lfbt);
  1709. this->Internal->LinkImplementationPropertyEntries.push_back(entry);
  1710. }
  1711. else if (prop == "SOURCES")
  1712. {
  1713. if(this->IsImported())
  1714. {
  1715. cmOStringStream e;
  1716. e << "SOURCES property can't be set on imported targets (\""
  1717. << this->Name << "\")\n";
  1718. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1719. return;
  1720. }
  1721. this->Internal->SourceFilesMap.clear();
  1722. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  1723. cmGeneratorExpression ge(&lfbt);
  1724. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  1725. this->Internal->SourceEntries.push_back(
  1726. new cmTargetInternals::TargetPropertyEntry(cge));
  1727. }
  1728. else
  1729. {
  1730. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  1731. this->MaybeInvalidatePropertyCache(prop);
  1732. }
  1733. }
  1734. //----------------------------------------------------------------------------
  1735. std::string cmTarget::GetExportName() const
  1736. {
  1737. const char *exportName = this->GetProperty("EXPORT_NAME");
  1738. if (exportName && *exportName)
  1739. {
  1740. if (!cmGeneratorExpression::IsValidTargetName(exportName))
  1741. {
  1742. cmOStringStream e;
  1743. e << "EXPORT_NAME property \"" << exportName << "\" for \""
  1744. << this->GetName() << "\": is not valid.";
  1745. cmSystemTools::Error(e.str().c_str());
  1746. return "";
  1747. }
  1748. return exportName;
  1749. }
  1750. return this->GetName();
  1751. }
  1752. //----------------------------------------------------------------------------
  1753. void cmTarget::AppendBuildInterfaceIncludes()
  1754. {
  1755. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  1756. this->GetType() != cmTarget::STATIC_LIBRARY &&
  1757. this->GetType() != cmTarget::MODULE_LIBRARY &&
  1758. this->GetType() != cmTarget::INTERFACE_LIBRARY &&
  1759. !this->IsExecutableWithExports())
  1760. {
  1761. return;
  1762. }
  1763. if (this->BuildInterfaceIncludesAppended)
  1764. {
  1765. return;
  1766. }
  1767. this->BuildInterfaceIncludesAppended = true;
  1768. if (this->Makefile->IsOn("CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE"))
  1769. {
  1770. const char *binDir = this->Makefile->GetStartOutputDirectory();
  1771. const char *srcDir = this->Makefile->GetStartDirectory();
  1772. const std::string dirs = std::string(binDir ? binDir : "")
  1773. + std::string(binDir ? ";" : "")
  1774. + std::string(srcDir ? srcDir : "");
  1775. if (!dirs.empty())
  1776. {
  1777. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  1778. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  1779. }
  1780. }
  1781. }
  1782. //----------------------------------------------------------------------------
  1783. void cmTarget::InsertInclude(const cmValueWithOrigin &entry,
  1784. bool before)
  1785. {
  1786. cmGeneratorExpression ge(&entry.Backtrace);
  1787. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1788. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  1789. : this->Internal->IncludeDirectoriesEntries.end();
  1790. this->Internal->IncludeDirectoriesEntries.insert(position,
  1791. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1792. }
  1793. //----------------------------------------------------------------------------
  1794. void cmTarget::InsertCompileOption(const cmValueWithOrigin &entry,
  1795. bool before)
  1796. {
  1797. cmGeneratorExpression ge(&entry.Backtrace);
  1798. std::vector<cmTargetInternals::TargetPropertyEntry*>::iterator position
  1799. = before ? this->Internal->CompileOptionsEntries.begin()
  1800. : this->Internal->CompileOptionsEntries.end();
  1801. this->Internal->CompileOptionsEntries.insert(position,
  1802. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1803. }
  1804. //----------------------------------------------------------------------------
  1805. void cmTarget::InsertCompileDefinition(const cmValueWithOrigin &entry)
  1806. {
  1807. cmGeneratorExpression ge(&entry.Backtrace);
  1808. this->Internal->CompileDefinitionsEntries.push_back(
  1809. new cmTargetInternals::TargetPropertyEntry(ge.Parse(entry.Value)));
  1810. }
  1811. //----------------------------------------------------------------------------
  1812. static void processIncludeDirectories(cmTarget const* tgt,
  1813. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  1814. std::vector<std::string> &includes,
  1815. UNORDERED_SET<std::string> &uniqueIncludes,
  1816. cmGeneratorExpressionDAGChecker *dagChecker,
  1817. const std::string& config, bool debugIncludes)
  1818. {
  1819. cmMakefile *mf = tgt->GetMakefile();
  1820. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  1821. it = entries.begin(), end = entries.end(); it != end; ++it)
  1822. {
  1823. cmLinkImplItem const& item = (*it)->LinkImplItem;
  1824. std::string const& targetName = item;
  1825. bool const fromImported = item.Target && item.Target->IsImported();
  1826. bool const checkCMP0027 = item.FromGenex;
  1827. std::vector<std::string> entryIncludes;
  1828. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  1829. config,
  1830. false,
  1831. tgt,
  1832. dagChecker),
  1833. entryIncludes);
  1834. std::string usedIncludes;
  1835. for(std::vector<std::string>::iterator
  1836. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  1837. {
  1838. if (fromImported
  1839. && !cmSystemTools::FileExists(li->c_str()))
  1840. {
  1841. cmOStringStream e;
  1842. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1843. if (checkCMP0027)
  1844. {
  1845. switch(tgt->GetPolicyStatusCMP0027())
  1846. {
  1847. case cmPolicies::WARN:
  1848. e << (mf->GetPolicies()
  1849. ->GetPolicyWarning(cmPolicies::CMP0027)) << "\n";
  1850. case cmPolicies::OLD:
  1851. messageType = cmake::AUTHOR_WARNING;
  1852. break;
  1853. case cmPolicies::REQUIRED_ALWAYS:
  1854. case cmPolicies::REQUIRED_IF_USED:
  1855. case cmPolicies::NEW:
  1856. break;
  1857. }
  1858. }
  1859. e << "Imported target \"" << targetName << "\" includes "
  1860. "non-existent path\n \"" << *li << "\"\nin its "
  1861. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  1862. "* The path was deleted, renamed, or moved to another "
  1863. "location.\n"
  1864. "* An install or uninstall procedure did not complete "
  1865. "successfully.\n"
  1866. "* The installation package was faulty and references files it "
  1867. "does not provide.\n";
  1868. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1869. return;
  1870. }
  1871. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  1872. {
  1873. cmOStringStream e;
  1874. bool noMessage = false;
  1875. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1876. if (!targetName.empty())
  1877. {
  1878. e << "Target \"" << targetName << "\" contains relative "
  1879. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  1880. " \"" << *li << "\"";
  1881. }
  1882. else
  1883. {
  1884. switch(tgt->GetPolicyStatusCMP0021())
  1885. {
  1886. case cmPolicies::WARN:
  1887. {
  1888. e << (mf->GetPolicies()
  1889. ->GetPolicyWarning(cmPolicies::CMP0021)) << "\n";
  1890. messageType = cmake::AUTHOR_WARNING;
  1891. }
  1892. break;
  1893. case cmPolicies::OLD:
  1894. noMessage = true;
  1895. case cmPolicies::REQUIRED_IF_USED:
  1896. case cmPolicies::REQUIRED_ALWAYS:
  1897. case cmPolicies::NEW:
  1898. // Issue the fatal message.
  1899. break;
  1900. }
  1901. e << "Found relative path while evaluating include directories of "
  1902. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  1903. }
  1904. if (!noMessage)
  1905. {
  1906. tgt->GetMakefile()->IssueMessage(messageType, e.str());
  1907. if (messageType == cmake::FATAL_ERROR)
  1908. {
  1909. return;
  1910. }
  1911. }
  1912. }
  1913. if (!cmSystemTools::IsOff(li->c_str()))
  1914. {
  1915. cmSystemTools::ConvertToUnixSlashes(*li);
  1916. }
  1917. std::string inc = *li;
  1918. if(uniqueIncludes.insert(inc).second)
  1919. {
  1920. includes.push_back(inc);
  1921. if (debugIncludes)
  1922. {
  1923. usedIncludes += " * " + inc + "\n";
  1924. }
  1925. }
  1926. }
  1927. if (!usedIncludes.empty())
  1928. {
  1929. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  1930. std::string("Used includes for target ")
  1931. + tgt->GetName() + ":\n"
  1932. + usedIncludes, (*it)->ge->GetBacktrace());
  1933. }
  1934. }
  1935. }
  1936. //----------------------------------------------------------------------------
  1937. std::vector<std::string>
  1938. cmTarget::GetIncludeDirectories(const std::string& config) const
  1939. {
  1940. std::vector<std::string> includes;
  1941. UNORDERED_SET<std::string> uniqueIncludes;
  1942. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  1943. "INCLUDE_DIRECTORIES", 0, 0);
  1944. std::vector<std::string> debugProperties;
  1945. const char *debugProp =
  1946. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  1947. if (debugProp)
  1948. {
  1949. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  1950. }
  1951. bool debugIncludes = !this->DebugIncludesDone
  1952. && std::find(debugProperties.begin(),
  1953. debugProperties.end(),
  1954. "INCLUDE_DIRECTORIES")
  1955. != debugProperties.end();
  1956. if (this->Makefile->IsGeneratingBuildSystem())
  1957. {
  1958. this->DebugIncludesDone = true;
  1959. }
  1960. processIncludeDirectories(this,
  1961. this->Internal->IncludeDirectoriesEntries,
  1962. includes,
  1963. uniqueIncludes,
  1964. &dagChecker,
  1965. config,
  1966. debugIncludes);
  1967. std::vector<cmTargetInternals::TargetPropertyEntry*>
  1968. linkInterfaceIncludeDirectoriesEntries;
  1969. this->Internal->AddInterfaceEntries(
  1970. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  1971. linkInterfaceIncludeDirectoriesEntries);
  1972. if(this->Makefile->IsOn("APPLE"))
  1973. {
  1974. LinkImplementation const* impl = this->GetLinkImplementation(config);
  1975. for(std::vector<cmLinkImplItem>::const_iterator
  1976. it = impl->Libraries.begin();
  1977. it != impl->Libraries.end(); ++it)
  1978. {
  1979. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  1980. static cmsys::RegularExpression
  1981. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  1982. if(!frameworkCheck.find(libDir))
  1983. {
  1984. continue;
  1985. }
  1986. libDir = frameworkCheck.match(1);
  1987. cmGeneratorExpression ge;
  1988. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  1989. ge.Parse(libDir.c_str());
  1990. linkInterfaceIncludeDirectoriesEntries
  1991. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  1992. }
  1993. }
  1994. processIncludeDirectories(this,
  1995. linkInterfaceIncludeDirectoriesEntries,
  1996. includes,
  1997. uniqueIncludes,
  1998. &dagChecker,
  1999. config,
  2000. debugIncludes);
  2001. deleteAndClear(linkInterfaceIncludeDirectoriesEntries);
  2002. return includes;
  2003. }
  2004. //----------------------------------------------------------------------------
  2005. static void processCompileOptionsInternal(cmTarget const* tgt,
  2006. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2007. std::vector<std::string> &options,
  2008. UNORDERED_SET<std::string> &uniqueOptions,
  2009. cmGeneratorExpressionDAGChecker *dagChecker,
  2010. const std::string& config, bool debugOptions, const char *logName)
  2011. {
  2012. cmMakefile *mf = tgt->GetMakefile();
  2013. for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
  2014. it = entries.begin(), end = entries.end(); it != end; ++it)
  2015. {
  2016. std::vector<std::string> entryOptions;
  2017. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2018. config,
  2019. false,
  2020. tgt,
  2021. dagChecker),
  2022. entryOptions);
  2023. std::string usedOptions;
  2024. for(std::vector<std::string>::iterator
  2025. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2026. {
  2027. std::string const& opt = *li;
  2028. if(uniqueOptions.insert(opt).second)
  2029. {
  2030. options.push_back(opt);
  2031. if (debugOptions)
  2032. {
  2033. usedOptions += " * " + opt + "\n";
  2034. }
  2035. }
  2036. }
  2037. if (!usedOptions.empty())
  2038. {
  2039. mf->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2040. std::string("Used compile ") + logName
  2041. + std::string(" for target ")
  2042. + tgt->GetName() + ":\n"
  2043. + usedOptions, (*it)->ge->GetBacktrace());
  2044. }
  2045. }
  2046. }
  2047. //----------------------------------------------------------------------------
  2048. static void processCompileOptions(cmTarget const* tgt,
  2049. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2050. std::vector<std::string> &options,
  2051. UNORDERED_SET<std::string> &uniqueOptions,
  2052. cmGeneratorExpressionDAGChecker *dagChecker,
  2053. const std::string& config, bool debugOptions)
  2054. {
  2055. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2056. dagChecker, config, debugOptions, "options");
  2057. }
  2058. //----------------------------------------------------------------------------
  2059. void cmTarget::GetAutoUicOptions(std::vector<std::string> &result,
  2060. const std::string& config) const
  2061. {
  2062. const char *prop
  2063. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  2064. config);
  2065. if (!prop)
  2066. {
  2067. return;
  2068. }
  2069. cmGeneratorExpression ge;
  2070. cmGeneratorExpressionDAGChecker dagChecker(
  2071. this->GetName(),
  2072. "AUTOUIC_OPTIONS", 0, 0);
  2073. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  2074. ->Evaluate(this->Makefile,
  2075. config,
  2076. false,
  2077. this,
  2078. &dagChecker),
  2079. result);
  2080. }
  2081. //----------------------------------------------------------------------------
  2082. void cmTarget::GetCompileOptions(std::vector<std::string> &result,
  2083. const std::string& config) const
  2084. {
  2085. UNORDERED_SET<std::string> uniqueOptions;
  2086. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2087. "COMPILE_OPTIONS", 0, 0);
  2088. std::vector<std::string> debugProperties;
  2089. const char *debugProp =
  2090. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2091. if (debugProp)
  2092. {
  2093. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2094. }
  2095. bool debugOptions = !this->DebugCompileOptionsDone
  2096. && std::find(debugProperties.begin(),
  2097. debugProperties.end(),
  2098. "COMPILE_OPTIONS")
  2099. != debugProperties.end();
  2100. if (this->Makefile->IsGeneratingBuildSystem())
  2101. {
  2102. this->DebugCompileOptionsDone = true;
  2103. }
  2104. processCompileOptions(this,
  2105. this->Internal->CompileOptionsEntries,
  2106. result,
  2107. uniqueOptions,
  2108. &dagChecker,
  2109. config,
  2110. debugOptions);
  2111. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2112. linkInterfaceCompileOptionsEntries;
  2113. this->Internal->AddInterfaceEntries(
  2114. this, config, "INTERFACE_COMPILE_OPTIONS",
  2115. linkInterfaceCompileOptionsEntries);
  2116. processCompileOptions(this,
  2117. linkInterfaceCompileOptionsEntries,
  2118. result,
  2119. uniqueOptions,
  2120. &dagChecker,
  2121. config,
  2122. debugOptions);
  2123. deleteAndClear(linkInterfaceCompileOptionsEntries);
  2124. }
  2125. //----------------------------------------------------------------------------
  2126. static void processCompileDefinitions(cmTarget const* tgt,
  2127. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2128. std::vector<std::string> &options,
  2129. UNORDERED_SET<std::string> &uniqueOptions,
  2130. cmGeneratorExpressionDAGChecker *dagChecker,
  2131. const std::string& config, bool debugOptions)
  2132. {
  2133. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2134. dagChecker, config, debugOptions,
  2135. "definitions");
  2136. }
  2137. //----------------------------------------------------------------------------
  2138. void cmTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2139. const std::string& config) const
  2140. {
  2141. UNORDERED_SET<std::string> uniqueOptions;
  2142. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2143. "COMPILE_DEFINITIONS", 0, 0);
  2144. std::vector<std::string> debugProperties;
  2145. const char *debugProp =
  2146. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2147. if (debugProp)
  2148. {
  2149. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2150. }
  2151. bool debugDefines = !this->DebugCompileDefinitionsDone
  2152. && std::find(debugProperties.begin(),
  2153. debugProperties.end(),
  2154. "COMPILE_DEFINITIONS")
  2155. != debugProperties.end();
  2156. if (this->Makefile->IsGeneratingBuildSystem())
  2157. {
  2158. this->DebugCompileDefinitionsDone = true;
  2159. }
  2160. processCompileDefinitions(this,
  2161. this->Internal->CompileDefinitionsEntries,
  2162. list,
  2163. uniqueOptions,
  2164. &dagChecker,
  2165. config,
  2166. debugDefines);
  2167. std::vector<cmTargetInternals::TargetPropertyEntry*>
  2168. linkInterfaceCompileDefinitionsEntries;
  2169. this->Internal->AddInterfaceEntries(
  2170. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2171. linkInterfaceCompileDefinitionsEntries);
  2172. if (!config.empty())
  2173. {
  2174. std::string configPropName = "COMPILE_DEFINITIONS_"
  2175. + cmSystemTools::UpperCase(config);
  2176. const char *configProp = this->GetProperty(configPropName);
  2177. if (configProp)
  2178. {
  2179. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2180. {
  2181. case cmPolicies::WARN:
  2182. {
  2183. cmOStringStream e;
  2184. e << this->Makefile->GetCMakeInstance()->GetPolicies()
  2185. ->GetPolicyWarning(cmPolicies::CMP0043);
  2186. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING,
  2187. e.str());
  2188. }
  2189. case cmPolicies::OLD:
  2190. {
  2191. cmGeneratorExpression ge;
  2192. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2193. ge.Parse(configProp);
  2194. linkInterfaceCompileDefinitionsEntries
  2195. .push_back(new cmTargetInternals::TargetPropertyEntry(cge));
  2196. }
  2197. break;
  2198. case cmPolicies::NEW:
  2199. case cmPolicies::REQUIRED_ALWAYS:
  2200. case cmPolicies::REQUIRED_IF_USED:
  2201. break;
  2202. }
  2203. }
  2204. }
  2205. processCompileDefinitions(this,
  2206. linkInterfaceCompileDefinitionsEntries,
  2207. list,
  2208. uniqueOptions,
  2209. &dagChecker,
  2210. config,
  2211. debugDefines);
  2212. deleteAndClear(linkInterfaceCompileDefinitionsEntries);
  2213. }
  2214. //----------------------------------------------------------------------------
  2215. static void processCompileFeatures(cmTarget const* tgt,
  2216. const std::vector<cmTargetInternals::TargetPropertyEntry*> &entries,
  2217. std::vector<std::string> &options,
  2218. UNORDERED_SET<std::string> &uniqueOptions,
  2219. cmGeneratorExpressionDAGChecker *dagChecker,
  2220. const std::string& config, bool debugOptions)
  2221. {
  2222. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2223. dagChecker, config, debugOptions, "features");
  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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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. cmOStringStream 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->GetOutputName(config, false);
  3690. fw_prefix += ".";
  3691. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  3692. if (!ext)
  3693. {
  3694. ext = "bundle";
  3695. }
  3696. fw_prefix += ext;
  3697. fw_prefix += "/Contents/MacOS/";
  3698. targetPrefix = fw_prefix.c_str();
  3699. targetSuffix = 0;
  3700. }
  3701. // Begin the final name with the prefix.
  3702. outPrefix = targetPrefix?targetPrefix:"";
  3703. // Append the target name or property-specified name.
  3704. outBase += this->GetOutputName(config, implib);
  3705. // Append the per-configuration postfix.
  3706. outBase += configPostfix?configPostfix:"";
  3707. // Name shared libraries with their version number on some platforms.
  3708. if(const char* soversion = this->GetProperty("SOVERSION"))
  3709. {
  3710. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3711. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3712. {
  3713. outBase += "-";
  3714. outBase += soversion;
  3715. }
  3716. }
  3717. // Append the suffix.
  3718. outSuffix = targetSuffix?targetSuffix:"";
  3719. }
  3720. //----------------------------------------------------------------------------
  3721. void cmTarget::GetLibraryNames(std::string& name,
  3722. std::string& soName,
  3723. std::string& realName,
  3724. std::string& impName,
  3725. std::string& pdbName,
  3726. const std::string& config) const
  3727. {
  3728. // This should not be called for imported targets.
  3729. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3730. // enforcement of the limited imported target API.
  3731. if(this->IsImported())
  3732. {
  3733. std::string msg = "GetLibraryNames called on imported target: ";
  3734. msg += this->GetName();
  3735. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3736. msg);
  3737. return;
  3738. }
  3739. assert(this->GetType() != INTERFACE_LIBRARY);
  3740. // Check for library version properties.
  3741. const char* version = this->GetProperty("VERSION");
  3742. const char* soversion = this->GetProperty("SOVERSION");
  3743. if(!this->HasSOName(config) ||
  3744. this->Makefile->IsOn("CMAKE_PLATFORM_NO_VERSIONED_SONAME") ||
  3745. this->IsFrameworkOnApple())
  3746. {
  3747. // Versioning is supported only for shared libraries and modules,
  3748. // and then only when the platform supports an soname flag.
  3749. version = 0;
  3750. soversion = 0;
  3751. }
  3752. if(version && !soversion)
  3753. {
  3754. // The soversion must be set if the library version is set. Use
  3755. // the library version as the soversion.
  3756. soversion = version;
  3757. }
  3758. if(!version && soversion)
  3759. {
  3760. // Use the soversion as the library version.
  3761. version = soversion;
  3762. }
  3763. // Get the components of the library name.
  3764. std::string prefix;
  3765. std::string base;
  3766. std::string suffix;
  3767. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3768. // The library name.
  3769. name = prefix+base+suffix;
  3770. if(this->IsFrameworkOnApple())
  3771. {
  3772. realName = prefix;
  3773. realName += "Versions/";
  3774. realName += this->GetFrameworkVersion();
  3775. realName += "/";
  3776. realName += base;
  3777. soName = realName;
  3778. }
  3779. else
  3780. {
  3781. // The library's soname.
  3782. this->ComputeVersionedName(soName, prefix, base, suffix,
  3783. name, soversion);
  3784. // The library's real name on disk.
  3785. this->ComputeVersionedName(realName, prefix, base, suffix,
  3786. name, version);
  3787. }
  3788. // The import library name.
  3789. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3790. this->GetType() == cmTarget::MODULE_LIBRARY)
  3791. {
  3792. impName = this->GetFullNameInternal(config, true);
  3793. }
  3794. else
  3795. {
  3796. impName = "";
  3797. }
  3798. // The program database file name.
  3799. pdbName = this->GetPDBName(config);
  3800. }
  3801. //----------------------------------------------------------------------------
  3802. void cmTarget::ComputeVersionedName(std::string& vName,
  3803. std::string const& prefix,
  3804. std::string const& base,
  3805. std::string const& suffix,
  3806. std::string const& name,
  3807. const char* version) const
  3808. {
  3809. vName = this->IsApple? (prefix+base) : name;
  3810. if(version)
  3811. {
  3812. vName += ".";
  3813. vName += version;
  3814. }
  3815. vName += this->IsApple? suffix : std::string();
  3816. }
  3817. //----------------------------------------------------------------------------
  3818. void cmTarget::GetExecutableNames(std::string& name,
  3819. std::string& realName,
  3820. std::string& impName,
  3821. std::string& pdbName,
  3822. const std::string& config) const
  3823. {
  3824. // This should not be called for imported targets.
  3825. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3826. // enforcement of the limited imported target API.
  3827. if(this->IsImported())
  3828. {
  3829. std::string msg =
  3830. "GetExecutableNames called on imported target: ";
  3831. msg += this->GetName();
  3832. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  3833. }
  3834. // This versioning is supported only for executables and then only
  3835. // when the platform supports symbolic links.
  3836. #if defined(_WIN32) && !defined(__CYGWIN__)
  3837. const char* version = 0;
  3838. #else
  3839. // Check for executable version properties.
  3840. const char* version = this->GetProperty("VERSION");
  3841. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3842. {
  3843. version = 0;
  3844. }
  3845. #endif
  3846. // Get the components of the executable name.
  3847. std::string prefix;
  3848. std::string base;
  3849. std::string suffix;
  3850. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3851. // The executable name.
  3852. name = prefix+base+suffix;
  3853. // The executable's real name on disk.
  3854. #if defined(__CYGWIN__)
  3855. realName = prefix+base;
  3856. #else
  3857. realName = name;
  3858. #endif
  3859. if(version)
  3860. {
  3861. realName += "-";
  3862. realName += version;
  3863. }
  3864. #if defined(__CYGWIN__)
  3865. realName += suffix;
  3866. #endif
  3867. // The import library name.
  3868. impName = this->GetFullNameInternal(config, true);
  3869. // The program database file name.
  3870. pdbName = this->GetPDBName(config);
  3871. }
  3872. //----------------------------------------------------------------------------
  3873. bool cmTarget::HasImplibGNUtoMS() const
  3874. {
  3875. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3876. }
  3877. //----------------------------------------------------------------------------
  3878. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3879. std::string& out, const char* newExt) const
  3880. {
  3881. if(this->HasImplibGNUtoMS() &&
  3882. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3883. {
  3884. out = gnuName.substr(0, gnuName.size()-6);
  3885. out += newExt? newExt : ".lib";
  3886. return true;
  3887. }
  3888. return false;
  3889. }
  3890. //----------------------------------------------------------------------------
  3891. void cmTarget::SetPropertyDefault(const std::string& property,
  3892. const char* default_value)
  3893. {
  3894. // Compute the name of the variable holding the default value.
  3895. std::string var = "CMAKE_";
  3896. var += property;
  3897. if(const char* value = this->Makefile->GetDefinition(var))
  3898. {
  3899. this->SetProperty(property, value);
  3900. }
  3901. else if(default_value)
  3902. {
  3903. this->SetProperty(property, default_value);
  3904. }
  3905. }
  3906. //----------------------------------------------------------------------------
  3907. bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const
  3908. {
  3909. if (this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3910. {
  3911. return false;
  3912. }
  3913. if(LinkImplementationLibraries const* impl =
  3914. this->GetLinkImplementationLibraries(config))
  3915. {
  3916. return !impl->Libraries.empty();
  3917. }
  3918. return false;
  3919. }
  3920. //----------------------------------------------------------------------------
  3921. bool cmTarget::HaveInstallTreeRPATH() const
  3922. {
  3923. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3924. return (install_rpath && *install_rpath) &&
  3925. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3926. }
  3927. //----------------------------------------------------------------------------
  3928. bool cmTarget::NeedRelinkBeforeInstall(const std::string& config) const
  3929. {
  3930. // Only executables and shared libraries can have an rpath and may
  3931. // need relinking.
  3932. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3933. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3934. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3935. {
  3936. return false;
  3937. }
  3938. // If there is no install location this target will not be installed
  3939. // and therefore does not need relinking.
  3940. if(!this->GetHaveInstallRule())
  3941. {
  3942. return false;
  3943. }
  3944. // If skipping all rpaths completely then no relinking is needed.
  3945. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3946. {
  3947. return false;
  3948. }
  3949. // If building with the install-tree rpath no relinking is needed.
  3950. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3951. {
  3952. return false;
  3953. }
  3954. // If chrpath is going to be used no relinking is needed.
  3955. if(this->IsChrpathUsed(config))
  3956. {
  3957. return false;
  3958. }
  3959. // Check for rpath support on this platform.
  3960. std::string ll = this->GetLinkerLanguage(config);
  3961. if(!ll.empty())
  3962. {
  3963. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3964. flagVar += ll;
  3965. flagVar += "_FLAG";
  3966. if(!this->Makefile->IsSet(flagVar))
  3967. {
  3968. // There is no rpath support on this platform so nothing needs
  3969. // relinking.
  3970. return false;
  3971. }
  3972. }
  3973. else
  3974. {
  3975. // No linker language is known. This error will be reported by
  3976. // other code.
  3977. return false;
  3978. }
  3979. // If either a build or install tree rpath is set then the rpath
  3980. // will likely change between the build tree and install tree and
  3981. // this target must be relinked.
  3982. return this->HaveBuildTreeRPATH(config) || this->HaveInstallTreeRPATH();
  3983. }
  3984. //----------------------------------------------------------------------------
  3985. std::string cmTarget::GetInstallNameDirForBuildTree(
  3986. const std::string& config) const
  3987. {
  3988. // If building directly for installation then the build tree install_name
  3989. // is the same as the install tree.
  3990. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3991. {
  3992. return GetInstallNameDirForInstallTree();
  3993. }
  3994. // Use the build tree directory for the target.
  3995. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3996. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3997. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3998. {
  3999. std::string dir;
  4000. bool macosx_rpath = this->MacOSXRpathInstallNameDirDefault();
  4001. if(macosx_rpath)
  4002. {
  4003. dir = "@rpath";
  4004. }
  4005. else
  4006. {
  4007. dir = this->GetDirectory(config);
  4008. }
  4009. dir += "/";
  4010. return dir;
  4011. }
  4012. else
  4013. {
  4014. return "";
  4015. }
  4016. }
  4017. //----------------------------------------------------------------------------
  4018. std::string cmTarget::GetInstallNameDirForInstallTree() const
  4019. {
  4020. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4021. {
  4022. std::string dir;
  4023. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  4024. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  4025. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  4026. {
  4027. if(install_name_dir && *install_name_dir)
  4028. {
  4029. dir = install_name_dir;
  4030. dir += "/";
  4031. }
  4032. }
  4033. if(!install_name_dir)
  4034. {
  4035. if(this->MacOSXRpathInstallNameDirDefault())
  4036. {
  4037. dir = "@rpath/";
  4038. }
  4039. }
  4040. return dir;
  4041. }
  4042. else
  4043. {
  4044. return "";
  4045. }
  4046. }
  4047. //----------------------------------------------------------------------------
  4048. const char* cmTarget::GetOutputTargetType(bool implib) const
  4049. {
  4050. switch(this->GetType())
  4051. {
  4052. case cmTarget::SHARED_LIBRARY:
  4053. if(this->DLLPlatform)
  4054. {
  4055. if(implib)
  4056. {
  4057. // A DLL import library is treated as an archive target.
  4058. return "ARCHIVE";
  4059. }
  4060. else
  4061. {
  4062. // A DLL shared library is treated as a runtime target.
  4063. return "RUNTIME";
  4064. }
  4065. }
  4066. else
  4067. {
  4068. // For non-DLL platforms shared libraries are treated as
  4069. // library targets.
  4070. return "LIBRARY";
  4071. }
  4072. case cmTarget::STATIC_LIBRARY:
  4073. // Static libraries are always treated as archive targets.
  4074. return "ARCHIVE";
  4075. case cmTarget::MODULE_LIBRARY:
  4076. if(implib)
  4077. {
  4078. // Module libraries are always treated as library targets.
  4079. return "ARCHIVE";
  4080. }
  4081. else
  4082. {
  4083. // Module import libraries are treated as archive targets.
  4084. return "LIBRARY";
  4085. }
  4086. case cmTarget::EXECUTABLE:
  4087. if(implib)
  4088. {
  4089. // Executable import libraries are treated as archive targets.
  4090. return "ARCHIVE";
  4091. }
  4092. else
  4093. {
  4094. // Executables are always treated as runtime targets.
  4095. return "RUNTIME";
  4096. }
  4097. default:
  4098. break;
  4099. }
  4100. return "";
  4101. }
  4102. //----------------------------------------------------------------------------
  4103. bool cmTarget::ComputeOutputDir(const std::string& config,
  4104. bool implib, std::string& out) const
  4105. {
  4106. bool usesDefaultOutputDir = false;
  4107. std::string conf = config;
  4108. // Look for a target property defining the target output directory
  4109. // based on the target type.
  4110. std::string targetTypeName = this->GetOutputTargetType(implib);
  4111. const char* propertyName = 0;
  4112. std::string propertyNameStr = targetTypeName;
  4113. if(!propertyNameStr.empty())
  4114. {
  4115. propertyNameStr += "_OUTPUT_DIRECTORY";
  4116. propertyName = propertyNameStr.c_str();
  4117. }
  4118. // Check for a per-configuration output directory target property.
  4119. std::string configUpper = cmSystemTools::UpperCase(conf);
  4120. const char* configProp = 0;
  4121. std::string configPropStr = targetTypeName;
  4122. if(!configPropStr.empty())
  4123. {
  4124. configPropStr += "_OUTPUT_DIRECTORY_";
  4125. configPropStr += configUpper;
  4126. configProp = configPropStr.c_str();
  4127. }
  4128. // Select an output directory.
  4129. if(const char* config_outdir = this->GetProperty(configProp))
  4130. {
  4131. // Use the user-specified per-configuration output directory.
  4132. out = config_outdir;
  4133. // Skip per-configuration subdirectory.
  4134. conf = "";
  4135. }
  4136. else if(const char* outdir = this->GetProperty(propertyName))
  4137. {
  4138. // Use the user-specified output directory.
  4139. out = outdir;
  4140. }
  4141. else if(this->GetType() == cmTarget::EXECUTABLE)
  4142. {
  4143. // Lookup the output path for executables.
  4144. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  4145. }
  4146. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  4147. this->GetType() == cmTarget::SHARED_LIBRARY ||
  4148. this->GetType() == cmTarget::MODULE_LIBRARY)
  4149. {
  4150. // Lookup the output path for libraries.
  4151. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  4152. }
  4153. if(out.empty())
  4154. {
  4155. // Default to the current output directory.
  4156. usesDefaultOutputDir = true;
  4157. out = ".";
  4158. }
  4159. // Convert the output path to a full path in case it is
  4160. // specified as a relative path. Treat a relative path as
  4161. // relative to the current output directory for this makefile.
  4162. out = (cmSystemTools::CollapseFullPath
  4163. (out, this->Makefile->GetStartOutputDirectory()));
  4164. // The generator may add the configuration's subdirectory.
  4165. if(!conf.empty())
  4166. {
  4167. const char *platforms = this->Makefile->GetDefinition(
  4168. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  4169. std::string suffix =
  4170. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  4171. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4172. AppendDirectoryForConfig("/", conf, suffix, out);
  4173. }
  4174. return usesDefaultOutputDir;
  4175. }
  4176. //----------------------------------------------------------------------------
  4177. bool cmTarget::ComputePDBOutputDir(const std::string& kind,
  4178. const std::string& config,
  4179. std::string& out) const
  4180. {
  4181. // Look for a target property defining the target output directory
  4182. // based on the target type.
  4183. const char* propertyName = 0;
  4184. std::string propertyNameStr = kind;
  4185. if(!propertyNameStr.empty())
  4186. {
  4187. propertyNameStr += "_OUTPUT_DIRECTORY";
  4188. propertyName = propertyNameStr.c_str();
  4189. }
  4190. std::string conf = config;
  4191. // Check for a per-configuration output directory target property.
  4192. std::string configUpper = cmSystemTools::UpperCase(conf);
  4193. const char* configProp = 0;
  4194. std::string configPropStr = kind;
  4195. if(!configPropStr.empty())
  4196. {
  4197. configPropStr += "_OUTPUT_DIRECTORY_";
  4198. configPropStr += configUpper;
  4199. configProp = configPropStr.c_str();
  4200. }
  4201. // Select an output directory.
  4202. if(const char* config_outdir = this->GetProperty(configProp))
  4203. {
  4204. // Use the user-specified per-configuration output directory.
  4205. out = config_outdir;
  4206. // Skip per-configuration subdirectory.
  4207. conf = "";
  4208. }
  4209. else if(const char* outdir = this->GetProperty(propertyName))
  4210. {
  4211. // Use the user-specified output directory.
  4212. out = outdir;
  4213. }
  4214. if(out.empty())
  4215. {
  4216. return false;
  4217. }
  4218. // Convert the output path to a full path in case it is
  4219. // specified as a relative path. Treat a relative path as
  4220. // relative to the current output directory for this makefile.
  4221. out = (cmSystemTools::CollapseFullPath
  4222. (out, this->Makefile->GetStartOutputDirectory()));
  4223. // The generator may add the configuration's subdirectory.
  4224. if(!conf.empty())
  4225. {
  4226. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4227. AppendDirectoryForConfig("/", conf, "", out);
  4228. }
  4229. return true;
  4230. }
  4231. //----------------------------------------------------------------------------
  4232. bool cmTarget::UsesDefaultOutputDir(const std::string& config,
  4233. bool implib) const
  4234. {
  4235. std::string dir;
  4236. return this->ComputeOutputDir(config, implib, dir);
  4237. }
  4238. //----------------------------------------------------------------------------
  4239. std::string cmTarget::GetOutputName(const std::string& config,
  4240. bool implib) const
  4241. {
  4242. std::vector<std::string> props;
  4243. std::string type = this->GetOutputTargetType(implib);
  4244. std::string configUpper = cmSystemTools::UpperCase(config);
  4245. if(!type.empty() && !configUpper.empty())
  4246. {
  4247. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4248. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4249. }
  4250. if(!type.empty())
  4251. {
  4252. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4253. props.push_back(type + "_OUTPUT_NAME");
  4254. }
  4255. if(!configUpper.empty())
  4256. {
  4257. // OUTPUT_NAME_<CONFIG>
  4258. props.push_back("OUTPUT_NAME_" + configUpper);
  4259. // <CONFIG>_OUTPUT_NAME
  4260. props.push_back(configUpper + "_OUTPUT_NAME");
  4261. }
  4262. // OUTPUT_NAME
  4263. props.push_back("OUTPUT_NAME");
  4264. for(std::vector<std::string>::const_iterator i = props.begin();
  4265. i != props.end(); ++i)
  4266. {
  4267. if(const char* outName = this->GetProperty(*i))
  4268. {
  4269. return outName;
  4270. }
  4271. }
  4272. return this->GetName();
  4273. }
  4274. //----------------------------------------------------------------------------
  4275. std::string cmTarget::GetFrameworkVersion() const
  4276. {
  4277. assert(this->GetType() != INTERFACE_LIBRARY);
  4278. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4279. {
  4280. return fversion;
  4281. }
  4282. else if(const char* tversion = this->GetProperty("VERSION"))
  4283. {
  4284. return tversion;
  4285. }
  4286. else
  4287. {
  4288. return "A";
  4289. }
  4290. }
  4291. //----------------------------------------------------------------------------
  4292. const char* cmTarget::GetExportMacro() const
  4293. {
  4294. // Define the symbol for targets that export symbols.
  4295. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4296. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4297. this->IsExecutableWithExports())
  4298. {
  4299. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4300. {
  4301. this->ExportMacro = custom_export_name;
  4302. }
  4303. else
  4304. {
  4305. std::string in = this->GetName();
  4306. in += "_EXPORTS";
  4307. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4308. }
  4309. return this->ExportMacro.c_str();
  4310. }
  4311. else
  4312. {
  4313. return 0;
  4314. }
  4315. }
  4316. //----------------------------------------------------------------------------
  4317. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p) const
  4318. {
  4319. return this->LinkImplicitNullProperties.find(p)
  4320. != this->LinkImplicitNullProperties.end();
  4321. }
  4322. //----------------------------------------------------------------------------
  4323. template<typename PropertyType>
  4324. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop,
  4325. PropertyType *);
  4326. //----------------------------------------------------------------------------
  4327. template<>
  4328. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop,
  4329. bool *)
  4330. {
  4331. return tgt->GetPropertyAsBool(prop);
  4332. }
  4333. //----------------------------------------------------------------------------
  4334. template<>
  4335. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  4336. const std::string& prop,
  4337. const char **)
  4338. {
  4339. return tgt->GetProperty(prop);
  4340. }
  4341. enum CompatibleType
  4342. {
  4343. BoolType,
  4344. StringType,
  4345. NumberMinType,
  4346. NumberMaxType
  4347. };
  4348. //----------------------------------------------------------------------------
  4349. template<typename PropertyType>
  4350. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  4351. PropertyType rhs,
  4352. CompatibleType t);
  4353. //----------------------------------------------------------------------------
  4354. template<>
  4355. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs, CompatibleType)
  4356. {
  4357. return std::make_pair(lhs == rhs, lhs);
  4358. }
  4359. //----------------------------------------------------------------------------
  4360. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  4361. const char *rhs)
  4362. {
  4363. const bool b = strcmp(lhs, rhs) == 0;
  4364. return std::make_pair(b, b ? lhs : 0);
  4365. }
  4366. #if defined(_MSC_VER) && _MSC_VER <= 1200
  4367. template<typename T> const T&
  4368. cmMaximum(const T& l, const T& r) {return l > r ? l : r;}
  4369. template<typename T> const T&
  4370. cmMinimum(const T& l, const T& r) {return l < r ? l : r;}
  4371. #else
  4372. #define cmMinimum std::min
  4373. #define cmMaximum std::max
  4374. #endif
  4375. //----------------------------------------------------------------------------
  4376. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  4377. const char *rhs,
  4378. CompatibleType t)
  4379. {
  4380. char *pEnd;
  4381. #if defined(_MSC_VER)
  4382. static const char* const null_ptr = 0;
  4383. #else
  4384. # define null_ptr 0
  4385. #endif
  4386. long lnum = strtol(lhs, &pEnd, 0);
  4387. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  4388. {
  4389. return std::pair<bool, const char*>(false, null_ptr);
  4390. }
  4391. long rnum = strtol(rhs, &pEnd, 0);
  4392. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  4393. {
  4394. return std::pair<bool, const char*>(false, null_ptr);
  4395. }
  4396. #if !defined(_MSC_VER)
  4397. #undef null_ptr
  4398. #endif
  4399. if (t == NumberMaxType)
  4400. {
  4401. return std::make_pair(true, cmMaximum(lnum, rnum) == lnum ? lhs : rhs);
  4402. }
  4403. else
  4404. {
  4405. return std::make_pair(true, cmMinimum(lnum, rnum) == lnum ? lhs : rhs);
  4406. }
  4407. }
  4408. //----------------------------------------------------------------------------
  4409. template<>
  4410. std::pair<bool, const char*> consistentProperty(const char *lhs,
  4411. const char *rhs,
  4412. CompatibleType t)
  4413. {
  4414. if (!lhs && !rhs)
  4415. {
  4416. return std::make_pair(true, lhs);
  4417. }
  4418. if (!lhs)
  4419. {
  4420. return std::make_pair(true, rhs);
  4421. }
  4422. if (!rhs)
  4423. {
  4424. return std::make_pair(true, lhs);
  4425. }
  4426. #if defined(_MSC_VER)
  4427. static const char* const null_ptr = 0;
  4428. #else
  4429. # define null_ptr 0
  4430. #endif
  4431. switch(t)
  4432. {
  4433. case BoolType:
  4434. assert(!"consistentProperty for strings called with BoolType");
  4435. return std::pair<bool, const char*>(false, null_ptr);
  4436. case StringType:
  4437. return consistentStringProperty(lhs, rhs);
  4438. case NumberMinType:
  4439. case NumberMaxType:
  4440. return consistentNumberProperty(lhs, rhs, t);
  4441. }
  4442. assert(!"Unreachable!");
  4443. return std::pair<bool, const char*>(false, null_ptr);
  4444. #if !defined(_MSC_VER)
  4445. #undef null_ptr
  4446. #endif
  4447. }
  4448. template<typename PropertyType>
  4449. PropertyType impliedValue(PropertyType);
  4450. template<>
  4451. bool impliedValue<bool>(bool)
  4452. {
  4453. return false;
  4454. }
  4455. template<>
  4456. const char* impliedValue<const char*>(const char*)
  4457. {
  4458. return "";
  4459. }
  4460. template<typename PropertyType>
  4461. std::string valueAsString(PropertyType);
  4462. template<>
  4463. std::string valueAsString<bool>(bool value)
  4464. {
  4465. return value ? "TRUE" : "FALSE";
  4466. }
  4467. template<>
  4468. std::string valueAsString<const char*>(const char* value)
  4469. {
  4470. return value ? value : "(unset)";
  4471. }
  4472. //----------------------------------------------------------------------------
  4473. void
  4474. cmTarget::ReportPropertyOrigin(const std::string &p,
  4475. const std::string &result,
  4476. const std::string &report,
  4477. const std::string &compatibilityType) const
  4478. {
  4479. std::vector<std::string> debugProperties;
  4480. const char *debugProp =
  4481. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  4482. if (debugProp)
  4483. {
  4484. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  4485. }
  4486. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  4487. && std::find(debugProperties.begin(),
  4488. debugProperties.end(),
  4489. p)
  4490. != debugProperties.end();
  4491. if (this->Makefile->IsGeneratingBuildSystem())
  4492. {
  4493. this->DebugCompatiblePropertiesDone[p] = true;
  4494. }
  4495. if (!debugOrigin)
  4496. {
  4497. return;
  4498. }
  4499. std::string areport = compatibilityType;
  4500. areport += std::string(" of property \"") + p + "\" for target \"";
  4501. areport += std::string(this->GetName());
  4502. areport += "\" (result: \"";
  4503. areport += result;
  4504. areport += "\"):\n" + report;
  4505. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  4506. }
  4507. //----------------------------------------------------------------------------
  4508. std::string compatibilityType(CompatibleType t)
  4509. {
  4510. switch(t)
  4511. {
  4512. case BoolType:
  4513. return "Boolean compatibility";
  4514. case StringType:
  4515. return "String compatibility";
  4516. case NumberMaxType:
  4517. return "Numeric maximum compatibility";
  4518. case NumberMinType:
  4519. return "Numeric minimum compatibility";
  4520. }
  4521. assert(!"Unreachable!");
  4522. return "";
  4523. }
  4524. //----------------------------------------------------------------------------
  4525. std::string compatibilityAgree(CompatibleType t, bool dominant)
  4526. {
  4527. switch(t)
  4528. {
  4529. case BoolType:
  4530. case StringType:
  4531. return dominant ? "(Disagree)\n" : "(Agree)\n";
  4532. case NumberMaxType:
  4533. case NumberMinType:
  4534. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  4535. }
  4536. assert(!"Unreachable!");
  4537. return "";
  4538. }
  4539. //----------------------------------------------------------------------------
  4540. template<typename PropertyType>
  4541. PropertyType checkInterfacePropertyCompatibility(cmTarget const* tgt,
  4542. const std::string &p,
  4543. const std::string& config,
  4544. const char *defaultValue,
  4545. CompatibleType t,
  4546. PropertyType *)
  4547. {
  4548. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p,
  4549. 0);
  4550. const bool explicitlySet = tgt->GetProperties()
  4551. .find(p)
  4552. != tgt->GetProperties().end();
  4553. const bool impliedByUse =
  4554. tgt->IsNullImpliedByLinkLibraries(p);
  4555. assert((impliedByUse ^ explicitlySet)
  4556. || (!impliedByUse && !explicitlySet));
  4557. std::vector<cmTarget const*> const& deps =
  4558. tgt->GetLinkImplementationClosure(config);
  4559. if(deps.empty())
  4560. {
  4561. return propContent;
  4562. }
  4563. bool propInitialized = explicitlySet;
  4564. std::string report = " * Target \"";
  4565. report += tgt->GetName();
  4566. if (explicitlySet)
  4567. {
  4568. report += "\" has property content \"";
  4569. report += valueAsString<PropertyType>(propContent);
  4570. report += "\"\n";
  4571. }
  4572. else if (impliedByUse)
  4573. {
  4574. report += "\" property is implied by use.\n";
  4575. }
  4576. else
  4577. {
  4578. report += "\" property not set.\n";
  4579. }
  4580. std::string interfaceProperty = "INTERFACE_" + p;
  4581. for(std::vector<cmTarget const*>::const_iterator li =
  4582. deps.begin();
  4583. li != deps.end(); ++li)
  4584. {
  4585. // An error should be reported if one dependency
  4586. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4587. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4588. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4589. // with a dependency.
  4590. cmTarget const* theTarget = *li;
  4591. const bool ifaceIsSet = theTarget->GetProperties()
  4592. .find(interfaceProperty)
  4593. != theTarget->GetProperties().end();
  4594. PropertyType ifacePropContent =
  4595. getTypedProperty<PropertyType>(theTarget,
  4596. interfaceProperty, 0);
  4597. std::string reportEntry;
  4598. if (ifaceIsSet)
  4599. {
  4600. reportEntry += " * Target \"";
  4601. reportEntry += theTarget->GetName();
  4602. reportEntry += "\" property value \"";
  4603. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  4604. reportEntry += "\" ";
  4605. }
  4606. if (explicitlySet)
  4607. {
  4608. if (ifaceIsSet)
  4609. {
  4610. std::pair<bool, PropertyType> consistent =
  4611. consistentProperty(propContent,
  4612. ifacePropContent, t);
  4613. report += reportEntry;
  4614. report += compatibilityAgree(t, propContent != consistent.second);
  4615. if (!consistent.first)
  4616. {
  4617. cmOStringStream e;
  4618. e << "Property " << p << " on target \""
  4619. << tgt->GetName() << "\" does\nnot match the "
  4620. "INTERFACE_" << p << " property requirement\nof "
  4621. "dependency \"" << theTarget->GetName() << "\".\n";
  4622. cmSystemTools::Error(e.str().c_str());
  4623. break;
  4624. }
  4625. else
  4626. {
  4627. propContent = consistent.second;
  4628. continue;
  4629. }
  4630. }
  4631. else
  4632. {
  4633. // Explicitly set on target and not set in iface. Can't disagree.
  4634. continue;
  4635. }
  4636. }
  4637. else if (impliedByUse)
  4638. {
  4639. propContent = impliedValue<PropertyType>(propContent);
  4640. if (ifaceIsSet)
  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. cmOStringStream e;
  4650. e << "Property " << p << " on target \""
  4651. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4652. << " because it was used to determine the link libraries\n"
  4653. "already. The INTERFACE_" << p << " property on\ndependency \""
  4654. << theTarget->GetName() << "\" is in conflict.\n";
  4655. cmSystemTools::Error(e.str().c_str());
  4656. break;
  4657. }
  4658. else
  4659. {
  4660. propContent = consistent.second;
  4661. continue;
  4662. }
  4663. }
  4664. else
  4665. {
  4666. // Implicitly set on target and not set in iface. Can't disagree.
  4667. continue;
  4668. }
  4669. }
  4670. else
  4671. {
  4672. if (ifaceIsSet)
  4673. {
  4674. if (propInitialized)
  4675. {
  4676. std::pair<bool, PropertyType> consistent =
  4677. consistentProperty(propContent,
  4678. ifacePropContent, t);
  4679. report += reportEntry;
  4680. report += compatibilityAgree(t, propContent != consistent.second);
  4681. if (!consistent.first)
  4682. {
  4683. cmOStringStream e;
  4684. e << "The INTERFACE_" << p << " property of \""
  4685. << theTarget->GetName() << "\" does\nnot agree with the value "
  4686. "of " << p << " already determined\nfor \""
  4687. << tgt->GetName() << "\".\n";
  4688. cmSystemTools::Error(e.str().c_str());
  4689. break;
  4690. }
  4691. else
  4692. {
  4693. propContent = consistent.second;
  4694. continue;
  4695. }
  4696. }
  4697. else
  4698. {
  4699. report += reportEntry + "(Interface set)\n";
  4700. propContent = ifacePropContent;
  4701. propInitialized = true;
  4702. }
  4703. }
  4704. else
  4705. {
  4706. // Not set. Nothing to agree on.
  4707. continue;
  4708. }
  4709. }
  4710. }
  4711. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  4712. report, compatibilityType(t));
  4713. return propContent;
  4714. }
  4715. //----------------------------------------------------------------------------
  4716. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4717. const std::string& config) const
  4718. {
  4719. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4720. BoolType, 0);
  4721. }
  4722. //----------------------------------------------------------------------------
  4723. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4724. const std::string &p,
  4725. const std::string& config) const
  4726. {
  4727. return checkInterfacePropertyCompatibility<const char *>(this,
  4728. p,
  4729. config,
  4730. "empty",
  4731. StringType, 0);
  4732. }
  4733. //----------------------------------------------------------------------------
  4734. const char * cmTarget::GetLinkInterfaceDependentNumberMinProperty(
  4735. const std::string &p,
  4736. const std::string& config) const
  4737. {
  4738. return checkInterfacePropertyCompatibility<const char *>(this,
  4739. p,
  4740. config,
  4741. "empty",
  4742. NumberMinType, 0);
  4743. }
  4744. //----------------------------------------------------------------------------
  4745. const char * cmTarget::GetLinkInterfaceDependentNumberMaxProperty(
  4746. const std::string &p,
  4747. const std::string& config) const
  4748. {
  4749. return checkInterfacePropertyCompatibility<const char *>(this,
  4750. p,
  4751. config,
  4752. "empty",
  4753. NumberMaxType, 0);
  4754. }
  4755. //----------------------------------------------------------------------------
  4756. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4757. const std::string& config) const
  4758. {
  4759. if (this->TargetTypeValue == OBJECT_LIBRARY
  4760. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4761. {
  4762. return false;
  4763. }
  4764. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  4765. }
  4766. //----------------------------------------------------------------------------
  4767. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4768. const std::string& config) const
  4769. {
  4770. if (this->TargetTypeValue == OBJECT_LIBRARY
  4771. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4772. {
  4773. return false;
  4774. }
  4775. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  4776. }
  4777. //----------------------------------------------------------------------------
  4778. bool cmTarget::IsLinkInterfaceDependentNumberMinProperty(const std::string &p,
  4779. const std::string& config) const
  4780. {
  4781. if (this->TargetTypeValue == OBJECT_LIBRARY
  4782. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4783. {
  4784. return false;
  4785. }
  4786. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  4787. }
  4788. //----------------------------------------------------------------------------
  4789. bool cmTarget::IsLinkInterfaceDependentNumberMaxProperty(const std::string &p,
  4790. const std::string& config) const
  4791. {
  4792. if (this->TargetTypeValue == OBJECT_LIBRARY
  4793. || this->TargetTypeValue == INTERFACE_LIBRARY)
  4794. {
  4795. return false;
  4796. }
  4797. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  4798. }
  4799. //----------------------------------------------------------------------------
  4800. void
  4801. cmTarget::GetObjectLibrariesCMP0026(std::vector<cmTarget*>& objlibs) const
  4802. {
  4803. // At configure-time, this method can be called as part of getting the
  4804. // LOCATION property or to export() a file to be include()d. However
  4805. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  4806. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  4807. // behavior of CMP0024 and CMP0026 only.
  4808. typedef cmTargetInternals::TargetPropertyEntry
  4809. TargetPropertyEntry;
  4810. for(std::vector<TargetPropertyEntry*>::const_iterator
  4811. i = this->Internal->SourceEntries.begin();
  4812. i != this->Internal->SourceEntries.end(); ++i)
  4813. {
  4814. std::string entry = (*i)->ge->GetInput();
  4815. std::vector<std::string> files;
  4816. cmSystemTools::ExpandListArgument(entry, files);
  4817. for (std::vector<std::string>::const_iterator
  4818. li = files.begin(); li != files.end(); ++li)
  4819. {
  4820. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  4821. (*li)[li->size() - 1] == '>')
  4822. {
  4823. std::string objLibName = li->substr(17, li->size()-18);
  4824. if (cmGeneratorExpression::Find(objLibName) != std::string::npos)
  4825. {
  4826. continue;
  4827. }
  4828. cmTarget *objLib = this->Makefile->FindTargetToUse(objLibName);
  4829. if(objLib)
  4830. {
  4831. objlibs.push_back(objLib);
  4832. }
  4833. }
  4834. }
  4835. }
  4836. }
  4837. //----------------------------------------------------------------------------
  4838. void cmTarget::GetLanguages(std::set<std::string>& languages,
  4839. const std::string& config) const
  4840. {
  4841. std::vector<cmSourceFile*> sourceFiles;
  4842. this->GetSourceFiles(sourceFiles, config);
  4843. for(std::vector<cmSourceFile*>::const_iterator
  4844. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  4845. {
  4846. const std::string& lang = (*i)->GetLanguage();
  4847. if(!lang.empty())
  4848. {
  4849. languages.insert(lang);
  4850. }
  4851. }
  4852. std::vector<cmTarget*> objectLibraries;
  4853. std::vector<cmSourceFile const*> externalObjects;
  4854. if (this->Makefile->GetGeneratorTargets().empty())
  4855. {
  4856. this->GetObjectLibrariesCMP0026(objectLibraries);
  4857. }
  4858. else
  4859. {
  4860. cmGeneratorTarget* gt = this->Makefile->GetLocalGenerator()
  4861. ->GetGlobalGenerator()
  4862. ->GetGeneratorTarget(this);
  4863. gt->GetExternalObjects(externalObjects, config);
  4864. for(std::vector<cmSourceFile const*>::const_iterator
  4865. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  4866. {
  4867. std::string objLib = (*i)->GetObjectLibrary();
  4868. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  4869. {
  4870. objectLibraries.push_back(tgt);
  4871. }
  4872. }
  4873. }
  4874. for(std::vector<cmTarget*>::const_iterator
  4875. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  4876. {
  4877. (*i)->GetLanguages(languages, config);
  4878. }
  4879. }
  4880. //----------------------------------------------------------------------------
  4881. bool cmTarget::IsChrpathUsed(const std::string& config) const
  4882. {
  4883. // Only certain target types have an rpath.
  4884. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4885. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4886. this->GetType() == cmTarget::EXECUTABLE))
  4887. {
  4888. return false;
  4889. }
  4890. // If the target will not be installed we do not need to change its
  4891. // rpath.
  4892. if(!this->GetHaveInstallRule())
  4893. {
  4894. return false;
  4895. }
  4896. // Skip chrpath if skipping rpath altogether.
  4897. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4898. {
  4899. return false;
  4900. }
  4901. // Skip chrpath if it does not need to be changed at install time.
  4902. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4903. {
  4904. return false;
  4905. }
  4906. // Allow the user to disable builtin chrpath explicitly.
  4907. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4908. {
  4909. return false;
  4910. }
  4911. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  4912. {
  4913. return true;
  4914. }
  4915. #if defined(CMAKE_USE_ELF_PARSER)
  4916. // Enable if the rpath flag uses a separator and the target uses ELF
  4917. // binaries.
  4918. std::string ll = this->GetLinkerLanguage(config);
  4919. if(!ll.empty())
  4920. {
  4921. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4922. sepVar += ll;
  4923. sepVar += "_FLAG_SEP";
  4924. const char* sep = this->Makefile->GetDefinition(sepVar);
  4925. if(sep && *sep)
  4926. {
  4927. // TODO: Add ELF check to ABI detection and get rid of
  4928. // CMAKE_EXECUTABLE_FORMAT.
  4929. if(const char* fmt =
  4930. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4931. {
  4932. return strcmp(fmt, "ELF") == 0;
  4933. }
  4934. }
  4935. }
  4936. #endif
  4937. static_cast<void>(config);
  4938. return false;
  4939. }
  4940. //----------------------------------------------------------------------------
  4941. cmTarget::ImportInfo const*
  4942. cmTarget::GetImportInfo(const std::string& config) const
  4943. {
  4944. // There is no imported information for non-imported targets.
  4945. if(!this->IsImported())
  4946. {
  4947. return 0;
  4948. }
  4949. // Lookup/compute/cache the import information for this
  4950. // configuration.
  4951. std::string config_upper;
  4952. if(!config.empty())
  4953. {
  4954. config_upper = cmSystemTools::UpperCase(config);
  4955. }
  4956. else
  4957. {
  4958. config_upper = "NOCONFIG";
  4959. }
  4960. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4961. ImportInfoMapType::const_iterator i =
  4962. this->Internal->ImportInfoMap.find(config_upper);
  4963. if(i == this->Internal->ImportInfoMap.end())
  4964. {
  4965. ImportInfo info;
  4966. this->ComputeImportInfo(config_upper, info);
  4967. ImportInfoMapType::value_type entry(config_upper, info);
  4968. i = this->Internal->ImportInfoMap.insert(entry).first;
  4969. }
  4970. if(this->GetType() == INTERFACE_LIBRARY)
  4971. {
  4972. return &i->second;
  4973. }
  4974. // If the location is empty then the target is not available for
  4975. // this configuration.
  4976. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4977. {
  4978. return 0;
  4979. }
  4980. // Return the import information.
  4981. return &i->second;
  4982. }
  4983. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4984. const char** loc,
  4985. const char** imp,
  4986. std::string& suffix) const
  4987. {
  4988. if (this->GetType() == INTERFACE_LIBRARY)
  4989. {
  4990. // This method attempts to find a config-specific LOCATION for the
  4991. // IMPORTED library. In the case of INTERFACE_LIBRARY, there is no
  4992. // LOCATION at all, so leaving *loc and *imp unchanged is the appropriate
  4993. // and valid response.
  4994. return true;
  4995. }
  4996. // Track the configuration-specific property suffix.
  4997. suffix = "_";
  4998. suffix += desired_config;
  4999. std::vector<std::string> mappedConfigs;
  5000. {
  5001. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  5002. mapProp += desired_config;
  5003. if(const char* mapValue = this->GetProperty(mapProp))
  5004. {
  5005. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  5006. }
  5007. }
  5008. // If we needed to find one of the mapped configurations but did not
  5009. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  5010. // library or an executable with exports.
  5011. bool allowImp = this->HasImportLibrary();
  5012. // If a mapping was found, check its configurations.
  5013. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  5014. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  5015. {
  5016. // Look for this configuration.
  5017. std::string mcUpper = cmSystemTools::UpperCase(*mci);
  5018. std::string locProp = "IMPORTED_LOCATION_";
  5019. locProp += mcUpper;
  5020. *loc = this->GetProperty(locProp);
  5021. if(allowImp)
  5022. {
  5023. std::string impProp = "IMPORTED_IMPLIB_";
  5024. impProp += mcUpper;
  5025. *imp = this->GetProperty(impProp);
  5026. }
  5027. // If it was found, use it for all properties below.
  5028. if(*loc || *imp)
  5029. {
  5030. suffix = "_";
  5031. suffix += mcUpper;
  5032. }
  5033. }
  5034. // If we needed to find one of the mapped configurations but did not
  5035. // then the target is not found. The project does not want any
  5036. // other configuration.
  5037. if(!mappedConfigs.empty() && !*loc && !*imp)
  5038. {
  5039. return false;
  5040. }
  5041. // If we have not yet found it then there are no mapped
  5042. // configurations. Look for an exact-match.
  5043. if(!*loc && !*imp)
  5044. {
  5045. std::string locProp = "IMPORTED_LOCATION";
  5046. locProp += suffix;
  5047. *loc = this->GetProperty(locProp);
  5048. if(allowImp)
  5049. {
  5050. std::string impProp = "IMPORTED_IMPLIB";
  5051. impProp += suffix;
  5052. *imp = this->GetProperty(impProp);
  5053. }
  5054. }
  5055. // If we have not yet found it then there are no mapped
  5056. // configurations and no exact match.
  5057. if(!*loc && !*imp)
  5058. {
  5059. // The suffix computed above is not useful.
  5060. suffix = "";
  5061. // Look for a configuration-less location. This may be set by
  5062. // manually-written code.
  5063. *loc = this->GetProperty("IMPORTED_LOCATION");
  5064. if(allowImp)
  5065. {
  5066. *imp = this->GetProperty("IMPORTED_IMPLIB");
  5067. }
  5068. }
  5069. // If we have not yet found it then the project is willing to try
  5070. // any available configuration.
  5071. if(!*loc && !*imp)
  5072. {
  5073. std::vector<std::string> availableConfigs;
  5074. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  5075. {
  5076. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  5077. }
  5078. for(std::vector<std::string>::const_iterator
  5079. aci = availableConfigs.begin();
  5080. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  5081. {
  5082. suffix = "_";
  5083. suffix += cmSystemTools::UpperCase(*aci);
  5084. std::string locProp = "IMPORTED_LOCATION";
  5085. locProp += suffix;
  5086. *loc = this->GetProperty(locProp);
  5087. if(allowImp)
  5088. {
  5089. std::string impProp = "IMPORTED_IMPLIB";
  5090. impProp += suffix;
  5091. *imp = this->GetProperty(impProp);
  5092. }
  5093. }
  5094. }
  5095. // If we have not yet found it then the target is not available.
  5096. if(!*loc && !*imp)
  5097. {
  5098. return false;
  5099. }
  5100. return true;
  5101. }
  5102. //----------------------------------------------------------------------------
  5103. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  5104. ImportInfo& info) const
  5105. {
  5106. // This method finds information about an imported target from its
  5107. // properties. The "IMPORTED_" namespace is reserved for properties
  5108. // defined by the project exporting the target.
  5109. // Initialize members.
  5110. info.NoSOName = false;
  5111. const char* loc = 0;
  5112. const char* imp = 0;
  5113. std::string suffix;
  5114. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  5115. {
  5116. return;
  5117. }
  5118. // Get the link interface.
  5119. {
  5120. std::string linkProp = "INTERFACE_LINK_LIBRARIES";
  5121. const char *propertyLibs = this->GetProperty(linkProp);
  5122. if (this->GetType() != INTERFACE_LIBRARY)
  5123. {
  5124. if(!propertyLibs)
  5125. {
  5126. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5127. linkProp += suffix;
  5128. propertyLibs = this->GetProperty(linkProp);
  5129. }
  5130. if(!propertyLibs)
  5131. {
  5132. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  5133. propertyLibs = this->GetProperty(linkProp);
  5134. }
  5135. }
  5136. if(propertyLibs)
  5137. {
  5138. info.LibrariesProp = linkProp;
  5139. info.Libraries = propertyLibs;
  5140. }
  5141. }
  5142. if(this->GetType() == INTERFACE_LIBRARY)
  5143. {
  5144. return;
  5145. }
  5146. // A provided configuration has been chosen. Load the
  5147. // configuration's properties.
  5148. // Get the location.
  5149. if(loc)
  5150. {
  5151. info.Location = loc;
  5152. }
  5153. else
  5154. {
  5155. std::string impProp = "IMPORTED_LOCATION";
  5156. impProp += suffix;
  5157. if(const char* config_location = this->GetProperty(impProp))
  5158. {
  5159. info.Location = config_location;
  5160. }
  5161. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  5162. {
  5163. info.Location = location;
  5164. }
  5165. }
  5166. // Get the soname.
  5167. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5168. {
  5169. std::string soProp = "IMPORTED_SONAME";
  5170. soProp += suffix;
  5171. if(const char* config_soname = this->GetProperty(soProp))
  5172. {
  5173. info.SOName = config_soname;
  5174. }
  5175. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  5176. {
  5177. info.SOName = soname;
  5178. }
  5179. }
  5180. // Get the "no-soname" mark.
  5181. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  5182. {
  5183. std::string soProp = "IMPORTED_NO_SONAME";
  5184. soProp += suffix;
  5185. if(const char* config_no_soname = this->GetProperty(soProp))
  5186. {
  5187. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  5188. }
  5189. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  5190. {
  5191. info.NoSOName = cmSystemTools::IsOn(no_soname);
  5192. }
  5193. }
  5194. // Get the import library.
  5195. if(imp)
  5196. {
  5197. info.ImportLibrary = imp;
  5198. }
  5199. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  5200. this->IsExecutableWithExports())
  5201. {
  5202. std::string impProp = "IMPORTED_IMPLIB";
  5203. impProp += suffix;
  5204. if(const char* config_implib = this->GetProperty(impProp))
  5205. {
  5206. info.ImportLibrary = config_implib;
  5207. }
  5208. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  5209. {
  5210. info.ImportLibrary = implib;
  5211. }
  5212. }
  5213. // Get the link dependencies.
  5214. {
  5215. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  5216. linkProp += suffix;
  5217. if(const char* config_libs = this->GetProperty(linkProp))
  5218. {
  5219. info.SharedDeps = config_libs;
  5220. }
  5221. else if(const char* libs =
  5222. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  5223. {
  5224. info.SharedDeps = libs;
  5225. }
  5226. }
  5227. // Get the link languages.
  5228. if(this->LinkLanguagePropagatesToDependents())
  5229. {
  5230. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  5231. linkProp += suffix;
  5232. if(const char* config_libs = this->GetProperty(linkProp))
  5233. {
  5234. info.Languages = config_libs;
  5235. }
  5236. else if(const char* libs =
  5237. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  5238. {
  5239. info.Languages = libs;
  5240. }
  5241. }
  5242. // Get the cyclic repetition count.
  5243. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  5244. {
  5245. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  5246. linkProp += suffix;
  5247. if(const char* config_reps = this->GetProperty(linkProp))
  5248. {
  5249. sscanf(config_reps, "%u", &info.Multiplicity);
  5250. }
  5251. else if(const char* reps =
  5252. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  5253. {
  5254. sscanf(reps, "%u", &info.Multiplicity);
  5255. }
  5256. }
  5257. }
  5258. //----------------------------------------------------------------------------
  5259. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(
  5260. const std::string& config,
  5261. cmTarget const* head) const
  5262. {
  5263. // Imported targets have their own link interface.
  5264. if(this->IsImported())
  5265. {
  5266. return this->GetImportLinkInterface(config, head, false);
  5267. }
  5268. // Link interfaces are not supported for executables that do not
  5269. // export symbols.
  5270. if(this->GetType() == cmTarget::EXECUTABLE &&
  5271. !this->IsExecutableWithExports())
  5272. {
  5273. return 0;
  5274. }
  5275. // Lookup any existing link interface for this configuration.
  5276. std::string CONFIG = cmSystemTools::UpperCase(config);
  5277. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5278. this->Internal->LinkInterfaceMap[CONFIG];
  5279. // If the link interface does not depend on the head target
  5280. // then return the one we computed first.
  5281. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5282. {
  5283. return &hm.begin()->second;
  5284. }
  5285. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  5286. if(!iface.LibrariesDone)
  5287. {
  5288. iface.LibrariesDone = true;
  5289. this->Internal->ComputeLinkInterfaceLibraries(
  5290. this, config, iface, head, false);
  5291. }
  5292. if(!iface.AllDone)
  5293. {
  5294. iface.AllDone = true;
  5295. if(iface.Exists)
  5296. {
  5297. this->Internal->ComputeLinkInterface(this, config, iface, head);
  5298. }
  5299. }
  5300. return iface.Exists? &iface : 0;
  5301. }
  5302. //----------------------------------------------------------------------------
  5303. cmTarget::LinkInterfaceLibraries const*
  5304. cmTarget::GetLinkInterfaceLibraries(const std::string& config,
  5305. cmTarget const* head,
  5306. bool usage_requirements_only) const
  5307. {
  5308. // Imported targets have their own link interface.
  5309. if(this->IsImported())
  5310. {
  5311. return this->GetImportLinkInterface(config, head, usage_requirements_only);
  5312. }
  5313. // Link interfaces are not supported for executables that do not
  5314. // export symbols.
  5315. if(this->GetType() == cmTarget::EXECUTABLE &&
  5316. !this->IsExecutableWithExports())
  5317. {
  5318. return 0;
  5319. }
  5320. // Lookup any existing link interface for this configuration.
  5321. std::string CONFIG = cmSystemTools::UpperCase(config);
  5322. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5323. (usage_requirements_only ?
  5324. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  5325. this->Internal->LinkInterfaceMap[CONFIG]);
  5326. // If the link interface does not depend on the head target
  5327. // then return the one we computed first.
  5328. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5329. {
  5330. return &hm.begin()->second;
  5331. }
  5332. cmTargetInternals::OptionalLinkInterface& iface = hm[head];
  5333. if(!iface.LibrariesDone)
  5334. {
  5335. iface.LibrariesDone = true;
  5336. this->Internal->ComputeLinkInterfaceLibraries(
  5337. this, config, iface, head, usage_requirements_only);
  5338. }
  5339. return iface.Exists? &iface : 0;
  5340. }
  5341. //----------------------------------------------------------------------------
  5342. cmTarget::LinkInterface const*
  5343. cmTarget::GetImportLinkInterface(const std::string& config,
  5344. cmTarget const* headTarget,
  5345. bool usage_requirements_only) const
  5346. {
  5347. cmTarget::ImportInfo const* info = this->GetImportInfo(config);
  5348. if(!info)
  5349. {
  5350. return 0;
  5351. }
  5352. std::string CONFIG = cmSystemTools::UpperCase(config);
  5353. cmTargetInternals::HeadToLinkInterfaceMap& hm =
  5354. (usage_requirements_only ?
  5355. this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] :
  5356. this->Internal->LinkInterfaceMap[CONFIG]);
  5357. // If the link interface does not depend on the head target
  5358. // then return the one we computed first.
  5359. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5360. {
  5361. return &hm.begin()->second;
  5362. }
  5363. cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget];
  5364. if(!iface.AllDone)
  5365. {
  5366. iface.AllDone = true;
  5367. iface.Multiplicity = info->Multiplicity;
  5368. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  5369. this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config,
  5370. headTarget, usage_requirements_only,
  5371. iface.Libraries,
  5372. iface.HadHeadSensitiveCondition);
  5373. std::vector<std::string> deps;
  5374. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  5375. this->LookupLinkItems(deps, iface.SharedDeps);
  5376. }
  5377. return &iface;
  5378. }
  5379. //----------------------------------------------------------------------------
  5380. void processILibs(const std::string& config,
  5381. cmTarget const* headTarget,
  5382. cmLinkItem const& item,
  5383. std::vector<cmTarget const*>& tgts,
  5384. std::set<cmTarget const*>& emitted)
  5385. {
  5386. if (item.Target && emitted.insert(item.Target).second)
  5387. {
  5388. tgts.push_back(item.Target);
  5389. if(cmTarget::LinkInterfaceLibraries const* iface =
  5390. item.Target->GetLinkInterfaceLibraries(config, headTarget, true))
  5391. {
  5392. for(std::vector<cmLinkItem>::const_iterator
  5393. it = iface->Libraries.begin();
  5394. it != iface->Libraries.end(); ++it)
  5395. {
  5396. processILibs(config, headTarget, *it, tgts, emitted);
  5397. }
  5398. }
  5399. }
  5400. }
  5401. //----------------------------------------------------------------------------
  5402. std::vector<cmTarget const*> const&
  5403. cmTarget::GetLinkImplementationClosure(const std::string& config) const
  5404. {
  5405. cmTargetInternals::LinkImplClosure& tgts =
  5406. this->Internal->LinkImplClosureMap[config];
  5407. if(!tgts.Done)
  5408. {
  5409. tgts.Done = true;
  5410. std::set<cmTarget const*> emitted;
  5411. cmTarget::LinkImplementationLibraries const* impl
  5412. = this->GetLinkImplementationLibraries(config);
  5413. for(std::vector<cmLinkImplItem>::const_iterator
  5414. it = impl->Libraries.begin();
  5415. it != impl->Libraries.end(); ++it)
  5416. {
  5417. processILibs(config, this, *it, tgts , emitted);
  5418. }
  5419. }
  5420. return tgts;
  5421. }
  5422. //----------------------------------------------------------------------------
  5423. cmTarget::CompatibleInterfaces const&
  5424. cmTarget::GetCompatibleInterfaces(std::string const& config) const
  5425. {
  5426. cmTargetInternals::CompatibleInterfaces& compat =
  5427. this->Internal->CompatibleInterfacesMap[config];
  5428. if(!compat.Done)
  5429. {
  5430. compat.Done = true;
  5431. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  5432. compat.PropsString.insert("AUTOUIC_OPTIONS");
  5433. std::vector<cmTarget const*> const& deps =
  5434. this->GetLinkImplementationClosure(config);
  5435. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  5436. li != deps.end(); ++li)
  5437. {
  5438. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  5439. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  5440. { \
  5441. std::vector<std::string> props; \
  5442. cmSystemTools::ExpandListArgument(prop, props); \
  5443. std::copy(props.begin(), props.end(), \
  5444. std::inserter(compat.Props##x, compat.Props##x.begin())); \
  5445. }
  5446. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  5447. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  5448. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  5449. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  5450. #undef CM_READ_COMPATIBLE_INTERFACE
  5451. }
  5452. }
  5453. return compat;
  5454. }
  5455. //----------------------------------------------------------------------------
  5456. void
  5457. cmTargetInternals::ComputeLinkInterfaceLibraries(
  5458. cmTarget const* thisTarget,
  5459. const std::string& config,
  5460. OptionalLinkInterface& iface,
  5461. cmTarget const* headTarget,
  5462. bool usage_requirements_only)
  5463. {
  5464. // Construct the property name suffix for this configuration.
  5465. std::string suffix = "_";
  5466. if(!config.empty())
  5467. {
  5468. suffix += cmSystemTools::UpperCase(config);
  5469. }
  5470. else
  5471. {
  5472. suffix += "NOCONFIG";
  5473. }
  5474. // An explicit list of interface libraries may be set for shared
  5475. // libraries and executables that export symbols.
  5476. const char* explicitLibraries = 0;
  5477. std::string linkIfaceProp;
  5478. if(thisTarget->PolicyStatusCMP0022 != cmPolicies::OLD &&
  5479. thisTarget->PolicyStatusCMP0022 != cmPolicies::WARN)
  5480. {
  5481. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  5482. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  5483. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5484. }
  5485. else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY ||
  5486. thisTarget->IsExecutableWithExports())
  5487. {
  5488. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  5489. // shared lib or executable.
  5490. // Lookup the per-configuration property.
  5491. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5492. linkIfaceProp += suffix;
  5493. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5494. // If not set, try the generic property.
  5495. if(!explicitLibraries)
  5496. {
  5497. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  5498. explicitLibraries = thisTarget->GetProperty(linkIfaceProp);
  5499. }
  5500. }
  5501. if(explicitLibraries &&
  5502. thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5503. !this->PolicyWarnedCMP0022)
  5504. {
  5505. // Compare the explicitly set old link interface properties to the
  5506. // preferred new link interface property one and warn if different.
  5507. const char* newExplicitLibraries =
  5508. thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES");
  5509. if (newExplicitLibraries
  5510. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  5511. {
  5512. cmOStringStream w;
  5513. w <<
  5514. (thisTarget->Makefile->GetPolicies()
  5515. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5516. "Target \"" << thisTarget->GetName() << "\" has an "
  5517. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  5518. linkIfaceProp << " properties."
  5519. "\n"
  5520. "INTERFACE_LINK_LIBRARIES:\n"
  5521. " " << newExplicitLibraries << "\n" <<
  5522. linkIfaceProp << ":\n"
  5523. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  5524. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5525. this->PolicyWarnedCMP0022 = true;
  5526. }
  5527. }
  5528. // There is no implicit link interface for executables or modules
  5529. // so if none was explicitly set then there is no link interface.
  5530. if(!explicitLibraries &&
  5531. (thisTarget->GetType() == cmTarget::EXECUTABLE ||
  5532. (thisTarget->GetType() == cmTarget::MODULE_LIBRARY)))
  5533. {
  5534. return;
  5535. }
  5536. iface.Exists = true;
  5537. iface.ExplicitLibraries = explicitLibraries;
  5538. if(explicitLibraries)
  5539. {
  5540. // The interface libraries have been explicitly set.
  5541. thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config,
  5542. headTarget, usage_requirements_only,
  5543. iface.Libraries,
  5544. iface.HadHeadSensitiveCondition);
  5545. }
  5546. else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
  5547. || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
  5548. // If CMP0022 is NEW then the plain tll signature sets the
  5549. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  5550. // cleared the property explicitly and we should not fall back
  5551. // to the link implementation.
  5552. {
  5553. // The link implementation is the default link interface.
  5554. cmTarget::LinkImplementationLibraries const* impl =
  5555. thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget);
  5556. std::copy(impl->Libraries.begin(), impl->Libraries.end(),
  5557. std::back_inserter(iface.Libraries));
  5558. if(thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN &&
  5559. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  5560. {
  5561. // Compare the link implementation fallback link interface to the
  5562. // preferred new link interface property and warn if different.
  5563. std::vector<cmLinkItem> ifaceLibs;
  5564. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  5565. if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp))
  5566. {
  5567. bool hadHeadSensitiveConditionDummy = false;
  5568. thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config,
  5569. headTarget, usage_requirements_only,
  5570. ifaceLibs, hadHeadSensitiveConditionDummy);
  5571. }
  5572. if (ifaceLibs != iface.Libraries)
  5573. {
  5574. std::string oldLibraries;
  5575. std::string newLibraries;
  5576. const char *sep = "";
  5577. for(std::vector<cmLinkImplItem>::const_iterator it
  5578. = impl->Libraries.begin(); it != impl->Libraries.end(); ++it)
  5579. {
  5580. oldLibraries += sep;
  5581. oldLibraries += *it;
  5582. sep = ";";
  5583. }
  5584. sep = "";
  5585. for(std::vector<cmLinkItem>::const_iterator it
  5586. = ifaceLibs.begin(); it != ifaceLibs.end(); ++it)
  5587. {
  5588. newLibraries += sep;
  5589. newLibraries += *it;
  5590. sep = ";";
  5591. }
  5592. if(oldLibraries.empty())
  5593. { oldLibraries = "(empty)"; }
  5594. if(newLibraries.empty())
  5595. { newLibraries = "(empty)"; }
  5596. cmOStringStream w;
  5597. w <<
  5598. (thisTarget->Makefile->GetPolicies()
  5599. ->GetPolicyWarning(cmPolicies::CMP0022)) << "\n"
  5600. "Target \"" << thisTarget->GetName() << "\" has an "
  5601. "INTERFACE_LINK_LIBRARIES property. "
  5602. "This should be preferred as the source of the link interface "
  5603. "for this library but because CMP0022 is not set CMake is "
  5604. "ignoring the property and using the link implementation "
  5605. "as the link interface instead."
  5606. "\n"
  5607. "INTERFACE_LINK_LIBRARIES:\n"
  5608. " " << newLibraries << "\n"
  5609. "Link implementation:\n"
  5610. " " << oldLibraries << "\n";
  5611. thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  5612. this->PolicyWarnedCMP0022 = true;
  5613. }
  5614. }
  5615. }
  5616. }
  5617. //----------------------------------------------------------------------------
  5618. void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget,
  5619. const std::string& config,
  5620. OptionalLinkInterface& iface,
  5621. cmTarget const* headTarget) const
  5622. {
  5623. if(iface.ExplicitLibraries)
  5624. {
  5625. if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY
  5626. || thisTarget->GetType() == cmTarget::STATIC_LIBRARY
  5627. || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY)
  5628. {
  5629. // Shared libraries may have runtime implementation dependencies
  5630. // on other shared libraries that are not in the interface.
  5631. UNORDERED_SET<std::string> emitted;
  5632. for(std::vector<cmLinkItem>::const_iterator
  5633. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  5634. {
  5635. emitted.insert(*li);
  5636. }
  5637. if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY)
  5638. {
  5639. cmTarget::LinkImplementation const* impl =
  5640. thisTarget->GetLinkImplementation(config);
  5641. for(std::vector<cmLinkImplItem>::const_iterator
  5642. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  5643. {
  5644. if(emitted.insert(*li).second)
  5645. {
  5646. if(li->Target)
  5647. {
  5648. // This is a runtime dependency on another shared library.
  5649. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  5650. {
  5651. iface.SharedDeps.push_back(*li);
  5652. }
  5653. }
  5654. else
  5655. {
  5656. // TODO: Recognize shared library file names. Perhaps this
  5657. // should be moved to cmComputeLinkInformation, but that creates
  5658. // a chicken-and-egg problem since this list is needed for its
  5659. // construction.
  5660. }
  5661. }
  5662. }
  5663. }
  5664. }
  5665. }
  5666. else if (thisTarget->PolicyStatusCMP0022 == cmPolicies::WARN
  5667. || thisTarget->PolicyStatusCMP0022 == cmPolicies::OLD)
  5668. {
  5669. // The link implementation is the default link interface.
  5670. cmTarget::LinkImplementationLibraries const*
  5671. impl = thisTarget->GetLinkImplementationLibrariesInternal(config,
  5672. headTarget);
  5673. iface.ImplementationIsInterface = true;
  5674. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  5675. }
  5676. if(thisTarget->LinkLanguagePropagatesToDependents())
  5677. {
  5678. // Targets using this archive need its language runtime libraries.
  5679. if(cmTarget::LinkImplementation const* impl =
  5680. thisTarget->GetLinkImplementation(config))
  5681. {
  5682. iface.Languages = impl->Languages;
  5683. }
  5684. }
  5685. if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY)
  5686. {
  5687. // Construct the property name suffix for this configuration.
  5688. std::string suffix = "_";
  5689. if(!config.empty())
  5690. {
  5691. suffix += cmSystemTools::UpperCase(config);
  5692. }
  5693. else
  5694. {
  5695. suffix += "NOCONFIG";
  5696. }
  5697. // How many repetitions are needed if this library has cyclic
  5698. // dependencies?
  5699. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  5700. propName += suffix;
  5701. if(const char* config_reps = thisTarget->GetProperty(propName))
  5702. {
  5703. sscanf(config_reps, "%u", &iface.Multiplicity);
  5704. }
  5705. else if(const char* reps =
  5706. thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  5707. {
  5708. sscanf(reps, "%u", &iface.Multiplicity);
  5709. }
  5710. }
  5711. }
  5712. //----------------------------------------------------------------------------
  5713. void cmTargetInternals::AddInterfaceEntries(
  5714. cmTarget const* thisTarget, std::string const& config,
  5715. std::string const& prop, std::vector<TargetPropertyEntry*>& entries)
  5716. {
  5717. if(cmTarget::LinkImplementationLibraries const* impl =
  5718. thisTarget->GetLinkImplementationLibraries(config))
  5719. {
  5720. for (std::vector<cmLinkImplItem>::const_iterator
  5721. it = impl->Libraries.begin(), end = impl->Libraries.end();
  5722. it != end; ++it)
  5723. {
  5724. if(it->Target)
  5725. {
  5726. std::string genex =
  5727. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  5728. cmGeneratorExpression ge(&it->Backtrace);
  5729. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  5730. cge->SetEvaluateForBuildsystem(true);
  5731. entries.push_back(
  5732. new cmTargetInternals::TargetPropertyEntry(cge, *it));
  5733. }
  5734. }
  5735. }
  5736. }
  5737. //----------------------------------------------------------------------------
  5738. cmTarget::LinkImplementation const*
  5739. cmTarget::GetLinkImplementation(const std::string& config) const
  5740. {
  5741. // There is no link implementation for imported targets.
  5742. if(this->IsImported())
  5743. {
  5744. return 0;
  5745. }
  5746. // Populate the link implementation for this configuration.
  5747. std::string CONFIG = cmSystemTools::UpperCase(config);
  5748. cmTargetInternals::OptionalLinkImplementation&
  5749. impl = this->Internal->LinkImplMap[CONFIG][this];
  5750. if(!impl.LibrariesDone)
  5751. {
  5752. impl.LibrariesDone = true;
  5753. this->Internal
  5754. ->ComputeLinkImplementationLibraries(this, config, impl, this);
  5755. }
  5756. if(!impl.LanguagesDone)
  5757. {
  5758. impl.LanguagesDone = true;
  5759. this->Internal->ComputeLinkImplementationLanguages(this, config, impl);
  5760. }
  5761. return &impl;
  5762. }
  5763. //----------------------------------------------------------------------------
  5764. cmTarget::LinkImplementationLibraries const*
  5765. cmTarget::GetLinkImplementationLibraries(const std::string& config) const
  5766. {
  5767. return this->GetLinkImplementationLibrariesInternal(config, this);
  5768. }
  5769. //----------------------------------------------------------------------------
  5770. cmTarget::LinkImplementationLibraries const*
  5771. cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config,
  5772. cmTarget const* head) const
  5773. {
  5774. // There is no link implementation for imported targets.
  5775. if(this->IsImported())
  5776. {
  5777. return 0;
  5778. }
  5779. // Populate the link implementation libraries for this configuration.
  5780. std::string CONFIG = cmSystemTools::UpperCase(config);
  5781. cmTargetInternals::HeadToLinkImplementationMap& hm =
  5782. this->Internal->LinkImplMap[CONFIG];
  5783. // If the link implementation does not depend on the head target
  5784. // then return the one we computed first.
  5785. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  5786. {
  5787. return &hm.begin()->second;
  5788. }
  5789. cmTargetInternals::OptionalLinkImplementation& impl = hm[head];
  5790. if(!impl.LibrariesDone)
  5791. {
  5792. impl.LibrariesDone = true;
  5793. this->Internal
  5794. ->ComputeLinkImplementationLibraries(this, config, impl, head);
  5795. }
  5796. return &impl;
  5797. }
  5798. //----------------------------------------------------------------------------
  5799. void
  5800. cmTargetInternals::ComputeLinkImplementationLibraries(
  5801. cmTarget const* thisTarget,
  5802. const std::string& config,
  5803. OptionalLinkImplementation& impl,
  5804. cmTarget const* head) const
  5805. {
  5806. // Collect libraries directly linked in this configuration.
  5807. for (std::vector<cmValueWithOrigin>::const_iterator
  5808. le = this->LinkImplementationPropertyEntries.begin(),
  5809. end = this->LinkImplementationPropertyEntries.end();
  5810. le != end; ++le)
  5811. {
  5812. std::vector<std::string> llibs;
  5813. cmGeneratorExpressionDAGChecker dagChecker(
  5814. thisTarget->GetName(),
  5815. "LINK_LIBRARIES", 0, 0);
  5816. cmGeneratorExpression ge(&le->Backtrace);
  5817. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  5818. ge.Parse(le->Value);
  5819. std::string const evaluated =
  5820. cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker);
  5821. cmSystemTools::ExpandListArgument(evaluated, llibs);
  5822. if(cge->GetHadHeadSensitiveCondition())
  5823. {
  5824. impl.HadHeadSensitiveCondition = true;
  5825. }
  5826. for(std::vector<std::string>::const_iterator li = llibs.begin();
  5827. li != llibs.end(); ++li)
  5828. {
  5829. // Skip entries that resolve to the target itself or are empty.
  5830. std::string name = thisTarget->CheckCMP0004(*li);
  5831. if(name == thisTarget->GetName() || name.empty())
  5832. {
  5833. if(name == thisTarget->GetName())
  5834. {
  5835. bool noMessage = false;
  5836. cmake::MessageType messageType = cmake::FATAL_ERROR;
  5837. cmOStringStream e;
  5838. switch(thisTarget->GetPolicyStatusCMP0038())
  5839. {
  5840. case cmPolicies::WARN:
  5841. {
  5842. e << (thisTarget->Makefile->GetPolicies()
  5843. ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
  5844. messageType = cmake::AUTHOR_WARNING;
  5845. }
  5846. break;
  5847. case cmPolicies::OLD:
  5848. noMessage = true;
  5849. case cmPolicies::REQUIRED_IF_USED:
  5850. case cmPolicies::REQUIRED_ALWAYS:
  5851. case cmPolicies::NEW:
  5852. // Issue the fatal message.
  5853. break;
  5854. }
  5855. if(!noMessage)
  5856. {
  5857. e << "Target \"" << thisTarget->GetName() << "\" links to itself.";
  5858. thisTarget->Makefile->GetCMakeInstance()->IssueMessage(
  5859. messageType, e.str(), thisTarget->GetBacktrace());
  5860. if (messageType == cmake::FATAL_ERROR)
  5861. {
  5862. return;
  5863. }
  5864. }
  5865. }
  5866. continue;
  5867. }
  5868. // The entry is meant for this configuration.
  5869. impl.Libraries.push_back(
  5870. cmLinkImplItem(name, thisTarget->FindTargetToLink(name),
  5871. le->Backtrace, evaluated != le->Value));
  5872. }
  5873. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  5874. for (std::set<std::string>::const_iterator it = seenProps.begin();
  5875. it != seenProps.end(); ++it)
  5876. {
  5877. if (!thisTarget->GetProperty(*it))
  5878. {
  5879. thisTarget->LinkImplicitNullProperties.insert(*it);
  5880. }
  5881. }
  5882. cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards);
  5883. }
  5884. cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config);
  5885. cmTarget::LinkLibraryVectorType const& oldllibs =
  5886. thisTarget->GetOriginalLinkLibraries();
  5887. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  5888. li != oldllibs.end(); ++li)
  5889. {
  5890. if(li->second != cmTarget::GENERAL && li->second != linkType)
  5891. {
  5892. std::string name = thisTarget->CheckCMP0004(li->first);
  5893. if(name == thisTarget->GetName() || name.empty())
  5894. {
  5895. continue;
  5896. }
  5897. // Support OLD behavior for CMP0003.
  5898. impl.WrongConfigLibraries.push_back(
  5899. cmLinkItem(name, thisTarget->FindTargetToLink(name)));
  5900. }
  5901. }
  5902. }
  5903. //----------------------------------------------------------------------------
  5904. void
  5905. cmTargetInternals::ComputeLinkImplementationLanguages(
  5906. cmTarget const* thisTarget,
  5907. const std::string& config,
  5908. OptionalLinkImplementation& impl) const
  5909. {
  5910. // This target needs runtime libraries for its source languages.
  5911. std::set<std::string> languages;
  5912. // Get languages used in our source files.
  5913. thisTarget->GetLanguages(languages, config);
  5914. // Copy the set of langauges to the link implementation.
  5915. for(std::set<std::string>::iterator li = languages.begin();
  5916. li != languages.end(); ++li)
  5917. {
  5918. impl.Languages.push_back(*li);
  5919. }
  5920. }
  5921. //----------------------------------------------------------------------------
  5922. cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const
  5923. {
  5924. cmTarget const* tgt = this->Makefile->FindTargetToUse(name);
  5925. // Skip targets that will not really be linked. This is probably a
  5926. // name conflict between an external library and an executable
  5927. // within the project.
  5928. if(tgt && tgt->GetType() == cmTarget::EXECUTABLE &&
  5929. !tgt->IsExecutableWithExports())
  5930. {
  5931. tgt = 0;
  5932. }
  5933. if(tgt && tgt->GetType() == cmTarget::OBJECT_LIBRARY)
  5934. {
  5935. cmOStringStream e;
  5936. e << "Target \"" << this->GetName() << "\" links to "
  5937. "OBJECT library \"" << tgt->GetName() << "\" but this is not "
  5938. "allowed. "
  5939. "One may link only to STATIC or SHARED libraries, or to executables "
  5940. "with the ENABLE_EXPORTS property set.";
  5941. cmake* cm = this->Makefile->GetCMakeInstance();
  5942. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5943. tgt = 0;
  5944. }
  5945. // Return the target found, if any.
  5946. return tgt;
  5947. }
  5948. //----------------------------------------------------------------------------
  5949. std::string cmTarget::CheckCMP0004(std::string const& item) const
  5950. {
  5951. // Strip whitespace off the library names because we used to do this
  5952. // in case variables were expanded at generate time. We no longer
  5953. // do the expansion but users link to libraries like " ${VAR} ".
  5954. std::string lib = item;
  5955. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5956. if(pos != lib.npos)
  5957. {
  5958. lib = lib.substr(pos, lib.npos);
  5959. }
  5960. pos = lib.find_last_not_of(" \t\r\n");
  5961. if(pos != lib.npos)
  5962. {
  5963. lib = lib.substr(0, pos+1);
  5964. }
  5965. if(lib != item)
  5966. {
  5967. cmake* cm = this->Makefile->GetCMakeInstance();
  5968. switch(this->PolicyStatusCMP0004)
  5969. {
  5970. case cmPolicies::WARN:
  5971. {
  5972. cmOStringStream w;
  5973. w << (this->Makefile->GetPolicies()
  5974. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  5975. << "Target \"" << this->GetName() << "\" links to item \""
  5976. << item << "\" which has leading or trailing whitespace.";
  5977. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5978. this->GetBacktrace());
  5979. }
  5980. case cmPolicies::OLD:
  5981. break;
  5982. case cmPolicies::NEW:
  5983. {
  5984. cmOStringStream e;
  5985. e << "Target \"" << this->GetName() << "\" links to item \""
  5986. << item << "\" which has leading or trailing whitespace. "
  5987. << "This is now an error according to policy CMP0004.";
  5988. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5989. }
  5990. break;
  5991. case cmPolicies::REQUIRED_IF_USED:
  5992. case cmPolicies::REQUIRED_ALWAYS:
  5993. {
  5994. cmOStringStream e;
  5995. e << (this->Makefile->GetPolicies()
  5996. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  5997. << "Target \"" << this->GetName() << "\" links to item \""
  5998. << item << "\" which has leading or trailing whitespace.";
  5999. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  6000. }
  6001. break;
  6002. }
  6003. }
  6004. return lib;
  6005. }
  6006. template<typename PropertyType>
  6007. PropertyType getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6008. const std::string& prop,
  6009. const std::string& config,
  6010. CompatibleType,
  6011. PropertyType *);
  6012. template<>
  6013. bool getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6014. const std::string& prop,
  6015. const std::string& config,
  6016. CompatibleType, bool *)
  6017. {
  6018. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  6019. }
  6020. template<>
  6021. const char * getLinkInterfaceDependentProperty(cmTarget const* tgt,
  6022. const std::string& prop,
  6023. const std::string& config,
  6024. CompatibleType t,
  6025. const char **)
  6026. {
  6027. switch(t)
  6028. {
  6029. case BoolType:
  6030. assert(!"String compatibility check function called for boolean");
  6031. return 0;
  6032. case StringType:
  6033. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  6034. case NumberMinType:
  6035. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  6036. case NumberMaxType:
  6037. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  6038. }
  6039. assert(!"Unreachable!");
  6040. return 0;
  6041. }
  6042. //----------------------------------------------------------------------------
  6043. template<typename PropertyType>
  6044. void checkPropertyConsistency(cmTarget const* depender,
  6045. cmTarget const* dependee,
  6046. const std::string& propName,
  6047. std::set<std::string> &emitted,
  6048. const std::string& config,
  6049. CompatibleType t,
  6050. PropertyType *)
  6051. {
  6052. const char *prop = dependee->GetProperty(propName);
  6053. if (!prop)
  6054. {
  6055. return;
  6056. }
  6057. std::vector<std::string> props;
  6058. cmSystemTools::ExpandListArgument(prop, props);
  6059. std::string pdir =
  6060. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  6061. pdir += "/Help/prop_tgt/";
  6062. for(std::vector<std::string>::iterator pi = props.begin();
  6063. pi != props.end(); ++pi)
  6064. {
  6065. std::string pname = cmSystemTools::HelpFileName(*pi);
  6066. std::string pfile = pdir + pname + ".rst";
  6067. if(cmSystemTools::FileExists(pfile.c_str(), true))
  6068. {
  6069. cmOStringStream e;
  6070. e << "Target \"" << dependee->GetName() << "\" has property \""
  6071. << *pi << "\" listed in its " << propName << " property. "
  6072. "This is not allowed. Only user-defined properties may appear "
  6073. "listed in the " << propName << " property.";
  6074. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  6075. return;
  6076. }
  6077. if(emitted.insert(*pi).second)
  6078. {
  6079. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  6080. t, 0);
  6081. if (cmSystemTools::GetErrorOccuredFlag())
  6082. {
  6083. return;
  6084. }
  6085. }
  6086. }
  6087. }
  6088. static std::string intersect(const std::set<std::string> &s1,
  6089. const std::set<std::string> &s2)
  6090. {
  6091. std::set<std::string> intersect;
  6092. std::set_intersection(s1.begin(),s1.end(),
  6093. s2.begin(),s2.end(),
  6094. std::inserter(intersect,intersect.begin()));
  6095. if (!intersect.empty())
  6096. {
  6097. return *intersect.begin();
  6098. }
  6099. return "";
  6100. }
  6101. static std::string intersect(const std::set<std::string> &s1,
  6102. const std::set<std::string> &s2,
  6103. const std::set<std::string> &s3)
  6104. {
  6105. std::string result;
  6106. result = intersect(s1, s2);
  6107. if (!result.empty())
  6108. return result;
  6109. result = intersect(s1, s3);
  6110. if (!result.empty())
  6111. return result;
  6112. return intersect(s2, s3);
  6113. }
  6114. static std::string intersect(const std::set<std::string> &s1,
  6115. const std::set<std::string> &s2,
  6116. const std::set<std::string> &s3,
  6117. const std::set<std::string> &s4)
  6118. {
  6119. std::string result;
  6120. result = intersect(s1, s2);
  6121. if (!result.empty())
  6122. return result;
  6123. result = intersect(s1, s3);
  6124. if (!result.empty())
  6125. return result;
  6126. result = intersect(s1, s4);
  6127. if (!result.empty())
  6128. return result;
  6129. return intersect(s2, s3, s4);
  6130. }
  6131. //----------------------------------------------------------------------------
  6132. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  6133. const std::string& config) const
  6134. {
  6135. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  6136. std::set<std::string> emittedBools;
  6137. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  6138. std::set<std::string> emittedStrings;
  6139. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  6140. std::set<std::string> emittedMinNumbers;
  6141. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  6142. std::set<std::string> emittedMaxNumbers;
  6143. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  6144. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  6145. deps.begin();
  6146. li != deps.end(); ++li)
  6147. {
  6148. if (!li->Target)
  6149. {
  6150. continue;
  6151. }
  6152. checkPropertyConsistency<bool>(this, li->Target,
  6153. strBool,
  6154. emittedBools, config, BoolType, 0);
  6155. if (cmSystemTools::GetErrorOccuredFlag())
  6156. {
  6157. return;
  6158. }
  6159. checkPropertyConsistency<const char *>(this, li->Target,
  6160. strString,
  6161. emittedStrings, config,
  6162. StringType, 0);
  6163. if (cmSystemTools::GetErrorOccuredFlag())
  6164. {
  6165. return;
  6166. }
  6167. checkPropertyConsistency<const char *>(this, li->Target,
  6168. strNumMin,
  6169. emittedMinNumbers, config,
  6170. NumberMinType, 0);
  6171. if (cmSystemTools::GetErrorOccuredFlag())
  6172. {
  6173. return;
  6174. }
  6175. checkPropertyConsistency<const char *>(this, li->Target,
  6176. strNumMax,
  6177. emittedMaxNumbers, config,
  6178. NumberMaxType, 0);
  6179. if (cmSystemTools::GetErrorOccuredFlag())
  6180. {
  6181. return;
  6182. }
  6183. }
  6184. std::string prop = intersect(emittedBools,
  6185. emittedStrings,
  6186. emittedMinNumbers,
  6187. emittedMaxNumbers);
  6188. if (!prop.empty())
  6189. {
  6190. // Use a std::set to keep the error message sorted.
  6191. std::set<std::string> props;
  6192. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  6193. if (i != emittedBools.end())
  6194. {
  6195. props.insert(strBool);
  6196. }
  6197. i = emittedStrings.find(prop);
  6198. if (i != emittedStrings.end())
  6199. {
  6200. props.insert(strString);
  6201. }
  6202. i = emittedMinNumbers.find(prop);
  6203. if (i != emittedMinNumbers.end())
  6204. {
  6205. props.insert(strNumMin);
  6206. }
  6207. i = emittedMaxNumbers.find(prop);
  6208. if (i != emittedMaxNumbers.end())
  6209. {
  6210. props.insert(strNumMax);
  6211. }
  6212. std::string propsString = *props.begin();
  6213. props.erase(props.begin());
  6214. while (props.size() > 1)
  6215. {
  6216. propsString += ", " + *props.begin();
  6217. props.erase(props.begin());
  6218. }
  6219. if (props.size() == 1)
  6220. {
  6221. propsString += " and the " + *props.begin();
  6222. }
  6223. cmOStringStream e;
  6224. e << "Property \"" << prop << "\" appears in both the "
  6225. << propsString <<
  6226. " property in the dependencies of target \"" << this->GetName() <<
  6227. "\". This is not allowed. A property may only require compatibility "
  6228. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  6229. "string interpretation, but not a mixture.";
  6230. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  6231. }
  6232. }
  6233. //----------------------------------------------------------------------------
  6234. cmComputeLinkInformation*
  6235. cmTarget::GetLinkInformation(const std::string& config) const
  6236. {
  6237. // Lookup any existing information for this configuration.
  6238. std::string key(cmSystemTools::UpperCase(config));
  6239. cmTargetLinkInformationMap::iterator
  6240. i = this->LinkInformation.find(key);
  6241. if(i == this->LinkInformation.end())
  6242. {
  6243. // Compute information for this configuration.
  6244. cmComputeLinkInformation* info =
  6245. new cmComputeLinkInformation(this, config);
  6246. if(!info || !info->Compute())
  6247. {
  6248. delete info;
  6249. info = 0;
  6250. }
  6251. // Store the information for this configuration.
  6252. cmTargetLinkInformationMap::value_type entry(key, info);
  6253. i = this->LinkInformation.insert(entry).first;
  6254. if (info)
  6255. {
  6256. this->CheckPropertyCompatibility(info, config);
  6257. }
  6258. }
  6259. return i->second;
  6260. }
  6261. //----------------------------------------------------------------------------
  6262. std::string cmTarget::GetFrameworkDirectory(const std::string& config,
  6263. bool rootDir) const
  6264. {
  6265. std::string fpath;
  6266. fpath += this->GetOutputName(config, false);
  6267. fpath += ".framework";
  6268. if(!rootDir)
  6269. {
  6270. fpath += "/Versions/";
  6271. fpath += this->GetFrameworkVersion();
  6272. }
  6273. return fpath;
  6274. }
  6275. //----------------------------------------------------------------------------
  6276. std::string cmTarget::GetCFBundleDirectory(const std::string& config,
  6277. bool contentOnly) const
  6278. {
  6279. std::string fpath;
  6280. fpath += this->GetOutputName(config, false);
  6281. fpath += ".";
  6282. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  6283. if (!ext)
  6284. {
  6285. ext = "bundle";
  6286. }
  6287. fpath += ext;
  6288. fpath += "/Contents";
  6289. if(!contentOnly)
  6290. fpath += "/MacOS";
  6291. return fpath;
  6292. }
  6293. //----------------------------------------------------------------------------
  6294. std::string cmTarget::GetAppBundleDirectory(const std::string& config,
  6295. bool contentOnly) const
  6296. {
  6297. std::string fpath = this->GetFullName(config, false);
  6298. fpath += ".app/Contents";
  6299. if(!contentOnly)
  6300. fpath += "/MacOS";
  6301. return fpath;
  6302. }
  6303. //----------------------------------------------------------------------------
  6304. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  6305. const std::string& config,
  6306. bool contentOnly) const
  6307. {
  6308. std::string fpath = base;
  6309. if(this->IsAppBundleOnApple())
  6310. {
  6311. fpath += this->GetAppBundleDirectory(config, contentOnly);
  6312. }
  6313. if(this->IsFrameworkOnApple())
  6314. {
  6315. fpath += this->GetFrameworkDirectory(config, contentOnly);
  6316. }
  6317. if(this->IsCFBundleOnApple())
  6318. {
  6319. fpath += this->GetCFBundleDirectory(config, contentOnly);
  6320. }
  6321. return fpath;
  6322. }
  6323. //----------------------------------------------------------------------------
  6324. std::string cmTarget::GetMacContentDirectory(const std::string& config,
  6325. bool implib) const
  6326. {
  6327. // Start with the output directory for the target.
  6328. std::string fpath = this->GetDirectory(config, implib);
  6329. fpath += "/";
  6330. bool contentOnly = true;
  6331. if(this->IsFrameworkOnApple())
  6332. {
  6333. // additional files with a framework go into the version specific
  6334. // directory
  6335. contentOnly = false;
  6336. }
  6337. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  6338. return fpath;
  6339. }
  6340. //----------------------------------------------------------------------------
  6341. cmTargetLinkInformationMap
  6342. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  6343. {
  6344. // Ideally cmTarget instances should never be copied. However until
  6345. // we can make a sweep to remove that, this copy constructor avoids
  6346. // allowing the resources (LinkInformation) from getting copied. In
  6347. // the worst case this will lead to extra cmComputeLinkInformation
  6348. // instances. We also enforce in debug mode that the map be emptied
  6349. // when copied.
  6350. static_cast<void>(r);
  6351. assert(r.empty());
  6352. }
  6353. //----------------------------------------------------------------------------
  6354. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  6355. {
  6356. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  6357. {
  6358. delete i->second;
  6359. }
  6360. }
  6361. //----------------------------------------------------------------------------
  6362. cmTargetInternalPointer::cmTargetInternalPointer()
  6363. {
  6364. this->Pointer = new cmTargetInternals;
  6365. }
  6366. //----------------------------------------------------------------------------
  6367. cmTargetInternalPointer
  6368. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  6369. {
  6370. // Ideally cmTarget instances should never be copied. However until
  6371. // we can make a sweep to remove that, this copy constructor avoids
  6372. // allowing the resources (Internals) to be copied.
  6373. this->Pointer = new cmTargetInternals(*r.Pointer);
  6374. }
  6375. //----------------------------------------------------------------------------
  6376. cmTargetInternalPointer::~cmTargetInternalPointer()
  6377. {
  6378. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  6379. deleteAndClear(this->Pointer->CompileOptionsEntries);
  6380. deleteAndClear(this->Pointer->CompileFeaturesEntries);
  6381. deleteAndClear(this->Pointer->CompileDefinitionsEntries);
  6382. deleteAndClear(this->Pointer->SourceEntries);
  6383. delete this->Pointer;
  6384. }
  6385. //----------------------------------------------------------------------------
  6386. cmTargetInternalPointer&
  6387. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  6388. {
  6389. if(this == &r) { return *this; } // avoid warning on HP about self check
  6390. // Ideally cmTarget instances should never be copied. However until
  6391. // we can make a sweep to remove that, this copy constructor avoids
  6392. // allowing the resources (Internals) to be copied.
  6393. cmTargetInternals* oldPointer = this->Pointer;
  6394. this->Pointer = new cmTargetInternals(*r.Pointer);
  6395. delete oldPointer;
  6396. return *this;
  6397. }