cmTarget.cxx 199 KB

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