cmGeneratorTarget.cxx 183 KB

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