cmTarget.cxx 222 KB

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