cmGeneratorTarget.cxx 184 KB

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