cmTarget.cxx 190 KB

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