cmGeneratorTarget.cxx 183 KB

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