cmTarget.cxx 161 KB

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