cmTarget.cxx 190 KB

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