cmGeneratorTarget.cxx 146 KB

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