cmGeneratorTarget.cxx 172 KB

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