cmTarget.cxx 159 KB

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