cmGeneratorTarget.cxx 179 KB

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