cmGeneratorTarget.cxx 175 KB

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