cmTarget.cxx 221 KB

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