cmGeneratorTarget.cxx 159 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2012 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 "cmGeneratorTarget.h"
  11. #include "cmTarget.h"
  12. #include "cmMakefile.h"
  13. #include "cmLocalGenerator.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmSourceFile.h"
  16. #include "cmGeneratorExpression.h"
  17. #include "cmGeneratorExpressionDAGChecker.h"
  18. #include "cmComputeLinkInformation.h"
  19. #include "cmCustomCommandGenerator.h"
  20. #include "cmAlgorithms.h"
  21. #include <queue>
  22. #include <errno.h>
  23. #include "assert.h"
  24. #if defined(CMAKE_BUILD_WITH_CMAKE)
  25. #include <cmsys/hash_set.hxx>
  26. #define UNORDERED_SET cmsys::hash_set
  27. #else
  28. #define UNORDERED_SET std::set
  29. #endif
  30. class cmGeneratorTarget::TargetPropertyEntry {
  31. static cmLinkImplItem NoLinkImplItem;
  32. public:
  33. TargetPropertyEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge,
  34. cmLinkImplItem const& item = NoLinkImplItem)
  35. : ge(cge), LinkImplItem(item)
  36. {}
  37. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  38. cmLinkImplItem const& LinkImplItem;
  39. };
  40. cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem;
  41. //----------------------------------------------------------------------------
  42. void reportBadObjLib(std::vector<cmSourceFile*> const& badObjLib,
  43. cmGeneratorTarget const* target, cmake *cm)
  44. {
  45. if(!badObjLib.empty())
  46. {
  47. std::ostringstream e;
  48. e << "OBJECT library \"" << target->GetName() << "\" contains:\n";
  49. for(std::vector<cmSourceFile*>::const_iterator i = badObjLib.begin();
  50. i != badObjLib.end(); ++i)
  51. {
  52. e << " " << (*i)->GetLocation().GetName() << "\n";
  53. }
  54. e << "but may contain only sources that compile, header files, and "
  55. "other files that would not affect linking of a normal library.";
  56. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  57. target->Target->GetBacktrace());
  58. }
  59. }
  60. struct ObjectSourcesTag {};
  61. struct CustomCommandsTag {};
  62. struct ExtraSourcesTag {};
  63. struct HeaderSourcesTag {};
  64. struct ExternalObjectsTag {};
  65. struct IDLSourcesTag {};
  66. struct ResxTag {};
  67. struct ModuleDefinitionFileTag {};
  68. struct AppManifestTag{};
  69. struct ManifestsTag{};
  70. struct CertificatesTag{};
  71. struct XamlTag{};
  72. template<typename Tag, typename OtherTag>
  73. struct IsSameTag
  74. {
  75. enum {
  76. Result = false
  77. };
  78. };
  79. template<typename Tag>
  80. struct IsSameTag<Tag, Tag>
  81. {
  82. enum {
  83. Result = true
  84. };
  85. };
  86. template<bool>
  87. struct DoAccept
  88. {
  89. template <typename T> static void Do(T&, cmSourceFile*) {}
  90. };
  91. template<>
  92. struct DoAccept<true>
  93. {
  94. static void Do(std::vector<cmSourceFile const*>& files, cmSourceFile* f)
  95. {
  96. files.push_back(f);
  97. }
  98. static void Do(cmGeneratorTarget::ResxData& data, cmSourceFile* f)
  99. {
  100. // Build and save the name of the corresponding .h file
  101. // This relationship will be used later when building the project files.
  102. // Both names would have been auto generated from Visual Studio
  103. // where the user supplied the file name and Visual Studio
  104. // appended the suffix.
  105. std::string resx = f->GetFullPath();
  106. std::string hFileName = resx.substr(0, resx.find_last_of(".")) + ".h";
  107. data.ExpectedResxHeaders.insert(hFileName);
  108. data.ResxSources.push_back(f);
  109. }
  110. static void Do(cmGeneratorTarget::XamlData& data, cmSourceFile* f)
  111. {
  112. // Build and save the name of the corresponding .h and .cpp file
  113. // This relationship will be used later when building the project files.
  114. // Both names would have been auto generated from Visual Studio
  115. // where the user supplied the file name and Visual Studio
  116. // appended the suffix.
  117. std::string xaml = f->GetFullPath();
  118. std::string hFileName = xaml + ".h";
  119. std::string cppFileName = xaml + ".cpp";
  120. data.ExpectedXamlHeaders.insert(hFileName);
  121. data.ExpectedXamlSources.insert(cppFileName);
  122. data.XamlSources.push_back(f);
  123. }
  124. static void Do(std::string& data, cmSourceFile* f)
  125. {
  126. data = f->GetFullPath();
  127. }
  128. };
  129. //----------------------------------------------------------------------------
  130. template<typename Tag, typename DataType = std::vector<cmSourceFile const*> >
  131. struct TagVisitor
  132. {
  133. DataType& Data;
  134. std::vector<cmSourceFile*> BadObjLibFiles;
  135. cmGeneratorTarget const* Target;
  136. cmGlobalGenerator *GlobalGenerator;
  137. cmsys::RegularExpression Header;
  138. bool IsObjLib;
  139. TagVisitor(cmGeneratorTarget const* target, DataType& data)
  140. : Data(data), Target(target),
  141. GlobalGenerator(target->GetLocalGenerator()->GetGlobalGenerator()),
  142. Header(CM_HEADER_REGEX),
  143. IsObjLib(target->GetType() == cmTarget::OBJECT_LIBRARY)
  144. {
  145. }
  146. ~TagVisitor()
  147. {
  148. reportBadObjLib(this->BadObjLibFiles, this->Target,
  149. this->GlobalGenerator->GetCMakeInstance());
  150. }
  151. void Accept(cmSourceFile *sf)
  152. {
  153. std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
  154. if(sf->GetCustomCommand())
  155. {
  156. DoAccept<IsSameTag<Tag, CustomCommandsTag>::Result>::Do(this->Data, sf);
  157. }
  158. else if(this->Target->GetType() == cmTarget::UTILITY)
  159. {
  160. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  161. }
  162. else if(sf->GetPropertyAsBool("HEADER_FILE_ONLY"))
  163. {
  164. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  165. }
  166. else if(sf->GetPropertyAsBool("EXTERNAL_OBJECT"))
  167. {
  168. DoAccept<IsSameTag<Tag, ExternalObjectsTag>::Result>::Do(this->Data, sf);
  169. if(this->IsObjLib)
  170. {
  171. this->BadObjLibFiles.push_back(sf);
  172. }
  173. }
  174. else if(!sf->GetLanguage().empty())
  175. {
  176. DoAccept<IsSameTag<Tag, ObjectSourcesTag>::Result>::Do(this->Data, sf);
  177. }
  178. else if(ext == "def")
  179. {
  180. DoAccept<IsSameTag<Tag, ModuleDefinitionFileTag>::Result>::Do(this->Data,
  181. sf);
  182. if(this->IsObjLib)
  183. {
  184. this->BadObjLibFiles.push_back(sf);
  185. }
  186. }
  187. else if(ext == "idl")
  188. {
  189. DoAccept<IsSameTag<Tag, IDLSourcesTag>::Result>::Do(this->Data, sf);
  190. if(this->IsObjLib)
  191. {
  192. this->BadObjLibFiles.push_back(sf);
  193. }
  194. }
  195. else if(ext == "resx")
  196. {
  197. DoAccept<IsSameTag<Tag, ResxTag>::Result>::Do(this->Data, sf);
  198. }
  199. else if (ext == "appxmanifest")
  200. {
  201. DoAccept<IsSameTag<Tag, AppManifestTag>::Result>::Do(this->Data, sf);
  202. }
  203. else if (ext == "manifest")
  204. {
  205. DoAccept<IsSameTag<Tag, ManifestsTag>::Result>::Do(this->Data, sf);
  206. }
  207. else if (ext == "pfx")
  208. {
  209. DoAccept<IsSameTag<Tag, CertificatesTag>::Result>::Do(this->Data, sf);
  210. }
  211. else if (ext == "xaml")
  212. {
  213. DoAccept<IsSameTag<Tag, XamlTag>::Result>::Do(this->Data, sf);
  214. }
  215. else if(this->Header.find(sf->GetFullPath().c_str()))
  216. {
  217. DoAccept<IsSameTag<Tag, HeaderSourcesTag>::Result>::Do(this->Data, sf);
  218. }
  219. else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
  220. {
  221. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  222. }
  223. else
  224. {
  225. DoAccept<IsSameTag<Tag, ExtraSourcesTag>::Result>::Do(this->Data, sf);
  226. }
  227. }
  228. };
  229. void CreatePropertyGeneratorExpressions(
  230. cmStringRange const& entries,
  231. cmBacktraceRange const& backtraces,
  232. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& items,
  233. bool evaluateForBuildsystem = false)
  234. {
  235. std::vector<cmListFileBacktrace>::const_iterator btIt = backtraces.begin();
  236. for (std::vector<std::string>::const_iterator it = entries.begin();
  237. it != entries.end(); ++it, ++btIt)
  238. {
  239. cmGeneratorExpression ge(*btIt);
  240. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(*it);
  241. cge->SetEvaluateForBuildsystem(evaluateForBuildsystem);
  242. items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  243. }
  244. }
  245. //----------------------------------------------------------------------------
  246. cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg)
  247. : Target(t),
  248. SourceFileFlagsConstructed(false),
  249. PolicyWarnedCMP0022(false),
  250. DebugIncludesDone(false),
  251. DebugCompileOptionsDone(false),
  252. DebugCompileFeaturesDone(false),
  253. DebugCompileDefinitionsDone(false),
  254. DebugSourcesDone(false),
  255. LinkImplementationLanguageIsContextDependent(true)
  256. {
  257. this->Makefile = this->Target->GetMakefile();
  258. this->LocalGenerator = lg;
  259. this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator();
  260. this->GlobalGenerator->ComputeTargetObjectDirectory(this);
  261. CreatePropertyGeneratorExpressions(
  262. t->GetIncludeDirectoriesEntries(),
  263. t->GetIncludeDirectoriesBacktraces(),
  264. this->IncludeDirectoriesEntries);
  265. CreatePropertyGeneratorExpressions(
  266. t->GetCompileOptionsEntries(),
  267. t->GetCompileOptionsBacktraces(),
  268. this->CompileOptionsEntries);
  269. CreatePropertyGeneratorExpressions(
  270. t->GetCompileFeaturesEntries(),
  271. t->GetCompileFeaturesBacktraces(),
  272. this->CompileFeaturesEntries);
  273. CreatePropertyGeneratorExpressions(
  274. t->GetCompileDefinitionsEntries(),
  275. t->GetCompileDefinitionsBacktraces(),
  276. this->CompileDefinitionsEntries);
  277. CreatePropertyGeneratorExpressions(
  278. t->GetSourceEntries(),
  279. t->GetSourceBacktraces(),
  280. this->SourceEntries, true);
  281. }
  282. cmGeneratorTarget::~cmGeneratorTarget()
  283. {
  284. cmDeleteAll(this->IncludeDirectoriesEntries);
  285. cmDeleteAll(this->CompileOptionsEntries);
  286. cmDeleteAll(this->CompileFeaturesEntries);
  287. cmDeleteAll(this->CompileDefinitionsEntries);
  288. cmDeleteAll(this->SourceEntries);
  289. cmDeleteAll(this->LinkInformation);
  290. this->LinkInformation.clear();
  291. }
  292. cmLocalGenerator* cmGeneratorTarget::GetLocalGenerator() const
  293. {
  294. return this->LocalGenerator;
  295. }
  296. //----------------------------------------------------------------------------
  297. int cmGeneratorTarget::GetType() const
  298. {
  299. return this->Target->GetType();
  300. }
  301. //----------------------------------------------------------------------------
  302. std::string cmGeneratorTarget::GetName() const
  303. {
  304. return this->Target->GetName();
  305. }
  306. //----------------------------------------------------------------------------
  307. const char *cmGeneratorTarget::GetProperty(const std::string& prop) const
  308. {
  309. return this->Target->GetProperty(prop);
  310. }
  311. //----------------------------------------------------------------------------
  312. std::string cmGeneratorTarget::GetOutputName(const std::string& config,
  313. bool implib) const
  314. {
  315. // Lookup/compute/cache the output name for this configuration.
  316. OutputNameKey key(config, implib);
  317. cmGeneratorTarget::OutputNameMapType::iterator i =
  318. this->OutputNameMap.find(key);
  319. if(i == this->OutputNameMap.end())
  320. {
  321. // Add empty name in map to detect potential recursion.
  322. OutputNameMapType::value_type entry(key, "");
  323. i = this->OutputNameMap.insert(entry).first;
  324. // Compute output name.
  325. std::vector<std::string> props;
  326. std::string type = this->Target->GetOutputTargetType(implib);
  327. std::string configUpper = cmSystemTools::UpperCase(config);
  328. if(!type.empty() && !configUpper.empty())
  329. {
  330. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  331. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  332. }
  333. if(!type.empty())
  334. {
  335. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  336. props.push_back(type + "_OUTPUT_NAME");
  337. }
  338. if(!configUpper.empty())
  339. {
  340. // OUTPUT_NAME_<CONFIG>
  341. props.push_back("OUTPUT_NAME_" + configUpper);
  342. // <CONFIG>_OUTPUT_NAME
  343. props.push_back(configUpper + "_OUTPUT_NAME");
  344. }
  345. // OUTPUT_NAME
  346. props.push_back("OUTPUT_NAME");
  347. std::string outName;
  348. for(std::vector<std::string>::const_iterator it = props.begin();
  349. it != props.end(); ++it)
  350. {
  351. if (const char* outNameProp = this->Target->GetProperty(*it))
  352. {
  353. outName = outNameProp;
  354. break;
  355. }
  356. }
  357. if(outName.empty())
  358. {
  359. outName = this->GetName();
  360. }
  361. // Now evaluate genex and update the previously-prepared map entry.
  362. cmGeneratorExpression ge;
  363. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(outName);
  364. i->second = cge->Evaluate(this->Makefile, config);
  365. }
  366. else if(i->second.empty())
  367. {
  368. // An empty map entry indicates we have been called recursively
  369. // from the above block.
  370. this->LocalGenerator->GetCMakeInstance()
  371. ->IssueMessage(
  372. cmake::FATAL_ERROR,
  373. "Target '" + this->GetName() + "' OUTPUT_NAME depends on itself.",
  374. this->Target->GetBacktrace());
  375. }
  376. return i->second;
  377. }
  378. void cmGeneratorTarget::AddSource(const std::string& src)
  379. {
  380. this->Target->AddSource(src);
  381. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  382. cmGeneratorExpression ge(lfbt);
  383. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(src);
  384. cge->SetEvaluateForBuildsystem(true);
  385. this->SourceEntries.push_back(
  386. new TargetPropertyEntry(cge));
  387. this->SourceFilesMap.clear();
  388. this->LinkImplementationLanguageIsContextDependent = true;
  389. }
  390. void cmGeneratorTarget::AddTracedSources(std::vector<std::string> const& srcs)
  391. {
  392. this->Target->AddTracedSources(srcs);
  393. if (!srcs.empty())
  394. {
  395. std::string srcFiles = cmJoin(srcs, ";");
  396. this->SourceFilesMap.clear();
  397. this->LinkImplementationLanguageIsContextDependent = true;
  398. cmListFileBacktrace lfbt = this->Makefile->GetBacktrace();
  399. cmGeneratorExpression ge(lfbt);
  400. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(srcFiles);
  401. cge->SetEvaluateForBuildsystem(true);
  402. this->SourceEntries.push_back(
  403. new cmGeneratorTarget::TargetPropertyEntry(cge));
  404. }
  405. }
  406. //----------------------------------------------------------------------------
  407. std::vector<cmSourceFile*> const*
  408. cmGeneratorTarget::GetSourceDepends(cmSourceFile const* sf) const
  409. {
  410. SourceEntriesType::const_iterator i = this->SourceDepends.find(sf);
  411. if(i != this->SourceDepends.end())
  412. {
  413. return &i->second.Depends;
  414. }
  415. return 0;
  416. }
  417. static void handleSystemIncludesDep(cmMakefile *mf, cmTarget const* depTgt,
  418. const std::string& config,
  419. cmTarget *headTarget,
  420. cmGeneratorExpressionDAGChecker *dagChecker,
  421. std::vector<std::string>& result,
  422. bool excludeImported)
  423. {
  424. if (const char* dirs =
  425. depTgt->GetProperty("INTERFACE_SYSTEM_INCLUDE_DIRECTORIES"))
  426. {
  427. cmGeneratorExpression ge;
  428. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  429. ->Evaluate(mf,
  430. config, false, headTarget,
  431. depTgt, dagChecker), result);
  432. }
  433. if (!depTgt->IsImported() || excludeImported)
  434. {
  435. return;
  436. }
  437. if (const char* dirs =
  438. depTgt->GetProperty("INTERFACE_INCLUDE_DIRECTORIES"))
  439. {
  440. cmGeneratorExpression ge;
  441. cmSystemTools::ExpandListArgument(ge.Parse(dirs)
  442. ->Evaluate(mf,
  443. config, false, headTarget,
  444. depTgt, dagChecker), result);
  445. }
  446. }
  447. #define IMPLEMENT_VISIT_IMPL(DATA, DATATYPE) \
  448. { \
  449. std::vector<cmSourceFile*> sourceFiles; \
  450. this->GetSourceFiles(sourceFiles, config); \
  451. TagVisitor<DATA ## Tag DATATYPE> visitor(this, data); \
  452. for(std::vector<cmSourceFile*>::const_iterator si = sourceFiles.begin(); \
  453. si != sourceFiles.end(); ++si) \
  454. { \
  455. visitor.Accept(*si); \
  456. } \
  457. } \
  458. #define IMPLEMENT_VISIT(DATA) \
  459. IMPLEMENT_VISIT_IMPL(DATA, EMPTY) \
  460. #define EMPTY
  461. #define COMMA ,
  462. //----------------------------------------------------------------------------
  463. void
  464. cmGeneratorTarget
  465. ::GetObjectSources(std::vector<cmSourceFile const*> &data,
  466. const std::string& config) const
  467. {
  468. IMPLEMENT_VISIT(ObjectSources);
  469. if (!this->Objects.empty())
  470. {
  471. return;
  472. }
  473. for(std::vector<cmSourceFile const*>::const_iterator it = data.begin();
  474. it != data.end(); ++it)
  475. {
  476. this->Objects[*it];
  477. }
  478. this->LocalGenerator->ComputeObjectFilenames(this->Objects, this);
  479. }
  480. void cmGeneratorTarget::ComputeObjectMapping()
  481. {
  482. if(!this->Objects.empty())
  483. {
  484. return;
  485. }
  486. std::vector<std::string> configs;
  487. this->Makefile->GetConfigurations(configs);
  488. if (configs.empty())
  489. {
  490. configs.push_back("");
  491. }
  492. for(std::vector<std::string>::const_iterator ci = configs.begin();
  493. ci != configs.end(); ++ci)
  494. {
  495. std::vector<cmSourceFile const*> sourceFiles;
  496. this->GetObjectSources(sourceFiles, *ci);
  497. }
  498. }
  499. //----------------------------------------------------------------------------
  500. const char* cmGeneratorTarget::GetFeature(const std::string& feature,
  501. const std::string& config) const
  502. {
  503. if(!config.empty())
  504. {
  505. std::string featureConfig = feature;
  506. featureConfig += "_";
  507. featureConfig += cmSystemTools::UpperCase(config);
  508. if(const char* value = this->Target->GetProperty(featureConfig))
  509. {
  510. return value;
  511. }
  512. }
  513. if(const char* value = this->Target->GetProperty(feature))
  514. {
  515. return value;
  516. }
  517. return this->LocalGenerator->GetFeature(feature, config);
  518. }
  519. //----------------------------------------------------------------------------
  520. bool cmGeneratorTarget::GetFeatureAsBool(const std::string& feature,
  521. const std::string& config) const
  522. {
  523. return cmSystemTools::IsOn(this->GetFeature(feature, config));
  524. }
  525. //----------------------------------------------------------------------------
  526. const std::string& cmGeneratorTarget::GetObjectName(cmSourceFile const* file)
  527. {
  528. this->ComputeObjectMapping();
  529. return this->Objects[file];
  530. }
  531. //----------------------------------------------------------------------------
  532. void cmGeneratorTarget::AddExplicitObjectName(cmSourceFile const* sf)
  533. {
  534. this->ExplicitObjectName.insert(sf);
  535. }
  536. //----------------------------------------------------------------------------
  537. bool cmGeneratorTarget::HasExplicitObjectName(cmSourceFile const* file) const
  538. {
  539. const_cast<cmGeneratorTarget*>(this)->ComputeObjectMapping();
  540. std::set<cmSourceFile const*>::const_iterator it
  541. = this->ExplicitObjectName.find(file);
  542. return it != this->ExplicitObjectName.end();
  543. }
  544. //----------------------------------------------------------------------------
  545. void cmGeneratorTarget
  546. ::GetIDLSources(std::vector<cmSourceFile const*>& data,
  547. const std::string& config) const
  548. {
  549. IMPLEMENT_VISIT(IDLSources);
  550. }
  551. //----------------------------------------------------------------------------
  552. void
  553. cmGeneratorTarget
  554. ::GetHeaderSources(std::vector<cmSourceFile const*>& data,
  555. const std::string& config) const
  556. {
  557. IMPLEMENT_VISIT(HeaderSources);
  558. }
  559. //----------------------------------------------------------------------------
  560. void cmGeneratorTarget
  561. ::GetExtraSources(std::vector<cmSourceFile const*>& data,
  562. const std::string& config) const
  563. {
  564. IMPLEMENT_VISIT(ExtraSources);
  565. }
  566. //----------------------------------------------------------------------------
  567. void
  568. cmGeneratorTarget
  569. ::GetCustomCommands(std::vector<cmSourceFile const*>& data,
  570. const std::string& config) const
  571. {
  572. IMPLEMENT_VISIT(CustomCommands);
  573. }
  574. //----------------------------------------------------------------------------
  575. void
  576. cmGeneratorTarget
  577. ::GetExternalObjects(std::vector<cmSourceFile const*>& data,
  578. const std::string& config) const
  579. {
  580. IMPLEMENT_VISIT(ExternalObjects);
  581. }
  582. //----------------------------------------------------------------------------
  583. void
  584. cmGeneratorTarget::GetExpectedResxHeaders(std::set<std::string>& srcs,
  585. const std::string& config) const
  586. {
  587. ResxData data;
  588. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  589. srcs = data.ExpectedResxHeaders;
  590. }
  591. //----------------------------------------------------------------------------
  592. void cmGeneratorTarget
  593. ::GetResxSources(std::vector<cmSourceFile const*>& srcs,
  594. const std::string& config) const
  595. {
  596. ResxData data;
  597. IMPLEMENT_VISIT_IMPL(Resx, COMMA cmGeneratorTarget::ResxData)
  598. srcs = data.ResxSources;
  599. }
  600. //----------------------------------------------------------------------------
  601. void
  602. cmGeneratorTarget
  603. ::GetAppManifest(std::vector<cmSourceFile const*>& data,
  604. const std::string& config) const
  605. {
  606. IMPLEMENT_VISIT(AppManifest);
  607. }
  608. //----------------------------------------------------------------------------
  609. void
  610. cmGeneratorTarget
  611. ::GetManifests(std::vector<cmSourceFile const*>& data,
  612. const std::string& config) const
  613. {
  614. IMPLEMENT_VISIT(Manifests);
  615. }
  616. //----------------------------------------------------------------------------
  617. void
  618. cmGeneratorTarget
  619. ::GetCertificates(std::vector<cmSourceFile const*>& data,
  620. const std::string& config) const
  621. {
  622. IMPLEMENT_VISIT(Certificates);
  623. }
  624. //----------------------------------------------------------------------------
  625. void
  626. cmGeneratorTarget::GetExpectedXamlHeaders(std::set<std::string>& headers,
  627. const std::string& config) const
  628. {
  629. XamlData data;
  630. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  631. headers = data.ExpectedXamlHeaders;
  632. }
  633. //----------------------------------------------------------------------------
  634. void
  635. cmGeneratorTarget::GetExpectedXamlSources(std::set<std::string>& srcs,
  636. const std::string& config) const
  637. {
  638. XamlData data;
  639. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  640. srcs = data.ExpectedXamlSources;
  641. }
  642. //----------------------------------------------------------------------------
  643. void cmGeneratorTarget
  644. ::GetXamlSources(std::vector<cmSourceFile const*>& srcs,
  645. const std::string& config) const
  646. {
  647. XamlData data;
  648. IMPLEMENT_VISIT_IMPL(Xaml, COMMA cmGeneratorTarget::XamlData)
  649. srcs = data.XamlSources;
  650. }
  651. //----------------------------------------------------------------------------
  652. const char* cmGeneratorTarget::GetLocation(const std::string& config) const
  653. {
  654. static std::string location;
  655. if (this->Target->IsImported())
  656. {
  657. location = this->Target->ImportedGetFullPath(config, false);
  658. }
  659. else
  660. {
  661. location = this->GetFullPath(config, false);
  662. }
  663. return location.c_str();
  664. }
  665. bool cmGeneratorTarget::IsImported() const
  666. {
  667. return this->Target->IsImported();
  668. }
  669. //----------------------------------------------------------------------------
  670. const char* cmGeneratorTarget::GetLocationForBuild() const
  671. {
  672. static std::string location;
  673. if(this->IsImported())
  674. {
  675. location = this->Target->ImportedGetFullPath("", false);
  676. return location.c_str();
  677. }
  678. // Now handle the deprecated build-time configuration location.
  679. location = this->Target->GetDirectory();
  680. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  681. if(cfgid && strcmp(cfgid, ".") != 0)
  682. {
  683. location += "/";
  684. location += cfgid;
  685. }
  686. if(this->Target->IsAppBundleOnApple())
  687. {
  688. std::string macdir = this->BuildMacContentDirectory("", "",
  689. false);
  690. if(!macdir.empty())
  691. {
  692. location += "/";
  693. location += macdir;
  694. }
  695. }
  696. location += "/";
  697. location += this->GetFullName("", false);
  698. return location.c_str();
  699. }
  700. //----------------------------------------------------------------------------
  701. bool cmGeneratorTarget::IsSystemIncludeDirectory(const std::string& dir,
  702. const std::string& config) const
  703. {
  704. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  705. std::string config_upper;
  706. if(!config.empty())
  707. {
  708. config_upper = cmSystemTools::UpperCase(config);
  709. }
  710. typedef std::map<std::string, std::vector<std::string> > IncludeCacheType;
  711. IncludeCacheType::const_iterator iter =
  712. this->SystemIncludesCache.find(config_upper);
  713. if (iter == this->SystemIncludesCache.end())
  714. {
  715. cmGeneratorExpressionDAGChecker dagChecker(
  716. this->GetName(),
  717. "SYSTEM_INCLUDE_DIRECTORIES", 0, 0);
  718. bool excludeImported
  719. = this->Target->GetPropertyAsBool("NO_SYSTEM_FROM_IMPORTED");
  720. std::vector<std::string> result;
  721. for (std::set<std::string>::const_iterator
  722. it = this->Target->GetSystemIncludeDirectories().begin();
  723. it != this->Target->GetSystemIncludeDirectories().end(); ++it)
  724. {
  725. cmGeneratorExpression ge;
  726. cmSystemTools::ExpandListArgument(ge.Parse(*it)
  727. ->Evaluate(this->Makefile,
  728. config, false, this->Target,
  729. &dagChecker), result);
  730. }
  731. std::vector<cmTarget const*> const& deps =
  732. this->GetLinkImplementationClosure(config);
  733. for(std::vector<cmTarget const*>::const_iterator
  734. li = deps.begin(), le = deps.end(); li != le; ++li)
  735. {
  736. handleSystemIncludesDep(this->Makefile, *li, config, this->Target,
  737. &dagChecker, result, excludeImported);
  738. }
  739. std::set<std::string> unique;
  740. for(std::vector<std::string>::iterator li = result.begin();
  741. li != result.end(); ++li)
  742. {
  743. cmSystemTools::ConvertToUnixSlashes(*li);
  744. unique.insert(*li);
  745. }
  746. result.clear();
  747. result.insert(result.end(), unique.begin(), unique.end());
  748. IncludeCacheType::value_type entry(config_upper, result);
  749. iter = this->SystemIncludesCache.insert(entry).first;
  750. }
  751. return std::binary_search(iter->second.begin(), iter->second.end(), dir);
  752. }
  753. //----------------------------------------------------------------------------
  754. bool cmGeneratorTarget::GetPropertyAsBool(const std::string& prop) const
  755. {
  756. return this->Target->GetPropertyAsBool(prop);
  757. }
  758. //----------------------------------------------------------------------------
  759. static void AddInterfaceEntries(
  760. cmGeneratorTarget const* thisTarget, std::string const& config,
  761. std::string const& prop,
  762. std::vector<cmGeneratorTarget::TargetPropertyEntry*>& entries)
  763. {
  764. if(cmLinkImplementationLibraries const* impl =
  765. thisTarget->GetLinkImplementationLibraries(config))
  766. {
  767. for (std::vector<cmLinkImplItem>::const_iterator
  768. it = impl->Libraries.begin(), end = impl->Libraries.end();
  769. it != end; ++it)
  770. {
  771. if(it->Target)
  772. {
  773. std::string genex =
  774. "$<TARGET_PROPERTY:" + *it + "," + prop + ">";
  775. cmGeneratorExpression ge(it->Backtrace);
  776. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(genex);
  777. cge->SetEvaluateForBuildsystem(true);
  778. entries.push_back(
  779. new cmGeneratorTarget::TargetPropertyEntry(cge, *it));
  780. }
  781. }
  782. }
  783. }
  784. //----------------------------------------------------------------------------
  785. static bool processSources(cmGeneratorTarget const* tgt,
  786. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  787. std::vector<std::string> &srcs,
  788. UNORDERED_SET<std::string> &uniqueSrcs,
  789. cmGeneratorExpressionDAGChecker *dagChecker,
  790. std::string const& config, bool debugSources)
  791. {
  792. cmMakefile *mf = tgt->Target->GetMakefile();
  793. bool contextDependent = false;
  794. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  795. it = entries.begin(), end = entries.end(); it != end; ++it)
  796. {
  797. cmLinkImplItem const& item = (*it)->LinkImplItem;
  798. std::string const& targetName = item;
  799. std::vector<std::string> entrySources;
  800. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  801. config,
  802. false,
  803. tgt->Target,
  804. tgt->Target,
  805. dagChecker),
  806. entrySources);
  807. if ((*it)->ge->GetHadContextSensitiveCondition())
  808. {
  809. contextDependent = true;
  810. }
  811. for(std::vector<std::string>::iterator i = entrySources.begin();
  812. i != entrySources.end(); ++i)
  813. {
  814. std::string& src = *i;
  815. cmSourceFile* sf = mf->GetOrCreateSource(src);
  816. std::string e;
  817. std::string fullPath = sf->GetFullPath(&e);
  818. if(fullPath.empty())
  819. {
  820. if(!e.empty())
  821. {
  822. cmake* cm = mf->GetCMakeInstance();
  823. cm->IssueMessage(cmake::FATAL_ERROR, e,
  824. tgt->Target->GetBacktrace());
  825. }
  826. return contextDependent;
  827. }
  828. if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
  829. {
  830. std::ostringstream err;
  831. if (!targetName.empty())
  832. {
  833. err << "Target \"" << targetName << "\" contains relative "
  834. "path in its INTERFACE_SOURCES:\n"
  835. " \"" << src << "\"";
  836. }
  837. else
  838. {
  839. err << "Found relative path while evaluating sources of "
  840. "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
  841. }
  842. tgt->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, err.str());
  843. return contextDependent;
  844. }
  845. src = fullPath;
  846. }
  847. std::string usedSources;
  848. for(std::vector<std::string>::iterator
  849. li = entrySources.begin(); li != entrySources.end(); ++li)
  850. {
  851. std::string src = *li;
  852. if(uniqueSrcs.insert(src).second)
  853. {
  854. srcs.push_back(src);
  855. if (debugSources)
  856. {
  857. usedSources += " * " + src + "\n";
  858. }
  859. }
  860. }
  861. if (!usedSources.empty())
  862. {
  863. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  864. std::string("Used sources for target ")
  865. + tgt->GetName() + ":\n"
  866. + usedSources, (*it)->ge->GetBacktrace());
  867. }
  868. }
  869. return contextDependent;
  870. }
  871. //----------------------------------------------------------------------------
  872. void cmGeneratorTarget::GetSourceFiles(std::vector<std::string> &files,
  873. const std::string& config) const
  874. {
  875. assert(this->GetType() != cmTarget::INTERFACE_LIBRARY);
  876. if (!this->Makefile->GetGlobalGenerator()->GetConfigureDoneCMP0026())
  877. {
  878. // At configure-time, this method can be called as part of getting the
  879. // LOCATION property or to export() a file to be include()d. However
  880. // there is no cmGeneratorTarget at configure-time, so search the SOURCES
  881. // for TARGET_OBJECTS instead for backwards compatibility with OLD
  882. // behavior of CMP0024 and CMP0026 only.
  883. cmStringRange sourceEntries = this->Target->GetSourceEntries();
  884. for(cmStringRange::const_iterator
  885. i = sourceEntries.begin();
  886. i != sourceEntries.end(); ++i)
  887. {
  888. std::string const& entry = *i;
  889. std::vector<std::string> items;
  890. cmSystemTools::ExpandListArgument(entry, items);
  891. for (std::vector<std::string>::const_iterator
  892. li = items.begin(); li != items.end(); ++li)
  893. {
  894. if(cmHasLiteralPrefix(*li, "$<TARGET_OBJECTS:") &&
  895. (*li)[li->size() - 1] == '>')
  896. {
  897. continue;
  898. }
  899. files.push_back(*li);
  900. }
  901. }
  902. return;
  903. }
  904. std::vector<std::string> debugProperties;
  905. const char *debugProp =
  906. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  907. if (debugProp)
  908. {
  909. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  910. }
  911. bool debugSources = !this->DebugSourcesDone
  912. && std::find(debugProperties.begin(),
  913. debugProperties.end(),
  914. "SOURCES")
  915. != debugProperties.end();
  916. if (this->Makefile->GetGlobalGenerator()->GetConfigureDoneCMP0026())
  917. {
  918. this->DebugSourcesDone = true;
  919. }
  920. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  921. "SOURCES", 0, 0);
  922. UNORDERED_SET<std::string> uniqueSrcs;
  923. bool contextDependentDirectSources = processSources(this,
  924. this->SourceEntries,
  925. files,
  926. uniqueSrcs,
  927. &dagChecker,
  928. config,
  929. debugSources);
  930. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  931. linkInterfaceSourcesEntries;
  932. AddInterfaceEntries(
  933. this, config, "INTERFACE_SOURCES",
  934. linkInterfaceSourcesEntries);
  935. std::vector<std::string>::size_type numFilesBefore = files.size();
  936. bool contextDependentInterfaceSources = processSources(this,
  937. linkInterfaceSourcesEntries,
  938. files,
  939. uniqueSrcs,
  940. &dagChecker,
  941. config,
  942. debugSources);
  943. if (!contextDependentDirectSources
  944. && !(contextDependentInterfaceSources && numFilesBefore < files.size()))
  945. {
  946. this->LinkImplementationLanguageIsContextDependent = false;
  947. }
  948. cmDeleteAll(linkInterfaceSourcesEntries);
  949. }
  950. //----------------------------------------------------------------------------
  951. void cmGeneratorTarget::GetSourceFiles(std::vector<cmSourceFile*> &files,
  952. const std::string& config) const
  953. {
  954. // Lookup any existing link implementation for this configuration.
  955. std::string key = cmSystemTools::UpperCase(config);
  956. if(!this->LinkImplementationLanguageIsContextDependent)
  957. {
  958. files = this->SourceFilesMap.begin()->second;
  959. return;
  960. }
  961. SourceFilesMapType::iterator
  962. it = this->SourceFilesMap.find(key);
  963. if(it != this->SourceFilesMap.end())
  964. {
  965. files = it->second;
  966. }
  967. else
  968. {
  969. std::vector<std::string> srcs;
  970. this->GetSourceFiles(srcs, config);
  971. std::set<cmSourceFile*> emitted;
  972. for(std::vector<std::string>::const_iterator i = srcs.begin();
  973. i != srcs.end(); ++i)
  974. {
  975. cmSourceFile* sf = this->Makefile->GetOrCreateSource(*i);
  976. if (emitted.insert(sf).second)
  977. {
  978. files.push_back(sf);
  979. }
  980. }
  981. this->SourceFilesMap[key] = files;
  982. }
  983. }
  984. //----------------------------------------------------------------------------
  985. std::string
  986. cmGeneratorTarget::GetCompilePDBName(const std::string& config) const
  987. {
  988. std::string prefix;
  989. std::string base;
  990. std::string suffix;
  991. this->GetFullNameInternal(config, false, prefix, base, suffix);
  992. // Check for a per-configuration output directory target property.
  993. std::string configUpper = cmSystemTools::UpperCase(config);
  994. std::string configProp = "COMPILE_PDB_NAME_";
  995. configProp += configUpper;
  996. const char* config_name = this->Target->GetProperty(configProp);
  997. if(config_name && *config_name)
  998. {
  999. return prefix + config_name + ".pdb";
  1000. }
  1001. const char* name = this->Target->GetProperty("COMPILE_PDB_NAME");
  1002. if(name && *name)
  1003. {
  1004. return prefix + name + ".pdb";
  1005. }
  1006. return "";
  1007. }
  1008. //----------------------------------------------------------------------------
  1009. std::string
  1010. cmGeneratorTarget::GetCompilePDBPath(const std::string& config) const
  1011. {
  1012. std::string dir = this->GetCompilePDBDirectory(config);
  1013. std::string name = this->GetCompilePDBName(config);
  1014. if(dir.empty() && !name.empty())
  1015. {
  1016. dir = this->Target->GetPDBDirectory(config);
  1017. }
  1018. if(!dir.empty())
  1019. {
  1020. dir += "/";
  1021. }
  1022. return dir + name;
  1023. }
  1024. //----------------------------------------------------------------------------
  1025. bool cmGeneratorTarget::HasSOName(const std::string& config) const
  1026. {
  1027. // soname is supported only for shared libraries and modules,
  1028. // and then only when the platform supports an soname flag.
  1029. return ((this->GetType() == cmTarget::SHARED_LIBRARY) &&
  1030. !this->GetPropertyAsBool("NO_SONAME") &&
  1031. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config)));
  1032. }
  1033. //----------------------------------------------------------------------------
  1034. bool
  1035. cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const
  1036. {
  1037. // Only executables and shared libraries can have an rpath and may
  1038. // need relinking.
  1039. if(this->GetType() != cmTarget::EXECUTABLE &&
  1040. this->GetType() != cmTarget::SHARED_LIBRARY &&
  1041. this->GetType() != cmTarget::MODULE_LIBRARY)
  1042. {
  1043. return false;
  1044. }
  1045. // If there is no install location this target will not be installed
  1046. // and therefore does not need relinking.
  1047. if(!this->Target->GetHaveInstallRule())
  1048. {
  1049. return false;
  1050. }
  1051. // If skipping all rpaths completely then no relinking is needed.
  1052. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1053. {
  1054. return false;
  1055. }
  1056. // If building with the install-tree rpath no relinking is needed.
  1057. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1058. {
  1059. return false;
  1060. }
  1061. // If chrpath is going to be used no relinking is needed.
  1062. if(this->IsChrpathUsed(config))
  1063. {
  1064. return false;
  1065. }
  1066. // Check for rpath support on this platform.
  1067. std::string ll = this->GetLinkerLanguage(config);
  1068. if(!ll.empty())
  1069. {
  1070. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1071. flagVar += ll;
  1072. flagVar += "_FLAG";
  1073. if(!this->Makefile->IsSet(flagVar))
  1074. {
  1075. // There is no rpath support on this platform so nothing needs
  1076. // relinking.
  1077. return false;
  1078. }
  1079. }
  1080. else
  1081. {
  1082. // No linker language is known. This error will be reported by
  1083. // other code.
  1084. return false;
  1085. }
  1086. // If either a build or install tree rpath is set then the rpath
  1087. // will likely change between the build tree and install tree and
  1088. // this target must be relinked.
  1089. return this->HaveBuildTreeRPATH(config)
  1090. || this->Target->HaveInstallTreeRPATH();
  1091. }
  1092. //----------------------------------------------------------------------------
  1093. bool cmGeneratorTarget::IsChrpathUsed(const std::string& config) const
  1094. {
  1095. // Only certain target types have an rpath.
  1096. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  1097. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1098. this->GetType() == cmTarget::EXECUTABLE))
  1099. {
  1100. return false;
  1101. }
  1102. // If the target will not be installed we do not need to change its
  1103. // rpath.
  1104. if(!this->Target->GetHaveInstallRule())
  1105. {
  1106. return false;
  1107. }
  1108. // Skip chrpath if skipping rpath altogether.
  1109. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  1110. {
  1111. return false;
  1112. }
  1113. // Skip chrpath if it does not need to be changed at install time.
  1114. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1115. {
  1116. return false;
  1117. }
  1118. // Allow the user to disable builtin chrpath explicitly.
  1119. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  1120. {
  1121. return false;
  1122. }
  1123. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1124. {
  1125. return true;
  1126. }
  1127. #if defined(CMAKE_USE_ELF_PARSER)
  1128. // Enable if the rpath flag uses a separator and the target uses ELF
  1129. // binaries.
  1130. std::string ll = this->GetLinkerLanguage(config);
  1131. if(!ll.empty())
  1132. {
  1133. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  1134. sepVar += ll;
  1135. sepVar += "_FLAG_SEP";
  1136. const char* sep = this->Makefile->GetDefinition(sepVar);
  1137. if(sep && *sep)
  1138. {
  1139. // TODO: Add ELF check to ABI detection and get rid of
  1140. // CMAKE_EXECUTABLE_FORMAT.
  1141. if(const char* fmt =
  1142. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  1143. {
  1144. return strcmp(fmt, "ELF") == 0;
  1145. }
  1146. }
  1147. }
  1148. #endif
  1149. static_cast<void>(config);
  1150. return false;
  1151. }
  1152. //----------------------------------------------------------------------------
  1153. std::string cmGeneratorTarget::GetSOName(const std::string& config) const
  1154. {
  1155. if(this->Target->IsImported())
  1156. {
  1157. // Lookup the imported soname.
  1158. if(cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config))
  1159. {
  1160. if(info->NoSOName)
  1161. {
  1162. // The imported library has no builtin soname so the name
  1163. // searched at runtime will be just the filename.
  1164. return cmSystemTools::GetFilenameName(info->Location);
  1165. }
  1166. else
  1167. {
  1168. // Use the soname given if any.
  1169. if(info->SOName.find("@rpath/") == 0)
  1170. {
  1171. return info->SOName.substr(6);
  1172. }
  1173. return info->SOName;
  1174. }
  1175. }
  1176. else
  1177. {
  1178. return "";
  1179. }
  1180. }
  1181. else
  1182. {
  1183. // Compute the soname that will be built.
  1184. std::string name;
  1185. std::string soName;
  1186. std::string realName;
  1187. std::string impName;
  1188. std::string pdbName;
  1189. this->GetLibraryNames(name, soName, realName,
  1190. impName, pdbName, config);
  1191. return soName;
  1192. }
  1193. }
  1194. //----------------------------------------------------------------------------
  1195. std::string
  1196. cmGeneratorTarget::GetAppBundleDirectory(const std::string& config,
  1197. bool contentOnly) const
  1198. {
  1199. std::string fpath = this->GetFullName(config, false);
  1200. fpath += ".app";
  1201. if(!this->Makefile->PlatformIsAppleIos())
  1202. {
  1203. fpath += "/Contents";
  1204. if(!contentOnly)
  1205. fpath += "/MacOS";
  1206. }
  1207. return fpath;
  1208. }
  1209. //----------------------------------------------------------------------------
  1210. bool cmGeneratorTarget::IsBundleOnApple() const
  1211. {
  1212. return this->Target->IsFrameworkOnApple()
  1213. || this->Target->IsAppBundleOnApple()
  1214. || this->Target->IsCFBundleOnApple();
  1215. }
  1216. //----------------------------------------------------------------------------
  1217. std::string cmGeneratorTarget::GetCFBundleDirectory(const std::string& config,
  1218. bool contentOnly) const
  1219. {
  1220. std::string fpath;
  1221. fpath += this->GetOutputName(config, false);
  1222. fpath += ".";
  1223. const char *ext = this->Target->GetProperty("BUNDLE_EXTENSION");
  1224. if (!ext)
  1225. {
  1226. if (this->Target->IsXCTestOnApple())
  1227. {
  1228. ext = "xctest";
  1229. }
  1230. else
  1231. {
  1232. ext = "bundle";
  1233. }
  1234. }
  1235. fpath += ext;
  1236. if(!this->Makefile->PlatformIsAppleIos())
  1237. {
  1238. fpath += "/Contents";
  1239. if(!contentOnly)
  1240. fpath += "/MacOS";
  1241. }
  1242. return fpath;
  1243. }
  1244. //----------------------------------------------------------------------------
  1245. std::string
  1246. cmGeneratorTarget::GetFrameworkDirectory(const std::string& config,
  1247. bool rootDir) const
  1248. {
  1249. std::string fpath;
  1250. fpath += this->GetOutputName(config, false);
  1251. fpath += ".framework";
  1252. if(!rootDir && !this->Makefile->PlatformIsAppleIos())
  1253. {
  1254. fpath += "/Versions/";
  1255. fpath += this->Target->GetFrameworkVersion();
  1256. }
  1257. return fpath;
  1258. }
  1259. //----------------------------------------------------------------------------
  1260. std::string
  1261. cmGeneratorTarget::GetFullName(const std::string& config, bool implib) const
  1262. {
  1263. if(this->Target->IsImported())
  1264. {
  1265. return this->Target->GetFullNameImported(config, implib);
  1266. }
  1267. else
  1268. {
  1269. return this->GetFullNameInternal(config, implib);
  1270. }
  1271. }
  1272. //----------------------------------------------------------------------------
  1273. std::string
  1274. cmGeneratorTarget::GetInstallNameDirForBuildTree(
  1275. const std::string& config) const
  1276. {
  1277. // If building directly for installation then the build tree install_name
  1278. // is the same as the install tree.
  1279. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  1280. {
  1281. return this->GetInstallNameDirForInstallTree();
  1282. }
  1283. // Use the build tree directory for the target.
  1284. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  1285. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1286. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  1287. {
  1288. std::string dir;
  1289. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1290. {
  1291. dir = "@rpath";
  1292. }
  1293. else
  1294. {
  1295. dir = this->Target->GetDirectory(config);
  1296. }
  1297. dir += "/";
  1298. return dir;
  1299. }
  1300. else
  1301. {
  1302. return "";
  1303. }
  1304. }
  1305. //----------------------------------------------------------------------------
  1306. std::string cmGeneratorTarget::GetInstallNameDirForInstallTree() const
  1307. {
  1308. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  1309. {
  1310. std::string dir;
  1311. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  1312. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  1313. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  1314. {
  1315. if(install_name_dir && *install_name_dir)
  1316. {
  1317. dir = install_name_dir;
  1318. dir += "/";
  1319. }
  1320. }
  1321. if(!install_name_dir)
  1322. {
  1323. if(this->Target->MacOSXRpathInstallNameDirDefault())
  1324. {
  1325. dir = "@rpath/";
  1326. }
  1327. }
  1328. return dir;
  1329. }
  1330. else
  1331. {
  1332. return "";
  1333. }
  1334. }
  1335. //----------------------------------------------------------------------------
  1336. class cmTargetCollectLinkLanguages
  1337. {
  1338. public:
  1339. cmTargetCollectLinkLanguages(cmGeneratorTarget const* target,
  1340. const std::string& config,
  1341. UNORDERED_SET<std::string>& languages,
  1342. cmTarget const* head):
  1343. Config(config), Languages(languages), HeadTarget(head),
  1344. Makefile(target->Target->GetMakefile()), Target(target)
  1345. { this->Visited.insert(target->Target); }
  1346. void Visit(cmLinkItem const& item)
  1347. {
  1348. if(!item.Target)
  1349. {
  1350. if(item.find("::") != std::string::npos)
  1351. {
  1352. bool noMessage = false;
  1353. cmake::MessageType messageType = cmake::FATAL_ERROR;
  1354. std::stringstream e;
  1355. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0028))
  1356. {
  1357. case cmPolicies::WARN:
  1358. {
  1359. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0028) << "\n";
  1360. messageType = cmake::AUTHOR_WARNING;
  1361. }
  1362. break;
  1363. case cmPolicies::OLD:
  1364. noMessage = true;
  1365. case cmPolicies::REQUIRED_IF_USED:
  1366. case cmPolicies::REQUIRED_ALWAYS:
  1367. case cmPolicies::NEW:
  1368. // Issue the fatal message.
  1369. break;
  1370. }
  1371. if(!noMessage)
  1372. {
  1373. e << "Target \"" << this->Target->GetName()
  1374. << "\" links to target \"" << item
  1375. << "\" but the target was not found. Perhaps a find_package() "
  1376. "call is missing for an IMPORTED target, or an ALIAS target is "
  1377. "missing?";
  1378. this->Target->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(
  1379. messageType, e.str(), this->Target->Target->GetBacktrace());
  1380. }
  1381. }
  1382. return;
  1383. }
  1384. if(!this->Visited.insert(item.Target).second)
  1385. {
  1386. return;
  1387. }
  1388. cmGeneratorTarget* gtgt =
  1389. this->Target->GetLocalGenerator()->GetGlobalGenerator()
  1390. ->GetGeneratorTarget(item.Target);
  1391. cmLinkInterface const* iface =
  1392. gtgt->GetLinkInterface(this->Config, this->HeadTarget);
  1393. if(!iface) { return; }
  1394. for(std::vector<std::string>::const_iterator
  1395. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  1396. {
  1397. this->Languages.insert(*li);
  1398. }
  1399. for(std::vector<cmLinkItem>::const_iterator
  1400. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  1401. {
  1402. this->Visit(*li);
  1403. }
  1404. }
  1405. private:
  1406. std::string Config;
  1407. UNORDERED_SET<std::string>& Languages;
  1408. cmTarget const* HeadTarget;
  1409. cmMakefile* Makefile;
  1410. const cmGeneratorTarget* Target;
  1411. std::set<cmTarget const*> Visited;
  1412. };
  1413. //----------------------------------------------------------------------------
  1414. cmGeneratorTarget::LinkClosure const*
  1415. cmGeneratorTarget::GetLinkClosure(const std::string& config) const
  1416. {
  1417. std::string key(cmSystemTools::UpperCase(config));
  1418. LinkClosureMapType::iterator
  1419. i = this->LinkClosureMap.find(key);
  1420. if(i == this->LinkClosureMap.end())
  1421. {
  1422. LinkClosure lc;
  1423. this->ComputeLinkClosure(config, lc);
  1424. LinkClosureMapType::value_type entry(key, lc);
  1425. i = this->LinkClosureMap.insert(entry).first;
  1426. }
  1427. return &i->second;
  1428. }
  1429. //----------------------------------------------------------------------------
  1430. class cmTargetSelectLinker
  1431. {
  1432. int Preference;
  1433. cmGeneratorTarget const* Target;
  1434. cmMakefile* Makefile;
  1435. cmGlobalGenerator* GG;
  1436. std::set<std::string> Preferred;
  1437. public:
  1438. cmTargetSelectLinker(cmGeneratorTarget const* target)
  1439. : Preference(0), Target(target)
  1440. {
  1441. this->Makefile = this->Target->Makefile;
  1442. this->GG = this->Target->GetLocalGenerator()->GetGlobalGenerator();
  1443. }
  1444. void Consider(const char* lang)
  1445. {
  1446. int preference = this->GG->GetLinkerPreference(lang);
  1447. if(preference > this->Preference)
  1448. {
  1449. this->Preference = preference;
  1450. this->Preferred.clear();
  1451. }
  1452. if(preference == this->Preference)
  1453. {
  1454. this->Preferred.insert(lang);
  1455. }
  1456. }
  1457. std::string Choose()
  1458. {
  1459. if(this->Preferred.empty())
  1460. {
  1461. return "";
  1462. }
  1463. else if(this->Preferred.size() > 1)
  1464. {
  1465. std::stringstream e;
  1466. e << "Target " << this->Target->GetName()
  1467. << " contains multiple languages with the highest linker preference"
  1468. << " (" << this->Preference << "):\n";
  1469. for(std::set<std::string>::const_iterator
  1470. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  1471. {
  1472. e << " " << *li << "\n";
  1473. }
  1474. e << "Set the LINKER_LANGUAGE property for this target.";
  1475. cmake* cm = this->Makefile->GetCMakeInstance();
  1476. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  1477. this->Target->Target->GetBacktrace());
  1478. }
  1479. return *this->Preferred.begin();
  1480. }
  1481. };
  1482. //----------------------------------------------------------------------------
  1483. void cmGeneratorTarget::ComputeLinkClosure(const std::string& config,
  1484. LinkClosure& lc) const
  1485. {
  1486. // Get languages built in this target.
  1487. UNORDERED_SET<std::string> languages;
  1488. cmLinkImplementation const* impl =
  1489. this->GetLinkImplementation(config);
  1490. assert(impl);
  1491. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1492. li != impl->Languages.end(); ++li)
  1493. {
  1494. languages.insert(*li);
  1495. }
  1496. // Add interface languages from linked targets.
  1497. cmTargetCollectLinkLanguages cll(this, config, languages, this->Target);
  1498. for(std::vector<cmLinkImplItem>::const_iterator li = impl->Libraries.begin();
  1499. li != impl->Libraries.end(); ++li)
  1500. {
  1501. cll.Visit(*li);
  1502. }
  1503. // Store the transitive closure of languages.
  1504. for(UNORDERED_SET<std::string>::const_iterator li = languages.begin();
  1505. li != languages.end(); ++li)
  1506. {
  1507. lc.Languages.push_back(*li);
  1508. }
  1509. // Choose the language whose linker should be used.
  1510. if(this->GetProperty("HAS_CXX"))
  1511. {
  1512. lc.LinkerLanguage = "CXX";
  1513. }
  1514. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  1515. {
  1516. lc.LinkerLanguage = linkerLang;
  1517. }
  1518. else
  1519. {
  1520. // Find the language with the highest preference value.
  1521. cmTargetSelectLinker tsl(this);
  1522. // First select from the languages compiled directly in this target.
  1523. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  1524. li != impl->Languages.end(); ++li)
  1525. {
  1526. tsl.Consider(li->c_str());
  1527. }
  1528. // Now consider languages that propagate from linked targets.
  1529. for(UNORDERED_SET<std::string>::const_iterator sit = languages.begin();
  1530. sit != languages.end(); ++sit)
  1531. {
  1532. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  1533. if(this->Makefile->IsOn(propagates))
  1534. {
  1535. tsl.Consider(sit->c_str());
  1536. }
  1537. }
  1538. lc.LinkerLanguage = tsl.Choose();
  1539. }
  1540. }
  1541. //----------------------------------------------------------------------------
  1542. void cmGeneratorTarget::GetFullNameComponents(std::string& prefix,
  1543. std::string& base,
  1544. std::string& suffix,
  1545. const std::string& config,
  1546. bool implib) const
  1547. {
  1548. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  1549. }
  1550. //----------------------------------------------------------------------------
  1551. std::string
  1552. cmGeneratorTarget::BuildMacContentDirectory(const std::string& base,
  1553. const std::string& config,
  1554. bool contentOnly) const
  1555. {
  1556. std::string fpath = base;
  1557. if(this->Target->IsAppBundleOnApple())
  1558. {
  1559. fpath += this->GetAppBundleDirectory(config, contentOnly);
  1560. }
  1561. if(this->Target->IsFrameworkOnApple())
  1562. {
  1563. fpath += this->GetFrameworkDirectory(config, contentOnly);
  1564. }
  1565. if(this->Target->IsCFBundleOnApple())
  1566. {
  1567. fpath += this->GetCFBundleDirectory(config, contentOnly);
  1568. }
  1569. return fpath;
  1570. }
  1571. //----------------------------------------------------------------------------
  1572. std::string
  1573. cmGeneratorTarget::GetMacContentDirectory(const std::string& config,
  1574. bool implib) const
  1575. {
  1576. // Start with the output directory for the target.
  1577. std::string fpath = this->Target->GetDirectory(config, implib);
  1578. fpath += "/";
  1579. bool contentOnly = true;
  1580. if(this->Target->IsFrameworkOnApple())
  1581. {
  1582. // additional files with a framework go into the version specific
  1583. // directory
  1584. contentOnly = false;
  1585. }
  1586. fpath = this->BuildMacContentDirectory(fpath, config, contentOnly);
  1587. return fpath;
  1588. }
  1589. //----------------------------------------------------------------------------
  1590. cmGeneratorTarget::CompileInfo const* cmGeneratorTarget::GetCompileInfo(
  1591. const std::string& config) const
  1592. {
  1593. // There is no compile information for imported targets.
  1594. if(this->IsImported())
  1595. {
  1596. return 0;
  1597. }
  1598. if(this->GetType() > cmTarget::OBJECT_LIBRARY)
  1599. {
  1600. std::string msg = "cmTarget::GetCompileInfo called for ";
  1601. msg += this->GetName();
  1602. msg += " which has type ";
  1603. msg += cmTarget::GetTargetTypeName(this->Target->GetType());
  1604. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  1605. return 0;
  1606. }
  1607. // Lookup/compute/cache the compile information for this configuration.
  1608. std::string config_upper;
  1609. if(!config.empty())
  1610. {
  1611. config_upper = cmSystemTools::UpperCase(config);
  1612. }
  1613. CompileInfoMapType::const_iterator i =
  1614. this->CompileInfoMap.find(config_upper);
  1615. if(i == this->CompileInfoMap.end())
  1616. {
  1617. CompileInfo info;
  1618. this->Target
  1619. ->ComputePDBOutputDir("COMPILE_PDB", config, info.CompilePdbDir);
  1620. CompileInfoMapType::value_type entry(config_upper, info);
  1621. i = this->CompileInfoMap.insert(entry).first;
  1622. }
  1623. return &i->second;
  1624. }
  1625. //----------------------------------------------------------------------------
  1626. std::string
  1627. cmGeneratorTarget::GetModuleDefinitionFile(const std::string& config) const
  1628. {
  1629. std::string data;
  1630. IMPLEMENT_VISIT_IMPL(ModuleDefinitionFile, COMMA std::string)
  1631. return data;
  1632. }
  1633. //----------------------------------------------------------------------------
  1634. void
  1635. cmGeneratorTarget::UseObjectLibraries(std::vector<std::string>& objs,
  1636. const std::string &config) const
  1637. {
  1638. std::vector<cmSourceFile const*> objectFiles;
  1639. this->GetExternalObjects(objectFiles, config);
  1640. std::vector<cmTarget*> objectLibraries;
  1641. for(std::vector<cmSourceFile const*>::const_iterator
  1642. it = objectFiles.begin(); it != objectFiles.end(); ++it)
  1643. {
  1644. std::string objLib = (*it)->GetObjectLibrary();
  1645. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  1646. {
  1647. objectLibraries.push_back(tgt);
  1648. }
  1649. }
  1650. std::vector<cmTarget*>::const_iterator end
  1651. = cmRemoveDuplicates(objectLibraries);
  1652. for(std::vector<cmTarget*>::const_iterator
  1653. ti = objectLibraries.begin();
  1654. ti != end; ++ti)
  1655. {
  1656. cmTarget* objLib = *ti;
  1657. cmGeneratorTarget* ogt =
  1658. this->GlobalGenerator->GetGeneratorTarget(objLib);
  1659. std::vector<cmSourceFile const*> objectSources;
  1660. ogt->GetObjectSources(objectSources, config);
  1661. for(std::vector<cmSourceFile const*>::const_iterator
  1662. si = objectSources.begin();
  1663. si != objectSources.end(); ++si)
  1664. {
  1665. std::string obj = ogt->ObjectDirectory;
  1666. obj += ogt->Objects[*si];
  1667. objs.push_back(obj);
  1668. }
  1669. }
  1670. }
  1671. //----------------------------------------------------------------------------
  1672. void cmGeneratorTarget::GetAutoUicOptions(std::vector<std::string> &result,
  1673. const std::string& config) const
  1674. {
  1675. const char *prop
  1676. = this->GetLinkInterfaceDependentStringProperty("AUTOUIC_OPTIONS",
  1677. config);
  1678. if (!prop)
  1679. {
  1680. return;
  1681. }
  1682. cmGeneratorExpression ge;
  1683. cmGeneratorExpressionDAGChecker dagChecker(
  1684. this->GetName(),
  1685. "AUTOUIC_OPTIONS", 0, 0);
  1686. cmSystemTools::ExpandListArgument(ge.Parse(prop)
  1687. ->Evaluate(this->Makefile,
  1688. config,
  1689. false,
  1690. this->Target,
  1691. &dagChecker),
  1692. result);
  1693. }
  1694. //----------------------------------------------------------------------------
  1695. void processILibs(const std::string& config,
  1696. cmTarget const* headTarget,
  1697. cmLinkItem const& item,
  1698. cmGlobalGenerator* gg,
  1699. std::vector<cmTarget const*>& tgts,
  1700. std::set<cmTarget const*>& emitted)
  1701. {
  1702. if (item.Target && emitted.insert(item.Target).second)
  1703. {
  1704. tgts.push_back(item.Target);
  1705. cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target);
  1706. if(cmLinkInterfaceLibraries const* iface =
  1707. gt->GetLinkInterfaceLibraries(config, headTarget, true))
  1708. {
  1709. for(std::vector<cmLinkItem>::const_iterator
  1710. it = iface->Libraries.begin();
  1711. it != iface->Libraries.end(); ++it)
  1712. {
  1713. processILibs(config, headTarget, *it, gg, tgts, emitted);
  1714. }
  1715. }
  1716. }
  1717. }
  1718. //----------------------------------------------------------------------------
  1719. const std::vector<const cmTarget*>&
  1720. cmGeneratorTarget::GetLinkImplementationClosure(
  1721. const std::string& config) const
  1722. {
  1723. LinkImplClosure& tgts =
  1724. this->LinkImplClosureMap[config];
  1725. if(!tgts.Done)
  1726. {
  1727. tgts.Done = true;
  1728. std::set<cmTarget const*> emitted;
  1729. cmLinkImplementationLibraries const* impl
  1730. = this->GetLinkImplementationLibraries(config);
  1731. for(std::vector<cmLinkImplItem>::const_iterator
  1732. it = impl->Libraries.begin();
  1733. it != impl->Libraries.end(); ++it)
  1734. {
  1735. processILibs(config, this->Target, *it,
  1736. this->LocalGenerator->GetGlobalGenerator(),
  1737. tgts , emitted);
  1738. }
  1739. }
  1740. return tgts;
  1741. }
  1742. //----------------------------------------------------------------------------
  1743. class cmTargetTraceDependencies
  1744. {
  1745. public:
  1746. cmTargetTraceDependencies(cmGeneratorTarget* target);
  1747. void Trace();
  1748. private:
  1749. cmTarget* Target;
  1750. cmGeneratorTarget* GeneratorTarget;
  1751. cmMakefile* Makefile;
  1752. cmGlobalGenerator const* GlobalGenerator;
  1753. typedef cmGeneratorTarget::SourceEntry SourceEntry;
  1754. SourceEntry* CurrentEntry;
  1755. std::queue<cmSourceFile*> SourceQueue;
  1756. std::set<cmSourceFile*> SourcesQueued;
  1757. typedef std::map<std::string, cmSourceFile*> NameMapType;
  1758. NameMapType NameMap;
  1759. std::vector<std::string> NewSources;
  1760. void QueueSource(cmSourceFile* sf);
  1761. void FollowName(std::string const& name);
  1762. void FollowNames(std::vector<std::string> const& names);
  1763. bool IsUtility(std::string const& dep);
  1764. void CheckCustomCommand(cmCustomCommand const& cc);
  1765. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1766. void FollowCommandDepends(cmCustomCommand const& cc,
  1767. const std::string& config,
  1768. std::set<std::string>& emitted);
  1769. };
  1770. //----------------------------------------------------------------------------
  1771. cmTargetTraceDependencies
  1772. ::cmTargetTraceDependencies(cmGeneratorTarget* target):
  1773. Target(target->Target), GeneratorTarget(target)
  1774. {
  1775. // Convenience.
  1776. this->Makefile = this->Target->GetMakefile();
  1777. this->GlobalGenerator = target->GetLocalGenerator()->GetGlobalGenerator();
  1778. this->CurrentEntry = 0;
  1779. // Queue all the source files already specified for the target.
  1780. if (this->Target->GetType() != cmTarget::INTERFACE_LIBRARY)
  1781. {
  1782. std::vector<std::string> configs;
  1783. this->Makefile->GetConfigurations(configs);
  1784. if (configs.empty())
  1785. {
  1786. configs.push_back("");
  1787. }
  1788. std::set<cmSourceFile*> emitted;
  1789. for(std::vector<std::string>::const_iterator ci = configs.begin();
  1790. ci != configs.end(); ++ci)
  1791. {
  1792. std::vector<cmSourceFile*> sources;
  1793. this->GeneratorTarget->GetSourceFiles(sources, *ci);
  1794. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1795. si != sources.end(); ++si)
  1796. {
  1797. cmSourceFile* sf = *si;
  1798. const std::set<cmTarget const*> tgts =
  1799. this->GlobalGenerator->GetFilenameTargetDepends(sf);
  1800. if (tgts.find(this->Target) != tgts.end())
  1801. {
  1802. std::ostringstream e;
  1803. e << "Evaluation output file\n \"" << sf->GetFullPath()
  1804. << "\"\ndepends on the sources of a target it is used in. This "
  1805. "is a dependency loop and is not allowed.";
  1806. this->GeneratorTarget
  1807. ->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  1808. return;
  1809. }
  1810. if(emitted.insert(sf).second && this->SourcesQueued.insert(sf).second)
  1811. {
  1812. this->SourceQueue.push(sf);
  1813. }
  1814. }
  1815. }
  1816. }
  1817. // Queue pre-build, pre-link, and post-build rule dependencies.
  1818. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1819. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1820. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1821. }
  1822. //----------------------------------------------------------------------------
  1823. void cmTargetTraceDependencies::Trace()
  1824. {
  1825. // Process one dependency at a time until the queue is empty.
  1826. while(!this->SourceQueue.empty())
  1827. {
  1828. // Get the next source from the queue.
  1829. cmSourceFile* sf = this->SourceQueue.front();
  1830. this->SourceQueue.pop();
  1831. this->CurrentEntry = &this->GeneratorTarget->SourceDepends[sf];
  1832. // Queue dependencies added explicitly by the user.
  1833. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1834. {
  1835. std::vector<std::string> objDeps;
  1836. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1837. for(std::vector<std::string>::iterator odi = objDeps.begin();
  1838. odi != objDeps.end(); ++odi)
  1839. {
  1840. if (cmSystemTools::FileIsFullPath(*odi))
  1841. {
  1842. *odi = cmSystemTools::CollapseFullPath(*odi);
  1843. }
  1844. }
  1845. this->FollowNames(objDeps);
  1846. }
  1847. // Queue the source needed to generate this file, if any.
  1848. this->FollowName(sf->GetFullPath());
  1849. // Queue dependencies added programatically by commands.
  1850. this->FollowNames(sf->GetDepends());
  1851. // Queue custom command dependencies.
  1852. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1853. {
  1854. this->CheckCustomCommand(*cc);
  1855. }
  1856. }
  1857. this->CurrentEntry = 0;
  1858. this->GeneratorTarget->AddTracedSources(this->NewSources);
  1859. }
  1860. //----------------------------------------------------------------------------
  1861. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1862. {
  1863. if(this->SourcesQueued.insert(sf).second)
  1864. {
  1865. this->SourceQueue.push(sf);
  1866. // Make sure this file is in the target at the end.
  1867. this->NewSources.push_back(sf->GetFullPath());
  1868. }
  1869. }
  1870. //----------------------------------------------------------------------------
  1871. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1872. {
  1873. NameMapType::iterator i = this->NameMap.find(name);
  1874. if(i == this->NameMap.end())
  1875. {
  1876. // Check if we know how to generate this file.
  1877. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name);
  1878. NameMapType::value_type entry(name, sf);
  1879. i = this->NameMap.insert(entry).first;
  1880. }
  1881. if(cmSourceFile* sf = i->second)
  1882. {
  1883. // Record the dependency we just followed.
  1884. if(this->CurrentEntry)
  1885. {
  1886. this->CurrentEntry->Depends.push_back(sf);
  1887. }
  1888. this->QueueSource(sf);
  1889. }
  1890. }
  1891. //----------------------------------------------------------------------------
  1892. void
  1893. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1894. {
  1895. for(std::vector<std::string>::const_iterator i = names.begin();
  1896. i != names.end(); ++i)
  1897. {
  1898. this->FollowName(*i);
  1899. }
  1900. }
  1901. //----------------------------------------------------------------------------
  1902. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1903. {
  1904. // Dependencies on targets (utilities) are supposed to be named by
  1905. // just the target name. However for compatibility we support
  1906. // naming the output file generated by the target (assuming there is
  1907. // no output-name property which old code would not have set). In
  1908. // that case the target name will be the file basename of the
  1909. // dependency.
  1910. std::string util = cmSystemTools::GetFilenameName(dep);
  1911. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1912. {
  1913. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1914. }
  1915. // Check for a target with this name.
  1916. if(cmGeneratorTarget* t
  1917. = this->Makefile->FindGeneratorTargetToUse(util))
  1918. {
  1919. // If we find the target and the dep was given as a full path,
  1920. // then make sure it was not a full path to something else, and
  1921. // the fact that the name matched a target was just a coincidence.
  1922. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1923. {
  1924. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1925. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1926. {
  1927. // This is really only for compatibility so we do not need to
  1928. // worry about configuration names and output names.
  1929. std::string tLocation = t->GetLocationForBuild();
  1930. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1931. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1932. depLocation = cmSystemTools::CollapseFullPath(depLocation);
  1933. tLocation = cmSystemTools::CollapseFullPath(tLocation);
  1934. if(depLocation == tLocation)
  1935. {
  1936. this->Target->AddUtility(util);
  1937. return true;
  1938. }
  1939. }
  1940. }
  1941. else
  1942. {
  1943. // The original name of the dependency was not a full path. It
  1944. // must name a target, so add the target-level dependency.
  1945. this->Target->AddUtility(util);
  1946. return true;
  1947. }
  1948. }
  1949. // The dependency does not name a target built in this project.
  1950. return false;
  1951. }
  1952. //----------------------------------------------------------------------------
  1953. void
  1954. cmTargetTraceDependencies
  1955. ::CheckCustomCommand(cmCustomCommand const& cc)
  1956. {
  1957. // Transform command names that reference targets built in this
  1958. // project to corresponding target-level dependencies.
  1959. cmGeneratorExpression ge(cc.GetBacktrace());
  1960. // Add target-level dependencies referenced by generator expressions.
  1961. std::set<cmTarget*> targets;
  1962. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1963. cit != cc.GetCommandLines().end(); ++cit)
  1964. {
  1965. std::string const& command = *cit->begin();
  1966. // Check for a target with this name.
  1967. if(cmTarget* t = this->Makefile->FindTargetToUse(command))
  1968. {
  1969. if(t->GetType() == cmTarget::EXECUTABLE)
  1970. {
  1971. // The command refers to an executable target built in
  1972. // this project. Add the target-level dependency to make
  1973. // sure the executable is up to date before this custom
  1974. // command possibly runs.
  1975. this->Target->AddUtility(command);
  1976. }
  1977. }
  1978. // Check for target references in generator expressions.
  1979. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1980. cli != cit->end(); ++cli)
  1981. {
  1982. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1983. = ge.Parse(*cli);
  1984. cge->Evaluate(this->Makefile, "", true);
  1985. std::set<cmTarget*> geTargets = cge->GetTargets();
  1986. targets.insert(geTargets.begin(), geTargets.end());
  1987. }
  1988. }
  1989. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1990. ti != targets.end(); ++ti)
  1991. {
  1992. this->Target->AddUtility((*ti)->GetName());
  1993. }
  1994. // Queue the custom command dependencies.
  1995. std::vector<std::string> configs;
  1996. std::set<std::string> emitted;
  1997. this->Makefile->GetConfigurations(configs);
  1998. if (configs.empty())
  1999. {
  2000. configs.push_back("");
  2001. }
  2002. for(std::vector<std::string>::const_iterator ci = configs.begin();
  2003. ci != configs.end(); ++ci)
  2004. {
  2005. this->FollowCommandDepends(cc, *ci, emitted);
  2006. }
  2007. }
  2008. //----------------------------------------------------------------------------
  2009. void cmTargetTraceDependencies::FollowCommandDepends(cmCustomCommand const& cc,
  2010. const std::string& config,
  2011. std::set<std::string>& emitted)
  2012. {
  2013. cmCustomCommandGenerator ccg(cc, config,
  2014. this->GeneratorTarget->LocalGenerator);
  2015. const std::vector<std::string>& depends = ccg.GetDepends();
  2016. for(std::vector<std::string>::const_iterator di = depends.begin();
  2017. di != depends.end(); ++di)
  2018. {
  2019. std::string const& dep = *di;
  2020. if(emitted.insert(dep).second)
  2021. {
  2022. if(!this->IsUtility(dep))
  2023. {
  2024. // The dependency does not name a target and may be a file we
  2025. // know how to generate. Queue it.
  2026. this->FollowName(dep);
  2027. }
  2028. }
  2029. }
  2030. }
  2031. //----------------------------------------------------------------------------
  2032. void
  2033. cmTargetTraceDependencies
  2034. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  2035. {
  2036. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  2037. cli != commands.end(); ++cli)
  2038. {
  2039. this->CheckCustomCommand(*cli);
  2040. }
  2041. }
  2042. //----------------------------------------------------------------------------
  2043. void cmGeneratorTarget::TraceDependencies()
  2044. {
  2045. // CMake-generated targets have no dependencies to trace. Normally tracing
  2046. // would find nothing anyway, but when building CMake itself the "install"
  2047. // target command ends up referencing the "cmake" target but we do not
  2048. // really want the dependency because "install" depend on "all" anyway.
  2049. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  2050. {
  2051. return;
  2052. }
  2053. // Use a helper object to trace the dependencies.
  2054. cmTargetTraceDependencies tracer(this);
  2055. tracer.Trace();
  2056. }
  2057. std::string
  2058. cmGeneratorTarget::GetCompilePDBDirectory(const std::string& config) const
  2059. {
  2060. if(CompileInfo const* info = this->GetCompileInfo(config))
  2061. {
  2062. return info->CompilePdbDir;
  2063. }
  2064. return "";
  2065. }
  2066. //----------------------------------------------------------------------------
  2067. void cmGeneratorTarget::GetAppleArchs(const std::string& config,
  2068. std::vector<std::string>& archVec) const
  2069. {
  2070. const char* archs = 0;
  2071. if(!config.empty())
  2072. {
  2073. std::string defVarName = "OSX_ARCHITECTURES_";
  2074. defVarName += cmSystemTools::UpperCase(config);
  2075. archs = this->Target->GetProperty(defVarName);
  2076. }
  2077. if(!archs)
  2078. {
  2079. archs = this->Target->GetProperty("OSX_ARCHITECTURES");
  2080. }
  2081. if(archs)
  2082. {
  2083. cmSystemTools::ExpandListArgument(std::string(archs), archVec);
  2084. }
  2085. }
  2086. //----------------------------------------------------------------------------
  2087. std::string
  2088. cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang,
  2089. std::string const& config) const
  2090. {
  2091. switch(this->GetType())
  2092. {
  2093. case cmTarget::STATIC_LIBRARY:
  2094. {
  2095. std::string var = "CMAKE_" + lang + "_CREATE_STATIC_LIBRARY";
  2096. if(this->GetFeatureAsBool(
  2097. "INTERPROCEDURAL_OPTIMIZATION", config))
  2098. {
  2099. std::string varIPO = var + "_IPO";
  2100. if(this->Makefile->GetDefinition(varIPO))
  2101. {
  2102. return varIPO;
  2103. }
  2104. }
  2105. return var;
  2106. }
  2107. case cmTarget::SHARED_LIBRARY:
  2108. return "CMAKE_" + lang + "_CREATE_SHARED_LIBRARY";
  2109. case cmTarget::MODULE_LIBRARY:
  2110. return "CMAKE_" + lang + "_CREATE_SHARED_MODULE";
  2111. case cmTarget::EXECUTABLE:
  2112. return "CMAKE_" + lang + "_LINK_EXECUTABLE";
  2113. default:
  2114. break;
  2115. }
  2116. return "";
  2117. }
  2118. //----------------------------------------------------------------------------
  2119. static void processIncludeDirectories(cmGeneratorTarget const* tgt,
  2120. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2121. std::vector<std::string> &includes,
  2122. UNORDERED_SET<std::string> &uniqueIncludes,
  2123. cmGeneratorExpressionDAGChecker *dagChecker,
  2124. const std::string& config, bool debugIncludes,
  2125. const std::string& language)
  2126. {
  2127. cmMakefile *mf = tgt->Target->GetMakefile();
  2128. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2129. it = entries.begin(), end = entries.end(); it != end; ++it)
  2130. {
  2131. cmLinkImplItem const& item = (*it)->LinkImplItem;
  2132. std::string const& targetName = item;
  2133. bool const fromImported = item.Target && item.Target->IsImported();
  2134. bool const checkCMP0027 = item.FromGenex;
  2135. std::vector<std::string> entryIncludes;
  2136. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2137. config,
  2138. false,
  2139. tgt->Target,
  2140. dagChecker, language),
  2141. entryIncludes);
  2142. std::string usedIncludes;
  2143. for(std::vector<std::string>::iterator
  2144. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  2145. {
  2146. if (fromImported
  2147. && !cmSystemTools::FileExists(li->c_str()))
  2148. {
  2149. std::ostringstream e;
  2150. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2151. if (checkCMP0027)
  2152. {
  2153. switch(tgt->Target->GetPolicyStatusCMP0027())
  2154. {
  2155. case cmPolicies::WARN:
  2156. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n";
  2157. case cmPolicies::OLD:
  2158. messageType = cmake::AUTHOR_WARNING;
  2159. break;
  2160. case cmPolicies::REQUIRED_ALWAYS:
  2161. case cmPolicies::REQUIRED_IF_USED:
  2162. case cmPolicies::NEW:
  2163. break;
  2164. }
  2165. }
  2166. e << "Imported target \"" << targetName << "\" includes "
  2167. "non-existent path\n \"" << *li << "\"\nin its "
  2168. "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n"
  2169. "* The path was deleted, renamed, or moved to another "
  2170. "location.\n"
  2171. "* An install or uninstall procedure did not complete "
  2172. "successfully.\n"
  2173. "* The installation package was faulty and references files it "
  2174. "does not provide.\n";
  2175. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2176. return;
  2177. }
  2178. if (!cmSystemTools::FileIsFullPath(li->c_str()))
  2179. {
  2180. std::ostringstream e;
  2181. bool noMessage = false;
  2182. cmake::MessageType messageType = cmake::FATAL_ERROR;
  2183. if (!targetName.empty())
  2184. {
  2185. e << "Target \"" << targetName << "\" contains relative "
  2186. "path in its INTERFACE_INCLUDE_DIRECTORIES:\n"
  2187. " \"" << *li << "\"";
  2188. }
  2189. else
  2190. {
  2191. switch(tgt->Target->GetPolicyStatusCMP0021())
  2192. {
  2193. case cmPolicies::WARN:
  2194. {
  2195. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n";
  2196. messageType = cmake::AUTHOR_WARNING;
  2197. }
  2198. break;
  2199. case cmPolicies::OLD:
  2200. noMessage = true;
  2201. case cmPolicies::REQUIRED_IF_USED:
  2202. case cmPolicies::REQUIRED_ALWAYS:
  2203. case cmPolicies::NEW:
  2204. // Issue the fatal message.
  2205. break;
  2206. }
  2207. e << "Found relative path while evaluating include directories of "
  2208. "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n";
  2209. }
  2210. if (!noMessage)
  2211. {
  2212. tgt->GetLocalGenerator()->IssueMessage(messageType, e.str());
  2213. if (messageType == cmake::FATAL_ERROR)
  2214. {
  2215. return;
  2216. }
  2217. }
  2218. }
  2219. if (!cmSystemTools::IsOff(li->c_str()))
  2220. {
  2221. cmSystemTools::ConvertToUnixSlashes(*li);
  2222. }
  2223. std::string inc = *li;
  2224. if(uniqueIncludes.insert(inc).second)
  2225. {
  2226. includes.push_back(inc);
  2227. if (debugIncludes)
  2228. {
  2229. usedIncludes += " * " + inc + "\n";
  2230. }
  2231. }
  2232. }
  2233. if (!usedIncludes.empty())
  2234. {
  2235. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2236. std::string("Used includes for target ")
  2237. + tgt->GetName() + ":\n"
  2238. + usedIncludes, (*it)->ge->GetBacktrace());
  2239. }
  2240. }
  2241. }
  2242. //----------------------------------------------------------------------------
  2243. std::vector<std::string>
  2244. cmGeneratorTarget::GetIncludeDirectories(const std::string& config,
  2245. const std::string& lang) const
  2246. {
  2247. std::vector<std::string> includes;
  2248. UNORDERED_SET<std::string> uniqueIncludes;
  2249. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2250. "INCLUDE_DIRECTORIES", 0, 0);
  2251. std::vector<std::string> debugProperties;
  2252. const char *debugProp =
  2253. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2254. if (debugProp)
  2255. {
  2256. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2257. }
  2258. bool debugIncludes = !this->DebugIncludesDone
  2259. && std::find(debugProperties.begin(),
  2260. debugProperties.end(),
  2261. "INCLUDE_DIRECTORIES")
  2262. != debugProperties.end();
  2263. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2264. {
  2265. this->DebugIncludesDone = true;
  2266. }
  2267. processIncludeDirectories(this,
  2268. this->IncludeDirectoriesEntries,
  2269. includes,
  2270. uniqueIncludes,
  2271. &dagChecker,
  2272. config,
  2273. debugIncludes,
  2274. lang);
  2275. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2276. linkInterfaceIncludeDirectoriesEntries;
  2277. AddInterfaceEntries(
  2278. this, config, "INTERFACE_INCLUDE_DIRECTORIES",
  2279. linkInterfaceIncludeDirectoriesEntries);
  2280. if(this->Makefile->IsOn("APPLE"))
  2281. {
  2282. cmLinkImplementationLibraries const* impl =
  2283. this->GetLinkImplementationLibraries(config);
  2284. for(std::vector<cmLinkImplItem>::const_iterator
  2285. it = impl->Libraries.begin();
  2286. it != impl->Libraries.end(); ++it)
  2287. {
  2288. std::string libDir = cmSystemTools::CollapseFullPath(*it);
  2289. static cmsys::RegularExpression
  2290. frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");
  2291. if(!frameworkCheck.find(libDir))
  2292. {
  2293. continue;
  2294. }
  2295. libDir = frameworkCheck.match(1);
  2296. cmGeneratorExpression ge;
  2297. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2298. ge.Parse(libDir.c_str());
  2299. linkInterfaceIncludeDirectoriesEntries
  2300. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2301. }
  2302. }
  2303. processIncludeDirectories(this,
  2304. linkInterfaceIncludeDirectoriesEntries,
  2305. includes,
  2306. uniqueIncludes,
  2307. &dagChecker,
  2308. config,
  2309. debugIncludes,
  2310. lang);
  2311. cmDeleteAll(linkInterfaceIncludeDirectoriesEntries);
  2312. return includes;
  2313. }
  2314. //----------------------------------------------------------------------------
  2315. static void processCompileOptionsInternal(cmGeneratorTarget const* tgt,
  2316. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2317. std::vector<std::string> &options,
  2318. UNORDERED_SET<std::string> &uniqueOptions,
  2319. cmGeneratorExpressionDAGChecker *dagChecker,
  2320. const std::string& config, bool debugOptions, const char *logName,
  2321. std::string const& language)
  2322. {
  2323. cmMakefile *mf = tgt->Target->GetMakefile();
  2324. for (std::vector<cmGeneratorTarget::TargetPropertyEntry*>::const_iterator
  2325. it = entries.begin(), end = entries.end(); it != end; ++it)
  2326. {
  2327. std::vector<std::string> entryOptions;
  2328. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
  2329. config,
  2330. false,
  2331. tgt->Target,
  2332. dagChecker,
  2333. language),
  2334. entryOptions);
  2335. std::string usedOptions;
  2336. for(std::vector<std::string>::iterator
  2337. li = entryOptions.begin(); li != entryOptions.end(); ++li)
  2338. {
  2339. std::string const& opt = *li;
  2340. if(uniqueOptions.insert(opt).second)
  2341. {
  2342. options.push_back(opt);
  2343. if (debugOptions)
  2344. {
  2345. usedOptions += " * " + opt + "\n";
  2346. }
  2347. }
  2348. }
  2349. if (!usedOptions.empty())
  2350. {
  2351. tgt->GetLocalGenerator()->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2352. std::string("Used compile ") + logName
  2353. + std::string(" for target ")
  2354. + tgt->GetName() + ":\n"
  2355. + usedOptions, (*it)->ge->GetBacktrace());
  2356. }
  2357. }
  2358. }
  2359. //----------------------------------------------------------------------------
  2360. static void processCompileOptions(cmGeneratorTarget const* tgt,
  2361. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2362. std::vector<std::string> &options,
  2363. UNORDERED_SET<std::string> &uniqueOptions,
  2364. cmGeneratorExpressionDAGChecker *dagChecker,
  2365. const std::string& config, bool debugOptions,
  2366. std::string const& language)
  2367. {
  2368. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2369. dagChecker, config, debugOptions, "options",
  2370. language);
  2371. }
  2372. //----------------------------------------------------------------------------
  2373. void cmGeneratorTarget::GetCompileOptions(std::vector<std::string> &result,
  2374. const std::string& config,
  2375. const std::string& language) const
  2376. {
  2377. UNORDERED_SET<std::string> uniqueOptions;
  2378. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2379. "COMPILE_OPTIONS", 0, 0);
  2380. std::vector<std::string> debugProperties;
  2381. const char *debugProp =
  2382. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2383. if (debugProp)
  2384. {
  2385. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2386. }
  2387. bool debugOptions = !this->DebugCompileOptionsDone
  2388. && std::find(debugProperties.begin(),
  2389. debugProperties.end(),
  2390. "COMPILE_OPTIONS")
  2391. != debugProperties.end();
  2392. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2393. {
  2394. this->DebugCompileOptionsDone = true;
  2395. }
  2396. processCompileOptions(this,
  2397. this->CompileOptionsEntries,
  2398. result,
  2399. uniqueOptions,
  2400. &dagChecker,
  2401. config,
  2402. debugOptions,
  2403. language);
  2404. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2405. linkInterfaceCompileOptionsEntries;
  2406. AddInterfaceEntries(
  2407. this, config, "INTERFACE_COMPILE_OPTIONS",
  2408. linkInterfaceCompileOptionsEntries);
  2409. processCompileOptions(this,
  2410. linkInterfaceCompileOptionsEntries,
  2411. result,
  2412. uniqueOptions,
  2413. &dagChecker,
  2414. config,
  2415. debugOptions,
  2416. language);
  2417. cmDeleteAll(linkInterfaceCompileOptionsEntries);
  2418. }
  2419. //----------------------------------------------------------------------------
  2420. static void processCompileFeatures(cmGeneratorTarget const* tgt,
  2421. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2422. std::vector<std::string> &options,
  2423. UNORDERED_SET<std::string> &uniqueOptions,
  2424. cmGeneratorExpressionDAGChecker *dagChecker,
  2425. const std::string& config, bool debugOptions)
  2426. {
  2427. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2428. dagChecker, config, debugOptions, "features",
  2429. std::string());
  2430. }
  2431. //----------------------------------------------------------------------------
  2432. void cmGeneratorTarget::GetCompileFeatures(std::vector<std::string> &result,
  2433. const std::string& config) const
  2434. {
  2435. UNORDERED_SET<std::string> uniqueFeatures;
  2436. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2437. "COMPILE_FEATURES",
  2438. 0, 0);
  2439. std::vector<std::string> debugProperties;
  2440. const char *debugProp =
  2441. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2442. if (debugProp)
  2443. {
  2444. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2445. }
  2446. bool debugFeatures = !this->DebugCompileFeaturesDone
  2447. && std::find(debugProperties.begin(),
  2448. debugProperties.end(),
  2449. "COMPILE_FEATURES")
  2450. != debugProperties.end();
  2451. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2452. {
  2453. this->DebugCompileFeaturesDone = true;
  2454. }
  2455. processCompileFeatures(this,
  2456. this->CompileFeaturesEntries,
  2457. result,
  2458. uniqueFeatures,
  2459. &dagChecker,
  2460. config,
  2461. debugFeatures);
  2462. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2463. linkInterfaceCompileFeaturesEntries;
  2464. AddInterfaceEntries(
  2465. this, config, "INTERFACE_COMPILE_FEATURES",
  2466. linkInterfaceCompileFeaturesEntries);
  2467. processCompileFeatures(this,
  2468. linkInterfaceCompileFeaturesEntries,
  2469. result,
  2470. uniqueFeatures,
  2471. &dagChecker,
  2472. config,
  2473. debugFeatures);
  2474. cmDeleteAll(linkInterfaceCompileFeaturesEntries);
  2475. }
  2476. //----------------------------------------------------------------------------
  2477. static void processCompileDefinitions(cmGeneratorTarget const* tgt,
  2478. const std::vector<cmGeneratorTarget::TargetPropertyEntry*> &entries,
  2479. std::vector<std::string> &options,
  2480. UNORDERED_SET<std::string> &uniqueOptions,
  2481. cmGeneratorExpressionDAGChecker *dagChecker,
  2482. const std::string& config, bool debugOptions,
  2483. std::string const& language)
  2484. {
  2485. processCompileOptionsInternal(tgt, entries, options, uniqueOptions,
  2486. dagChecker, config, debugOptions,
  2487. "definitions", language);
  2488. }
  2489. //----------------------------------------------------------------------------
  2490. void cmGeneratorTarget::GetCompileDefinitions(std::vector<std::string> &list,
  2491. const std::string& config,
  2492. const std::string& language) const
  2493. {
  2494. UNORDERED_SET<std::string> uniqueOptions;
  2495. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(),
  2496. "COMPILE_DEFINITIONS", 0, 0);
  2497. std::vector<std::string> debugProperties;
  2498. const char *debugProp =
  2499. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2500. if (debugProp)
  2501. {
  2502. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2503. }
  2504. bool debugDefines = !this->DebugCompileDefinitionsDone
  2505. && std::find(debugProperties.begin(),
  2506. debugProperties.end(),
  2507. "COMPILE_DEFINITIONS")
  2508. != debugProperties.end();
  2509. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  2510. {
  2511. this->DebugCompileDefinitionsDone = true;
  2512. }
  2513. processCompileDefinitions(this,
  2514. this->CompileDefinitionsEntries,
  2515. list,
  2516. uniqueOptions,
  2517. &dagChecker,
  2518. config,
  2519. debugDefines,
  2520. language);
  2521. std::vector<cmGeneratorTarget::TargetPropertyEntry*>
  2522. linkInterfaceCompileDefinitionsEntries;
  2523. AddInterfaceEntries(
  2524. this, config, "INTERFACE_COMPILE_DEFINITIONS",
  2525. linkInterfaceCompileDefinitionsEntries);
  2526. if (!config.empty())
  2527. {
  2528. std::string configPropName = "COMPILE_DEFINITIONS_"
  2529. + cmSystemTools::UpperCase(config);
  2530. const char *configProp = this->Target->GetProperty(configPropName);
  2531. if (configProp)
  2532. {
  2533. switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043))
  2534. {
  2535. case cmPolicies::WARN:
  2536. {
  2537. std::ostringstream e;
  2538. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043);
  2539. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING,
  2540. e.str());
  2541. }
  2542. case cmPolicies::OLD:
  2543. {
  2544. cmGeneratorExpression ge;
  2545. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge =
  2546. ge.Parse(configProp);
  2547. linkInterfaceCompileDefinitionsEntries
  2548. .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge));
  2549. }
  2550. break;
  2551. case cmPolicies::NEW:
  2552. case cmPolicies::REQUIRED_ALWAYS:
  2553. case cmPolicies::REQUIRED_IF_USED:
  2554. break;
  2555. }
  2556. }
  2557. }
  2558. processCompileDefinitions(this,
  2559. linkInterfaceCompileDefinitionsEntries,
  2560. list,
  2561. uniqueOptions,
  2562. &dagChecker,
  2563. config,
  2564. debugDefines,
  2565. language);
  2566. cmDeleteAll(linkInterfaceCompileDefinitionsEntries);
  2567. }
  2568. //----------------------------------------------------------------------------
  2569. void cmGeneratorTarget::ComputeTargetManifest(
  2570. const std::string& config) const
  2571. {
  2572. if (this->Target->IsImported())
  2573. {
  2574. return;
  2575. }
  2576. cmGlobalGenerator* gg = this->LocalGenerator->GetGlobalGenerator();
  2577. // Get the names.
  2578. std::string name;
  2579. std::string soName;
  2580. std::string realName;
  2581. std::string impName;
  2582. std::string pdbName;
  2583. if(this->GetType() == cmTarget::EXECUTABLE)
  2584. {
  2585. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2586. }
  2587. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2588. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2589. this->GetType() == cmTarget::MODULE_LIBRARY)
  2590. {
  2591. this->GetLibraryNames(name, soName, realName, impName, pdbName,
  2592. config);
  2593. }
  2594. else
  2595. {
  2596. return;
  2597. }
  2598. // Get the directory.
  2599. std::string dir = this->Target->GetDirectory(config, false);
  2600. // Add each name.
  2601. std::string f;
  2602. if(!name.empty())
  2603. {
  2604. f = dir;
  2605. f += "/";
  2606. f += name;
  2607. gg->AddToManifest(f);
  2608. }
  2609. if(!soName.empty())
  2610. {
  2611. f = dir;
  2612. f += "/";
  2613. f += soName;
  2614. gg->AddToManifest(f);
  2615. }
  2616. if(!realName.empty())
  2617. {
  2618. f = dir;
  2619. f += "/";
  2620. f += realName;
  2621. gg->AddToManifest(f);
  2622. }
  2623. if(!pdbName.empty())
  2624. {
  2625. f = dir;
  2626. f += "/";
  2627. f += pdbName;
  2628. gg->AddToManifest(f);
  2629. }
  2630. if(!impName.empty())
  2631. {
  2632. f = this->Target->GetDirectory(config, true);
  2633. f += "/";
  2634. f += impName;
  2635. gg->AddToManifest(f);
  2636. }
  2637. }
  2638. //----------------------------------------------------------------------------
  2639. std::string cmGeneratorTarget::GetFullPath(const std::string& config,
  2640. bool implib, bool realname) const
  2641. {
  2642. if(this->Target->IsImported())
  2643. {
  2644. return this->Target->ImportedGetFullPath(config, implib);
  2645. }
  2646. else
  2647. {
  2648. return this->NormalGetFullPath(config, implib, realname);
  2649. }
  2650. }
  2651. std::string cmGeneratorTarget::NormalGetFullPath(const std::string& config,
  2652. bool implib,
  2653. bool realname) const
  2654. {
  2655. std::string fpath = this->Target->GetDirectory(config, implib);
  2656. fpath += "/";
  2657. if(this->Target->IsAppBundleOnApple())
  2658. {
  2659. fpath = this->BuildMacContentDirectory(fpath, config, false);
  2660. fpath += "/";
  2661. }
  2662. // Add the full name of the target.
  2663. if(implib)
  2664. {
  2665. fpath += this->GetFullName(config, true);
  2666. }
  2667. else if(realname)
  2668. {
  2669. fpath += this->NormalGetRealName(config);
  2670. }
  2671. else
  2672. {
  2673. fpath += this->GetFullName(config, false);
  2674. }
  2675. return fpath;
  2676. }
  2677. //----------------------------------------------------------------------------
  2678. std::string
  2679. cmGeneratorTarget::NormalGetRealName(const std::string& config) const
  2680. {
  2681. // This should not be called for imported targets.
  2682. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2683. // enforcement of the limited imported target API.
  2684. if(this->Target->IsImported())
  2685. {
  2686. std::string msg = "NormalGetRealName called on imported target: ";
  2687. msg += this->GetName();
  2688. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2689. }
  2690. if(this->GetType() == cmTarget::EXECUTABLE)
  2691. {
  2692. // Compute the real name that will be built.
  2693. std::string name;
  2694. std::string realName;
  2695. std::string impName;
  2696. std::string pdbName;
  2697. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2698. return realName;
  2699. }
  2700. else
  2701. {
  2702. // Compute the real name that will be built.
  2703. std::string name;
  2704. std::string soName;
  2705. std::string realName;
  2706. std::string impName;
  2707. std::string pdbName;
  2708. this->GetLibraryNames(name, soName, realName,
  2709. impName, pdbName, config);
  2710. return realName;
  2711. }
  2712. }
  2713. //----------------------------------------------------------------------------
  2714. void cmGeneratorTarget::GetLibraryNames(std::string& name,
  2715. std::string& soName,
  2716. std::string& realName,
  2717. std::string& impName,
  2718. std::string& pdbName,
  2719. const std::string& config) const
  2720. {
  2721. // This should not be called for imported targets.
  2722. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2723. // enforcement of the limited imported target API.
  2724. if(this->Target->IsImported())
  2725. {
  2726. std::string msg = "GetLibraryNames called on imported target: ";
  2727. msg += this->GetName();
  2728. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR,
  2729. msg);
  2730. return;
  2731. }
  2732. // Check for library version properties.
  2733. const char* version = this->GetProperty("VERSION");
  2734. const char* soversion = this->GetProperty("SOVERSION");
  2735. if(!this->HasSOName(config) ||
  2736. this->Target->IsFrameworkOnApple())
  2737. {
  2738. // Versioning is supported only for shared libraries and modules,
  2739. // and then only when the platform supports an soname flag.
  2740. version = 0;
  2741. soversion = 0;
  2742. }
  2743. if(version && !soversion)
  2744. {
  2745. // The soversion must be set if the library version is set. Use
  2746. // the library version as the soversion.
  2747. soversion = version;
  2748. }
  2749. if(!version && soversion)
  2750. {
  2751. // Use the soversion as the library version.
  2752. version = soversion;
  2753. }
  2754. // Get the components of the library name.
  2755. std::string prefix;
  2756. std::string base;
  2757. std::string suffix;
  2758. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2759. // The library name.
  2760. name = prefix+base+suffix;
  2761. if(this->Target->IsFrameworkOnApple())
  2762. {
  2763. realName = prefix;
  2764. if(!this->Makefile->PlatformIsAppleIos())
  2765. {
  2766. realName += "Versions/";
  2767. realName += this->Target->GetFrameworkVersion();
  2768. realName += "/";
  2769. }
  2770. realName += base;
  2771. soName = realName;
  2772. }
  2773. else
  2774. {
  2775. // The library's soname.
  2776. this->Target->ComputeVersionedName(soName, prefix, base, suffix,
  2777. name, soversion);
  2778. // The library's real name on disk.
  2779. this->Target->ComputeVersionedName(realName, prefix, base, suffix,
  2780. name, version);
  2781. }
  2782. // The import library name.
  2783. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2784. this->GetType() == cmTarget::MODULE_LIBRARY)
  2785. {
  2786. impName = this->GetFullNameInternal(config, true);
  2787. }
  2788. else
  2789. {
  2790. impName = "";
  2791. }
  2792. // The program database file name.
  2793. pdbName = this->GetPDBName(config);
  2794. }
  2795. //----------------------------------------------------------------------------
  2796. void cmGeneratorTarget::GetExecutableNames(std::string& name,
  2797. std::string& realName,
  2798. std::string& impName,
  2799. std::string& pdbName,
  2800. const std::string& config) const
  2801. {
  2802. // This should not be called for imported targets.
  2803. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2804. // enforcement of the limited imported target API.
  2805. if(this->Target->IsImported())
  2806. {
  2807. std::string msg =
  2808. "GetExecutableNames called on imported target: ";
  2809. msg += this->GetName();
  2810. this->LocalGenerator->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2811. }
  2812. // This versioning is supported only for executables and then only
  2813. // when the platform supports symbolic links.
  2814. #if defined(_WIN32) && !defined(__CYGWIN__)
  2815. const char* version = 0;
  2816. #else
  2817. // Check for executable version properties.
  2818. const char* version = this->GetProperty("VERSION");
  2819. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  2820. {
  2821. version = 0;
  2822. }
  2823. #endif
  2824. // Get the components of the executable name.
  2825. std::string prefix;
  2826. std::string base;
  2827. std::string suffix;
  2828. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2829. // The executable name.
  2830. name = prefix+base+suffix;
  2831. // The executable's real name on disk.
  2832. #if defined(__CYGWIN__)
  2833. realName = prefix+base;
  2834. #else
  2835. realName = name;
  2836. #endif
  2837. if(version)
  2838. {
  2839. realName += "-";
  2840. realName += version;
  2841. }
  2842. #if defined(__CYGWIN__)
  2843. realName += suffix;
  2844. #endif
  2845. // The import library name.
  2846. impName = this->GetFullNameInternal(config, true);
  2847. // The program database file name.
  2848. pdbName = this->GetPDBName(config);
  2849. }
  2850. //----------------------------------------------------------------------------
  2851. std::string cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2852. bool implib) const
  2853. {
  2854. std::string prefix;
  2855. std::string base;
  2856. std::string suffix;
  2857. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  2858. return prefix+base+suffix;
  2859. }
  2860. //----------------------------------------------------------------------------
  2861. void cmGeneratorTarget::GetFullNameInternal(const std::string& config,
  2862. bool implib,
  2863. std::string& outPrefix,
  2864. std::string& outBase,
  2865. std::string& outSuffix) const
  2866. {
  2867. // Use just the target name for non-main target types.
  2868. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  2869. this->GetType() != cmTarget::SHARED_LIBRARY &&
  2870. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2871. this->GetType() != cmTarget::EXECUTABLE)
  2872. {
  2873. outPrefix = "";
  2874. outBase = this->GetName();
  2875. outSuffix = "";
  2876. return;
  2877. }
  2878. // Return an empty name for the import library if this platform
  2879. // does not support import libraries.
  2880. if(implib &&
  2881. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2882. {
  2883. outPrefix = "";
  2884. outBase = "";
  2885. outSuffix = "";
  2886. return;
  2887. }
  2888. // The implib option is only allowed for shared libraries, module
  2889. // libraries, and executables.
  2890. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2891. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2892. this->GetType() != cmTarget::EXECUTABLE)
  2893. {
  2894. implib = false;
  2895. }
  2896. // Compute the full name for main target types.
  2897. const char* targetPrefix = (implib
  2898. ? this->GetProperty("IMPORT_PREFIX")
  2899. : this->GetProperty("PREFIX"));
  2900. const char* targetSuffix = (implib
  2901. ? this->GetProperty("IMPORT_SUFFIX")
  2902. : this->GetProperty("SUFFIX"));
  2903. const char* configPostfix = 0;
  2904. if(!config.empty())
  2905. {
  2906. std::string configProp = cmSystemTools::UpperCase(config);
  2907. configProp += "_POSTFIX";
  2908. configPostfix = this->GetProperty(configProp);
  2909. // Mac application bundles and frameworks have no postfix.
  2910. if(configPostfix &&
  2911. (this->Target->IsAppBundleOnApple()
  2912. || this->Target->IsFrameworkOnApple()))
  2913. {
  2914. configPostfix = 0;
  2915. }
  2916. }
  2917. const char* prefixVar = this->Target->GetPrefixVariableInternal(implib);
  2918. const char* suffixVar = this->Target->GetSuffixVariableInternal(implib);
  2919. // Check for language-specific default prefix and suffix.
  2920. std::string ll = this->GetLinkerLanguage(config);
  2921. if(!ll.empty())
  2922. {
  2923. if(!targetSuffix && suffixVar && *suffixVar)
  2924. {
  2925. std::string langSuff = suffixVar + std::string("_") + ll;
  2926. targetSuffix = this->Makefile->GetDefinition(langSuff);
  2927. }
  2928. if(!targetPrefix && prefixVar && *prefixVar)
  2929. {
  2930. std::string langPrefix = prefixVar + std::string("_") + ll;
  2931. targetPrefix = this->Makefile->GetDefinition(langPrefix);
  2932. }
  2933. }
  2934. // if there is no prefix on the target use the cmake definition
  2935. if(!targetPrefix && prefixVar)
  2936. {
  2937. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2938. }
  2939. // if there is no suffix on the target use the cmake definition
  2940. if(!targetSuffix && suffixVar)
  2941. {
  2942. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2943. }
  2944. // frameworks have directory prefix but no suffix
  2945. std::string fw_prefix;
  2946. if(this->Target->IsFrameworkOnApple())
  2947. {
  2948. fw_prefix = this->GetOutputName(config, false);
  2949. fw_prefix += ".framework/";
  2950. targetPrefix = fw_prefix.c_str();
  2951. targetSuffix = 0;
  2952. }
  2953. if(this->Target->IsCFBundleOnApple())
  2954. {
  2955. fw_prefix = this->GetCFBundleDirectory(config, false);
  2956. fw_prefix += "/";
  2957. targetPrefix = fw_prefix.c_str();
  2958. targetSuffix = 0;
  2959. }
  2960. // Begin the final name with the prefix.
  2961. outPrefix = targetPrefix?targetPrefix:"";
  2962. // Append the target name or property-specified name.
  2963. outBase += this->GetOutputName(config, implib);
  2964. // Append the per-configuration postfix.
  2965. outBase += configPostfix?configPostfix:"";
  2966. // Name shared libraries with their version number on some platforms.
  2967. if(const char* soversion = this->GetProperty("SOVERSION"))
  2968. {
  2969. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  2970. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2971. {
  2972. outBase += "-";
  2973. outBase += soversion;
  2974. }
  2975. }
  2976. // Append the suffix.
  2977. outSuffix = targetSuffix?targetSuffix:"";
  2978. }
  2979. //----------------------------------------------------------------------------
  2980. std::string
  2981. cmGeneratorTarget::GetLinkerLanguage(const std::string& config) const
  2982. {
  2983. return this->GetLinkClosure(config)->LinkerLanguage;
  2984. }
  2985. //----------------------------------------------------------------------------
  2986. std::string cmGeneratorTarget::GetPDBName(const std::string& config) const
  2987. {
  2988. std::string prefix;
  2989. std::string base;
  2990. std::string suffix;
  2991. this->GetFullNameInternal(config, false, prefix, base, suffix);
  2992. std::vector<std::string> props;
  2993. std::string configUpper =
  2994. cmSystemTools::UpperCase(config);
  2995. if(!configUpper.empty())
  2996. {
  2997. // PDB_NAME_<CONFIG>
  2998. props.push_back("PDB_NAME_" + configUpper);
  2999. }
  3000. // PDB_NAME
  3001. props.push_back("PDB_NAME");
  3002. for(std::vector<std::string>::const_iterator i = props.begin();
  3003. i != props.end(); ++i)
  3004. {
  3005. if(const char* outName = this->GetProperty(*i))
  3006. {
  3007. base = outName;
  3008. break;
  3009. }
  3010. }
  3011. return prefix+base+".pdb";
  3012. }
  3013. bool cmStrictTargetComparison::operator()(cmTarget const* t1,
  3014. cmTarget const* t2) const
  3015. {
  3016. int nameResult = strcmp(t1->GetName().c_str(), t2->GetName().c_str());
  3017. if (nameResult == 0)
  3018. {
  3019. return strcmp(t1->GetMakefile()->GetCurrentBinaryDirectory(),
  3020. t2->GetMakefile()->GetCurrentBinaryDirectory()) < 0;
  3021. }
  3022. return nameResult < 0;
  3023. }
  3024. //----------------------------------------------------------------------------
  3025. struct cmGeneratorTarget::SourceFileFlags
  3026. cmGeneratorTarget::GetTargetSourceFileFlags(const cmSourceFile* sf) const
  3027. {
  3028. struct SourceFileFlags flags;
  3029. this->ConstructSourceFileFlags();
  3030. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  3031. this->SourceFlagsMap.find(sf);
  3032. if(si != this->SourceFlagsMap.end())
  3033. {
  3034. flags = si->second;
  3035. }
  3036. else
  3037. {
  3038. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  3039. // were not listed in one of the other lists.
  3040. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  3041. {
  3042. flags.MacFolder = location;
  3043. if(strcmp(location, "Resources") == 0)
  3044. {
  3045. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3046. }
  3047. else
  3048. {
  3049. flags.Type = cmGeneratorTarget::SourceFileTypeMacContent;
  3050. }
  3051. }
  3052. }
  3053. return flags;
  3054. }
  3055. //----------------------------------------------------------------------------
  3056. void cmGeneratorTarget::ConstructSourceFileFlags() const
  3057. {
  3058. if(this->SourceFileFlagsConstructed)
  3059. {
  3060. return;
  3061. }
  3062. this->SourceFileFlagsConstructed = true;
  3063. // Process public headers to mark the source files.
  3064. if(const char* files = this->Target->GetProperty("PUBLIC_HEADER"))
  3065. {
  3066. std::vector<std::string> relFiles;
  3067. cmSystemTools::ExpandListArgument(files, relFiles);
  3068. for(std::vector<std::string>::iterator it = relFiles.begin();
  3069. it != relFiles.end(); ++it)
  3070. {
  3071. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3072. {
  3073. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3074. flags.MacFolder = "Headers";
  3075. flags.Type = cmGeneratorTarget::SourceFileTypePublicHeader;
  3076. }
  3077. }
  3078. }
  3079. // Process private headers after public headers so that they take
  3080. // precedence if a file is listed in both.
  3081. if(const char* files = this->Target->GetProperty("PRIVATE_HEADER"))
  3082. {
  3083. std::vector<std::string> relFiles;
  3084. cmSystemTools::ExpandListArgument(files, relFiles);
  3085. for(std::vector<std::string>::iterator it = relFiles.begin();
  3086. it != relFiles.end(); ++it)
  3087. {
  3088. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3089. {
  3090. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3091. flags.MacFolder = "PrivateHeaders";
  3092. flags.Type = cmGeneratorTarget::SourceFileTypePrivateHeader;
  3093. }
  3094. }
  3095. }
  3096. // Mark sources listed as resources.
  3097. if(const char* files = this->Target->GetProperty("RESOURCE"))
  3098. {
  3099. std::vector<std::string> relFiles;
  3100. cmSystemTools::ExpandListArgument(files, relFiles);
  3101. for(std::vector<std::string>::iterator it = relFiles.begin();
  3102. it != relFiles.end(); ++it)
  3103. {
  3104. if(cmSourceFile* sf = this->Makefile->GetSource(*it))
  3105. {
  3106. SourceFileFlags& flags = this->SourceFlagsMap[sf];
  3107. flags.MacFolder = "Resources";
  3108. flags.Type = cmGeneratorTarget::SourceFileTypeResource;
  3109. }
  3110. }
  3111. }
  3112. }
  3113. //----------------------------------------------------------------------------
  3114. const cmGeneratorTarget::CompatibleInterfacesBase&
  3115. cmGeneratorTarget::GetCompatibleInterfaces(std::string const& config) const
  3116. {
  3117. cmGeneratorTarget::CompatibleInterfaces& compat =
  3118. this->CompatibleInterfacesMap[config];
  3119. if(!compat.Done)
  3120. {
  3121. compat.Done = true;
  3122. compat.PropsBool.insert("POSITION_INDEPENDENT_CODE");
  3123. compat.PropsString.insert("AUTOUIC_OPTIONS");
  3124. std::vector<cmTarget const*> const& deps =
  3125. this->GetLinkImplementationClosure(config);
  3126. for(std::vector<cmTarget const*>::const_iterator li = deps.begin();
  3127. li != deps.end(); ++li)
  3128. {
  3129. #define CM_READ_COMPATIBLE_INTERFACE(X, x) \
  3130. if(const char* prop = (*li)->GetProperty("COMPATIBLE_INTERFACE_" #X)) \
  3131. { \
  3132. std::vector<std::string> props; \
  3133. cmSystemTools::ExpandListArgument(prop, props); \
  3134. compat.Props##x.insert(props.begin(), props.end()); \
  3135. }
  3136. CM_READ_COMPATIBLE_INTERFACE(BOOL, Bool)
  3137. CM_READ_COMPATIBLE_INTERFACE(STRING, String)
  3138. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MIN, NumberMin)
  3139. CM_READ_COMPATIBLE_INTERFACE(NUMBER_MAX, NumberMax)
  3140. #undef CM_READ_COMPATIBLE_INTERFACE
  3141. }
  3142. }
  3143. return compat;
  3144. }
  3145. //----------------------------------------------------------------------------
  3146. bool cmGeneratorTarget::IsLinkInterfaceDependentBoolProperty(
  3147. const std::string &p, const std::string& config) const
  3148. {
  3149. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  3150. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  3151. {
  3152. return false;
  3153. }
  3154. return this->GetCompatibleInterfaces(config).PropsBool.count(p) > 0;
  3155. }
  3156. //----------------------------------------------------------------------------
  3157. bool cmGeneratorTarget::IsLinkInterfaceDependentStringProperty(
  3158. const std::string &p, const std::string& config) const
  3159. {
  3160. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  3161. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  3162. {
  3163. return false;
  3164. }
  3165. return this->GetCompatibleInterfaces(config).PropsString.count(p) > 0;
  3166. }
  3167. //----------------------------------------------------------------------------
  3168. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMinProperty(
  3169. const std::string &p, const std::string& config) const
  3170. {
  3171. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  3172. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  3173. {
  3174. return false;
  3175. }
  3176. return this->GetCompatibleInterfaces(config).PropsNumberMin.count(p) > 0;
  3177. }
  3178. //----------------------------------------------------------------------------
  3179. bool cmGeneratorTarget::IsLinkInterfaceDependentNumberMaxProperty(
  3180. const std::string &p, const std::string& config) const
  3181. {
  3182. if (this->Target->GetType() == cmTarget::OBJECT_LIBRARY
  3183. || this->Target->GetType() == cmTarget::INTERFACE_LIBRARY)
  3184. {
  3185. return false;
  3186. }
  3187. return this->GetCompatibleInterfaces(config).PropsNumberMax.count(p) > 0;
  3188. }
  3189. enum CompatibleType
  3190. {
  3191. BoolType,
  3192. StringType,
  3193. NumberMinType,
  3194. NumberMaxType
  3195. };
  3196. template<typename PropertyType>
  3197. PropertyType getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3198. const std::string& prop,
  3199. const std::string& config,
  3200. CompatibleType,
  3201. PropertyType *);
  3202. template<>
  3203. bool getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3204. const std::string& prop,
  3205. const std::string& config,
  3206. CompatibleType, bool *)
  3207. {
  3208. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  3209. }
  3210. template<>
  3211. const char * getLinkInterfaceDependentProperty(cmGeneratorTarget const* tgt,
  3212. const std::string& prop,
  3213. const std::string& config,
  3214. CompatibleType t,
  3215. const char **)
  3216. {
  3217. switch(t)
  3218. {
  3219. case BoolType:
  3220. assert(0 && "String compatibility check function called for boolean");
  3221. return 0;
  3222. case StringType:
  3223. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  3224. case NumberMinType:
  3225. return tgt->GetLinkInterfaceDependentNumberMinProperty(prop, config);
  3226. case NumberMaxType:
  3227. return tgt->GetLinkInterfaceDependentNumberMaxProperty(prop, config);
  3228. }
  3229. assert(0 && "Unreachable!");
  3230. return 0;
  3231. }
  3232. //----------------------------------------------------------------------------
  3233. template<typename PropertyType>
  3234. void checkPropertyConsistency(cmGeneratorTarget const* depender,
  3235. cmTarget const* dependee,
  3236. const std::string& propName,
  3237. std::set<std::string> &emitted,
  3238. const std::string& config,
  3239. CompatibleType t,
  3240. PropertyType *)
  3241. {
  3242. const char *prop = dependee->GetProperty(propName);
  3243. if (!prop)
  3244. {
  3245. return;
  3246. }
  3247. std::vector<std::string> props;
  3248. cmSystemTools::ExpandListArgument(prop, props);
  3249. std::string pdir =
  3250. dependee->GetMakefile()->GetRequiredDefinition("CMAKE_ROOT");
  3251. pdir += "/Help/prop_tgt/";
  3252. for(std::vector<std::string>::iterator pi = props.begin();
  3253. pi != props.end(); ++pi)
  3254. {
  3255. std::string pname = cmSystemTools::HelpFileName(*pi);
  3256. std::string pfile = pdir + pname + ".rst";
  3257. if(cmSystemTools::FileExists(pfile.c_str(), true))
  3258. {
  3259. std::ostringstream e;
  3260. e << "Target \"" << dependee->GetName() << "\" has property \""
  3261. << *pi << "\" listed in its " << propName << " property. "
  3262. "This is not allowed. Only user-defined properties may appear "
  3263. "listed in the " << propName << " property.";
  3264. depender->GetLocalGenerator()->IssueMessage(cmake::FATAL_ERROR, e.str());
  3265. return;
  3266. }
  3267. if(emitted.insert(*pi).second)
  3268. {
  3269. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  3270. t, 0);
  3271. if (cmSystemTools::GetErrorOccuredFlag())
  3272. {
  3273. return;
  3274. }
  3275. }
  3276. }
  3277. }
  3278. static std::string intersect(const std::set<std::string> &s1,
  3279. const std::set<std::string> &s2)
  3280. {
  3281. std::set<std::string> intersect;
  3282. std::set_intersection(s1.begin(),s1.end(),
  3283. s2.begin(),s2.end(),
  3284. std::inserter(intersect,intersect.begin()));
  3285. if (!intersect.empty())
  3286. {
  3287. return *intersect.begin();
  3288. }
  3289. return "";
  3290. }
  3291. static std::string intersect(const std::set<std::string> &s1,
  3292. const std::set<std::string> &s2,
  3293. const std::set<std::string> &s3)
  3294. {
  3295. std::string result;
  3296. result = intersect(s1, s2);
  3297. if (!result.empty())
  3298. return result;
  3299. result = intersect(s1, s3);
  3300. if (!result.empty())
  3301. return result;
  3302. return intersect(s2, s3);
  3303. }
  3304. static std::string intersect(const std::set<std::string> &s1,
  3305. const std::set<std::string> &s2,
  3306. const std::set<std::string> &s3,
  3307. const std::set<std::string> &s4)
  3308. {
  3309. std::string result;
  3310. result = intersect(s1, s2);
  3311. if (!result.empty())
  3312. return result;
  3313. result = intersect(s1, s3);
  3314. if (!result.empty())
  3315. return result;
  3316. result = intersect(s1, s4);
  3317. if (!result.empty())
  3318. return result;
  3319. return intersect(s2, s3, s4);
  3320. }
  3321. //----------------------------------------------------------------------------
  3322. void cmGeneratorTarget::CheckPropertyCompatibility(
  3323. cmComputeLinkInformation *info, const std::string& config) const
  3324. {
  3325. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  3326. std::set<std::string> emittedBools;
  3327. static std::string strBool = "COMPATIBLE_INTERFACE_BOOL";
  3328. std::set<std::string> emittedStrings;
  3329. static std::string strString = "COMPATIBLE_INTERFACE_STRING";
  3330. std::set<std::string> emittedMinNumbers;
  3331. static std::string strNumMin = "COMPATIBLE_INTERFACE_NUMBER_MIN";
  3332. std::set<std::string> emittedMaxNumbers;
  3333. static std::string strNumMax = "COMPATIBLE_INTERFACE_NUMBER_MAX";
  3334. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  3335. deps.begin(); li != deps.end(); ++li)
  3336. {
  3337. if (!li->Target)
  3338. {
  3339. continue;
  3340. }
  3341. checkPropertyConsistency<bool>(this, li->Target,
  3342. strBool,
  3343. emittedBools, config, BoolType, 0);
  3344. if (cmSystemTools::GetErrorOccuredFlag())
  3345. {
  3346. return;
  3347. }
  3348. checkPropertyConsistency<const char *>(this, li->Target,
  3349. strString,
  3350. emittedStrings, config,
  3351. StringType, 0);
  3352. if (cmSystemTools::GetErrorOccuredFlag())
  3353. {
  3354. return;
  3355. }
  3356. checkPropertyConsistency<const char *>(this, li->Target,
  3357. strNumMin,
  3358. emittedMinNumbers, config,
  3359. NumberMinType, 0);
  3360. if (cmSystemTools::GetErrorOccuredFlag())
  3361. {
  3362. return;
  3363. }
  3364. checkPropertyConsistency<const char *>(this, li->Target,
  3365. strNumMax,
  3366. emittedMaxNumbers, config,
  3367. NumberMaxType, 0);
  3368. if (cmSystemTools::GetErrorOccuredFlag())
  3369. {
  3370. return;
  3371. }
  3372. }
  3373. std::string prop = intersect(emittedBools,
  3374. emittedStrings,
  3375. emittedMinNumbers,
  3376. emittedMaxNumbers);
  3377. if (!prop.empty())
  3378. {
  3379. // Use a sorted std::vector to keep the error message sorted.
  3380. std::vector<std::string> props;
  3381. std::set<std::string>::const_iterator i = emittedBools.find(prop);
  3382. if (i != emittedBools.end())
  3383. {
  3384. props.push_back(strBool);
  3385. }
  3386. i = emittedStrings.find(prop);
  3387. if (i != emittedStrings.end())
  3388. {
  3389. props.push_back(strString);
  3390. }
  3391. i = emittedMinNumbers.find(prop);
  3392. if (i != emittedMinNumbers.end())
  3393. {
  3394. props.push_back(strNumMin);
  3395. }
  3396. i = emittedMaxNumbers.find(prop);
  3397. if (i != emittedMaxNumbers.end())
  3398. {
  3399. props.push_back(strNumMax);
  3400. }
  3401. std::sort(props.begin(), props.end());
  3402. std::string propsString = cmJoin(cmMakeRange(props).retreat(1), ", ");
  3403. propsString += " and the " + props.back();
  3404. std::ostringstream e;
  3405. e << "Property \"" << prop << "\" appears in both the "
  3406. << propsString <<
  3407. " property in the dependencies of target \"" << this->GetName() <<
  3408. "\". This is not allowed. A property may only require compatibility "
  3409. "in a boolean interpretation, a numeric minimum, a numeric maximum or a "
  3410. "string interpretation, but not a mixture.";
  3411. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  3412. }
  3413. }
  3414. //----------------------------------------------------------------------------
  3415. std::string compatibilityType(CompatibleType t)
  3416. {
  3417. switch(t)
  3418. {
  3419. case BoolType:
  3420. return "Boolean compatibility";
  3421. case StringType:
  3422. return "String compatibility";
  3423. case NumberMaxType:
  3424. return "Numeric maximum compatibility";
  3425. case NumberMinType:
  3426. return "Numeric minimum compatibility";
  3427. }
  3428. assert(0 && "Unreachable!");
  3429. return "";
  3430. }
  3431. //----------------------------------------------------------------------------
  3432. std::string compatibilityAgree(CompatibleType t, bool dominant)
  3433. {
  3434. switch(t)
  3435. {
  3436. case BoolType:
  3437. case StringType:
  3438. return dominant ? "(Disagree)\n" : "(Agree)\n";
  3439. case NumberMaxType:
  3440. case NumberMinType:
  3441. return dominant ? "(Dominant)\n" : "(Ignored)\n";
  3442. }
  3443. assert(0 && "Unreachable!");
  3444. return "";
  3445. }
  3446. //----------------------------------------------------------------------------
  3447. template<typename PropertyType>
  3448. PropertyType getTypedProperty(cmTarget const* tgt, const std::string& prop);
  3449. //----------------------------------------------------------------------------
  3450. template<>
  3451. bool getTypedProperty<bool>(cmTarget const* tgt, const std::string& prop)
  3452. {
  3453. return tgt->GetPropertyAsBool(prop);
  3454. }
  3455. //----------------------------------------------------------------------------
  3456. template<>
  3457. const char *getTypedProperty<const char *>(cmTarget const* tgt,
  3458. const std::string& prop)
  3459. {
  3460. return tgt->GetProperty(prop);
  3461. }
  3462. template<typename PropertyType>
  3463. std::string valueAsString(PropertyType);
  3464. template<>
  3465. std::string valueAsString<bool>(bool value)
  3466. {
  3467. return value ? "TRUE" : "FALSE";
  3468. }
  3469. template<>
  3470. std::string valueAsString<const char*>(const char* value)
  3471. {
  3472. return value ? value : "(unset)";
  3473. }
  3474. template<typename PropertyType>
  3475. PropertyType impliedValue(PropertyType);
  3476. template<>
  3477. bool impliedValue<bool>(bool)
  3478. {
  3479. return false;
  3480. }
  3481. template<>
  3482. const char* impliedValue<const char*>(const char*)
  3483. {
  3484. return "";
  3485. }
  3486. //----------------------------------------------------------------------------
  3487. template<typename PropertyType>
  3488. std::pair<bool, PropertyType> consistentProperty(PropertyType lhs,
  3489. PropertyType rhs,
  3490. CompatibleType t);
  3491. //----------------------------------------------------------------------------
  3492. template<>
  3493. std::pair<bool, bool> consistentProperty(bool lhs, bool rhs,
  3494. CompatibleType)
  3495. {
  3496. return std::make_pair(lhs == rhs, lhs);
  3497. }
  3498. //----------------------------------------------------------------------------
  3499. std::pair<bool, const char*> consistentStringProperty(const char *lhs,
  3500. const char *rhs)
  3501. {
  3502. const bool b = strcmp(lhs, rhs) == 0;
  3503. return std::make_pair(b, b ? lhs : 0);
  3504. }
  3505. //----------------------------------------------------------------------------
  3506. std::pair<bool, const char*> consistentNumberProperty(const char *lhs,
  3507. const char *rhs,
  3508. CompatibleType t)
  3509. {
  3510. char *pEnd;
  3511. const char* const null_ptr = 0;
  3512. long lnum = strtol(lhs, &pEnd, 0);
  3513. if (pEnd == lhs || *pEnd != '\0' || errno == ERANGE)
  3514. {
  3515. return std::pair<bool, const char*>(false, null_ptr);
  3516. }
  3517. long rnum = strtol(rhs, &pEnd, 0);
  3518. if (pEnd == rhs || *pEnd != '\0' || errno == ERANGE)
  3519. {
  3520. return std::pair<bool, const char*>(false, null_ptr);
  3521. }
  3522. if (t == NumberMaxType)
  3523. {
  3524. return std::make_pair(true, std::max(lnum, rnum) == lnum ? lhs : rhs);
  3525. }
  3526. else
  3527. {
  3528. return std::make_pair(true, std::min(lnum, rnum) == lnum ? lhs : rhs);
  3529. }
  3530. }
  3531. //----------------------------------------------------------------------------
  3532. template<>
  3533. std::pair<bool, const char*> consistentProperty(const char *lhs,
  3534. const char *rhs,
  3535. CompatibleType t)
  3536. {
  3537. if (!lhs && !rhs)
  3538. {
  3539. return std::make_pair(true, lhs);
  3540. }
  3541. if (!lhs)
  3542. {
  3543. return std::make_pair(true, rhs);
  3544. }
  3545. if (!rhs)
  3546. {
  3547. return std::make_pair(true, lhs);
  3548. }
  3549. const char* const null_ptr = 0;
  3550. switch(t)
  3551. {
  3552. case BoolType:
  3553. assert(0 && "consistentProperty for strings called with BoolType");
  3554. return std::pair<bool, const char*>(false, null_ptr);
  3555. case StringType:
  3556. return consistentStringProperty(lhs, rhs);
  3557. case NumberMinType:
  3558. case NumberMaxType:
  3559. return consistentNumberProperty(lhs, rhs, t);
  3560. }
  3561. assert(0 && "Unreachable!");
  3562. return std::pair<bool, const char*>(false, null_ptr);
  3563. }
  3564. //----------------------------------------------------------------------------
  3565. template<typename PropertyType>
  3566. PropertyType checkInterfacePropertyCompatibility(cmGeneratorTarget const* tgt,
  3567. const std::string &p,
  3568. const std::string& config,
  3569. const char *defaultValue,
  3570. CompatibleType t,
  3571. PropertyType *)
  3572. {
  3573. PropertyType propContent = getTypedProperty<PropertyType>(tgt->Target, p);
  3574. const bool explicitlySet = tgt->Target->GetProperties()
  3575. .find(p)
  3576. != tgt->Target->GetProperties().end();
  3577. const bool impliedByUse =
  3578. tgt->Target->IsNullImpliedByLinkLibraries(p);
  3579. assert((impliedByUse ^ explicitlySet)
  3580. || (!impliedByUse && !explicitlySet));
  3581. std::vector<cmTarget const*> const& deps =
  3582. tgt->GetLinkImplementationClosure(config);
  3583. if(deps.empty())
  3584. {
  3585. return propContent;
  3586. }
  3587. bool propInitialized = explicitlySet;
  3588. std::string report = " * Target \"";
  3589. report += tgt->GetName();
  3590. if (explicitlySet)
  3591. {
  3592. report += "\" has property content \"";
  3593. report += valueAsString<PropertyType>(propContent);
  3594. report += "\"\n";
  3595. }
  3596. else if (impliedByUse)
  3597. {
  3598. report += "\" property is implied by use.\n";
  3599. }
  3600. else
  3601. {
  3602. report += "\" property not set.\n";
  3603. }
  3604. std::string interfaceProperty = "INTERFACE_" + p;
  3605. for(std::vector<cmTarget const*>::const_iterator li =
  3606. deps.begin();
  3607. li != deps.end(); ++li)
  3608. {
  3609. // An error should be reported if one dependency
  3610. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  3611. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  3612. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  3613. // with a dependency.
  3614. cmTarget const* theTarget = *li;
  3615. const bool ifaceIsSet = theTarget->GetProperties()
  3616. .find(interfaceProperty)
  3617. != theTarget->GetProperties().end();
  3618. PropertyType ifacePropContent =
  3619. getTypedProperty<PropertyType>(theTarget,
  3620. interfaceProperty);
  3621. std::string reportEntry;
  3622. if (ifaceIsSet)
  3623. {
  3624. reportEntry += " * Target \"";
  3625. reportEntry += theTarget->GetName();
  3626. reportEntry += "\" property value \"";
  3627. reportEntry += valueAsString<PropertyType>(ifacePropContent);
  3628. reportEntry += "\" ";
  3629. }
  3630. if (explicitlySet)
  3631. {
  3632. if (ifaceIsSet)
  3633. {
  3634. std::pair<bool, PropertyType> consistent =
  3635. consistentProperty(propContent,
  3636. ifacePropContent, t);
  3637. report += reportEntry;
  3638. report += compatibilityAgree(t, propContent != consistent.second);
  3639. if (!consistent.first)
  3640. {
  3641. std::ostringstream e;
  3642. e << "Property " << p << " on target \""
  3643. << tgt->GetName() << "\" does\nnot match the "
  3644. "INTERFACE_" << p << " property requirement\nof "
  3645. "dependency \"" << theTarget->GetName() << "\".\n";
  3646. cmSystemTools::Error(e.str().c_str());
  3647. break;
  3648. }
  3649. else
  3650. {
  3651. propContent = consistent.second;
  3652. continue;
  3653. }
  3654. }
  3655. else
  3656. {
  3657. // Explicitly set on target and not set in iface. Can't disagree.
  3658. continue;
  3659. }
  3660. }
  3661. else if (impliedByUse)
  3662. {
  3663. propContent = impliedValue<PropertyType>(propContent);
  3664. if (ifaceIsSet)
  3665. {
  3666. std::pair<bool, PropertyType> consistent =
  3667. consistentProperty(propContent,
  3668. ifacePropContent, t);
  3669. report += reportEntry;
  3670. report += compatibilityAgree(t, propContent != consistent.second);
  3671. if (!consistent.first)
  3672. {
  3673. std::ostringstream e;
  3674. e << "Property " << p << " on target \""
  3675. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  3676. << " because it was used to determine the link libraries\n"
  3677. "already. The INTERFACE_" << p << " property on\ndependency \""
  3678. << theTarget->GetName() << "\" is in conflict.\n";
  3679. cmSystemTools::Error(e.str().c_str());
  3680. break;
  3681. }
  3682. else
  3683. {
  3684. propContent = consistent.second;
  3685. continue;
  3686. }
  3687. }
  3688. else
  3689. {
  3690. // Implicitly set on target and not set in iface. Can't disagree.
  3691. continue;
  3692. }
  3693. }
  3694. else
  3695. {
  3696. if (ifaceIsSet)
  3697. {
  3698. if (propInitialized)
  3699. {
  3700. std::pair<bool, PropertyType> consistent =
  3701. consistentProperty(propContent,
  3702. ifacePropContent, t);
  3703. report += reportEntry;
  3704. report += compatibilityAgree(t, propContent != consistent.second);
  3705. if (!consistent.first)
  3706. {
  3707. std::ostringstream e;
  3708. e << "The INTERFACE_" << p << " property of \""
  3709. << theTarget->GetName() << "\" does\nnot agree with the value "
  3710. "of " << p << " already determined\nfor \""
  3711. << tgt->GetName() << "\".\n";
  3712. cmSystemTools::Error(e.str().c_str());
  3713. break;
  3714. }
  3715. else
  3716. {
  3717. propContent = consistent.second;
  3718. continue;
  3719. }
  3720. }
  3721. else
  3722. {
  3723. report += reportEntry + "(Interface set)\n";
  3724. propContent = ifacePropContent;
  3725. propInitialized = true;
  3726. }
  3727. }
  3728. else
  3729. {
  3730. // Not set. Nothing to agree on.
  3731. continue;
  3732. }
  3733. }
  3734. }
  3735. tgt->ReportPropertyOrigin(p, valueAsString<PropertyType>(propContent),
  3736. report, compatibilityType(t));
  3737. return propContent;
  3738. }
  3739. //----------------------------------------------------------------------------
  3740. bool cmGeneratorTarget::GetLinkInterfaceDependentBoolProperty(
  3741. const std::string &p, const std::string& config) const
  3742. {
  3743. return checkInterfacePropertyCompatibility<bool>(this, p, config,
  3744. "FALSE",
  3745. BoolType, 0);
  3746. }
  3747. //----------------------------------------------------------------------------
  3748. const char* cmGeneratorTarget::GetLinkInterfaceDependentStringProperty(
  3749. const std::string &p,
  3750. const std::string& config) const
  3751. {
  3752. return checkInterfacePropertyCompatibility<const char *>(this,
  3753. p,
  3754. config,
  3755. "empty",
  3756. StringType, 0);
  3757. }
  3758. //----------------------------------------------------------------------------
  3759. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMinProperty(
  3760. const std::string &p,
  3761. const std::string& config) const
  3762. {
  3763. return checkInterfacePropertyCompatibility<const char *>(this,
  3764. p,
  3765. config,
  3766. "empty",
  3767. NumberMinType, 0);
  3768. }
  3769. //----------------------------------------------------------------------------
  3770. const char * cmGeneratorTarget::GetLinkInterfaceDependentNumberMaxProperty(
  3771. const std::string &p,
  3772. const std::string& config) const
  3773. {
  3774. return checkInterfacePropertyCompatibility<const char *>(this,
  3775. p,
  3776. config,
  3777. "empty",
  3778. NumberMaxType, 0);
  3779. }
  3780. //----------------------------------------------------------------------------
  3781. cmComputeLinkInformation*
  3782. cmGeneratorTarget::GetLinkInformation(const std::string& config) const
  3783. {
  3784. // Lookup any existing information for this configuration.
  3785. std::string key(cmSystemTools::UpperCase(config));
  3786. cmTargetLinkInformationMap::iterator
  3787. i = this->LinkInformation.find(key);
  3788. if(i == this->LinkInformation.end())
  3789. {
  3790. // Compute information for this configuration.
  3791. cmComputeLinkInformation* info =
  3792. new cmComputeLinkInformation(this, config);
  3793. if(!info || !info->Compute())
  3794. {
  3795. delete info;
  3796. info = 0;
  3797. }
  3798. // Store the information for this configuration.
  3799. cmTargetLinkInformationMap::value_type entry(key, info);
  3800. i = this->LinkInformation.insert(entry).first;
  3801. if (info)
  3802. {
  3803. this->CheckPropertyCompatibility(info, config);
  3804. }
  3805. }
  3806. return i->second;
  3807. }
  3808. //----------------------------------------------------------------------------
  3809. void
  3810. cmGeneratorTarget::ReportPropertyOrigin(const std::string &p,
  3811. const std::string &result,
  3812. const std::string &report,
  3813. const std::string &compatibilityType) const
  3814. {
  3815. std::vector<std::string> debugProperties;
  3816. const char *debugProp = this->Target->GetMakefile()
  3817. ->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  3818. if (debugProp)
  3819. {
  3820. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  3821. }
  3822. bool debugOrigin = !this->DebugCompatiblePropertiesDone[p]
  3823. && std::find(debugProperties.begin(),
  3824. debugProperties.end(),
  3825. p)
  3826. != debugProperties.end();
  3827. if (this->GlobalGenerator->GetConfigureDoneCMP0026())
  3828. {
  3829. this->DebugCompatiblePropertiesDone[p] = true;
  3830. }
  3831. if (!debugOrigin)
  3832. {
  3833. return;
  3834. }
  3835. std::string areport = compatibilityType;
  3836. areport += std::string(" of property \"") + p + "\" for target \"";
  3837. areport += std::string(this->GetName());
  3838. areport += "\" (result: \"";
  3839. areport += result;
  3840. areport += "\"):\n" + report;
  3841. this->LocalGenerator->GetCMakeInstance()->IssueMessage(cmake::LOG, areport);
  3842. }
  3843. //----------------------------------------------------------------------------
  3844. void cmGeneratorTarget::LookupLinkItems(std::vector<std::string> const& names,
  3845. std::vector<cmLinkItem>& items) const
  3846. {
  3847. for(std::vector<std::string>::const_iterator i = names.begin();
  3848. i != names.end(); ++i)
  3849. {
  3850. std::string name = this->Target->CheckCMP0004(*i);
  3851. if(name == this->GetName() || name.empty())
  3852. {
  3853. continue;
  3854. }
  3855. items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name)));
  3856. }
  3857. }
  3858. //----------------------------------------------------------------------------
  3859. void cmGeneratorTarget::ExpandLinkItems(std::string const& prop,
  3860. std::string const& value,
  3861. std::string const& config,
  3862. cmTarget const* headTarget,
  3863. bool usage_requirements_only,
  3864. std::vector<cmLinkItem>& items,
  3865. bool& hadHeadSensitiveCondition) const
  3866. {
  3867. cmGeneratorExpression ge;
  3868. cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0);
  3869. // The $<LINK_ONLY> expression may be in a link interface to specify private
  3870. // link dependencies that are otherwise excluded from usage requirements.
  3871. if(usage_requirements_only)
  3872. {
  3873. dagChecker.SetTransitivePropertiesOnly();
  3874. }
  3875. std::vector<std::string> libs;
  3876. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  3877. cmSystemTools::ExpandListArgument(cge->Evaluate(
  3878. this->Makefile,
  3879. config,
  3880. false,
  3881. headTarget,
  3882. this->Target, &dagChecker), libs);
  3883. this->LookupLinkItems(libs, items);
  3884. hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition();
  3885. }
  3886. //----------------------------------------------------------------------------
  3887. cmLinkInterface const*
  3888. cmGeneratorTarget::GetLinkInterface(const std::string& config,
  3889. cmTarget const* head) const
  3890. {
  3891. // Imported targets have their own link interface.
  3892. if(this->IsImported())
  3893. {
  3894. return this->GetImportLinkInterface(config, head, false);
  3895. }
  3896. // Link interfaces are not supported for executables that do not
  3897. // export symbols.
  3898. if(this->GetType() == cmTarget::EXECUTABLE &&
  3899. !this->Target->IsExecutableWithExports())
  3900. {
  3901. return 0;
  3902. }
  3903. // Lookup any existing link interface for this configuration.
  3904. cmHeadToLinkInterfaceMap& hm =
  3905. this->GetHeadToLinkInterfaceMap(config);
  3906. // If the link interface does not depend on the head target
  3907. // then return the one we computed first.
  3908. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  3909. {
  3910. return &hm.begin()->second;
  3911. }
  3912. cmOptionalLinkInterface& iface = hm[head];
  3913. if(!iface.LibrariesDone)
  3914. {
  3915. iface.LibrariesDone = true;
  3916. this->ComputeLinkInterfaceLibraries(
  3917. config, iface, head, false);
  3918. }
  3919. if(!iface.AllDone)
  3920. {
  3921. iface.AllDone = true;
  3922. if(iface.Exists)
  3923. {
  3924. this->ComputeLinkInterface(config, iface, head);
  3925. }
  3926. }
  3927. return iface.Exists? &iface : 0;
  3928. }
  3929. //----------------------------------------------------------------------------
  3930. void cmGeneratorTarget::ComputeLinkInterface(const std::string& config,
  3931. cmOptionalLinkInterface &iface,
  3932. cmTarget const* headTarget) const
  3933. {
  3934. if(iface.ExplicitLibraries)
  3935. {
  3936. if(this->GetType() == cmTarget::SHARED_LIBRARY
  3937. || this->GetType() == cmTarget::STATIC_LIBRARY
  3938. || this->GetType() == cmTarget::INTERFACE_LIBRARY)
  3939. {
  3940. // Shared libraries may have runtime implementation dependencies
  3941. // on other shared libraries that are not in the interface.
  3942. UNORDERED_SET<std::string> emitted;
  3943. for(std::vector<cmLinkItem>::const_iterator
  3944. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  3945. {
  3946. emitted.insert(*li);
  3947. }
  3948. if (this->GetType() != cmTarget::INTERFACE_LIBRARY)
  3949. {
  3950. cmLinkImplementation const* impl =
  3951. this->GetLinkImplementation(config);
  3952. for(std::vector<cmLinkImplItem>::const_iterator
  3953. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  3954. {
  3955. if(emitted.insert(*li).second)
  3956. {
  3957. if(li->Target)
  3958. {
  3959. // This is a runtime dependency on another shared library.
  3960. if(li->Target->GetType() == cmTarget::SHARED_LIBRARY)
  3961. {
  3962. iface.SharedDeps.push_back(*li);
  3963. }
  3964. }
  3965. else
  3966. {
  3967. // TODO: Recognize shared library file names. Perhaps this
  3968. // should be moved to cmComputeLinkInformation, but that creates
  3969. // a chicken-and-egg problem since this list is needed for its
  3970. // construction.
  3971. }
  3972. }
  3973. }
  3974. }
  3975. }
  3976. }
  3977. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  3978. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  3979. {
  3980. // The link implementation is the default link interface.
  3981. cmLinkImplementationLibraries const*
  3982. impl = this->GetLinkImplementationLibrariesInternal(config, headTarget);
  3983. iface.ImplementationIsInterface = true;
  3984. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  3985. }
  3986. if(this->Target->LinkLanguagePropagatesToDependents())
  3987. {
  3988. // Targets using this archive need its language runtime libraries.
  3989. if(cmLinkImplementation const* impl =
  3990. this->GetLinkImplementation(config))
  3991. {
  3992. iface.Languages = impl->Languages;
  3993. }
  3994. }
  3995. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  3996. {
  3997. // Construct the property name suffix for this configuration.
  3998. std::string suffix = "_";
  3999. if(!config.empty())
  4000. {
  4001. suffix += cmSystemTools::UpperCase(config);
  4002. }
  4003. else
  4004. {
  4005. suffix += "NOCONFIG";
  4006. }
  4007. // How many repetitions are needed if this library has cyclic
  4008. // dependencies?
  4009. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4010. propName += suffix;
  4011. if(const char* config_reps = this->GetProperty(propName))
  4012. {
  4013. sscanf(config_reps, "%u", &iface.Multiplicity);
  4014. }
  4015. else if(const char* reps =
  4016. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4017. {
  4018. sscanf(reps, "%u", &iface.Multiplicity);
  4019. }
  4020. }
  4021. }
  4022. //----------------------------------------------------------------------------
  4023. const cmLinkInterfaceLibraries *
  4024. cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config,
  4025. cmTarget const* head,
  4026. bool usage_requirements_only) const
  4027. {
  4028. // Imported targets have their own link interface.
  4029. if(this->IsImported())
  4030. {
  4031. return this->GetImportLinkInterface(config, head,
  4032. usage_requirements_only);
  4033. }
  4034. // Link interfaces are not supported for executables that do not
  4035. // export symbols.
  4036. if(this->GetType() == cmTarget::EXECUTABLE &&
  4037. !this->Target->IsExecutableWithExports())
  4038. {
  4039. return 0;
  4040. }
  4041. // Lookup any existing link interface for this configuration.
  4042. std::string CONFIG = cmSystemTools::UpperCase(config);
  4043. cmHeadToLinkInterfaceMap& hm =
  4044. (usage_requirements_only ?
  4045. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  4046. this->GetHeadToLinkInterfaceMap(config));
  4047. // If the link interface does not depend on the head target
  4048. // then return the one we computed first.
  4049. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4050. {
  4051. return &hm.begin()->second;
  4052. }
  4053. cmOptionalLinkInterface& iface = hm[head];
  4054. if(!iface.LibrariesDone)
  4055. {
  4056. iface.LibrariesDone = true;
  4057. this->ComputeLinkInterfaceLibraries(
  4058. config, iface, head, usage_requirements_only);
  4059. }
  4060. return iface.Exists? &iface : 0;
  4061. }
  4062. //----------------------------------------------------------------------------
  4063. void
  4064. cmGeneratorTarget::ComputeLinkInterfaceLibraries(
  4065. const std::string& config,
  4066. cmOptionalLinkInterface& iface,
  4067. cmTarget const* headTarget,
  4068. bool usage_requirements_only) const
  4069. {
  4070. // Construct the property name suffix for this configuration.
  4071. std::string suffix = "_";
  4072. if(!config.empty())
  4073. {
  4074. suffix += cmSystemTools::UpperCase(config);
  4075. }
  4076. else
  4077. {
  4078. suffix += "NOCONFIG";
  4079. }
  4080. // An explicit list of interface libraries may be set for shared
  4081. // libraries and executables that export symbols.
  4082. const char* explicitLibraries = 0;
  4083. std::string linkIfaceProp;
  4084. if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD &&
  4085. this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN)
  4086. {
  4087. // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES.
  4088. linkIfaceProp = "INTERFACE_LINK_LIBRARIES";
  4089. explicitLibraries = this->GetProperty(linkIfaceProp);
  4090. }
  4091. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4092. this->Target->IsExecutableWithExports())
  4093. {
  4094. // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a
  4095. // shared lib or executable.
  4096. // Lookup the per-configuration property.
  4097. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4098. linkIfaceProp += suffix;
  4099. explicitLibraries = this->GetProperty(linkIfaceProp);
  4100. // If not set, try the generic property.
  4101. if(!explicitLibraries)
  4102. {
  4103. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4104. explicitLibraries = this->GetProperty(linkIfaceProp);
  4105. }
  4106. }
  4107. if(explicitLibraries &&
  4108. this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4109. !this->PolicyWarnedCMP0022)
  4110. {
  4111. // Compare the explicitly set old link interface properties to the
  4112. // preferred new link interface property one and warn if different.
  4113. const char* newExplicitLibraries =
  4114. this->GetProperty("INTERFACE_LINK_LIBRARIES");
  4115. if (newExplicitLibraries
  4116. && strcmp(newExplicitLibraries, explicitLibraries) != 0)
  4117. {
  4118. std::ostringstream w;
  4119. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4120. "Target \"" << this->GetName() << "\" has an "
  4121. "INTERFACE_LINK_LIBRARIES property which differs from its " <<
  4122. linkIfaceProp << " properties."
  4123. "\n"
  4124. "INTERFACE_LINK_LIBRARIES:\n"
  4125. " " << newExplicitLibraries << "\n" <<
  4126. linkIfaceProp << ":\n"
  4127. " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n";
  4128. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4129. this->PolicyWarnedCMP0022 = true;
  4130. }
  4131. }
  4132. // There is no implicit link interface for executables or modules
  4133. // so if none was explicitly set then there is no link interface.
  4134. if(!explicitLibraries &&
  4135. (this->GetType() == cmTarget::EXECUTABLE ||
  4136. (this->GetType() == cmTarget::MODULE_LIBRARY)))
  4137. {
  4138. return;
  4139. }
  4140. iface.Exists = true;
  4141. iface.ExplicitLibraries = explicitLibraries;
  4142. if(explicitLibraries)
  4143. {
  4144. // The interface libraries have been explicitly set.
  4145. this->ExpandLinkItems(linkIfaceProp, explicitLibraries,
  4146. config,
  4147. headTarget, usage_requirements_only,
  4148. iface.Libraries,
  4149. iface.HadHeadSensitiveCondition);
  4150. }
  4151. else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN
  4152. || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD)
  4153. // If CMP0022 is NEW then the plain tll signature sets the
  4154. // INTERFACE_LINK_LIBRARIES, so if we get here then the project
  4155. // cleared the property explicitly and we should not fall back
  4156. // to the link implementation.
  4157. {
  4158. // The link implementation is the default link interface.
  4159. cmLinkImplementationLibraries const* impl =
  4160. this->GetLinkImplementationLibrariesInternal(config, headTarget);
  4161. iface.Libraries.insert(iface.Libraries.end(),
  4162. impl->Libraries.begin(), impl->Libraries.end());
  4163. if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN &&
  4164. !this->PolicyWarnedCMP0022 && !usage_requirements_only)
  4165. {
  4166. // Compare the link implementation fallback link interface to the
  4167. // preferred new link interface property and warn if different.
  4168. std::vector<cmLinkItem> ifaceLibs;
  4169. static const std::string newProp = "INTERFACE_LINK_LIBRARIES";
  4170. if(const char* newExplicitLibraries = this->GetProperty(newProp))
  4171. {
  4172. bool hadHeadSensitiveConditionDummy = false;
  4173. this->ExpandLinkItems(newProp, newExplicitLibraries, config,
  4174. headTarget, usage_requirements_only,
  4175. ifaceLibs, hadHeadSensitiveConditionDummy);
  4176. }
  4177. if (ifaceLibs != iface.Libraries)
  4178. {
  4179. std::string oldLibraries = cmJoin(impl->Libraries, ";");
  4180. std::string newLibraries = cmJoin(ifaceLibs, ";");
  4181. if(oldLibraries.empty())
  4182. { oldLibraries = "(empty)"; }
  4183. if(newLibraries.empty())
  4184. { newLibraries = "(empty)"; }
  4185. std::ostringstream w;
  4186. w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n"
  4187. "Target \"" << this->GetName() << "\" has an "
  4188. "INTERFACE_LINK_LIBRARIES property. "
  4189. "This should be preferred as the source of the link interface "
  4190. "for this library but because CMP0022 is not set CMake is "
  4191. "ignoring the property and using the link implementation "
  4192. "as the link interface instead."
  4193. "\n"
  4194. "INTERFACE_LINK_LIBRARIES:\n"
  4195. " " << newLibraries << "\n"
  4196. "Link implementation:\n"
  4197. " " << oldLibraries << "\n";
  4198. this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  4199. this->PolicyWarnedCMP0022 = true;
  4200. }
  4201. }
  4202. }
  4203. }
  4204. //----------------------------------------------------------------------------
  4205. const cmLinkInterface *
  4206. cmGeneratorTarget::GetImportLinkInterface(const std::string& config,
  4207. cmTarget const* headTarget,
  4208. bool usage_requirements_only) const
  4209. {
  4210. cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config);
  4211. if(!info)
  4212. {
  4213. return 0;
  4214. }
  4215. std::string CONFIG = cmSystemTools::UpperCase(config);
  4216. cmHeadToLinkInterfaceMap& hm =
  4217. (usage_requirements_only ?
  4218. this->GetHeadToLinkInterfaceUsageRequirementsMap(config) :
  4219. this->GetHeadToLinkInterfaceMap(config));
  4220. // If the link interface does not depend on the head target
  4221. // then return the one we computed first.
  4222. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4223. {
  4224. return &hm.begin()->second;
  4225. }
  4226. cmOptionalLinkInterface& iface = hm[headTarget];
  4227. if(!iface.AllDone)
  4228. {
  4229. iface.AllDone = true;
  4230. iface.Multiplicity = info->Multiplicity;
  4231. cmSystemTools::ExpandListArgument(info->Languages, iface.Languages);
  4232. this->ExpandLinkItems(info->LibrariesProp, info->Libraries,
  4233. config,
  4234. headTarget, usage_requirements_only,
  4235. iface.Libraries,
  4236. iface.HadHeadSensitiveCondition);
  4237. std::vector<std::string> deps;
  4238. cmSystemTools::ExpandListArgument(info->SharedDeps, deps);
  4239. this->LookupLinkItems(deps, iface.SharedDeps);
  4240. }
  4241. return &iface;
  4242. }
  4243. cmHeadToLinkInterfaceMap&
  4244. cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const
  4245. {
  4246. std::string CONFIG = cmSystemTools::UpperCase(config);
  4247. return this->LinkInterfaceMap[CONFIG];
  4248. }
  4249. cmHeadToLinkInterfaceMap&
  4250. cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap(
  4251. const std::string &config) const
  4252. {
  4253. std::string CONFIG = cmSystemTools::UpperCase(config);
  4254. return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG];
  4255. }
  4256. //----------------------------------------------------------------------------
  4257. const cmLinkImplementation *
  4258. cmGeneratorTarget::GetLinkImplementation(const std::string& config) const
  4259. {
  4260. // There is no link implementation for imported targets.
  4261. if(this->Target->IsImported())
  4262. {
  4263. return 0;
  4264. }
  4265. std::string CONFIG = cmSystemTools::UpperCase(config);
  4266. cmOptionalLinkImplementation& impl = this->LinkImplMap[CONFIG][this->Target];
  4267. if(!impl.LibrariesDone)
  4268. {
  4269. impl.LibrariesDone = true;
  4270. this->ComputeLinkImplementationLibraries(config, impl, this->Target);
  4271. }
  4272. if(!impl.LanguagesDone)
  4273. {
  4274. impl.LanguagesDone = true;
  4275. this->ComputeLinkImplementationLanguages(config, impl);
  4276. }
  4277. return &impl;
  4278. }
  4279. //----------------------------------------------------------------------------
  4280. bool cmGeneratorTarget::GetConfigCommonSourceFiles(
  4281. std::vector<cmSourceFile*>& files) const
  4282. {
  4283. std::vector<std::string> configs;
  4284. this->Makefile->GetConfigurations(configs);
  4285. if (configs.empty())
  4286. {
  4287. configs.push_back("");
  4288. }
  4289. std::vector<std::string>::const_iterator it = configs.begin();
  4290. const std::string& firstConfig = *it;
  4291. this->GetSourceFiles(files, firstConfig);
  4292. for ( ; it != configs.end(); ++it)
  4293. {
  4294. std::vector<cmSourceFile*> configFiles;
  4295. this->GetSourceFiles(configFiles, *it);
  4296. if (configFiles != files)
  4297. {
  4298. std::string firstConfigFiles;
  4299. const char* sep = "";
  4300. for (std::vector<cmSourceFile*>::const_iterator fi = files.begin();
  4301. fi != files.end(); ++fi)
  4302. {
  4303. firstConfigFiles += sep;
  4304. firstConfigFiles += (*fi)->GetFullPath();
  4305. sep = "\n ";
  4306. }
  4307. std::string thisConfigFiles;
  4308. sep = "";
  4309. for (std::vector<cmSourceFile*>::const_iterator fi = configFiles.begin();
  4310. fi != configFiles.end(); ++fi)
  4311. {
  4312. thisConfigFiles += sep;
  4313. thisConfigFiles += (*fi)->GetFullPath();
  4314. sep = "\n ";
  4315. }
  4316. std::ostringstream e;
  4317. e << "Target \"" << this->GetName()
  4318. << "\" has source files which vary by "
  4319. "configuration. This is not supported by the \""
  4320. << this->GlobalGenerator->GetName()
  4321. << "\" generator.\n"
  4322. "Config \"" << firstConfig << "\":\n"
  4323. " " << firstConfigFiles << "\n"
  4324. "Config \"" << *it << "\":\n"
  4325. " " << thisConfigFiles << "\n";
  4326. this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str());
  4327. return false;
  4328. }
  4329. }
  4330. return true;
  4331. }
  4332. //----------------------------------------------------------------------------
  4333. void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages,
  4334. const std::string& config) const
  4335. {
  4336. std::vector<cmSourceFile*> sourceFiles;
  4337. this->GetSourceFiles(sourceFiles, config);
  4338. for(std::vector<cmSourceFile*>::const_iterator
  4339. i = sourceFiles.begin(); i != sourceFiles.end(); ++i)
  4340. {
  4341. const std::string& lang = (*i)->GetLanguage();
  4342. if(!lang.empty())
  4343. {
  4344. languages.insert(lang);
  4345. }
  4346. }
  4347. std::vector<cmGeneratorTarget*> objectLibraries;
  4348. std::vector<cmSourceFile const*> externalObjects;
  4349. if (!this->GlobalGenerator->GetConfigureDoneCMP0026())
  4350. {
  4351. std::vector<cmTarget*> objectTargets;
  4352. this->Target->GetObjectLibrariesCMP0026(objectTargets);
  4353. objectLibraries.reserve(objectTargets.size());
  4354. for (std::vector<cmTarget*>::const_iterator it = objectTargets.begin();
  4355. it != objectTargets.end(); ++it)
  4356. {
  4357. objectLibraries.push_back(this->GlobalGenerator
  4358. ->GetGeneratorTarget(*it));
  4359. }
  4360. }
  4361. else
  4362. {
  4363. this->GetExternalObjects(externalObjects, config);
  4364. for(std::vector<cmSourceFile const*>::const_iterator
  4365. i = externalObjects.begin(); i != externalObjects.end(); ++i)
  4366. {
  4367. std::string objLib = (*i)->GetObjectLibrary();
  4368. if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib))
  4369. {
  4370. objectLibraries.push_back(this->GlobalGenerator
  4371. ->GetGeneratorTarget(tgt));
  4372. }
  4373. }
  4374. }
  4375. for(std::vector<cmGeneratorTarget*>::const_iterator
  4376. i = objectLibraries.begin(); i != objectLibraries.end(); ++i)
  4377. {
  4378. (*i)->GetLanguages(languages, config);
  4379. }
  4380. }
  4381. //----------------------------------------------------------------------------
  4382. void cmGeneratorTarget::ComputeLinkImplementationLanguages(
  4383. const std::string& config,
  4384. cmOptionalLinkImplementation& impl) const
  4385. {
  4386. // This target needs runtime libraries for its source languages.
  4387. std::set<std::string> languages;
  4388. // Get languages used in our source files.
  4389. this->GetLanguages(languages, config);
  4390. // Copy the set of langauges to the link implementation.
  4391. impl.Languages.insert(impl.Languages.begin(),
  4392. languages.begin(), languages.end());
  4393. }
  4394. //----------------------------------------------------------------------------
  4395. bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const
  4396. {
  4397. if (this->Target->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  4398. {
  4399. return false;
  4400. }
  4401. if(cmLinkImplementationLibraries const* impl =
  4402. this->GetLinkImplementationLibraries(config))
  4403. {
  4404. return !impl->Libraries.empty();
  4405. }
  4406. return false;
  4407. }
  4408. //----------------------------------------------------------------------------
  4409. cmLinkImplementationLibraries const*
  4410. cmGeneratorTarget::GetLinkImplementationLibraries(
  4411. const std::string& config) const
  4412. {
  4413. return this->GetLinkImplementationLibrariesInternal(config, this->Target);
  4414. }
  4415. //----------------------------------------------------------------------------
  4416. cmLinkImplementationLibraries const*
  4417. cmGeneratorTarget::GetLinkImplementationLibrariesInternal(
  4418. const std::string& config, cmTarget const* head) const
  4419. {
  4420. // There is no link implementation for imported targets.
  4421. if(this->IsImported())
  4422. {
  4423. return 0;
  4424. }
  4425. // Populate the link implementation libraries for this configuration.
  4426. std::string CONFIG = cmSystemTools::UpperCase(config);
  4427. HeadToLinkImplementationMap& hm =
  4428. this->LinkImplMap[CONFIG];
  4429. // If the link implementation does not depend on the head target
  4430. // then return the one we computed first.
  4431. if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition)
  4432. {
  4433. return &hm.begin()->second;
  4434. }
  4435. cmOptionalLinkImplementation& impl = hm[head];
  4436. if(!impl.LibrariesDone)
  4437. {
  4438. impl.LibrariesDone = true;
  4439. this->ComputeLinkImplementationLibraries(config, impl, head);
  4440. }
  4441. return &impl;
  4442. }
  4443. //----------------------------------------------------------------------------
  4444. void cmGeneratorTarget::ComputeLinkImplementationLibraries(
  4445. const std::string& config,
  4446. cmOptionalLinkImplementation& impl,
  4447. cmTarget const* head) const
  4448. {
  4449. cmStringRange entryRange =
  4450. this->Target->GetLinkImplementationEntries();
  4451. cmBacktraceRange btRange =
  4452. this->Target->GetLinkImplementationBacktraces();
  4453. cmBacktraceRange::const_iterator btIt = btRange.begin();
  4454. // Collect libraries directly linked in this configuration.
  4455. for (cmStringRange::const_iterator le = entryRange.begin(),
  4456. end = entryRange.end(); le != end; ++le, ++btIt)
  4457. {
  4458. std::vector<std::string> llibs;
  4459. cmGeneratorExpressionDAGChecker dagChecker(
  4460. this->GetName(),
  4461. "LINK_LIBRARIES", 0, 0);
  4462. cmGeneratorExpression ge(*btIt);
  4463. cmsys::auto_ptr<cmCompiledGeneratorExpression> const cge =
  4464. ge.Parse(*le);
  4465. std::string const evaluated =
  4466. cge->Evaluate(this->Makefile, config, false, head, &dagChecker);
  4467. cmSystemTools::ExpandListArgument(evaluated, llibs);
  4468. if(cge->GetHadHeadSensitiveCondition())
  4469. {
  4470. impl.HadHeadSensitiveCondition = true;
  4471. }
  4472. for(std::vector<std::string>::const_iterator li = llibs.begin();
  4473. li != llibs.end(); ++li)
  4474. {
  4475. // Skip entries that resolve to the target itself or are empty.
  4476. std::string name = this->Target->CheckCMP0004(*li);
  4477. if(name == this->GetName() || name.empty())
  4478. {
  4479. if(name == this->GetName())
  4480. {
  4481. bool noMessage = false;
  4482. cmake::MessageType messageType = cmake::FATAL_ERROR;
  4483. std::ostringstream e;
  4484. switch(this->Target->GetPolicyStatusCMP0038())
  4485. {
  4486. case cmPolicies::WARN:
  4487. {
  4488. e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0038) << "\n";
  4489. messageType = cmake::AUTHOR_WARNING;
  4490. }
  4491. break;
  4492. case cmPolicies::OLD:
  4493. noMessage = true;
  4494. case cmPolicies::REQUIRED_IF_USED:
  4495. case cmPolicies::REQUIRED_ALWAYS:
  4496. case cmPolicies::NEW:
  4497. // Issue the fatal message.
  4498. break;
  4499. }
  4500. if(!noMessage)
  4501. {
  4502. e << "Target \"" << this->GetName() << "\" links to itself.";
  4503. this->LocalGenerator->GetCMakeInstance()->IssueMessage(
  4504. messageType, e.str(), this->Target->GetBacktrace());
  4505. if (messageType == cmake::FATAL_ERROR)
  4506. {
  4507. return;
  4508. }
  4509. }
  4510. }
  4511. continue;
  4512. }
  4513. // The entry is meant for this configuration.
  4514. impl.Libraries.push_back(
  4515. cmLinkImplItem(name, this->Target->FindTargetToLink(name),
  4516. *btIt, evaluated != *le));
  4517. }
  4518. std::set<std::string> const& seenProps = cge->GetSeenTargetProperties();
  4519. for (std::set<std::string>::const_iterator it = seenProps.begin();
  4520. it != seenProps.end(); ++it)
  4521. {
  4522. if (!this->GetProperty(*it))
  4523. {
  4524. this->Target->LinkImplicitNullProperties.insert(*it);
  4525. }
  4526. }
  4527. cge->GetMaxLanguageStandard(this->Target,
  4528. this->MaxLanguageStandards);
  4529. }
  4530. cmTarget::LinkLibraryType linkType = this->Target->ComputeLinkType(config);
  4531. cmTarget::LinkLibraryVectorType const& oldllibs =
  4532. this->Target->GetOriginalLinkLibraries();
  4533. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4534. li != oldllibs.end(); ++li)
  4535. {
  4536. if(li->second != cmTarget::GENERAL && li->second != linkType)
  4537. {
  4538. std::string name = this->Target->CheckCMP0004(li->first);
  4539. if(name == this->GetName() || name.empty())
  4540. {
  4541. continue;
  4542. }
  4543. // Support OLD behavior for CMP0003.
  4544. impl.WrongConfigLibraries.push_back(
  4545. cmLinkItem(name, this->Target->FindTargetToLink(name)));
  4546. }
  4547. }
  4548. }