cmGeneratorTarget.cxx 179 KB

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