cmGeneratorTarget.cxx 183 KB

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