cmGeneratorTarget.cxx 172 KB

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