cmTarget.cxx 222 KB

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