cmGeneratorTarget.cxx 178 KB

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