cmTarget.cxx 226 KB

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