cmTarget.cxx 179 KB

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