cmTarget.cxx 189 KB

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