cmGeneratorTarget.cxx 172 KB

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