cmTarget.cxx 204 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmTarget.h"
  11. #include "cmake.h"
  12. #include "cmMakefile.h"
  13. #include "cmSourceFile.h"
  14. #include "cmLocalGenerator.h"
  15. #include "cmGlobalGenerator.h"
  16. #include "cmComputeLinkInformation.h"
  17. #include "cmDocumentCompileDefinitions.h"
  18. #include "cmDocumentGeneratorExpressions.h"
  19. #include "cmDocumentLocationUndefined.h"
  20. #include "cmListFileCache.h"
  21. #include "cmGeneratorExpression.h"
  22. #include "cmGeneratorExpressionDAGChecker.h"
  23. #include <cmsys/RegularExpression.hxx>
  24. #include <map>
  25. #include <set>
  26. #include <queue>
  27. #include <stdlib.h> // required for atof
  28. #include <assert.h>
  29. const char* cmTarget::GetTargetTypeName(TargetType targetType)
  30. {
  31. switch( targetType )
  32. {
  33. case cmTarget::STATIC_LIBRARY:
  34. return "STATIC_LIBRARY";
  35. case cmTarget::MODULE_LIBRARY:
  36. return "MODULE_LIBRARY";
  37. case cmTarget::SHARED_LIBRARY:
  38. return "SHARED_LIBRARY";
  39. case cmTarget::OBJECT_LIBRARY:
  40. return "OBJECT_LIBRARY";
  41. case cmTarget::EXECUTABLE:
  42. return "EXECUTABLE";
  43. case cmTarget::UTILITY:
  44. return "UTILITY";
  45. case cmTarget::GLOBAL_TARGET:
  46. return "GLOBAL_TARGET";
  47. case cmTarget::UNKNOWN_LIBRARY:
  48. return "UNKNOWN_LIBRARY";
  49. }
  50. assert(0 && "Unexpected target type");
  51. return 0;
  52. }
  53. //----------------------------------------------------------------------------
  54. struct cmTarget::OutputInfo
  55. {
  56. std::string OutDir;
  57. std::string ImpDir;
  58. std::string PdbDir;
  59. };
  60. //----------------------------------------------------------------------------
  61. struct cmTarget::ImportInfo
  62. {
  63. bool NoSOName;
  64. std::string Location;
  65. std::string SOName;
  66. std::string ImportLibrary;
  67. cmTarget::LinkInterface LinkInterface;
  68. };
  69. struct TargetConfigPair : public std::pair<cmTarget*, std::string> {
  70. TargetConfigPair(cmTarget* tgt, const std::string &config)
  71. : std::pair<cmTarget*, std::string>(tgt, config) {}
  72. };
  73. //----------------------------------------------------------------------------
  74. class cmTargetInternals
  75. {
  76. public:
  77. cmTargetInternals()
  78. {
  79. this->SourceFileFlagsConstructed = false;
  80. }
  81. cmTargetInternals(cmTargetInternals const& r)
  82. {
  83. this->SourceFileFlagsConstructed = false;
  84. // Only some of these entries are part of the object state.
  85. // Others not copied here are result caches.
  86. this->SourceEntries = r.SourceEntries;
  87. }
  88. typedef cmTarget::SourceFileFlags SourceFileFlags;
  89. std::map<cmSourceFile const*, SourceFileFlags> SourceFlagsMap;
  90. bool SourceFileFlagsConstructed;
  91. // The backtrace when the target was created.
  92. cmListFileBacktrace Backtrace;
  93. // Cache link interface computation from each configuration.
  94. struct OptionalLinkInterface: public cmTarget::LinkInterface
  95. {
  96. OptionalLinkInterface(): Exists(false) {}
  97. bool Exists;
  98. };
  99. typedef std::map<TargetConfigPair, OptionalLinkInterface>
  100. LinkInterfaceMapType;
  101. LinkInterfaceMapType LinkInterfaceMap;
  102. typedef std::map<cmStdString, cmTarget::OutputInfo> OutputInfoMapType;
  103. OutputInfoMapType OutputInfoMap;
  104. typedef std::map<TargetConfigPair, cmTarget::ImportInfo>
  105. ImportInfoMapType;
  106. ImportInfoMapType ImportInfoMap;
  107. // Cache link implementation computation from each configuration.
  108. typedef std::map<TargetConfigPair,
  109. cmTarget::LinkImplementation> LinkImplMapType;
  110. LinkImplMapType LinkImplMap;
  111. typedef std::map<TargetConfigPair, cmTarget::LinkClosure>
  112. LinkClosureMapType;
  113. LinkClosureMapType LinkClosureMap;
  114. struct SourceEntry { std::vector<cmSourceFile*> Depends; };
  115. typedef std::map<cmSourceFile*, SourceEntry> SourceEntriesType;
  116. SourceEntriesType SourceEntries;
  117. struct IncludeDirectoriesEntry {
  118. IncludeDirectoriesEntry(cmsys::auto_ptr<cmCompiledGeneratorExpression> cge)
  119. : ge(cge)
  120. {}
  121. const cmsys::auto_ptr<cmCompiledGeneratorExpression> ge;
  122. };
  123. std::vector<IncludeDirectoriesEntry*> IncludeDirectoriesEntries;
  124. };
  125. //----------------------------------------------------------------------------
  126. cmTarget::cmTarget()
  127. {
  128. this->Makefile = 0;
  129. this->PolicyStatusCMP0003 = cmPolicies::WARN;
  130. this->PolicyStatusCMP0004 = cmPolicies::WARN;
  131. this->PolicyStatusCMP0008 = cmPolicies::WARN;
  132. this->PolicyStatusCMP0020 = cmPolicies::WARN;
  133. this->LinkLibrariesAnalyzed = false;
  134. this->HaveInstallRule = false;
  135. this->DLLPlatform = false;
  136. this->IsApple = false;
  137. this->IsImportedTarget = false;
  138. this->BuildInterfaceIncludesAppended = false;
  139. this->DebugIncludesDone = false;
  140. }
  141. //----------------------------------------------------------------------------
  142. void cmTarget::DefineProperties(cmake *cm)
  143. {
  144. cm->DefineProperty
  145. ("AUTOMOC", cmProperty::TARGET,
  146. "Should the target be processed with automoc (for Qt projects).",
  147. "AUTOMOC is a boolean specifying whether CMake will handle "
  148. "the Qt moc preprocessor automatically, i.e. without having to use "
  149. "the QT4_WRAP_CPP() macro. Currently Qt4 is supported. "
  150. "When this property is set to TRUE, CMake will scan the source files "
  151. "at build time and invoke moc accordingly. "
  152. "If an #include statement like #include \"moc_foo.cpp\" is found, "
  153. "the Q_OBJECT class declaration is expected in the header, and moc is "
  154. "run on the header file. "
  155. "If an #include statement like #include \"foo.moc\" is found, "
  156. "then a Q_OBJECT is expected in the current source file and moc "
  157. "is run on the file itself. "
  158. "Additionally, all header files are parsed for Q_OBJECT macros, "
  159. "and if found, moc is also executed on those files. The resulting "
  160. "moc files, which are not included as shown above in any of the source "
  161. "files are included in a generated <targetname>_automoc.cpp file, "
  162. "which is compiled as part of the target."
  163. "This property is initialized by the value of the variable "
  164. "CMAKE_AUTOMOC if it is set when a target is created.\n"
  165. "Additional command line options for moc can be set via the "
  166. "AUTOMOC_MOC_OPTIONS property.\n"
  167. "By setting the CMAKE_AUTOMOC_RELAXED_MODE variable to TRUE the rules "
  168. "for searching the files which will be processed by moc can be relaxed. "
  169. "See the documentation for this variable for more details.");
  170. cm->DefineProperty
  171. ("AUTOMOC_MOC_OPTIONS", cmProperty::TARGET,
  172. "Additional options for moc when using automoc (see the AUTOMOC property)",
  173. "This property is only used if the AUTOMOC property is set to TRUE for "
  174. "this target. In this case, it holds additional command line options "
  175. "which will be used when moc is executed during the build, i.e. it is "
  176. "equivalent to the optional OPTIONS argument of the qt4_wrap_cpp() "
  177. "macro.\n"
  178. "By default it is empty.");
  179. cm->DefineProperty
  180. ("BUILD_WITH_INSTALL_RPATH", cmProperty::TARGET,
  181. "Should build tree targets have install tree rpaths.",
  182. "BUILD_WITH_INSTALL_RPATH is a boolean specifying whether to link "
  183. "the target in the build tree with the INSTALL_RPATH. This takes "
  184. "precedence over SKIP_BUILD_RPATH and avoids the need for relinking "
  185. "before installation. "
  186. "This property is initialized by the value of the variable "
  187. "CMAKE_BUILD_WITH_INSTALL_RPATH if it is set when a target is created.");
  188. cm->DefineProperty
  189. ("COMPILE_FLAGS", cmProperty::TARGET,
  190. "Additional flags to use when compiling this target's sources.",
  191. "The COMPILE_FLAGS property sets additional compiler flags used "
  192. "to build sources within the target. Use COMPILE_DEFINITIONS "
  193. "to pass additional preprocessor definitions.");
  194. cm->DefineProperty
  195. ("COMPILE_DEFINITIONS", cmProperty::TARGET,
  196. "Preprocessor definitions for compiling a target's sources.",
  197. "The COMPILE_DEFINITIONS property may be set to a "
  198. "semicolon-separated list of preprocessor "
  199. "definitions using the syntax VAR or VAR=value. Function-style "
  200. "definitions are not supported. CMake will automatically escape "
  201. "the value correctly for the native build system (note that CMake "
  202. "language syntax may require escapes to specify some values). "
  203. "This property may be set on a per-configuration basis using the name "
  204. "COMPILE_DEFINITIONS_<CONFIG> where <CONFIG> is an upper-case name "
  205. "(ex. \"COMPILE_DEFINITIONS_DEBUG\").\n"
  206. "CMake will automatically drop some definitions that "
  207. "are not supported by the native build tool. "
  208. "The VS6 IDE does not support definition values with spaces "
  209. "(but NMake does).\n"
  210. "Contents of COMPILE_DEFINITIONS may use \"generator expressions\" with "
  211. "the syntax \"$<...>\". "
  212. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS
  213. CM_DOCUMENT_COMPILE_DEFINITIONS_DISCLAIMER);
  214. cm->DefineProperty
  215. ("COMPILE_DEFINITIONS_<CONFIG>", cmProperty::TARGET,
  216. "Per-configuration preprocessor definitions on a target.",
  217. "This is the configuration-specific version of COMPILE_DEFINITIONS.");
  218. cm->DefineProperty
  219. ("DEFINE_SYMBOL", cmProperty::TARGET,
  220. "Define a symbol when compiling this target's sources.",
  221. "DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
  222. "compiling sources in a shared library. "
  223. "If not set here then it is set to target_EXPORTS by default "
  224. "(with some substitutions if the target is not a valid C "
  225. "identifier). This is useful for headers to know whether they are "
  226. "being included from inside their library our outside to properly "
  227. "setup dllexport/dllimport decorations. ");
  228. cm->DefineProperty
  229. ("DEBUG_POSTFIX", cmProperty::TARGET,
  230. "See target property <CONFIG>_POSTFIX.",
  231. "This property is a special case of the more-general <CONFIG>_POSTFIX "
  232. "property for the DEBUG configuration.");
  233. cm->DefineProperty
  234. ("<CONFIG>_POSTFIX", cmProperty::TARGET,
  235. "Postfix to append to the target file name for configuration <CONFIG>.",
  236. "When building with configuration <CONFIG> the value of this property "
  237. "is appended to the target file name built on disk. "
  238. "For non-executable targets, this property is initialized by the value "
  239. "of the variable CMAKE_<CONFIG>_POSTFIX if it is set when a target is "
  240. "created. "
  241. "This property is ignored on the Mac for Frameworks and App Bundles.");
  242. cm->DefineProperty
  243. ("EchoString", cmProperty::TARGET,
  244. "A message to be displayed when the target is built.",
  245. "A message to display on some generators (such as makefiles) when "
  246. "the target is built.");
  247. cm->DefineProperty
  248. ("BUNDLE", cmProperty::TARGET,
  249. "This target is a CFBundle on the Mac.",
  250. "If a module library target has this property set to true it will "
  251. "be built as a CFBundle when built on the mac. It will have the "
  252. "directory structure required for a CFBundle and will be suitable "
  253. "to be used for creating Browser Plugins or other application "
  254. "resources.");
  255. cm->DefineProperty
  256. ("BUNDLE_EXTENSION", cmProperty::TARGET,
  257. "The file extension used to name a BUNDLE target on the Mac.",
  258. "The default value is \"bundle\" - you can also use \"plugin\" or "
  259. "whatever file extension is required by the host app for your "
  260. "bundle.");
  261. cm->DefineProperty
  262. ("EXCLUDE_FROM_DEFAULT_BUILD", cmProperty::TARGET,
  263. "Exclude target from \"Build Solution\".",
  264. "This property is only used by Visual Studio generators 7 and above. "
  265. "When set to TRUE, the target will not be built when you press "
  266. "\"Build Solution\".");
  267. cm->DefineProperty
  268. ("EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG>", cmProperty::TARGET,
  269. "Per-configuration version of target exclusion from \"Build Solution\". ",
  270. "This is the configuration-specific version of "
  271. "EXCLUDE_FROM_DEFAULT_BUILD. If the generic EXCLUDE_FROM_DEFAULT_BUILD "
  272. "is also set on a target, EXCLUDE_FROM_DEFAULT_BUILD_<CONFIG> takes "
  273. "precedence in configurations for which it has a value.");
  274. cm->DefineProperty
  275. ("FRAMEWORK", cmProperty::TARGET,
  276. "This target is a framework on the Mac.",
  277. "If a shared library target has this property set to true it will "
  278. "be built as a framework when built on the mac. It will have the "
  279. "directory structure required for a framework and will be suitable "
  280. "to be used with the -framework option");
  281. cm->DefineProperty
  282. ("HAS_CXX", cmProperty::TARGET,
  283. "Link the target using the C++ linker tool (obsolete).",
  284. "This is equivalent to setting the LINKER_LANGUAGE property to CXX. "
  285. "See that property's documentation for details.");
  286. cm->DefineProperty
  287. ("IMPLICIT_DEPENDS_INCLUDE_TRANSFORM", cmProperty::TARGET,
  288. "Specify #include line transforms for dependencies in a target.",
  289. "This property specifies rules to transform macro-like #include lines "
  290. "during implicit dependency scanning of C and C++ source files. "
  291. "The list of rules must be semicolon-separated with each entry of "
  292. "the form \"A_MACRO(%)=value-with-%\" (the % must be literal). "
  293. "During dependency scanning occurrences of A_MACRO(...) on #include "
  294. "lines will be replaced by the value given with the macro argument "
  295. "substituted for '%'. For example, the entry\n"
  296. " MYDIR(%)=<mydir/%>\n"
  297. "will convert lines of the form\n"
  298. " #include MYDIR(myheader.h)\n"
  299. "to\n"
  300. " #include <mydir/myheader.h>\n"
  301. "allowing the dependency to be followed.\n"
  302. "This property applies to sources in the target on which it is set.");
  303. cm->DefineProperty
  304. ("IMPORT_PREFIX", cmProperty::TARGET,
  305. "What comes before the import library name.",
  306. "Similar to the target property PREFIX, but used for import libraries "
  307. "(typically corresponding to a DLL) instead of regular libraries. "
  308. "A target property that can be set to override the prefix "
  309. "(such as \"lib\") on an import library name.");
  310. cm->DefineProperty
  311. ("IMPORT_SUFFIX", cmProperty::TARGET,
  312. "What comes after the import library name.",
  313. "Similar to the target property SUFFIX, but used for import libraries "
  314. "(typically corresponding to a DLL) instead of regular libraries. "
  315. "A target property that can be set to override the suffix "
  316. "(such as \".lib\") on an import library name.");
  317. cm->DefineProperty
  318. ("IMPORTED", cmProperty::TARGET,
  319. "Read-only indication of whether a target is IMPORTED.",
  320. "The boolean value of this property is true for targets created with "
  321. "the IMPORTED option to add_executable or add_library. "
  322. "It is false for targets built within the project.");
  323. cm->DefineProperty
  324. ("IMPORTED_CONFIGURATIONS", cmProperty::TARGET,
  325. "Configurations provided for an IMPORTED target.",
  326. "Set this to the list of configuration names available for an "
  327. "IMPORTED target. "
  328. "The names correspond to configurations defined in the project from "
  329. "which the target is imported. "
  330. "If the importing project uses a different set of configurations "
  331. "the names may be mapped using the MAP_IMPORTED_CONFIG_<CONFIG> "
  332. "property. "
  333. "Ignored for non-imported targets.");
  334. cm->DefineProperty
  335. ("IMPORTED_IMPLIB", cmProperty::TARGET,
  336. "Full path to the import library for an IMPORTED target.",
  337. "Set this to the location of the \".lib\" part of a windows DLL. "
  338. "Ignored for non-imported targets.");
  339. cm->DefineProperty
  340. ("IMPORTED_IMPLIB_<CONFIG>", cmProperty::TARGET,
  341. "<CONFIG>-specific version of IMPORTED_IMPLIB property.",
  342. "Configuration names correspond to those provided by the project "
  343. "from which the target is imported.");
  344. cm->DefineProperty
  345. ("IMPORTED_LINK_DEPENDENT_LIBRARIES", cmProperty::TARGET,
  346. "Dependent shared libraries of an imported shared library.",
  347. "Shared libraries may be linked to other shared libraries as part "
  348. "of their implementation. On some platforms the linker searches "
  349. "for the dependent libraries of shared libraries they are including "
  350. "in the link. "
  351. "Set this property to the list of dependent shared libraries of an "
  352. "imported library. "
  353. "The list "
  354. "should be disjoint from the list of interface libraries in the "
  355. "IMPORTED_LINK_INTERFACE_LIBRARIES property. On platforms requiring "
  356. "dependent shared libraries to be found at link time CMake uses this "
  357. "list to add appropriate files or paths to the link command line. "
  358. "Ignored for non-imported targets.");
  359. cm->DefineProperty
  360. ("IMPORTED_LINK_DEPENDENT_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  361. "<CONFIG>-specific version of IMPORTED_LINK_DEPENDENT_LIBRARIES.",
  362. "Configuration names correspond to those provided by the project "
  363. "from which the target is imported. "
  364. "If set, this property completely overrides the generic property "
  365. "for the named configuration.");
  366. cm->DefineProperty
  367. ("IMPORTED_LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  368. "Transitive link interface of an IMPORTED target.",
  369. "Set this to the list of libraries whose interface is included when "
  370. "an IMPORTED library target is linked to another target. "
  371. "The libraries will be included on the link line for the target. "
  372. "Unlike the LINK_INTERFACE_LIBRARIES property, this property applies "
  373. "to all imported target types, including STATIC libraries. "
  374. "This property is ignored for non-imported targets.");
  375. cm->DefineProperty
  376. ("IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  377. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LIBRARIES.",
  378. "Configuration names correspond to those provided by the project "
  379. "from which the target is imported. "
  380. "If set, this property completely overrides the generic property "
  381. "for the named configuration.");
  382. cm->DefineProperty
  383. ("IMPORTED_LINK_INTERFACE_LANGUAGES", cmProperty::TARGET,
  384. "Languages compiled into an IMPORTED static library.",
  385. "Set this to the list of languages of source files compiled to "
  386. "produce a STATIC IMPORTED library (such as \"C\" or \"CXX\"). "
  387. "CMake accounts for these languages when computing how to link a "
  388. "target to the imported library. "
  389. "For example, when a C executable links to an imported C++ static "
  390. "library CMake chooses the C++ linker to satisfy language runtime "
  391. "dependencies of the static library. "
  392. "\n"
  393. "This property is ignored for targets that are not STATIC libraries. "
  394. "This property is ignored for non-imported targets.");
  395. cm->DefineProperty
  396. ("IMPORTED_LINK_INTERFACE_LANGUAGES_<CONFIG>", cmProperty::TARGET,
  397. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_LANGUAGES.",
  398. "Configuration names correspond to those provided by the project "
  399. "from which the target is imported. "
  400. "If set, this property completely overrides the generic property "
  401. "for the named configuration.");
  402. cm->DefineProperty
  403. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  404. "Repetition count for cycles of IMPORTED static libraries.",
  405. "This is LINK_INTERFACE_MULTIPLICITY for IMPORTED targets.");
  406. cm->DefineProperty
  407. ("IMPORTED_LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  408. "<CONFIG>-specific version of IMPORTED_LINK_INTERFACE_MULTIPLICITY.",
  409. "If set, this property completely overrides the generic property "
  410. "for the named configuration.");
  411. cm->DefineProperty
  412. ("IMPORTED_LOCATION", cmProperty::TARGET,
  413. "Full path to the main file on disk for an IMPORTED target.",
  414. "Set this to the location of an IMPORTED target file on disk. "
  415. "For executables this is the location of the executable file. "
  416. "For bundles on OS X this is the location of the executable file "
  417. "inside Contents/MacOS under the application bundle folder. "
  418. "For static libraries and modules this is the location of the "
  419. "library or module. "
  420. "For shared libraries on non-DLL platforms this is the location of "
  421. "the shared library. "
  422. "For frameworks on OS X this is the location of the library file "
  423. "symlink just inside the framework folder. "
  424. "For DLLs this is the location of the \".dll\" part of the library. "
  425. "For UNKNOWN libraries this is the location of the file to be linked. "
  426. "Ignored for non-imported targets."
  427. "\n"
  428. "Projects may skip IMPORTED_LOCATION if the configuration-specific "
  429. "property IMPORTED_LOCATION_<CONFIG> is set. "
  430. "To get the location of an imported target read one of the "
  431. "LOCATION or LOCATION_<CONFIG> properties.");
  432. cm->DefineProperty
  433. ("IMPORTED_LOCATION_<CONFIG>", cmProperty::TARGET,
  434. "<CONFIG>-specific version of IMPORTED_LOCATION property.",
  435. "Configuration names correspond to those provided by the project "
  436. "from which the target is imported.");
  437. cm->DefineProperty
  438. ("IMPORTED_SONAME", cmProperty::TARGET,
  439. "The \"soname\" of an IMPORTED target of shared library type.",
  440. "Set this to the \"soname\" embedded in an imported shared library. "
  441. "This is meaningful only on platforms supporting the feature. "
  442. "Ignored for non-imported targets.");
  443. cm->DefineProperty
  444. ("IMPORTED_SONAME_<CONFIG>", cmProperty::TARGET,
  445. "<CONFIG>-specific version of IMPORTED_SONAME property.",
  446. "Configuration names correspond to those provided by the project "
  447. "from which the target is imported.");
  448. cm->DefineProperty
  449. ("IMPORTED_NO_SONAME", cmProperty::TARGET,
  450. "Specifies that an IMPORTED shared library target has no \"soname\". ",
  451. "Set this property to true for an imported shared library file that "
  452. "has no \"soname\" field. "
  453. "CMake may adjust generated link commands for some platforms to prevent "
  454. "the linker from using the path to the library in place of its missing "
  455. "soname. "
  456. "Ignored for non-imported targets.");
  457. cm->DefineProperty
  458. ("IMPORTED_NO_SONAME_<CONFIG>", cmProperty::TARGET,
  459. "<CONFIG>-specific version of IMPORTED_NO_SONAME property.",
  460. "Configuration names correspond to those provided by the project "
  461. "from which the target is imported.");
  462. cm->DefineProperty
  463. ("EXCLUDE_FROM_ALL", cmProperty::TARGET,
  464. "Exclude the target from the all target.",
  465. "A property on a target that indicates if the target is excluded "
  466. "from the default build target. If it is not, then with a Makefile "
  467. "for example typing make will cause this target to be built. "
  468. "The same concept applies to the default build of other generators. "
  469. "Installing a target with EXCLUDE_FROM_ALL set to true has "
  470. "undefined behavior.");
  471. cm->DefineProperty
  472. ("LINK_LIBRARIES", cmProperty::TARGET,
  473. "List of direct link dependencies.",
  474. "This property specifies the list of libraries or targets which will be "
  475. "used for linking. "
  476. "In addition to accepting values from the target_link_libraries "
  477. "command, values may be set directly on any target using the "
  478. "set_property command. "
  479. "\n"
  480. "The target property values are used by the generators to set "
  481. "the link libraries for the compiler. "
  482. "See also the target_link_libraries command.\n"
  483. "Contents of LINK_LIBRARIES may use \"generator expressions\" with "
  484. "the syntax \"$<...>\". "
  485. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  486. cm->DefineProperty
  487. ("INCLUDE_DIRECTORIES", cmProperty::TARGET,
  488. "List of preprocessor include file search directories.",
  489. "This property specifies the list of directories given "
  490. "so far to the include_directories command. "
  491. "This property exists on directories and targets. "
  492. "In addition to accepting values from the include_directories "
  493. "command, values may be set directly on any directory or any "
  494. "target using the set_property command. "
  495. "A target gets its initial value for this property from the value "
  496. "of the directory property. "
  497. "A directory gets its initial value from its parent directory if "
  498. "it has one. "
  499. "Both directory and target property values are adjusted by calls "
  500. "to the include_directories command."
  501. "\n"
  502. "The target property values are used by the generators to set "
  503. "the include paths for the compiler. "
  504. "See also the include_directories command.\n"
  505. "Contents of INCLUDE_DIRECTORIES may use \"generator expressions\" with "
  506. "the syntax \"$<...>\". "
  507. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  508. cm->DefineProperty
  509. ("INSTALL_NAME_DIR", cmProperty::TARGET,
  510. "Mac OSX directory name for installed targets.",
  511. "INSTALL_NAME_DIR is a string specifying the "
  512. "directory portion of the \"install_name\" field of shared libraries "
  513. "on Mac OSX to use in the installed targets. ");
  514. cm->DefineProperty
  515. ("INSTALL_RPATH", cmProperty::TARGET,
  516. "The rpath to use for installed targets.",
  517. "A semicolon-separated list specifying the rpath "
  518. "to use in installed targets (for platforms that support it). "
  519. "This property is initialized by the value of the variable "
  520. "CMAKE_INSTALL_RPATH if it is set when a target is created.");
  521. cm->DefineProperty
  522. ("INSTALL_RPATH_USE_LINK_PATH", cmProperty::TARGET,
  523. "Add paths to linker search and installed rpath.",
  524. "INSTALL_RPATH_USE_LINK_PATH is a boolean that if set to true will "
  525. "append directories in the linker search path and outside the "
  526. "project to the INSTALL_RPATH. "
  527. "This property is initialized by the value of the variable "
  528. "CMAKE_INSTALL_RPATH_USE_LINK_PATH if it is set when a target is "
  529. "created.");
  530. cm->DefineProperty
  531. ("INTERPROCEDURAL_OPTIMIZATION", cmProperty::TARGET,
  532. "Enable interprocedural optimization for a target.",
  533. "If set to true, enables interprocedural optimizations "
  534. "if they are known to be supported by the compiler.");
  535. cm->DefineProperty
  536. ("INTERPROCEDURAL_OPTIMIZATION_<CONFIG>", cmProperty::TARGET,
  537. "Per-configuration interprocedural optimization for a target.",
  538. "This is a per-configuration version of INTERPROCEDURAL_OPTIMIZATION. "
  539. "If set, this property overrides the generic property "
  540. "for the named configuration.");
  541. cm->DefineProperty
  542. ("LABELS", cmProperty::TARGET,
  543. "Specify a list of text labels associated with a target.",
  544. "Target label semantics are currently unspecified.");
  545. cm->DefineProperty
  546. ("LINK_FLAGS", cmProperty::TARGET,
  547. "Additional flags to use when linking this target.",
  548. "The LINK_FLAGS property can be used to add extra flags to the "
  549. "link step of a target. LINK_FLAGS_<CONFIG> will add to the "
  550. "configuration <CONFIG>, "
  551. "for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. ");
  552. cm->DefineProperty
  553. ("LINK_FLAGS_<CONFIG>", cmProperty::TARGET,
  554. "Per-configuration linker flags for a target.",
  555. "This is the configuration-specific version of LINK_FLAGS.");
  556. #define CM_LINK_SEARCH_SUMMARY \
  557. "Some linkers support switches such as -Bstatic and -Bdynamic " \
  558. "to determine whether to use static or shared libraries for -lXXX " \
  559. "options. CMake uses these options to set the link type for " \
  560. "libraries whose full paths are not known or (in some cases) are in " \
  561. "implicit link directories for the platform. "
  562. cm->DefineProperty
  563. ("LINK_SEARCH_START_STATIC", cmProperty::TARGET,
  564. "Assume the linker looks for static libraries by default.",
  565. CM_LINK_SEARCH_SUMMARY
  566. "By default the linker search type is assumed to be -Bdynamic at "
  567. "the beginning of the library list. This property switches the "
  568. "assumption to -Bstatic. It is intended for use when linking an "
  569. "executable statically (e.g. with the GNU -static option). "
  570. "See also LINK_SEARCH_END_STATIC.");
  571. cm->DefineProperty
  572. ("LINK_SEARCH_END_STATIC", cmProperty::TARGET,
  573. "End a link line such that static system libraries are used.",
  574. CM_LINK_SEARCH_SUMMARY
  575. "By default CMake adds an option at the end of the library list (if "
  576. "necessary) to set the linker search type back to its starting type. "
  577. "This property switches the final linker search type to -Bstatic "
  578. "regardless of how it started. "
  579. "See also LINK_SEARCH_START_STATIC.");
  580. cm->DefineProperty
  581. ("LINKER_LANGUAGE", cmProperty::TARGET,
  582. "Specifies language whose compiler will invoke the linker.",
  583. "For executables, shared libraries, and modules, this sets the "
  584. "language whose compiler is used to link the target "
  585. "(such as \"C\" or \"CXX\"). "
  586. "A typical value for an executable is the language of the source "
  587. "file providing the program entry point (main). "
  588. "If not set, the language with the highest linker preference "
  589. "value is the default. "
  590. "See documentation of CMAKE_<LANG>_LINKER_PREFERENCE variables.");
  591. cm->DefineProperty
  592. ("LOCATION", cmProperty::TARGET,
  593. "Read-only location of a target on disk.",
  594. "For an imported target, this read-only property returns the value of "
  595. "the LOCATION_<CONFIG> property for an unspecified configuration "
  596. "<CONFIG> provided by the target.\n"
  597. "For a non-imported target, this property is provided for compatibility "
  598. "with CMake 2.4 and below. "
  599. "It was meant to get the location of an executable target's output file "
  600. "for use in add_custom_command. "
  601. "The path may contain a build-system-specific portion that "
  602. "is replaced at build time with the configuration getting built "
  603. "(such as \"$(ConfigurationName)\" in VS). "
  604. "In CMake 2.6 and above add_custom_command automatically recognizes a "
  605. "target name in its COMMAND and DEPENDS options and computes the "
  606. "target location. "
  607. "In CMake 2.8.4 and above add_custom_command recognizes generator "
  608. "expressions to refer to target locations anywhere in the command. "
  609. "Therefore this property is not needed for creating custom commands."
  610. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  611. cm->DefineProperty
  612. ("LOCATION_<CONFIG>", cmProperty::TARGET,
  613. "Read-only property providing a target location on disk.",
  614. "A read-only property that indicates where a target's main file is "
  615. "located on disk for the configuration <CONFIG>. "
  616. "The property is defined only for library and executable targets. "
  617. "An imported target may provide a set of configurations different "
  618. "from that of the importing project. "
  619. "By default CMake looks for an exact-match but otherwise uses an "
  620. "arbitrary available configuration. "
  621. "Use the MAP_IMPORTED_CONFIG_<CONFIG> property to map imported "
  622. "configurations explicitly."
  623. CM_LOCATION_UNDEFINED_BEHAVIOR("reading this property"));
  624. cm->DefineProperty
  625. ("LINK_DEPENDS", cmProperty::TARGET,
  626. "Additional files on which a target binary depends for linking.",
  627. "Specifies a semicolon-separated list of full-paths to files on which "
  628. "the link rule for this target depends. "
  629. "The target binary will be linked if any of the named files is newer "
  630. "than it."
  631. "\n"
  632. "This property is ignored by non-Makefile generators. "
  633. "It is intended to specify dependencies on \"linker scripts\" for "
  634. "custom Makefile link rules.");
  635. cm->DefineProperty
  636. ("LINK_DEPENDS_NO_SHARED", cmProperty::TARGET,
  637. "Do not depend on linked shared library files.",
  638. "Set this property to true to tell CMake generators not to add "
  639. "file-level dependencies on the shared library files linked by "
  640. "this target. "
  641. "Modification to the shared libraries will not be sufficient to "
  642. "re-link this target. "
  643. "Logical target-level dependencies will not be affected so the "
  644. "linked shared libraries will still be brought up to date before "
  645. "this target is built."
  646. "\n"
  647. "This property is initialized by the value of the variable "
  648. "CMAKE_LINK_DEPENDS_NO_SHARED if it is set when a target is "
  649. "created.");
  650. cm->DefineProperty
  651. ("LINK_INTERFACE_LIBRARIES", cmProperty::TARGET,
  652. "List public interface libraries for a shared library or executable.",
  653. "By default linking to a shared library target transitively "
  654. "links to targets with which the library itself was linked. "
  655. "For an executable with exports (see the ENABLE_EXPORTS property) "
  656. "no default transitive link dependencies are used. "
  657. "This property replaces the default transitive link dependencies with "
  658. "an explicit list. "
  659. "When the target is linked into another target the libraries "
  660. "listed (and recursively their link interface libraries) will be "
  661. "provided to the other target also. "
  662. "If the list is empty then no transitive link dependencies will be "
  663. "incorporated when this target is linked into another target even if "
  664. "the default set is non-empty. "
  665. "This property is initialized by the value of the variable "
  666. "CMAKE_LINK_INTERFACE_LIBRARIES if it is set when a target is "
  667. "created. "
  668. "This property is ignored for STATIC libraries.");
  669. cm->DefineProperty
  670. ("LINK_INTERFACE_LIBRARIES_<CONFIG>", cmProperty::TARGET,
  671. "Per-configuration list of public interface libraries for a target.",
  672. "This is the configuration-specific version of "
  673. "LINK_INTERFACE_LIBRARIES. "
  674. "If set, this property completely overrides the generic property "
  675. "for the named configuration.");
  676. cm->DefineProperty
  677. ("INTERFACE_INCLUDE_DIRECTORIES", cmProperty::TARGET,
  678. "List of public include directories for a library.",
  679. "Targets may populate this property to publish the include directories "
  680. "required to compile against the headers for the target. Consuming "
  681. "targets can add entries to their own INCLUDE_DIRECTORIES property such "
  682. "as $<TARGET_PROPERTY:foo,INTERFACE_INCLUDE_DIRECTORIES> to use the "
  683. "include directories specified in the interface of 'foo'."
  684. "\n"
  685. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  686. cm->DefineProperty
  687. ("INTERFACE_COMPILE_DEFINITIONS", cmProperty::TARGET,
  688. "List of public compile definitions for a library.",
  689. "Targets may populate this property to publish the compile definitions "
  690. "required to compile against the headers for the target. Consuming "
  691. "targets can add entries to their own COMPILE_DEFINITIONS property such "
  692. "as $<TARGET_PROPERTY:foo,INTERFACE_COMPILE_DEFINITIONS> to use the "
  693. "compile definitions specified in the interface of 'foo'."
  694. "\n"
  695. CM_DOCUMENT_COMMAND_GENERATOR_EXPRESSIONS);
  696. cm->DefineProperty
  697. ("LINK_INTERFACE_MULTIPLICITY", cmProperty::TARGET,
  698. "Repetition count for STATIC libraries with cyclic dependencies.",
  699. "When linking to a STATIC library target with cyclic dependencies the "
  700. "linker may need to scan more than once through the archives in the "
  701. "strongly connected component of the dependency graph. "
  702. "CMake by default constructs the link line so that the linker will "
  703. "scan through the component at least twice. "
  704. "This property specifies the minimum number of scans if it is larger "
  705. "than the default. "
  706. "CMake uses the largest value specified by any target in a component.");
  707. cm->DefineProperty
  708. ("LINK_INTERFACE_MULTIPLICITY_<CONFIG>", cmProperty::TARGET,
  709. "Per-configuration repetition count for cycles of STATIC libraries.",
  710. "This is the configuration-specific version of "
  711. "LINK_INTERFACE_MULTIPLICITY. "
  712. "If set, this property completely overrides the generic property "
  713. "for the named configuration.");
  714. cm->DefineProperty
  715. ("MAP_IMPORTED_CONFIG_<CONFIG>", cmProperty::TARGET,
  716. "Map from project configuration to IMPORTED target's configuration.",
  717. "Set this to the list of configurations of an imported target that "
  718. "may be used for the current project's <CONFIG> configuration. "
  719. "Targets imported from another project may not provide the same set "
  720. "of configuration names available in the current project. "
  721. "Setting this property tells CMake what imported configurations are "
  722. "suitable for use when building the <CONFIG> configuration. "
  723. "The first configuration in the list found to be provided by the "
  724. "imported target is selected. If this property is set and no matching "
  725. "configurations are available, then the imported target is considered "
  726. "to be not found. This property is ignored for non-imported targets.",
  727. false /* TODO: make this chained */ );
  728. cm->DefineProperty
  729. ("OSX_ARCHITECTURES", cmProperty::TARGET,
  730. "Target specific architectures for OS X.",
  731. "The OSX_ARCHITECTURES property sets the target binary architecture "
  732. "for targets on OS X. "
  733. "This property is initialized by the value of the variable "
  734. "CMAKE_OSX_ARCHITECTURES if it is set when a target is created. "
  735. "Use OSX_ARCHITECTURES_<CONFIG> to set the binary architectures on a "
  736. "per-configuration basis. "
  737. "<CONFIG> is an upper-case name (ex: \"OSX_ARCHITECTURES_DEBUG\").");
  738. cm->DefineProperty
  739. ("OSX_ARCHITECTURES_<CONFIG>", cmProperty::TARGET,
  740. "Per-configuration OS X binary architectures for a target.",
  741. "This property is the configuration-specific version of "
  742. "OSX_ARCHITECTURES.");
  743. cm->DefineProperty
  744. ("OUTPUT_NAME", cmProperty::TARGET,
  745. "Output name for target files.",
  746. "This sets the base name for output files created for an executable or "
  747. "library target. "
  748. "If not set, the logical target name is used by default.");
  749. cm->DefineProperty
  750. ("OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  751. "Per-configuration target file base name.",
  752. "This is the configuration-specific version of OUTPUT_NAME.");
  753. cm->DefineProperty
  754. ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET,
  755. "Old per-configuration target file base name.",
  756. "This is a configuration-specific version of OUTPUT_NAME. "
  757. "Use OUTPUT_NAME_<CONFIG> instead.");
  758. cm->DefineProperty
  759. ("PDB_NAME", cmProperty::TARGET,
  760. "Output name for MS debug symbols .pdb file.",
  761. "Set the base name for debug symbols file created for an "
  762. "executable or library target. "
  763. "If not set, the logical target name is used by default. "
  764. "\n"
  765. "This property is not implemented by the Visual Studio 6 generator.");
  766. cm->DefineProperty
  767. ("PDB_NAME_<CONFIG>", cmProperty::TARGET,
  768. "Per-configuration name for MS debug symbols .pdb file. ",
  769. "This is the configuration-specific version of PDB_NAME. "
  770. "\n"
  771. "This property is not implemented by the Visual Studio 6 generator.");
  772. cm->DefineProperty
  773. ("PRE_INSTALL_SCRIPT", cmProperty::TARGET,
  774. "Deprecated install support.",
  775. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  776. "old way to specify CMake scripts to run before and after "
  777. "installing a target. They are used only when the old "
  778. "INSTALL_TARGETS command is used to install the target. Use the "
  779. "INSTALL command instead.");
  780. cm->DefineProperty
  781. ("PREFIX", cmProperty::TARGET,
  782. "What comes before the library name.",
  783. "A target property that can be set to override the prefix "
  784. "(such as \"lib\") on a library name.");
  785. cm->DefineProperty
  786. ("POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  787. "Whether to create a position-independent target",
  788. "The POSITION_INDEPENDENT_CODE property determines whether position "
  789. "independent executables or shared libraries will be created. "
  790. "This property is true by default for SHARED and MODULE library "
  791. "targets and false otherwise. "
  792. "This property is initialized by the value of the variable "
  793. "CMAKE_POSITION_INDEPENDENT_CODE if it is set when a target is "
  794. "created.");
  795. cm->DefineProperty
  796. ("INTERFACE_POSITION_INDEPENDENT_CODE", cmProperty::TARGET,
  797. "Whether consumers need to create a position-independent target",
  798. "The INTERFACE_POSITION_INDEPENDENT_CODE property informs consumers of "
  799. "this target whether they must set their POSITION_INDEPENDENT_CODE "
  800. "property to ON. If this property is set to ON, then the "
  801. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  802. "ON. Similarly, if this property is set to OFF, then the "
  803. "POSITION_INDEPENDENT_CODE property on all consumers will be set to "
  804. "OFF. If this property is undefined, then consumers will determine "
  805. "their POSITION_INDEPENDENT_CODE property by other means. Consumers "
  806. "must ensure that the targets that they link to have a consistent "
  807. "requirement for their INTERFACE_POSITION_INDEPENDENT_CODE property.");
  808. cm->DefineProperty
  809. ("COMPATIBLE_INTERFACE_BOOL", cmProperty::TARGET,
  810. "Properties which must be compatible with their link interface",
  811. "The COMPATIBLE_INTERFACE_BOOL property may contain a list of properties"
  812. "for this target which must be consistent when evaluated as a boolean "
  813. "in the INTERFACE of all linked dependencies. For example, if a "
  814. "property \"FOO\" appears in the list, then the \"INTERFACE_FOO\" "
  815. "property content in all dependencies must be consistent with each "
  816. "other, and with the \"FOO\" property in this target. "
  817. "Consistency in this sense has the meaning that if the property is set,"
  818. "then it must have the same boolean value as all others, and if the "
  819. "property is not set, then it is ignored.");
  820. cm->DefineProperty
  821. ("COMPATIBLE_INTERFACE_STRING", cmProperty::TARGET,
  822. "Properties which must be string-compatible with their link interface",
  823. "The COMPATIBLE_INTERFACE_STRING property may contain a list of "
  824. "properties for this target which must be the same when evaluated as "
  825. "a string in the INTERFACE of all linked dependencies. For example, "
  826. "if a property \"FOO\" appears in the list, then the \"INTERFACE_FOO\" "
  827. "property content in all dependencies must be equal with each "
  828. "other, and with the \"FOO\" property in this target. If the "
  829. "property is not set, then it is ignored.");
  830. cm->DefineProperty
  831. ("POST_INSTALL_SCRIPT", cmProperty::TARGET,
  832. "Deprecated install support.",
  833. "The PRE_INSTALL_SCRIPT and POST_INSTALL_SCRIPT properties are the "
  834. "old way to specify CMake scripts to run before and after "
  835. "installing a target. They are used only when the old "
  836. "INSTALL_TARGETS command is used to install the target. Use the "
  837. "INSTALL command instead.");
  838. cm->DefineProperty
  839. ("PRIVATE_HEADER", cmProperty::TARGET,
  840. "Specify private header files in a FRAMEWORK shared library target.",
  841. "Shared library targets marked with the FRAMEWORK property generate "
  842. "frameworks on OS X and normal shared libraries on other platforms. "
  843. "This property may be set to a list of header files to be placed "
  844. "in the PrivateHeaders directory inside the framework folder. "
  845. "On non-Apple platforms these headers may be installed using the "
  846. "PRIVATE_HEADER option to the install(TARGETS) command.");
  847. cm->DefineProperty
  848. ("PUBLIC_HEADER", cmProperty::TARGET,
  849. "Specify public header files in a FRAMEWORK shared library target.",
  850. "Shared library targets marked with the FRAMEWORK property generate "
  851. "frameworks on OS X and normal shared libraries on other platforms. "
  852. "This property may be set to a list of header files to be placed "
  853. "in the Headers directory inside the framework folder. "
  854. "On non-Apple platforms these headers may be installed using the "
  855. "PUBLIC_HEADER option to the install(TARGETS) command.");
  856. cm->DefineProperty
  857. ("RESOURCE", cmProperty::TARGET,
  858. "Specify resource files in a FRAMEWORK shared library target.",
  859. "Shared library targets marked with the FRAMEWORK property generate "
  860. "frameworks on OS X and normal shared libraries on other platforms. "
  861. "This property may be set to a list of files to be placed "
  862. "in the Resources directory inside the framework folder. "
  863. "On non-Apple platforms these files may be installed using the "
  864. "RESOURCE option to the install(TARGETS) command.");
  865. cm->DefineProperty
  866. ("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
  867. "Specify a launcher for compile rules.",
  868. "See the global property of the same name for details. "
  869. "This overrides the global and directory property for a target.",
  870. true);
  871. cm->DefineProperty
  872. ("RULE_LAUNCH_LINK", cmProperty::TARGET,
  873. "Specify a launcher for link rules.",
  874. "See the global property of the same name for details. "
  875. "This overrides the global and directory property for a target.",
  876. true);
  877. cm->DefineProperty
  878. ("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
  879. "Specify a launcher for custom rules.",
  880. "See the global property of the same name for details. "
  881. "This overrides the global and directory property for a target.",
  882. true);
  883. cm->DefineProperty
  884. ("SKIP_BUILD_RPATH", cmProperty::TARGET,
  885. "Should rpaths be used for the build tree.",
  886. "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic "
  887. "generation of an rpath allowing the target to run from the "
  888. "build tree. "
  889. "This property is initialized by the value of the variable "
  890. "CMAKE_SKIP_BUILD_RPATH if it is set when a target is created.");
  891. cm->DefineProperty
  892. ("NO_SONAME", cmProperty::TARGET,
  893. "Whether to set \"soname\" when linking a shared library or module.",
  894. "Enable this boolean property if a generated shared library or module "
  895. "should not have \"soname\" set. Default is to set \"soname\" on all "
  896. "shared libraries and modules as long as the platform supports it. "
  897. "Generally, use this property only for leaf private libraries or "
  898. "plugins. If you use it on normal shared libraries which other targets "
  899. "link against, on some platforms a linker will insert a full path to "
  900. "the library (as specified at link time) into the dynamic section of "
  901. "the dependent binary. Therefore, once installed, dynamic loader may "
  902. "eventually fail to locate the library for the binary.");
  903. cm->DefineProperty
  904. ("SOVERSION", cmProperty::TARGET,
  905. "What version number is this target.",
  906. "For shared libraries VERSION and SOVERSION can be used to specify "
  907. "the build version and api version respectively. When building or "
  908. "installing appropriate symlinks are created if the platform "
  909. "supports symlinks and the linker supports so-names. "
  910. "If only one of both is specified the missing is assumed to have "
  911. "the same version number. "
  912. "SOVERSION is ignored if NO_SONAME property is set. "
  913. "For shared libraries and executables on Windows the VERSION "
  914. "attribute is parsed to extract a \"major.minor\" version number. "
  915. "These numbers are used as the image version of the binary. ");
  916. cm->DefineProperty
  917. ("STATIC_LIBRARY_FLAGS", cmProperty::TARGET,
  918. "Extra flags to use when linking static libraries.",
  919. "Extra flags to use when linking a static library.");
  920. cm->DefineProperty
  921. ("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
  922. "Per-configuration flags for creating a static library.",
  923. "This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
  924. cm->DefineProperty
  925. ("SUFFIX", cmProperty::TARGET,
  926. "What comes after the target name.",
  927. "A target property that can be set to override the suffix "
  928. "(such as \".so\" or \".exe\") on the name of a library, module or "
  929. "executable.");
  930. cm->DefineProperty
  931. ("TYPE", cmProperty::TARGET,
  932. "The type of the target.",
  933. "This read-only property can be used to test the type of the given "
  934. "target. It will be one of STATIC_LIBRARY, MODULE_LIBRARY, "
  935. "SHARED_LIBRARY, EXECUTABLE or one of the internal target types.");
  936. cm->DefineProperty
  937. ("VERSION", cmProperty::TARGET,
  938. "What version number is this target.",
  939. "For shared libraries VERSION and SOVERSION can be used to specify "
  940. "the build version and api version respectively. When building or "
  941. "installing appropriate symlinks are created if the platform "
  942. "supports symlinks and the linker supports so-names. "
  943. "If only one of both is specified the missing is assumed to have "
  944. "the same version number. "
  945. "For executables VERSION can be used to specify the build version. "
  946. "When building or installing appropriate symlinks are created if "
  947. "the platform supports symlinks. "
  948. "For shared libraries and executables on Windows the VERSION "
  949. "attribute is parsed to extract a \"major.minor\" version number. "
  950. "These numbers are used as the image version of the binary. ");
  951. cm->DefineProperty
  952. ("WIN32_EXECUTABLE", cmProperty::TARGET,
  953. "Build an executable with a WinMain entry point on windows.",
  954. "When this property is set to true the executable when linked "
  955. "on Windows will be created with a WinMain() entry point instead "
  956. "of just main(). "
  957. "This makes it a GUI executable instead of a console application. "
  958. "See the CMAKE_MFC_FLAG variable documentation to configure use "
  959. "of MFC for WinMain executables. "
  960. "This property is initialized by the value of the variable "
  961. "CMAKE_WIN32_EXECUTABLE if it is set when a target is created.");
  962. cm->DefineProperty
  963. ("MACOSX_BUNDLE", cmProperty::TARGET,
  964. "Build an executable as an application bundle on Mac OS X.",
  965. "When this property is set to true the executable when built "
  966. "on Mac OS X will be created as an application bundle. "
  967. "This makes it a GUI executable that can be launched from "
  968. "the Finder. "
  969. "See the MACOSX_BUNDLE_INFO_PLIST target property for information "
  970. "about creation of the Info.plist file for the application bundle. "
  971. "This property is initialized by the value of the variable "
  972. "CMAKE_MACOSX_BUNDLE if it is set when a target is created.");
  973. cm->DefineProperty
  974. ("MACOSX_BUNDLE_INFO_PLIST", cmProperty::TARGET,
  975. "Specify a custom Info.plist template for a Mac OS X App Bundle.",
  976. "An executable target with MACOSX_BUNDLE enabled will be built as an "
  977. "application bundle on Mac OS X. "
  978. "By default its Info.plist file is created by configuring a template "
  979. "called MacOSXBundleInfo.plist.in located in the CMAKE_MODULE_PATH. "
  980. "This property specifies an alternative template file name which "
  981. "may be a full path.\n"
  982. "The following target properties may be set to specify content to "
  983. "be configured into the file:\n"
  984. " MACOSX_BUNDLE_INFO_STRING\n"
  985. " MACOSX_BUNDLE_ICON_FILE\n"
  986. " MACOSX_BUNDLE_GUI_IDENTIFIER\n"
  987. " MACOSX_BUNDLE_LONG_VERSION_STRING\n"
  988. " MACOSX_BUNDLE_BUNDLE_NAME\n"
  989. " MACOSX_BUNDLE_SHORT_VERSION_STRING\n"
  990. " MACOSX_BUNDLE_BUNDLE_VERSION\n"
  991. " MACOSX_BUNDLE_COPYRIGHT\n"
  992. "CMake variables of the same name may be set to affect all targets "
  993. "in a directory that do not have each specific property set. "
  994. "If a custom Info.plist is specified by this property it may of course "
  995. "hard-code all the settings instead of using the target properties.");
  996. cm->DefineProperty
  997. ("MACOSX_FRAMEWORK_INFO_PLIST", cmProperty::TARGET,
  998. "Specify a custom Info.plist template for a Mac OS X Framework.",
  999. "An library target with FRAMEWORK enabled will be built as a "
  1000. "framework on Mac OS X. "
  1001. "By default its Info.plist file is created by configuring a template "
  1002. "called MacOSXFrameworkInfo.plist.in located in the CMAKE_MODULE_PATH. "
  1003. "This property specifies an alternative template file name which "
  1004. "may be a full path.\n"
  1005. "The following target properties may be set to specify content to "
  1006. "be configured into the file:\n"
  1007. " MACOSX_FRAMEWORK_ICON_FILE\n"
  1008. " MACOSX_FRAMEWORK_IDENTIFIER\n"
  1009. " MACOSX_FRAMEWORK_SHORT_VERSION_STRING\n"
  1010. " MACOSX_FRAMEWORK_BUNDLE_VERSION\n"
  1011. "CMake variables of the same name may be set to affect all targets "
  1012. "in a directory that do not have each specific property set. "
  1013. "If a custom Info.plist is specified by this property it may of course "
  1014. "hard-code all the settings instead of using the target properties.");
  1015. cm->DefineProperty
  1016. ("ENABLE_EXPORTS", cmProperty::TARGET,
  1017. "Specify whether an executable exports symbols for loadable modules.",
  1018. "Normally an executable does not export any symbols because it is "
  1019. "the final program. It is possible for an executable to export "
  1020. "symbols to be used by loadable modules. When this property is "
  1021. "set to true CMake will allow other targets to \"link\" to the "
  1022. "executable with the TARGET_LINK_LIBRARIES command. "
  1023. "On all platforms a target-level dependency on the executable is "
  1024. "created for targets that link to it. "
  1025. "For DLL platforms an import library will be created for the "
  1026. "exported symbols and then used for linking. "
  1027. "All Windows-based systems including Cygwin are DLL platforms. "
  1028. "For non-DLL platforms that require all symbols to be resolved at "
  1029. "link time, such as Mac OS X, the module will \"link\" to the "
  1030. "executable using a flag like \"-bundle_loader\". "
  1031. "For other non-DLL platforms the link rule is simply ignored since "
  1032. "the dynamic loader will automatically bind symbols when the "
  1033. "module is loaded. "
  1034. );
  1035. cm->DefineProperty
  1036. ("Fortran_FORMAT", cmProperty::TARGET,
  1037. "Set to FIXED or FREE to indicate the Fortran source layout.",
  1038. "This property tells CMake whether the Fortran source files "
  1039. "in a target use fixed-format or free-format. "
  1040. "CMake will pass the corresponding format flag to the compiler. "
  1041. "Use the source-specific Fortran_FORMAT property to change the "
  1042. "format of a specific source file. "
  1043. "If the variable CMAKE_Fortran_FORMAT is set when a target "
  1044. "is created its value is used to initialize this property.");
  1045. cm->DefineProperty
  1046. ("Fortran_MODULE_DIRECTORY", cmProperty::TARGET,
  1047. "Specify output directory for Fortran modules provided by the target.",
  1048. "If the target contains Fortran source files that provide modules "
  1049. "and the compiler supports a module output directory this specifies "
  1050. "the directory in which the modules will be placed. "
  1051. "When this property is not set the modules will be placed in the "
  1052. "build directory corresponding to the target's source directory. "
  1053. "If the variable CMAKE_Fortran_MODULE_DIRECTORY is set when a target "
  1054. "is created its value is used to initialize this property."
  1055. "\n"
  1056. "Note that some compilers will automatically search the module output "
  1057. "directory for modules USEd during compilation but others will not. "
  1058. "If your sources USE modules their location must be specified by "
  1059. "INCLUDE_DIRECTORIES regardless of this property.");
  1060. cm->DefineProperty
  1061. ("GNUtoMS", cmProperty::TARGET,
  1062. "Convert GNU import library (.dll.a) to MS format (.lib).",
  1063. "When linking a shared library or executable that exports symbols "
  1064. "using GNU tools on Windows (MinGW/MSYS) with Visual Studio installed "
  1065. "convert the import library (.dll.a) from GNU to MS format (.lib). "
  1066. "Both import libraries will be installed by install(TARGETS) and "
  1067. "exported by install(EXPORT) and export() to be linked by applications "
  1068. "with either GNU- or MS-compatible tools."
  1069. "\n"
  1070. "If the variable CMAKE_GNUtoMS is set when a target "
  1071. "is created its value is used to initialize this property. "
  1072. "The variable must be set prior to the first command that enables "
  1073. "a language such as project() or enable_language(). "
  1074. "CMake provides the variable as an option to the user automatically "
  1075. "when configuring on Windows with GNU tools.");
  1076. cm->DefineProperty
  1077. ("XCODE_ATTRIBUTE_<an-attribute>", cmProperty::TARGET,
  1078. "Set Xcode target attributes directly.",
  1079. "Tell the Xcode generator to set '<an-attribute>' to a given value "
  1080. "in the generated Xcode project. Ignored on other generators.");
  1081. cm->DefineProperty
  1082. ("GENERATOR_FILE_NAME", cmProperty::TARGET,
  1083. "Generator's file for this target.",
  1084. "An internal property used by some generators to record the name of "
  1085. "project or dsp file associated with this target.");
  1086. cm->DefineProperty
  1087. ("SOURCES", cmProperty::TARGET,
  1088. "Source names specified for a target.",
  1089. "Read-only list of sources specified for a target. "
  1090. "The names returned are suitable for passing to the "
  1091. "set_source_files_properties command.");
  1092. cm->DefineProperty
  1093. ("FOLDER", cmProperty::TARGET,
  1094. "Set the folder name. Use to organize targets in an IDE.",
  1095. "Targets with no FOLDER property will appear as top level "
  1096. "entities in IDEs like Visual Studio. Targets with the same "
  1097. "FOLDER property value will appear next to each other in a "
  1098. "folder of that name. To nest folders, use FOLDER values such "
  1099. "as 'GUI/Dialogs' with '/' characters separating folder levels.");
  1100. cm->DefineProperty
  1101. ("PROJECT_LABEL", cmProperty::TARGET,
  1102. "Change the name of a target in an IDE.",
  1103. "Can be used to change the name of the target in an IDE "
  1104. "like Visual Studio. ");
  1105. cm->DefineProperty
  1106. ("VS_KEYWORD", cmProperty::TARGET,
  1107. "Visual Studio project keyword.",
  1108. "Can be set to change the visual studio keyword, for example "
  1109. "Qt integration works better if this is set to Qt4VSv1.0. ");
  1110. cm->DefineProperty
  1111. ("VS_SCC_PROVIDER", cmProperty::TARGET,
  1112. "Visual Studio Source Code Control Provider.",
  1113. "Can be set to change the visual studio source code control "
  1114. "provider property.");
  1115. cm->DefineProperty
  1116. ("VS_SCC_LOCALPATH", cmProperty::TARGET,
  1117. "Visual Studio Source Code Control Local Path.",
  1118. "Can be set to change the visual studio source code control "
  1119. "local path property.");
  1120. cm->DefineProperty
  1121. ("VS_SCC_PROJECTNAME", cmProperty::TARGET,
  1122. "Visual Studio Source Code Control Project.",
  1123. "Can be set to change the visual studio source code control "
  1124. "project name property.");
  1125. cm->DefineProperty
  1126. ("VS_SCC_AUXPATH", cmProperty::TARGET,
  1127. "Visual Studio Source Code Control Aux Path.",
  1128. "Can be set to change the visual studio source code control "
  1129. "auxpath property.");
  1130. cm->DefineProperty
  1131. ("VS_GLOBAL_PROJECT_TYPES", cmProperty::TARGET,
  1132. "Visual Studio project type(s).",
  1133. "Can be set to one or more UUIDs recognized by Visual Studio "
  1134. "to indicate the type of project. This value is copied "
  1135. "verbatim into the generated project file. Example for a "
  1136. "managed C++ unit testing project:\n"
  1137. " {3AC096D0-A1C2-E12C-1390-A8335801FDAB};"
  1138. "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\n"
  1139. "UUIDs are semicolon-delimited.");
  1140. cm->DefineProperty
  1141. ("VS_GLOBAL_KEYWORD", cmProperty::TARGET,
  1142. "Visual Studio project keyword.",
  1143. "Sets the \"keyword\" attribute for a generated Visual Studio "
  1144. "project. Defaults to \"Win32Proj\". You may wish to override "
  1145. "this value with \"ManagedCProj\", for example, in a Visual "
  1146. "Studio managed C++ unit test project.");
  1147. cm->DefineProperty
  1148. ("VS_DOTNET_REFERENCES", cmProperty::TARGET,
  1149. "Visual Studio managed project .NET references",
  1150. "Adds one or more semicolon-delimited .NET references to a "
  1151. "generated Visual Studio project. For example, \"System;"
  1152. "System.Windows.Forms\".");
  1153. cm->DefineProperty
  1154. ("VS_WINRT_EXTENSIONS", cmProperty::TARGET,
  1155. "Visual Studio project C++/CX language extensions for Windows Runtime",
  1156. "Can be set to enable C++/CX language extensions.");
  1157. cm->DefineProperty
  1158. ("VS_WINRT_REFERENCES", cmProperty::TARGET,
  1159. "Visual Studio project Windows Runtime Metadata references",
  1160. "Adds one or more semicolon-delimited WinRT references to a "
  1161. "generated Visual Studio project. For example, \"Windows;"
  1162. "Windows.UI.Core\".");
  1163. cm->DefineProperty
  1164. ("VS_GLOBAL_<variable>", cmProperty::TARGET,
  1165. "Visual Studio project-specific global variable.",
  1166. "Tell the Visual Studio generator to set the global variable "
  1167. "'<variable>' to a given value in the generated Visual Studio "
  1168. "project. Ignored on other generators. Qt integration works "
  1169. "better if VS_GLOBAL_QtVersion is set to the version "
  1170. "FindQt4.cmake found. For example, \"4.7.3\"");
  1171. #define CM_TARGET_FILE_TYPES_DOC \
  1172. "There are three kinds of target files that may be built: " \
  1173. "archive, library, and runtime. " \
  1174. "Executables are always treated as runtime targets. " \
  1175. "Static libraries are always treated as archive targets. " \
  1176. "Module libraries are always treated as library targets. " \
  1177. "For non-DLL platforms shared libraries are treated as library " \
  1178. "targets. " \
  1179. "For DLL platforms the DLL part of a shared library is treated as " \
  1180. "a runtime target and the corresponding import library is treated as " \
  1181. "an archive target. " \
  1182. "All Windows-based systems including Cygwin are DLL platforms."
  1183. #define CM_TARGET_OUTDIR_DOC(TYPE, type) \
  1184. "This property specifies the directory into which " #type " target " \
  1185. "files should be built. " \
  1186. "Multi-configuration generators (VS, Xcode) append " \
  1187. "a per-configuration subdirectory to the specified directory. " \
  1188. CM_TARGET_FILE_TYPES_DOC " " \
  1189. "This property is initialized by the value of the variable " \
  1190. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY if it is set when a target is created."
  1191. #define CM_TARGET_OUTDIR_CONFIG_DOC(TYPE) \
  1192. "This is a per-configuration version of " #TYPE "_OUTPUT_DIRECTORY, " \
  1193. "but multi-configuration generators (VS, Xcode) do NOT append " \
  1194. "a per-configuration subdirectory to the specified directory. " \
  1195. "This property is initialized by the value of the variable " \
  1196. "CMAKE_" #TYPE "_OUTPUT_DIRECTORY_<CONFIG> " \
  1197. "if it is set when a target is created."
  1198. cm->DefineProperty
  1199. ("ARCHIVE_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1200. "Output directory in which to build ARCHIVE target files.",
  1201. CM_TARGET_OUTDIR_DOC(ARCHIVE, archive));
  1202. cm->DefineProperty
  1203. ("ARCHIVE_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1204. "Per-configuration output directory for ARCHIVE target files.",
  1205. CM_TARGET_OUTDIR_CONFIG_DOC(ARCHIVE));
  1206. cm->DefineProperty
  1207. ("LIBRARY_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1208. "Output directory in which to build LIBRARY target files.",
  1209. CM_TARGET_OUTDIR_DOC(LIBRARY, library));
  1210. cm->DefineProperty
  1211. ("LIBRARY_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1212. "Per-configuration output directory for LIBRARY target files.",
  1213. CM_TARGET_OUTDIR_CONFIG_DOC(LIBRARY));
  1214. cm->DefineProperty
  1215. ("RUNTIME_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1216. "Output directory in which to build RUNTIME target files.",
  1217. CM_TARGET_OUTDIR_DOC(RUNTIME, runtime));
  1218. cm->DefineProperty
  1219. ("RUNTIME_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1220. "Per-configuration output directory for RUNTIME target files.",
  1221. CM_TARGET_OUTDIR_CONFIG_DOC(RUNTIME));
  1222. cm->DefineProperty
  1223. ("PDB_OUTPUT_DIRECTORY", cmProperty::TARGET,
  1224. "Output directory for MS debug symbols .pdb files.",
  1225. "This property specifies the directory into which the MS debug symbols "
  1226. "will be placed. "
  1227. "This property is initialized by the value of the variable "
  1228. "CMAKE_PDB_OUTPUT_DIRECTORY if it is set when a target is created."
  1229. "\n"
  1230. "This property is not implemented by the Visual Studio 6 generator.");
  1231. cm->DefineProperty
  1232. ("PDB_OUTPUT_DIRECTORY_<CONFIG>", cmProperty::TARGET,
  1233. "Per-configuration output directory for MS debug symbols .pdb files.",
  1234. "This is a per-configuration version of PDB_OUTPUT_DIRECTORY, "
  1235. "but multi-configuration generators (VS, Xcode) do NOT append "
  1236. "a per-configuration subdirectory to the specified directory. "
  1237. "This property is initialized by the value of the variable "
  1238. "CMAKE_PDB_OUTPUT_DIRECTORY_<CONFIG> "
  1239. "if it is set when a target is created."
  1240. "\n"
  1241. "This property is not implemented by the Visual Studio 6 generator.");
  1242. cm->DefineProperty
  1243. ("ARCHIVE_OUTPUT_NAME", cmProperty::TARGET,
  1244. "Output name for ARCHIVE target files.",
  1245. "This property specifies the base name for archive target files. "
  1246. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1247. CM_TARGET_FILE_TYPES_DOC);
  1248. cm->DefineProperty
  1249. ("ARCHIVE_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1250. "Per-configuration output name for ARCHIVE target files.",
  1251. "This is the configuration-specific version of ARCHIVE_OUTPUT_NAME.");
  1252. cm->DefineProperty
  1253. ("LIBRARY_OUTPUT_NAME", cmProperty::TARGET,
  1254. "Output name for LIBRARY target files.",
  1255. "This property specifies the base name for library target files. "
  1256. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1257. CM_TARGET_FILE_TYPES_DOC);
  1258. cm->DefineProperty
  1259. ("LIBRARY_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1260. "Per-configuration output name for LIBRARY target files.",
  1261. "This is the configuration-specific version of LIBRARY_OUTPUT_NAME.");
  1262. cm->DefineProperty
  1263. ("RUNTIME_OUTPUT_NAME", cmProperty::TARGET,
  1264. "Output name for RUNTIME target files.",
  1265. "This property specifies the base name for runtime target files. "
  1266. "It overrides OUTPUT_NAME and OUTPUT_NAME_<CONFIG> properties. "
  1267. CM_TARGET_FILE_TYPES_DOC);
  1268. cm->DefineProperty
  1269. ("RUNTIME_OUTPUT_NAME_<CONFIG>", cmProperty::TARGET,
  1270. "Per-configuration output name for RUNTIME target files.",
  1271. "This is the configuration-specific version of RUNTIME_OUTPUT_NAME.");
  1272. }
  1273. void cmTarget::SetType(TargetType type, const char* name)
  1274. {
  1275. this->Name = name;
  1276. // only add dependency information for library targets
  1277. this->TargetTypeValue = type;
  1278. if(this->TargetTypeValue >= STATIC_LIBRARY
  1279. && this->TargetTypeValue <= MODULE_LIBRARY)
  1280. {
  1281. this->RecordDependencies = true;
  1282. }
  1283. else
  1284. {
  1285. this->RecordDependencies = false;
  1286. }
  1287. }
  1288. //----------------------------------------------------------------------------
  1289. void cmTarget::SetMakefile(cmMakefile* mf)
  1290. {
  1291. // Set our makefile.
  1292. this->Makefile = mf;
  1293. // set the cmake instance of the properties
  1294. this->Properties.SetCMakeInstance(mf->GetCMakeInstance());
  1295. // Check whether this is a DLL platform.
  1296. this->DLLPlatform = (this->Makefile->IsOn("WIN32") ||
  1297. this->Makefile->IsOn("CYGWIN") ||
  1298. this->Makefile->IsOn("MINGW"));
  1299. // Check whether we are targeting an Apple platform.
  1300. this->IsApple = this->Makefile->IsOn("APPLE");
  1301. // Setup default property values.
  1302. this->SetPropertyDefault("INSTALL_NAME_DIR", "");
  1303. this->SetPropertyDefault("INSTALL_RPATH", "");
  1304. this->SetPropertyDefault("INSTALL_RPATH_USE_LINK_PATH", "OFF");
  1305. this->SetPropertyDefault("SKIP_BUILD_RPATH", "OFF");
  1306. this->SetPropertyDefault("BUILD_WITH_INSTALL_RPATH", "OFF");
  1307. this->SetPropertyDefault("ARCHIVE_OUTPUT_DIRECTORY", 0);
  1308. this->SetPropertyDefault("LIBRARY_OUTPUT_DIRECTORY", 0);
  1309. this->SetPropertyDefault("RUNTIME_OUTPUT_DIRECTORY", 0);
  1310. this->SetPropertyDefault("PDB_OUTPUT_DIRECTORY", 0);
  1311. this->SetPropertyDefault("Fortran_FORMAT", 0);
  1312. this->SetPropertyDefault("Fortran_MODULE_DIRECTORY", 0);
  1313. this->SetPropertyDefault("GNUtoMS", 0);
  1314. this->SetPropertyDefault("OSX_ARCHITECTURES", 0);
  1315. this->SetPropertyDefault("AUTOMOC", 0);
  1316. this->SetPropertyDefault("AUTOMOC_MOC_OPTIONS", 0);
  1317. this->SetPropertyDefault("LINK_DEPENDS_NO_SHARED", 0);
  1318. this->SetPropertyDefault("LINK_INTERFACE_LIBRARIES", 0);
  1319. this->SetPropertyDefault("WIN32_EXECUTABLE", 0);
  1320. this->SetPropertyDefault("MACOSX_BUNDLE", 0);
  1321. // Collect the set of configuration types.
  1322. std::vector<std::string> configNames;
  1323. mf->GetConfigurations(configNames);
  1324. // Setup per-configuration property default values.
  1325. const char* configProps[] = {
  1326. "ARCHIVE_OUTPUT_DIRECTORY_",
  1327. "LIBRARY_OUTPUT_DIRECTORY_",
  1328. "RUNTIME_OUTPUT_DIRECTORY_",
  1329. "PDB_OUTPUT_DIRECTORY_",
  1330. 0};
  1331. for(std::vector<std::string>::iterator ci = configNames.begin();
  1332. ci != configNames.end(); ++ci)
  1333. {
  1334. std::string configUpper = cmSystemTools::UpperCase(*ci);
  1335. for(const char** p = configProps; *p; ++p)
  1336. {
  1337. std::string property = *p;
  1338. property += configUpper;
  1339. this->SetPropertyDefault(property.c_str(), 0);
  1340. }
  1341. // Initialize per-configuration name postfix property from the
  1342. // variable only for non-executable targets. This preserves
  1343. // compatibility with previous CMake versions in which executables
  1344. // did not support this variable. Projects may still specify the
  1345. // property directly. TODO: Make this depend on backwards
  1346. // compatibility setting.
  1347. if(this->TargetTypeValue != cmTarget::EXECUTABLE)
  1348. {
  1349. std::string property = cmSystemTools::UpperCase(*ci);
  1350. property += "_POSTFIX";
  1351. this->SetPropertyDefault(property.c_str(), 0);
  1352. }
  1353. }
  1354. // Save the backtrace of target construction.
  1355. this->Makefile->GetBacktrace(this->Internal->Backtrace);
  1356. // Initialize the INCLUDE_DIRECTORIES property based on the current value
  1357. // of the same directory property:
  1358. const std::vector<cmMakefileIncludeDirectoriesEntry> parentIncludes =
  1359. this->Makefile->GetIncludeDirectoriesEntries();
  1360. for (std::vector<cmMakefileIncludeDirectoriesEntry>::const_iterator it
  1361. = parentIncludes.begin(); it != parentIncludes.end(); ++it)
  1362. {
  1363. this->InsertInclude(*it);
  1364. }
  1365. if(this->TargetTypeValue == cmTarget::SHARED_LIBRARY
  1366. || this->TargetTypeValue == cmTarget::MODULE_LIBRARY)
  1367. {
  1368. this->SetProperty("POSITION_INDEPENDENT_CODE", "True");
  1369. }
  1370. this->SetPropertyDefault("POSITION_INDEPENDENT_CODE", 0);
  1371. // Record current policies for later use.
  1372. this->PolicyStatusCMP0003 =
  1373. this->Makefile->GetPolicyStatus(cmPolicies::CMP0003);
  1374. this->PolicyStatusCMP0004 =
  1375. this->Makefile->GetPolicyStatus(cmPolicies::CMP0004);
  1376. this->PolicyStatusCMP0008 =
  1377. this->Makefile->GetPolicyStatus(cmPolicies::CMP0008);
  1378. this->PolicyStatusCMP0020 =
  1379. this->Makefile->GetPolicyStatus(cmPolicies::CMP0020);
  1380. }
  1381. //----------------------------------------------------------------------------
  1382. void cmTarget::FinishConfigure()
  1383. {
  1384. // Erase any cached link information that might have been comptued
  1385. // on-demand during the configuration. This ensures that build
  1386. // system generation uses up-to-date information even if other cache
  1387. // invalidation code in this source file is buggy.
  1388. this->ClearLinkMaps();
  1389. // Do old-style link dependency analysis.
  1390. this->AnalyzeLibDependencies(*this->Makefile);
  1391. }
  1392. //----------------------------------------------------------------------------
  1393. void cmTarget::ClearLinkMaps()
  1394. {
  1395. this->Internal->LinkImplMap.clear();
  1396. this->Internal->LinkInterfaceMap.clear();
  1397. this->Internal->LinkClosureMap.clear();
  1398. for (cmTargetLinkInformationMap::const_iterator it
  1399. = this->LinkInformation.begin();
  1400. it != this->LinkInformation.end(); ++it)
  1401. {
  1402. delete it->second;
  1403. }
  1404. this->LinkInformation.clear();
  1405. }
  1406. //----------------------------------------------------------------------------
  1407. cmListFileBacktrace const& cmTarget::GetBacktrace() const
  1408. {
  1409. return this->Internal->Backtrace;
  1410. }
  1411. //----------------------------------------------------------------------------
  1412. std::string cmTarget::GetSupportDirectory() const
  1413. {
  1414. std::string dir = this->Makefile->GetCurrentOutputDirectory();
  1415. dir += cmake::GetCMakeFilesDirectory();
  1416. dir += "/";
  1417. dir += this->Name;
  1418. #if defined(__VMS)
  1419. dir += "_dir";
  1420. #else
  1421. dir += ".dir";
  1422. #endif
  1423. return dir;
  1424. }
  1425. //----------------------------------------------------------------------------
  1426. bool cmTarget::IsExecutableWithExports()
  1427. {
  1428. return (this->GetType() == cmTarget::EXECUTABLE &&
  1429. this->GetPropertyAsBool("ENABLE_EXPORTS"));
  1430. }
  1431. //----------------------------------------------------------------------------
  1432. bool cmTarget::IsLinkable()
  1433. {
  1434. return (this->GetType() == cmTarget::STATIC_LIBRARY ||
  1435. this->GetType() == cmTarget::SHARED_LIBRARY ||
  1436. this->GetType() == cmTarget::MODULE_LIBRARY ||
  1437. this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
  1438. this->IsExecutableWithExports());
  1439. }
  1440. //----------------------------------------------------------------------------
  1441. bool cmTarget::HasImportLibrary()
  1442. {
  1443. return (this->DLLPlatform &&
  1444. (this->GetType() == cmTarget::SHARED_LIBRARY ||
  1445. this->IsExecutableWithExports()));
  1446. }
  1447. //----------------------------------------------------------------------------
  1448. bool cmTarget::IsFrameworkOnApple()
  1449. {
  1450. return (this->GetType() == cmTarget::SHARED_LIBRARY &&
  1451. this->Makefile->IsOn("APPLE") &&
  1452. this->GetPropertyAsBool("FRAMEWORK"));
  1453. }
  1454. //----------------------------------------------------------------------------
  1455. bool cmTarget::IsAppBundleOnApple()
  1456. {
  1457. return (this->GetType() == cmTarget::EXECUTABLE &&
  1458. this->Makefile->IsOn("APPLE") &&
  1459. this->GetPropertyAsBool("MACOSX_BUNDLE"));
  1460. }
  1461. //----------------------------------------------------------------------------
  1462. bool cmTarget::IsCFBundleOnApple()
  1463. {
  1464. return (this->GetType() == cmTarget::MODULE_LIBRARY &&
  1465. this->Makefile->IsOn("APPLE") &&
  1466. this->GetPropertyAsBool("BUNDLE"));
  1467. }
  1468. //----------------------------------------------------------------------------
  1469. class cmTargetTraceDependencies
  1470. {
  1471. public:
  1472. cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1473. const char* vsProjectFile);
  1474. void Trace();
  1475. private:
  1476. cmTarget* Target;
  1477. cmTargetInternals* Internal;
  1478. cmMakefile* Makefile;
  1479. cmGlobalGenerator* GlobalGenerator;
  1480. typedef cmTargetInternals::SourceEntry SourceEntry;
  1481. SourceEntry* CurrentEntry;
  1482. std::queue<cmSourceFile*> SourceQueue;
  1483. std::set<cmSourceFile*> SourcesQueued;
  1484. typedef std::map<cmStdString, cmSourceFile*> NameMapType;
  1485. NameMapType NameMap;
  1486. void QueueSource(cmSourceFile* sf);
  1487. void FollowName(std::string const& name);
  1488. void FollowNames(std::vector<std::string> const& names);
  1489. bool IsUtility(std::string const& dep);
  1490. void CheckCustomCommand(cmCustomCommand const& cc);
  1491. void CheckCustomCommands(const std::vector<cmCustomCommand>& commands);
  1492. };
  1493. //----------------------------------------------------------------------------
  1494. cmTargetTraceDependencies
  1495. ::cmTargetTraceDependencies(cmTarget* target, cmTargetInternals* internal,
  1496. const char* vsProjectFile):
  1497. Target(target), Internal(internal)
  1498. {
  1499. // Convenience.
  1500. this->Makefile = this->Target->GetMakefile();
  1501. this->GlobalGenerator =
  1502. this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  1503. this->CurrentEntry = 0;
  1504. // Queue all the source files already specified for the target.
  1505. std::vector<cmSourceFile*> const& sources = this->Target->GetSourceFiles();
  1506. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1507. si != sources.end(); ++si)
  1508. {
  1509. this->QueueSource(*si);
  1510. }
  1511. // Queue the VS project file to check dependencies on the rule to
  1512. // generate it.
  1513. if(vsProjectFile)
  1514. {
  1515. this->FollowName(vsProjectFile);
  1516. }
  1517. // Queue pre-build, pre-link, and post-build rule dependencies.
  1518. this->CheckCustomCommands(this->Target->GetPreBuildCommands());
  1519. this->CheckCustomCommands(this->Target->GetPreLinkCommands());
  1520. this->CheckCustomCommands(this->Target->GetPostBuildCommands());
  1521. }
  1522. //----------------------------------------------------------------------------
  1523. void cmTargetTraceDependencies::Trace()
  1524. {
  1525. // Process one dependency at a time until the queue is empty.
  1526. while(!this->SourceQueue.empty())
  1527. {
  1528. // Get the next source from the queue.
  1529. cmSourceFile* sf = this->SourceQueue.front();
  1530. this->SourceQueue.pop();
  1531. this->CurrentEntry = &this->Internal->SourceEntries[sf];
  1532. // Queue dependencies added explicitly by the user.
  1533. if(const char* additionalDeps = sf->GetProperty("OBJECT_DEPENDS"))
  1534. {
  1535. std::vector<std::string> objDeps;
  1536. cmSystemTools::ExpandListArgument(additionalDeps, objDeps);
  1537. this->FollowNames(objDeps);
  1538. }
  1539. // Queue the source needed to generate this file, if any.
  1540. this->FollowName(sf->GetFullPath());
  1541. // Queue dependencies added programatically by commands.
  1542. this->FollowNames(sf->GetDepends());
  1543. // Queue custom command dependencies.
  1544. if(cmCustomCommand const* cc = sf->GetCustomCommand())
  1545. {
  1546. this->CheckCustomCommand(*cc);
  1547. }
  1548. }
  1549. this->CurrentEntry = 0;
  1550. }
  1551. //----------------------------------------------------------------------------
  1552. void cmTargetTraceDependencies::QueueSource(cmSourceFile* sf)
  1553. {
  1554. if(this->SourcesQueued.insert(sf).second)
  1555. {
  1556. this->SourceQueue.push(sf);
  1557. // Make sure this file is in the target.
  1558. this->Target->AddSourceFile(sf);
  1559. }
  1560. }
  1561. //----------------------------------------------------------------------------
  1562. void cmTargetTraceDependencies::FollowName(std::string const& name)
  1563. {
  1564. NameMapType::iterator i = this->NameMap.find(name);
  1565. if(i == this->NameMap.end())
  1566. {
  1567. // Check if we know how to generate this file.
  1568. cmSourceFile* sf = this->Makefile->GetSourceFileWithOutput(name.c_str());
  1569. NameMapType::value_type entry(name, sf);
  1570. i = this->NameMap.insert(entry).first;
  1571. }
  1572. if(cmSourceFile* sf = i->second)
  1573. {
  1574. // Record the dependency we just followed.
  1575. if(this->CurrentEntry)
  1576. {
  1577. this->CurrentEntry->Depends.push_back(sf);
  1578. }
  1579. this->QueueSource(sf);
  1580. }
  1581. }
  1582. //----------------------------------------------------------------------------
  1583. void
  1584. cmTargetTraceDependencies::FollowNames(std::vector<std::string> const& names)
  1585. {
  1586. for(std::vector<std::string>::const_iterator i = names.begin();
  1587. i != names.end(); ++i)
  1588. {
  1589. this->FollowName(*i);
  1590. }
  1591. }
  1592. //----------------------------------------------------------------------------
  1593. bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
  1594. {
  1595. // Dependencies on targets (utilities) are supposed to be named by
  1596. // just the target name. However for compatibility we support
  1597. // naming the output file generated by the target (assuming there is
  1598. // no output-name property which old code would not have set). In
  1599. // that case the target name will be the file basename of the
  1600. // dependency.
  1601. std::string util = cmSystemTools::GetFilenameName(dep);
  1602. if(cmSystemTools::GetFilenameLastExtension(util) == ".exe")
  1603. {
  1604. util = cmSystemTools::GetFilenameWithoutLastExtension(util);
  1605. }
  1606. // Check for a target with this name.
  1607. if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
  1608. {
  1609. // If we find the target and the dep was given as a full path,
  1610. // then make sure it was not a full path to something else, and
  1611. // the fact that the name matched a target was just a coincidence.
  1612. if(cmSystemTools::FileIsFullPath(dep.c_str()))
  1613. {
  1614. if(t->GetType() >= cmTarget::EXECUTABLE &&
  1615. t->GetType() <= cmTarget::MODULE_LIBRARY)
  1616. {
  1617. // This is really only for compatibility so we do not need to
  1618. // worry about configuration names and output names.
  1619. std::string tLocation = t->GetLocation(0);
  1620. tLocation = cmSystemTools::GetFilenamePath(tLocation);
  1621. std::string depLocation = cmSystemTools::GetFilenamePath(dep);
  1622. depLocation = cmSystemTools::CollapseFullPath(depLocation.c_str());
  1623. tLocation = cmSystemTools::CollapseFullPath(tLocation.c_str());
  1624. if(depLocation == tLocation)
  1625. {
  1626. this->Target->AddUtility(util.c_str());
  1627. return true;
  1628. }
  1629. }
  1630. }
  1631. else
  1632. {
  1633. // The original name of the dependency was not a full path. It
  1634. // must name a target, so add the target-level dependency.
  1635. this->Target->AddUtility(util.c_str());
  1636. return true;
  1637. }
  1638. }
  1639. // The dependency does not name a target built in this project.
  1640. return false;
  1641. }
  1642. //----------------------------------------------------------------------------
  1643. void
  1644. cmTargetTraceDependencies
  1645. ::CheckCustomCommand(cmCustomCommand const& cc)
  1646. {
  1647. // Transform command names that reference targets built in this
  1648. // project to corresponding target-level dependencies.
  1649. cmGeneratorExpression ge(cc.GetBacktrace());
  1650. // Add target-level dependencies referenced by generator expressions.
  1651. std::set<cmTarget*> targets;
  1652. for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
  1653. cit != cc.GetCommandLines().end(); ++cit)
  1654. {
  1655. std::string const& command = *cit->begin();
  1656. // Check for a target with this name.
  1657. if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
  1658. {
  1659. if(t->GetType() == cmTarget::EXECUTABLE)
  1660. {
  1661. // The command refers to an executable target built in
  1662. // this project. Add the target-level dependency to make
  1663. // sure the executable is up to date before this custom
  1664. // command possibly runs.
  1665. this->Target->AddUtility(command.c_str());
  1666. }
  1667. }
  1668. // Check for target references in generator expressions.
  1669. for(cmCustomCommandLine::const_iterator cli = cit->begin();
  1670. cli != cit->end(); ++cli)
  1671. {
  1672. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge
  1673. = ge.Parse(*cli);
  1674. cge->Evaluate(this->Makefile, 0, true);
  1675. std::set<cmTarget*> geTargets = cge->GetTargets();
  1676. for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
  1677. it != geTargets.end(); ++it)
  1678. {
  1679. targets.insert(*it);
  1680. }
  1681. }
  1682. }
  1683. for(std::set<cmTarget*>::iterator ti = targets.begin();
  1684. ti != targets.end(); ++ti)
  1685. {
  1686. this->Target->AddUtility((*ti)->GetName());
  1687. }
  1688. // Queue the custom command dependencies.
  1689. std::vector<std::string> const& depends = cc.GetDepends();
  1690. for(std::vector<std::string>::const_iterator di = depends.begin();
  1691. di != depends.end(); ++di)
  1692. {
  1693. std::string const& dep = *di;
  1694. if(!this->IsUtility(dep))
  1695. {
  1696. // The dependency does not name a target and may be a file we
  1697. // know how to generate. Queue it.
  1698. this->FollowName(dep);
  1699. }
  1700. }
  1701. }
  1702. //----------------------------------------------------------------------------
  1703. void
  1704. cmTargetTraceDependencies
  1705. ::CheckCustomCommands(const std::vector<cmCustomCommand>& commands)
  1706. {
  1707. for(std::vector<cmCustomCommand>::const_iterator cli = commands.begin();
  1708. cli != commands.end(); ++cli)
  1709. {
  1710. this->CheckCustomCommand(*cli);
  1711. }
  1712. }
  1713. //----------------------------------------------------------------------------
  1714. void cmTarget::TraceDependencies(const char* vsProjectFile)
  1715. {
  1716. // CMake-generated targets have no dependencies to trace. Normally tracing
  1717. // would find nothing anyway, but when building CMake itself the "install"
  1718. // target command ends up referencing the "cmake" target but we do not
  1719. // really want the dependency because "install" depend on "all" anyway.
  1720. if(this->GetType() == cmTarget::GLOBAL_TARGET)
  1721. {
  1722. return;
  1723. }
  1724. // Use a helper object to trace the dependencies.
  1725. cmTargetTraceDependencies tracer(this, this->Internal.Get(), vsProjectFile);
  1726. tracer.Trace();
  1727. }
  1728. //----------------------------------------------------------------------------
  1729. bool cmTarget::FindSourceFiles()
  1730. {
  1731. for(std::vector<cmSourceFile*>::const_iterator
  1732. si = this->SourceFiles.begin();
  1733. si != this->SourceFiles.end(); ++si)
  1734. {
  1735. std::string e;
  1736. if((*si)->GetFullPath(&e).empty())
  1737. {
  1738. if(!e.empty())
  1739. {
  1740. cmake* cm = this->Makefile->GetCMakeInstance();
  1741. cm->IssueMessage(cmake::FATAL_ERROR, e,
  1742. this->GetBacktrace());
  1743. }
  1744. return false;
  1745. }
  1746. }
  1747. return true;
  1748. }
  1749. //----------------------------------------------------------------------------
  1750. std::vector<cmSourceFile*> const& cmTarget::GetSourceFiles()
  1751. {
  1752. return this->SourceFiles;
  1753. }
  1754. //----------------------------------------------------------------------------
  1755. void cmTarget::AddSourceFile(cmSourceFile* sf)
  1756. {
  1757. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1758. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1759. if(i == this->Internal->SourceEntries.end())
  1760. {
  1761. typedef cmTargetInternals::SourceEntry SourceEntry;
  1762. SourceEntriesType::value_type entry(sf, SourceEntry());
  1763. i = this->Internal->SourceEntries.insert(entry).first;
  1764. this->SourceFiles.push_back(sf);
  1765. }
  1766. }
  1767. //----------------------------------------------------------------------------
  1768. std::vector<cmSourceFile*> const*
  1769. cmTarget::GetSourceDepends(cmSourceFile* sf)
  1770. {
  1771. typedef cmTargetInternals::SourceEntriesType SourceEntriesType;
  1772. SourceEntriesType::iterator i = this->Internal->SourceEntries.find(sf);
  1773. if(i != this->Internal->SourceEntries.end())
  1774. {
  1775. return &i->second.Depends;
  1776. }
  1777. return 0;
  1778. }
  1779. //----------------------------------------------------------------------------
  1780. void cmTarget::AddSources(std::vector<std::string> const& srcs)
  1781. {
  1782. for(std::vector<std::string>::const_iterator i = srcs.begin();
  1783. i != srcs.end(); ++i)
  1784. {
  1785. const char* src = i->c_str();
  1786. if(src[0] == '$' && src[1] == '<')
  1787. {
  1788. this->ProcessSourceExpression(*i);
  1789. }
  1790. else
  1791. {
  1792. this->AddSource(src);
  1793. }
  1794. }
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. cmSourceFile* cmTarget::AddSource(const char* s)
  1798. {
  1799. std::string src = s;
  1800. // For backwards compatibility replace varibles in source names.
  1801. // This should eventually be removed.
  1802. this->Makefile->ExpandVariablesInString(src);
  1803. cmSourceFile* sf = this->Makefile->GetOrCreateSource(src.c_str());
  1804. this->AddSourceFile(sf);
  1805. return sf;
  1806. }
  1807. //----------------------------------------------------------------------------
  1808. void cmTarget::ProcessSourceExpression(std::string const& expr)
  1809. {
  1810. if(strncmp(expr.c_str(), "$<TARGET_OBJECTS:", 17) == 0 &&
  1811. expr[expr.size()-1] == '>')
  1812. {
  1813. std::string objLibName = expr.substr(17, expr.size()-18);
  1814. this->ObjectLibraries.push_back(objLibName);
  1815. }
  1816. else
  1817. {
  1818. cmOStringStream e;
  1819. e << "Unrecognized generator expression:\n"
  1820. << " " << expr;
  1821. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  1822. }
  1823. }
  1824. //----------------------------------------------------------------------------
  1825. struct cmTarget::SourceFileFlags
  1826. cmTarget::GetTargetSourceFileFlags(const cmSourceFile* sf)
  1827. {
  1828. struct SourceFileFlags flags;
  1829. this->ConstructSourceFileFlags();
  1830. std::map<cmSourceFile const*, SourceFileFlags>::iterator si =
  1831. this->Internal->SourceFlagsMap.find(sf);
  1832. if(si != this->Internal->SourceFlagsMap.end())
  1833. {
  1834. flags = si->second;
  1835. }
  1836. return flags;
  1837. }
  1838. //----------------------------------------------------------------------------
  1839. void cmTarget::ConstructSourceFileFlags()
  1840. {
  1841. if(this->Internal->SourceFileFlagsConstructed)
  1842. {
  1843. return;
  1844. }
  1845. this->Internal->SourceFileFlagsConstructed = true;
  1846. // Process public headers to mark the source files.
  1847. if(const char* files = this->GetProperty("PUBLIC_HEADER"))
  1848. {
  1849. std::vector<std::string> relFiles;
  1850. cmSystemTools::ExpandListArgument(files, relFiles);
  1851. for(std::vector<std::string>::iterator it = relFiles.begin();
  1852. it != relFiles.end(); ++it)
  1853. {
  1854. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1855. {
  1856. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1857. flags.MacFolder = "Headers";
  1858. flags.Type = cmTarget::SourceFileTypePublicHeader;
  1859. }
  1860. }
  1861. }
  1862. // Process private headers after public headers so that they take
  1863. // precedence if a file is listed in both.
  1864. if(const char* files = this->GetProperty("PRIVATE_HEADER"))
  1865. {
  1866. std::vector<std::string> relFiles;
  1867. cmSystemTools::ExpandListArgument(files, relFiles);
  1868. for(std::vector<std::string>::iterator it = relFiles.begin();
  1869. it != relFiles.end(); ++it)
  1870. {
  1871. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1872. {
  1873. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1874. flags.MacFolder = "PrivateHeaders";
  1875. flags.Type = cmTarget::SourceFileTypePrivateHeader;
  1876. }
  1877. }
  1878. }
  1879. // Mark sources listed as resources.
  1880. if(const char* files = this->GetProperty("RESOURCE"))
  1881. {
  1882. std::vector<std::string> relFiles;
  1883. cmSystemTools::ExpandListArgument(files, relFiles);
  1884. for(std::vector<std::string>::iterator it = relFiles.begin();
  1885. it != relFiles.end(); ++it)
  1886. {
  1887. if(cmSourceFile* sf = this->Makefile->GetSource(it->c_str()))
  1888. {
  1889. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1890. flags.MacFolder = "Resources";
  1891. flags.Type = cmTarget::SourceFileTypeResource;
  1892. }
  1893. }
  1894. }
  1895. // Handle the MACOSX_PACKAGE_LOCATION property on source files that
  1896. // were not listed in one of the other lists.
  1897. std::vector<cmSourceFile*> const& sources = this->GetSourceFiles();
  1898. for(std::vector<cmSourceFile*>::const_iterator si = sources.begin();
  1899. si != sources.end(); ++si)
  1900. {
  1901. cmSourceFile* sf = *si;
  1902. if(const char* location = sf->GetProperty("MACOSX_PACKAGE_LOCATION"))
  1903. {
  1904. SourceFileFlags& flags = this->Internal->SourceFlagsMap[sf];
  1905. if(flags.Type == cmTarget::SourceFileTypeNormal)
  1906. {
  1907. flags.MacFolder = location;
  1908. if(strcmp(location, "Resources") == 0)
  1909. {
  1910. flags.Type = cmTarget::SourceFileTypeResource;
  1911. }
  1912. else
  1913. {
  1914. flags.Type = cmTarget::SourceFileTypeMacContent;
  1915. }
  1916. }
  1917. }
  1918. }
  1919. }
  1920. //----------------------------------------------------------------------------
  1921. void cmTarget::MergeLinkLibraries( cmMakefile& mf,
  1922. const char *selfname,
  1923. const LinkLibraryVectorType& libs )
  1924. {
  1925. // Only add on libraries we haven't added on before.
  1926. // Assumption: the global link libraries could only grow, never shrink
  1927. LinkLibraryVectorType::const_iterator i = libs.begin();
  1928. i += this->PrevLinkedLibraries.size();
  1929. for( ; i != libs.end(); ++i )
  1930. {
  1931. // We call this so that the dependencies get written to the cache
  1932. this->AddLinkLibrary( mf, selfname, i->first.c_str(), i->second );
  1933. }
  1934. this->PrevLinkedLibraries = libs;
  1935. }
  1936. //----------------------------------------------------------------------------
  1937. void cmTarget::AddLinkDirectory(const char* d)
  1938. {
  1939. // Make sure we don't add unnecessary search directories.
  1940. if(this->LinkDirectoriesEmmitted.insert(d).second)
  1941. {
  1942. this->LinkDirectories.push_back(d);
  1943. }
  1944. }
  1945. //----------------------------------------------------------------------------
  1946. const std::vector<std::string>& cmTarget::GetLinkDirectories()
  1947. {
  1948. return this->LinkDirectories;
  1949. }
  1950. //----------------------------------------------------------------------------
  1951. cmTarget::LinkLibraryType cmTarget::ComputeLinkType(const char* config)
  1952. {
  1953. // No configuration is always optimized.
  1954. if(!(config && *config))
  1955. {
  1956. return cmTarget::OPTIMIZED;
  1957. }
  1958. // Get the list of configurations considered to be DEBUG.
  1959. std::vector<std::string> const& debugConfigs =
  1960. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  1961. // Check if any entry in the list matches this configuration.
  1962. std::string configUpper = cmSystemTools::UpperCase(config);
  1963. for(std::vector<std::string>::const_iterator i = debugConfigs.begin();
  1964. i != debugConfigs.end(); ++i)
  1965. {
  1966. if(*i == configUpper)
  1967. {
  1968. return cmTarget::DEBUG;
  1969. }
  1970. }
  1971. // The current configuration is not a debug configuration.
  1972. return cmTarget::OPTIMIZED;
  1973. }
  1974. //----------------------------------------------------------------------------
  1975. void cmTarget::ClearDependencyInformation( cmMakefile& mf,
  1976. const char* target )
  1977. {
  1978. // Clear the dependencies. The cache variable must exist iff we are
  1979. // recording dependency information for this target.
  1980. std::string depname = target;
  1981. depname += "_LIB_DEPENDS";
  1982. if (this->RecordDependencies)
  1983. {
  1984. mf.AddCacheDefinition(depname.c_str(), "",
  1985. "Dependencies for target", cmCacheManager::STATIC);
  1986. }
  1987. else
  1988. {
  1989. if (mf.GetDefinition( depname.c_str() ))
  1990. {
  1991. std::string message = "Target ";
  1992. message += target;
  1993. message += " has dependency information when it shouldn't.\n";
  1994. message += "Your cache is probably stale. Please remove the entry\n ";
  1995. message += depname;
  1996. message += "\nfrom the cache.";
  1997. cmSystemTools::Error( message.c_str() );
  1998. }
  1999. }
  2000. }
  2001. //----------------------------------------------------------------------------
  2002. bool cmTarget::NameResolvesToFramework(const std::string& libname)
  2003. {
  2004. return this->GetMakefile()->GetLocalGenerator()->GetGlobalGenerator()->
  2005. NameResolvesToFramework(libname);
  2006. }
  2007. //----------------------------------------------------------------------------
  2008. void cmTarget::GetDirectLinkLibraries(const char *config,
  2009. std::vector<std::string> &libs, cmTarget *head)
  2010. {
  2011. const char *prop = this->GetProperty("LINK_LIBRARIES");
  2012. if (prop)
  2013. {
  2014. cmListFileBacktrace lfbt;
  2015. cmGeneratorExpression ge(lfbt);
  2016. const cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(prop);
  2017. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2018. this->GetName(),
  2019. "LINK_LIBRARIES", 0, 0);
  2020. cmSystemTools::ExpandListArgument(cge->Evaluate(this->Makefile,
  2021. config,
  2022. false,
  2023. head,
  2024. &dagChecker),
  2025. libs);
  2026. this->AddLinkDependentTargetsForProperties(cge->GetSeenTargetProperties());
  2027. }
  2028. }
  2029. //----------------------------------------------------------------------------
  2030. std::string cmTarget::GetDebugGeneratorExpressions(const std::string &value,
  2031. cmTarget::LinkLibraryType llt)
  2032. {
  2033. if (llt == GENERAL)
  2034. {
  2035. return value;
  2036. }
  2037. // Get the list of configurations considered to be DEBUG.
  2038. std::vector<std::string> const& debugConfigs =
  2039. this->Makefile->GetCMakeInstance()->GetDebugConfigs();
  2040. std::string configString = "$<CONFIG:" + debugConfigs[0] + ">";
  2041. if (debugConfigs.size() > 1)
  2042. {
  2043. for(std::vector<std::string>::const_iterator
  2044. li = debugConfigs.begin() + 1; li != debugConfigs.end(); ++li)
  2045. {
  2046. configString += ",$<CONFIG:" + *li + ">";
  2047. }
  2048. configString = "$<OR:" + configString + ">";
  2049. }
  2050. if (llt == OPTIMIZED)
  2051. {
  2052. configString = "$<NOT:" + configString + ">";
  2053. }
  2054. return "$<" + configString + ":" + value + ">";
  2055. }
  2056. //----------------------------------------------------------------------------
  2057. static std::string targetNameGenex(const char *lib)
  2058. {
  2059. return std::string("$<TARGET_NAME:") + lib + ">";
  2060. }
  2061. //----------------------------------------------------------------------------
  2062. static bool isGeneratorExpression(const std::string &lib)
  2063. {
  2064. const std::string::size_type openpos = lib.find("$<");
  2065. return (openpos != std::string::npos)
  2066. && (lib.find(">", openpos) != std::string::npos);
  2067. }
  2068. //----------------------------------------------------------------------------
  2069. void cmTarget::AddLinkLibrary(cmMakefile& mf,
  2070. const char *target, const char* lib,
  2071. LinkLibraryType llt)
  2072. {
  2073. // Never add a self dependency, even if the user asks for it.
  2074. if(strcmp( target, lib ) == 0)
  2075. {
  2076. return;
  2077. }
  2078. {
  2079. cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
  2080. const bool isNonImportedTarget = tgt && !tgt->IsImported();
  2081. const std::string libName = (isNonImportedTarget && llt != GENERAL)
  2082. ? targetNameGenex(lib)
  2083. : std::string(lib);
  2084. this->AppendProperty("LINK_LIBRARIES",
  2085. this->GetDebugGeneratorExpressions(libName,
  2086. llt).c_str());
  2087. }
  2088. if (isGeneratorExpression(lib))
  2089. {
  2090. return;
  2091. }
  2092. cmTarget::LibraryID tmp;
  2093. tmp.first = lib;
  2094. tmp.second = llt;
  2095. this->LinkLibraries.push_back( tmp );
  2096. this->OriginalLinkLibraries.push_back(tmp);
  2097. this->ClearLinkMaps();
  2098. // Add the explicit dependency information for this target. This is
  2099. // simply a set of libraries separated by ";". There should always
  2100. // be a trailing ";". These library names are not canonical, in that
  2101. // they may be "-framework x", "-ly", "/path/libz.a", etc.
  2102. // We shouldn't remove duplicates here because external libraries
  2103. // may be purposefully duplicated to handle recursive dependencies,
  2104. // and we removing one instance will break the link line. Duplicates
  2105. // will be appropriately eliminated at emit time.
  2106. if(this->RecordDependencies)
  2107. {
  2108. std::string targetEntry = target;
  2109. targetEntry += "_LIB_DEPENDS";
  2110. std::string dependencies;
  2111. const char* old_val = mf.GetDefinition( targetEntry.c_str() );
  2112. if( old_val )
  2113. {
  2114. dependencies += old_val;
  2115. }
  2116. switch (llt)
  2117. {
  2118. case cmTarget::GENERAL:
  2119. dependencies += "general";
  2120. break;
  2121. case cmTarget::DEBUG:
  2122. dependencies += "debug";
  2123. break;
  2124. case cmTarget::OPTIMIZED:
  2125. dependencies += "optimized";
  2126. break;
  2127. }
  2128. dependencies += ";";
  2129. dependencies += lib;
  2130. dependencies += ";";
  2131. mf.AddCacheDefinition( targetEntry.c_str(), dependencies.c_str(),
  2132. "Dependencies for the target",
  2133. cmCacheManager::STATIC );
  2134. }
  2135. }
  2136. //----------------------------------------------------------------------------
  2137. void
  2138. cmTarget::AnalyzeLibDependencies( const cmMakefile& mf )
  2139. {
  2140. // There are two key parts of the dependency analysis: (1)
  2141. // determining the libraries in the link line, and (2) constructing
  2142. // the dependency graph for those libraries.
  2143. //
  2144. // The latter is done using the cache entries that record the
  2145. // dependencies of each library.
  2146. //
  2147. // The former is a more thorny issue, since it is not clear how to
  2148. // determine if two libraries listed on the link line refer to the a
  2149. // single library or not. For example, consider the link "libraries"
  2150. // /usr/lib/libtiff.so -ltiff
  2151. // Is this one library or two? The solution implemented here is the
  2152. // simplest (and probably the only practical) one: two libraries are
  2153. // the same if their "link strings" are identical. Thus, the two
  2154. // libraries above are considered distinct. This also means that for
  2155. // dependency analysis to be effective, the CMake user must specify
  2156. // libraries build by his project without using any linker flags or
  2157. // file extensions. That is,
  2158. // LINK_LIBRARIES( One Two )
  2159. // instead of
  2160. // LINK_LIBRARIES( -lOne ${binarypath}/libTwo.a )
  2161. // The former is probably what most users would do, but it never
  2162. // hurts to document the assumptions. :-) Therefore, in the analysis
  2163. // code, the "canonical name" of a library is simply its name as
  2164. // given to a LINK_LIBRARIES command.
  2165. //
  2166. // Also, we will leave the original link line intact; we will just add any
  2167. // dependencies that were missing.
  2168. //
  2169. // There is a problem with recursive external libraries
  2170. // (i.e. libraries with no dependency information that are
  2171. // recursively dependent). We must make sure that the we emit one of
  2172. // the libraries twice to satisfy the recursion, but we shouldn't
  2173. // emit it more times than necessary. In particular, we must make
  2174. // sure that handling this improbable case doesn't cost us when
  2175. // dealing with the common case of non-recursive libraries. The
  2176. // solution is to assume that the recursion is satisfied at one node
  2177. // of the dependency tree. To illustrate, assume libA and libB are
  2178. // extrenal and mutually dependent. Suppose libX depends on
  2179. // libA, and libY on libA and libX. Then
  2180. // TARGET_LINK_LIBRARIES( Y X A B A )
  2181. // TARGET_LINK_LIBRARIES( X A B A )
  2182. // TARGET_LINK_LIBRARIES( Exec Y )
  2183. // would result in "-lY -lX -lA -lB -lA". This is the correct way to
  2184. // specify the dependencies, since the mutual dependency of A and B
  2185. // is resolved *every time libA is specified*.
  2186. //
  2187. // Something like
  2188. // TARGET_LINK_LIBRARIES( Y X A B A )
  2189. // TARGET_LINK_LIBRARIES( X A B )
  2190. // TARGET_LINK_LIBRARIES( Exec Y )
  2191. // would result in "-lY -lX -lA -lB", and the mutual dependency
  2192. // information is lost. This is because in some case (Y), the mutual
  2193. // dependency of A and B is listed, while in another other case (X),
  2194. // it is not. Depending on which line actually emits A, the mutual
  2195. // dependency may or may not be on the final link line. We can't
  2196. // handle this pathalogical case cleanly without emitting extra
  2197. // libraries for the normal cases. Besides, the dependency
  2198. // information for X is wrong anyway: if we build an executable
  2199. // depending on X alone, we would not have the mutual dependency on
  2200. // A and B resolved.
  2201. //
  2202. // IMPROVEMENTS:
  2203. // -- The current algorithm will not always pick the "optimal" link line
  2204. // when recursive dependencies are present. It will instead break the
  2205. // cycles at an aribtrary point. The majority of projects won't have
  2206. // cyclic dependencies, so this is probably not a big deal. Note that
  2207. // the link line is always correct, just not necessary optimal.
  2208. {
  2209. // Expand variables in link library names. This is for backwards
  2210. // compatibility with very early CMake versions and should
  2211. // eventually be removed. This code was moved here from the end of
  2212. // old source list processing code which was called just before this
  2213. // method.
  2214. for(LinkLibraryVectorType::iterator p = this->LinkLibraries.begin();
  2215. p != this->LinkLibraries.end(); ++p)
  2216. {
  2217. this->Makefile->ExpandVariablesInString(p->first, true, true);
  2218. }
  2219. }
  2220. typedef std::vector< std::string > LinkLine;
  2221. // The dependency map.
  2222. DependencyMap dep_map;
  2223. // 1. Build the dependency graph
  2224. //
  2225. for(LinkLibraryVectorType::reverse_iterator lib
  2226. = this->LinkLibraries.rbegin();
  2227. lib != this->LinkLibraries.rend(); ++lib)
  2228. {
  2229. this->GatherDependencies( mf, *lib, dep_map);
  2230. }
  2231. // 2. Remove any dependencies that are already satisfied in the original
  2232. // link line.
  2233. //
  2234. for(LinkLibraryVectorType::iterator lib = this->LinkLibraries.begin();
  2235. lib != this->LinkLibraries.end(); ++lib)
  2236. {
  2237. for( LinkLibraryVectorType::iterator lib2 = lib;
  2238. lib2 != this->LinkLibraries.end(); ++lib2)
  2239. {
  2240. this->DeleteDependency( dep_map, *lib, *lib2);
  2241. }
  2242. }
  2243. // 3. Create the new link line by simply emitting any dependencies that are
  2244. // missing. Start from the back and keep adding.
  2245. //
  2246. std::set<DependencyMap::key_type> done, visited;
  2247. std::vector<DependencyMap::key_type> newLinkLibraries;
  2248. for(LinkLibraryVectorType::reverse_iterator lib =
  2249. this->LinkLibraries.rbegin();
  2250. lib != this->LinkLibraries.rend(); ++lib)
  2251. {
  2252. // skip zero size library entries, this may happen
  2253. // if a variable expands to nothing.
  2254. if (lib->first.size() != 0)
  2255. {
  2256. this->Emit( *lib, dep_map, done, visited, newLinkLibraries );
  2257. }
  2258. }
  2259. // 4. Add the new libraries to the link line.
  2260. //
  2261. for( std::vector<DependencyMap::key_type>::reverse_iterator k =
  2262. newLinkLibraries.rbegin();
  2263. k != newLinkLibraries.rend(); ++k )
  2264. {
  2265. // get the llt from the dep_map
  2266. this->LinkLibraries.push_back( std::make_pair(k->first,k->second) );
  2267. }
  2268. this->LinkLibrariesAnalyzed = true;
  2269. }
  2270. //----------------------------------------------------------------------------
  2271. void cmTarget::InsertDependency( DependencyMap& depMap,
  2272. const LibraryID& lib,
  2273. const LibraryID& dep)
  2274. {
  2275. depMap[lib].push_back(dep);
  2276. }
  2277. //----------------------------------------------------------------------------
  2278. void cmTarget::DeleteDependency( DependencyMap& depMap,
  2279. const LibraryID& lib,
  2280. const LibraryID& dep)
  2281. {
  2282. // Make sure there is an entry in the map for lib. If so, delete all
  2283. // dependencies to dep. There may be repeated entries because of
  2284. // external libraries that are specified multiple times.
  2285. DependencyMap::iterator map_itr = depMap.find( lib );
  2286. if( map_itr != depMap.end() )
  2287. {
  2288. DependencyList& depList = map_itr->second;
  2289. DependencyList::iterator itr;
  2290. while( (itr = std::find(depList.begin(), depList.end(), dep)) !=
  2291. depList.end() )
  2292. {
  2293. depList.erase( itr );
  2294. }
  2295. }
  2296. }
  2297. //----------------------------------------------------------------------------
  2298. void cmTarget::Emit(const LibraryID lib,
  2299. const DependencyMap& dep_map,
  2300. std::set<LibraryID>& emitted,
  2301. std::set<LibraryID>& visited,
  2302. DependencyList& link_line )
  2303. {
  2304. // It's already been emitted
  2305. if( emitted.find(lib) != emitted.end() )
  2306. {
  2307. return;
  2308. }
  2309. // Emit the dependencies only if this library node hasn't been
  2310. // visited before. If it has, then we have a cycle. The recursion
  2311. // that got us here should take care of everything.
  2312. if( visited.insert(lib).second )
  2313. {
  2314. if( dep_map.find(lib) != dep_map.end() ) // does it have dependencies?
  2315. {
  2316. const DependencyList& dep_on = dep_map.find( lib )->second;
  2317. DependencyList::const_reverse_iterator i;
  2318. // To cater for recursive external libraries, we must emit
  2319. // duplicates on this link line *unless* they were emitted by
  2320. // some other node, in which case we assume that the recursion
  2321. // was resolved then. We making the simplifying assumption that
  2322. // any duplicates on a single link line are on purpose, and must
  2323. // be preserved.
  2324. // This variable will keep track of the libraries that were
  2325. // emitted directly from the current node, and not from a
  2326. // recursive call. This way, if we come across a library that
  2327. // has already been emitted, we repeat it iff it has been
  2328. // emitted here.
  2329. std::set<DependencyMap::key_type> emitted_here;
  2330. for( i = dep_on.rbegin(); i != dep_on.rend(); ++i )
  2331. {
  2332. if( emitted_here.find(*i) != emitted_here.end() )
  2333. {
  2334. // a repeat. Must emit.
  2335. emitted.insert(*i);
  2336. link_line.push_back( *i );
  2337. }
  2338. else
  2339. {
  2340. // Emit only if no-one else has
  2341. if( emitted.find(*i) == emitted.end() )
  2342. {
  2343. // emit dependencies
  2344. Emit( *i, dep_map, emitted, visited, link_line );
  2345. // emit self
  2346. emitted.insert(*i);
  2347. emitted_here.insert(*i);
  2348. link_line.push_back( *i );
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. //----------------------------------------------------------------------------
  2356. void cmTarget::GatherDependencies( const cmMakefile& mf,
  2357. const LibraryID& lib,
  2358. DependencyMap& dep_map)
  2359. {
  2360. // If the library is already in the dependency map, then it has
  2361. // already been fully processed.
  2362. if( dep_map.find(lib) != dep_map.end() )
  2363. {
  2364. return;
  2365. }
  2366. const char* deps = mf.GetDefinition( (lib.first+"_LIB_DEPENDS").c_str() );
  2367. if( deps && strcmp(deps,"") != 0 )
  2368. {
  2369. // Make sure this library is in the map, even if it has an empty
  2370. // set of dependencies. This distinguishes the case of explicitly
  2371. // no dependencies with that of unspecified dependencies.
  2372. dep_map[lib];
  2373. // Parse the dependency information, which is a set of
  2374. // type, library pairs separated by ";". There is always a trailing ";".
  2375. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  2376. std::string depline = deps;
  2377. std::string::size_type start = 0;
  2378. std::string::size_type end;
  2379. end = depline.find( ";", start );
  2380. while( end != std::string::npos )
  2381. {
  2382. std::string l = depline.substr( start, end-start );
  2383. if( l.size() != 0 )
  2384. {
  2385. if (l == "debug")
  2386. {
  2387. llt = cmTarget::DEBUG;
  2388. }
  2389. else if (l == "optimized")
  2390. {
  2391. llt = cmTarget::OPTIMIZED;
  2392. }
  2393. else if (l == "general")
  2394. {
  2395. llt = cmTarget::GENERAL;
  2396. }
  2397. else
  2398. {
  2399. LibraryID lib2(l,llt);
  2400. this->InsertDependency( dep_map, lib, lib2);
  2401. this->GatherDependencies( mf, lib2, dep_map);
  2402. llt = cmTarget::GENERAL;
  2403. }
  2404. }
  2405. start = end+1; // skip the ;
  2406. end = depline.find( ";", start );
  2407. }
  2408. // cannot depend on itself
  2409. this->DeleteDependency( dep_map, lib, lib);
  2410. }
  2411. }
  2412. //----------------------------------------------------------------------------
  2413. void deleteAndClear(
  2414. std::vector<cmTargetInternals::IncludeDirectoriesEntry*> &entries)
  2415. {
  2416. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  2417. it = entries.begin(),
  2418. end = entries.end();
  2419. it != end; ++it)
  2420. {
  2421. delete *it;
  2422. }
  2423. entries.clear();
  2424. }
  2425. //----------------------------------------------------------------------------
  2426. void cmTarget::SetProperty(const char* prop, const char* value)
  2427. {
  2428. if (!prop)
  2429. {
  2430. return;
  2431. }
  2432. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2433. {
  2434. cmListFileBacktrace lfbt;
  2435. this->Makefile->GetBacktrace(lfbt);
  2436. cmGeneratorExpression ge(lfbt);
  2437. deleteAndClear(this->Internal->IncludeDirectoriesEntries);
  2438. cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(value);
  2439. this->Internal->IncludeDirectoriesEntries.push_back(
  2440. new cmTargetInternals::IncludeDirectoriesEntry(cge));
  2441. return;
  2442. }
  2443. this->Properties.SetProperty(prop, value, cmProperty::TARGET);
  2444. this->MaybeInvalidatePropertyCache(prop);
  2445. }
  2446. //----------------------------------------------------------------------------
  2447. void cmTarget::AppendProperty(const char* prop, const char* value,
  2448. bool asString)
  2449. {
  2450. if (!prop)
  2451. {
  2452. return;
  2453. }
  2454. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2455. {
  2456. cmListFileBacktrace lfbt;
  2457. this->Makefile->GetBacktrace(lfbt);
  2458. cmGeneratorExpression ge(lfbt);
  2459. this->Internal->IncludeDirectoriesEntries.push_back(
  2460. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(value)));
  2461. return;
  2462. }
  2463. this->Properties.AppendProperty(prop, value, cmProperty::TARGET, asString);
  2464. this->MaybeInvalidatePropertyCache(prop);
  2465. }
  2466. //----------------------------------------------------------------------------
  2467. void cmTarget::AppendBuildInterfaceIncludes()
  2468. {
  2469. if (this->BuildInterfaceIncludesAppended)
  2470. {
  2471. return;
  2472. }
  2473. this->BuildInterfaceIncludesAppended = true;
  2474. if (this->Makefile->IsOn("CMAKE_BUILD_INTERFACE_INCLUDES"))
  2475. {
  2476. const char *binDir = this->Makefile->GetStartOutputDirectory();
  2477. const char *srcDir = this->Makefile->GetStartDirectory();
  2478. const std::string dirs = std::string(binDir ? binDir : "")
  2479. + std::string(binDir ? ";" : "")
  2480. + std::string(srcDir ? srcDir : "");
  2481. if (!dirs.empty())
  2482. {
  2483. this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
  2484. ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
  2485. }
  2486. }
  2487. }
  2488. //----------------------------------------------------------------------------
  2489. void cmTarget::InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry,
  2490. bool before)
  2491. {
  2492. cmGeneratorExpression ge(entry.Backtrace);
  2493. std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::iterator position
  2494. = before ? this->Internal->IncludeDirectoriesEntries.begin()
  2495. : this->Internal->IncludeDirectoriesEntries.end();
  2496. this->Internal->IncludeDirectoriesEntries.insert(position,
  2497. new cmTargetInternals::IncludeDirectoriesEntry(ge.Parse(entry.Value)));
  2498. }
  2499. //----------------------------------------------------------------------------
  2500. std::vector<std::string> cmTarget::GetIncludeDirectories(const char *config)
  2501. {
  2502. std::vector<std::string> includes;
  2503. std::set<std::string> uniqueIncludes;
  2504. cmListFileBacktrace lfbt;
  2505. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2506. this->GetName(),
  2507. "INCLUDE_DIRECTORIES", 0, 0);
  2508. std::vector<std::string> debugProperties;
  2509. const char *debugProp =
  2510. this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES");
  2511. if (debugProp)
  2512. {
  2513. cmSystemTools::ExpandListArgument(debugProp, debugProperties);
  2514. }
  2515. bool debugIncludes = !this->DebugIncludesDone
  2516. && std::find(debugProperties.begin(),
  2517. debugProperties.end(),
  2518. "INCLUDE_DIRECTORIES")
  2519. != debugProperties.end();
  2520. if (this->Makefile->IsGeneratingBuildSystem())
  2521. {
  2522. this->DebugIncludesDone = true;
  2523. }
  2524. for (std::vector<cmTargetInternals::IncludeDirectoriesEntry*>::const_iterator
  2525. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2526. end = this->Internal->IncludeDirectoriesEntries.end();
  2527. it != end; ++it)
  2528. {
  2529. std::vector<std::string> entryIncludes;
  2530. cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(this->Makefile,
  2531. config,
  2532. false,
  2533. this,
  2534. &dagChecker),
  2535. entryIncludes);
  2536. std::string usedIncludes;
  2537. for(std::vector<std::string>::const_iterator
  2538. li = entryIncludes.begin(); li != entryIncludes.end(); ++li)
  2539. {
  2540. std::string inc = *li;
  2541. if (!cmSystemTools::IsOff(inc.c_str()))
  2542. {
  2543. cmSystemTools::ConvertToUnixSlashes(inc);
  2544. }
  2545. if(uniqueIncludes.insert(inc).second)
  2546. {
  2547. includes.push_back(*li);
  2548. if (debugIncludes)
  2549. {
  2550. usedIncludes += " * " + *li + "\n";
  2551. }
  2552. }
  2553. }
  2554. if (!usedIncludes.empty())
  2555. {
  2556. this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG,
  2557. "Used includes for target " + this->Name + ":\n"
  2558. + usedIncludes, (*it)->ge->GetBacktrace());
  2559. }
  2560. }
  2561. return includes;
  2562. }
  2563. //----------------------------------------------------------------------------
  2564. std::string cmTarget::GetCompileDefinitions(const char *config)
  2565. {
  2566. std::string defPropName = "COMPILE_DEFINITIONS";
  2567. if (config)
  2568. {
  2569. defPropName += "_" + cmSystemTools::UpperCase(config);
  2570. }
  2571. const char *prop = this->GetProperty(defPropName.c_str());
  2572. if (!prop)
  2573. {
  2574. return "";
  2575. }
  2576. cmListFileBacktrace lfbt;
  2577. cmGeneratorExpression ge(lfbt);
  2578. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  2579. this->GetName(),
  2580. defPropName, 0, 0);
  2581. return ge.Parse(prop)->Evaluate(this->Makefile,
  2582. config,
  2583. false,
  2584. this,
  2585. &dagChecker);
  2586. }
  2587. //----------------------------------------------------------------------------
  2588. void cmTarget::MaybeInvalidatePropertyCache(const char* prop)
  2589. {
  2590. // Wipe out maps caching information affected by this property.
  2591. if(this->IsImported() && strncmp(prop, "IMPORTED", 8) == 0)
  2592. {
  2593. this->Internal->ImportInfoMap.clear();
  2594. }
  2595. if(!this->IsImported() && strncmp(prop, "LINK_INTERFACE_", 15) == 0)
  2596. {
  2597. this->ClearLinkMaps();
  2598. }
  2599. }
  2600. //----------------------------------------------------------------------------
  2601. static void cmTargetCheckLINK_INTERFACE_LIBRARIES(
  2602. const char* prop, const char* value, cmMakefile* context, bool imported
  2603. )
  2604. {
  2605. // Look for link-type keywords in the value.
  2606. static cmsys::RegularExpression
  2607. keys("(^|;)(debug|optimized|general)(;|$)");
  2608. if(!keys.find(value))
  2609. {
  2610. return;
  2611. }
  2612. // Support imported and non-imported versions of the property.
  2613. const char* base = (imported?
  2614. "IMPORTED_LINK_INTERFACE_LIBRARIES" :
  2615. "LINK_INTERFACE_LIBRARIES");
  2616. // Report an error.
  2617. cmOStringStream e;
  2618. e << "Property " << prop << " may not contain link-type keyword \""
  2619. << keys.match(2) << "\". "
  2620. << "The " << base << " property has a per-configuration "
  2621. << "version called " << base << "_<CONFIG> which may be "
  2622. << "used to specify per-configuration rules.";
  2623. if(!imported)
  2624. {
  2625. e << " "
  2626. << "Alternatively, an IMPORTED library may be created, configured "
  2627. << "with a per-configuration location, and then named in the "
  2628. << "property value. "
  2629. << "See the add_library command's IMPORTED mode for details."
  2630. << "\n"
  2631. << "If you have a list of libraries that already contains the "
  2632. << "keyword, use the target_link_libraries command with its "
  2633. << "LINK_INTERFACE_LIBRARIES mode to set the property. "
  2634. << "The command automatically recognizes link-type keywords and sets "
  2635. << "the LINK_INTERFACE_LIBRARIES and LINK_INTERFACE_LIBRARIES_DEBUG "
  2636. << "properties accordingly.";
  2637. }
  2638. context->IssueMessage(cmake::FATAL_ERROR, e.str());
  2639. }
  2640. //----------------------------------------------------------------------------
  2641. void cmTarget::CheckProperty(const char* prop, cmMakefile* context)
  2642. {
  2643. // Certain properties need checking.
  2644. if(strncmp(prop, "LINK_INTERFACE_LIBRARIES", 24) == 0)
  2645. {
  2646. if(const char* value = this->GetProperty(prop))
  2647. {
  2648. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, false);
  2649. }
  2650. }
  2651. if(strncmp(prop, "IMPORTED_LINK_INTERFACE_LIBRARIES", 33) == 0)
  2652. {
  2653. if(const char* value = this->GetProperty(prop))
  2654. {
  2655. cmTargetCheckLINK_INTERFACE_LIBRARIES(prop, value, context, true);
  2656. }
  2657. }
  2658. }
  2659. //----------------------------------------------------------------------------
  2660. void cmTarget::MarkAsImported()
  2661. {
  2662. this->IsImportedTarget = true;
  2663. }
  2664. //----------------------------------------------------------------------------
  2665. bool cmTarget::HaveWellDefinedOutputFiles()
  2666. {
  2667. return
  2668. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2669. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2670. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2671. this->GetType() == cmTarget::EXECUTABLE;
  2672. }
  2673. //----------------------------------------------------------------------------
  2674. cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config)
  2675. {
  2676. // There is no output information for imported targets.
  2677. if(this->IsImported())
  2678. {
  2679. return 0;
  2680. }
  2681. // Only libraries and executables have well-defined output files.
  2682. if(!this->HaveWellDefinedOutputFiles())
  2683. {
  2684. std::string msg = "cmTarget::GetOutputInfo called for ";
  2685. msg += this->GetName();
  2686. msg += " which has type ";
  2687. msg += cmTarget::GetTargetTypeName(this->GetType());
  2688. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg);
  2689. abort();
  2690. return 0;
  2691. }
  2692. // Lookup/compute/cache the output information for this configuration.
  2693. std::string config_upper;
  2694. if(config && *config)
  2695. {
  2696. config_upper = cmSystemTools::UpperCase(config);
  2697. }
  2698. typedef cmTargetInternals::OutputInfoMapType OutputInfoMapType;
  2699. OutputInfoMapType::const_iterator i =
  2700. this->Internal->OutputInfoMap.find(config_upper);
  2701. if(i == this->Internal->OutputInfoMap.end())
  2702. {
  2703. OutputInfo info;
  2704. this->ComputeOutputDir(config, false, info.OutDir);
  2705. this->ComputeOutputDir(config, true, info.ImpDir);
  2706. if(!this->ComputePDBOutputDir(config, info.PdbDir))
  2707. {
  2708. info.PdbDir = info.OutDir;
  2709. }
  2710. OutputInfoMapType::value_type entry(config_upper, info);
  2711. i = this->Internal->OutputInfoMap.insert(entry).first;
  2712. }
  2713. return &i->second;
  2714. }
  2715. //----------------------------------------------------------------------------
  2716. std::string cmTarget::GetDirectory(const char* config, bool implib)
  2717. {
  2718. if (this->IsImported())
  2719. {
  2720. // Return the directory from which the target is imported.
  2721. return
  2722. cmSystemTools::GetFilenamePath(
  2723. this->ImportedGetFullPath(config, implib));
  2724. }
  2725. else if(OutputInfo const* info = this->GetOutputInfo(config))
  2726. {
  2727. // Return the directory in which the target will be built.
  2728. return implib? info->ImpDir : info->OutDir;
  2729. }
  2730. return "";
  2731. }
  2732. //----------------------------------------------------------------------------
  2733. std::string cmTarget::GetPDBDirectory(const char* config)
  2734. {
  2735. if(OutputInfo const* info = this->GetOutputInfo(config))
  2736. {
  2737. // Return the directory in which the target will be built.
  2738. return info->PdbDir;
  2739. }
  2740. return "";
  2741. }
  2742. //----------------------------------------------------------------------------
  2743. const char* cmTarget::GetLocation(const char* config)
  2744. {
  2745. if (this->IsImported())
  2746. {
  2747. return this->ImportedGetLocation(config);
  2748. }
  2749. else
  2750. {
  2751. return this->NormalGetLocation(config);
  2752. }
  2753. }
  2754. //----------------------------------------------------------------------------
  2755. const char* cmTarget::ImportedGetLocation(const char* config)
  2756. {
  2757. this->Location = this->ImportedGetFullPath(config, false);
  2758. return this->Location.c_str();
  2759. }
  2760. //----------------------------------------------------------------------------
  2761. const char* cmTarget::NormalGetLocation(const char* config)
  2762. {
  2763. // Handle the configuration-specific case first.
  2764. if(config)
  2765. {
  2766. this->Location = this->GetFullPath(config, false);
  2767. return this->Location.c_str();
  2768. }
  2769. // Now handle the deprecated build-time configuration location.
  2770. this->Location = this->GetDirectory();
  2771. if(!this->Location.empty())
  2772. {
  2773. this->Location += "/";
  2774. }
  2775. const char* cfgid = this->Makefile->GetDefinition("CMAKE_CFG_INTDIR");
  2776. if(cfgid && strcmp(cfgid, ".") != 0)
  2777. {
  2778. this->Location += cfgid;
  2779. this->Location += "/";
  2780. }
  2781. this->Location = this->BuildMacContentDirectory(this->Location, config);
  2782. this->Location += this->GetFullName(config, false);
  2783. return this->Location.c_str();
  2784. }
  2785. //----------------------------------------------------------------------------
  2786. void cmTarget::GetTargetVersion(int& major, int& minor)
  2787. {
  2788. int patch;
  2789. this->GetTargetVersion(false, major, minor, patch);
  2790. }
  2791. //----------------------------------------------------------------------------
  2792. void cmTarget::GetTargetVersion(bool soversion,
  2793. int& major, int& minor, int& patch)
  2794. {
  2795. // Set the default values.
  2796. major = 0;
  2797. minor = 0;
  2798. patch = 0;
  2799. // Look for a VERSION or SOVERSION property.
  2800. const char* prop = soversion? "SOVERSION" : "VERSION";
  2801. if(const char* version = this->GetProperty(prop))
  2802. {
  2803. // Try to parse the version number and store the results that were
  2804. // successfully parsed.
  2805. int parsed_major;
  2806. int parsed_minor;
  2807. int parsed_patch;
  2808. switch(sscanf(version, "%d.%d.%d",
  2809. &parsed_major, &parsed_minor, &parsed_patch))
  2810. {
  2811. case 3: patch = parsed_patch; // no break!
  2812. case 2: minor = parsed_minor; // no break!
  2813. case 1: major = parsed_major; // no break!
  2814. default: break;
  2815. }
  2816. }
  2817. }
  2818. //----------------------------------------------------------------------------
  2819. const char* cmTarget::GetFeature(const char* feature, const char* config)
  2820. {
  2821. if(config && *config)
  2822. {
  2823. std::string featureConfig = feature;
  2824. featureConfig += "_";
  2825. featureConfig += cmSystemTools::UpperCase(config);
  2826. if(const char* value = this->GetProperty(featureConfig.c_str()))
  2827. {
  2828. return value;
  2829. }
  2830. }
  2831. if(const char* value = this->GetProperty(feature))
  2832. {
  2833. return value;
  2834. }
  2835. return this->Makefile->GetFeature(feature, config);
  2836. }
  2837. //----------------------------------------------------------------------------
  2838. const char *cmTarget::GetProperty(const char* prop)
  2839. {
  2840. return this->GetProperty(prop, cmProperty::TARGET);
  2841. }
  2842. //----------------------------------------------------------------------------
  2843. const char *cmTarget::GetProperty(const char* prop,
  2844. cmProperty::ScopeType scope)
  2845. {
  2846. if(!prop)
  2847. {
  2848. return 0;
  2849. }
  2850. // Watch for special "computed" properties that are dependent on
  2851. // other properties or variables. Always recompute them.
  2852. if(this->GetType() == cmTarget::EXECUTABLE ||
  2853. this->GetType() == cmTarget::STATIC_LIBRARY ||
  2854. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2855. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2856. this->GetType() == cmTarget::UNKNOWN_LIBRARY)
  2857. {
  2858. if(strcmp(prop,"LOCATION") == 0)
  2859. {
  2860. // Set the LOCATION property of the target.
  2861. //
  2862. // For an imported target this is the location of an arbitrary
  2863. // available configuration.
  2864. //
  2865. // For a non-imported target this is deprecated because it
  2866. // cannot take into account the per-configuration name of the
  2867. // target because the configuration type may not be known at
  2868. // CMake time.
  2869. this->SetProperty("LOCATION", this->GetLocation(0));
  2870. }
  2871. // Support "LOCATION_<CONFIG>".
  2872. if(strncmp(prop, "LOCATION_", 9) == 0)
  2873. {
  2874. std::string configName = prop+9;
  2875. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2876. }
  2877. else
  2878. {
  2879. // Support "<CONFIG>_LOCATION" for compatiblity.
  2880. int len = static_cast<int>(strlen(prop));
  2881. if(len > 9 && strcmp(prop+len-9, "_LOCATION") == 0)
  2882. {
  2883. std::string configName(prop, len-9);
  2884. if(configName != "IMPORTED")
  2885. {
  2886. this->SetProperty(prop, this->GetLocation(configName.c_str()));
  2887. }
  2888. }
  2889. }
  2890. }
  2891. if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0)
  2892. {
  2893. static std::string output;
  2894. output = "";
  2895. std::string sep;
  2896. typedef cmTargetInternals::IncludeDirectoriesEntry
  2897. IncludeDirectoriesEntry;
  2898. for (std::vector<IncludeDirectoriesEntry*>::const_iterator
  2899. it = this->Internal->IncludeDirectoriesEntries.begin(),
  2900. end = this->Internal->IncludeDirectoriesEntries.end();
  2901. it != end; ++it)
  2902. {
  2903. output += sep;
  2904. output += (*it)->ge->GetInput();
  2905. sep = ";";
  2906. }
  2907. return output.c_str();
  2908. }
  2909. if (strcmp(prop,"IMPORTED") == 0)
  2910. {
  2911. return this->IsImported()?"TRUE":"FALSE";
  2912. }
  2913. if(!strcmp(prop,"SOURCES"))
  2914. {
  2915. cmOStringStream ss;
  2916. const char* sep = "";
  2917. for(std::vector<cmSourceFile*>::const_iterator
  2918. i = this->SourceFiles.begin();
  2919. i != this->SourceFiles.end(); ++i)
  2920. {
  2921. // Separate from the previous list entries.
  2922. ss << sep;
  2923. sep = ";";
  2924. // Construct what is known about this source file location.
  2925. cmSourceFileLocation const& location = (*i)->GetLocation();
  2926. std::string sname = location.GetDirectory();
  2927. if(!sname.empty())
  2928. {
  2929. sname += "/";
  2930. }
  2931. sname += location.GetName();
  2932. // Append this list entry.
  2933. ss << sname;
  2934. }
  2935. this->SetProperty("SOURCES", ss.str().c_str());
  2936. }
  2937. // the type property returns what type the target is
  2938. if (!strcmp(prop,"TYPE"))
  2939. {
  2940. return cmTarget::GetTargetTypeName(this->GetType());
  2941. }
  2942. bool chain = false;
  2943. const char *retVal =
  2944. this->Properties.GetPropertyValue(prop, scope, chain);
  2945. if (chain)
  2946. {
  2947. return this->Makefile->GetProperty(prop,scope);
  2948. }
  2949. return retVal;
  2950. }
  2951. //----------------------------------------------------------------------------
  2952. bool cmTarget::GetPropertyAsBool(const char* prop)
  2953. {
  2954. return cmSystemTools::IsOn(this->GetProperty(prop));
  2955. }
  2956. //----------------------------------------------------------------------------
  2957. class cmTargetCollectLinkLanguages
  2958. {
  2959. public:
  2960. cmTargetCollectLinkLanguages(cmTarget* target, const char* config,
  2961. std::set<cmStdString>& languages,
  2962. cmTarget* head):
  2963. Config(config), Languages(languages), HeadTarget(head)
  2964. { this->Visited.insert(target); }
  2965. void Visit(cmTarget* target)
  2966. {
  2967. if(!target || !this->Visited.insert(target).second)
  2968. {
  2969. return;
  2970. }
  2971. cmTarget::LinkInterface const* iface =
  2972. target->GetLinkInterface(this->Config, this->HeadTarget);
  2973. if(!iface) { return; }
  2974. for(std::vector<std::string>::const_iterator
  2975. li = iface->Languages.begin(); li != iface->Languages.end(); ++li)
  2976. {
  2977. this->Languages.insert(*li);
  2978. }
  2979. cmMakefile* mf = target->GetMakefile();
  2980. for(std::vector<std::string>::const_iterator
  2981. li = iface->Libraries.begin(); li != iface->Libraries.end(); ++li)
  2982. {
  2983. this->Visit(mf->FindTargetToUse(li->c_str()));
  2984. }
  2985. }
  2986. private:
  2987. const char* Config;
  2988. std::set<cmStdString>& Languages;
  2989. cmTarget* HeadTarget;
  2990. std::set<cmTarget*> Visited;
  2991. };
  2992. //----------------------------------------------------------------------------
  2993. const char* cmTarget::GetLinkerLanguage(const char* config, cmTarget *head)
  2994. {
  2995. cmTarget *headTarget = head ? head : this;
  2996. const char* lang = this->GetLinkClosure(config, headTarget)
  2997. ->LinkerLanguage.c_str();
  2998. return *lang? lang : 0;
  2999. }
  3000. //----------------------------------------------------------------------------
  3001. cmTarget::LinkClosure const* cmTarget::GetLinkClosure(const char* config,
  3002. cmTarget *head)
  3003. {
  3004. TargetConfigPair key(head, cmSystemTools::UpperCase(config ? config : ""));
  3005. cmTargetInternals::LinkClosureMapType::iterator
  3006. i = this->Internal->LinkClosureMap.find(key);
  3007. if(i == this->Internal->LinkClosureMap.end())
  3008. {
  3009. LinkClosure lc;
  3010. this->ComputeLinkClosure(config, lc, head);
  3011. cmTargetInternals::LinkClosureMapType::value_type entry(key, lc);
  3012. i = this->Internal->LinkClosureMap.insert(entry).first;
  3013. }
  3014. return &i->second;
  3015. }
  3016. //----------------------------------------------------------------------------
  3017. class cmTargetSelectLinker
  3018. {
  3019. int Preference;
  3020. cmTarget* Target;
  3021. cmMakefile* Makefile;
  3022. cmGlobalGenerator* GG;
  3023. std::set<cmStdString> Preferred;
  3024. public:
  3025. cmTargetSelectLinker(cmTarget* target): Preference(0), Target(target)
  3026. {
  3027. this->Makefile = this->Target->GetMakefile();
  3028. this->GG = this->Makefile->GetLocalGenerator()->GetGlobalGenerator();
  3029. }
  3030. void Consider(const char* lang)
  3031. {
  3032. int preference = this->GG->GetLinkerPreference(lang);
  3033. if(preference > this->Preference)
  3034. {
  3035. this->Preference = preference;
  3036. this->Preferred.clear();
  3037. }
  3038. if(preference == this->Preference)
  3039. {
  3040. this->Preferred.insert(lang);
  3041. }
  3042. }
  3043. std::string Choose()
  3044. {
  3045. if(this->Preferred.empty())
  3046. {
  3047. return "";
  3048. }
  3049. else if(this->Preferred.size() > 1)
  3050. {
  3051. cmOStringStream e;
  3052. e << "Target " << this->Target->GetName()
  3053. << " contains multiple languages with the highest linker preference"
  3054. << " (" << this->Preference << "):\n";
  3055. for(std::set<cmStdString>::const_iterator
  3056. li = this->Preferred.begin(); li != this->Preferred.end(); ++li)
  3057. {
  3058. e << " " << *li << "\n";
  3059. }
  3060. e << "Set the LINKER_LANGUAGE property for this target.";
  3061. cmake* cm = this->Makefile->GetCMakeInstance();
  3062. cm->IssueMessage(cmake::FATAL_ERROR, e.str(),
  3063. this->Target->GetBacktrace());
  3064. }
  3065. return *this->Preferred.begin();
  3066. }
  3067. };
  3068. //----------------------------------------------------------------------------
  3069. void cmTarget::ComputeLinkClosure(const char* config, LinkClosure& lc,
  3070. cmTarget *head)
  3071. {
  3072. // Get languages built in this target.
  3073. std::set<cmStdString> languages;
  3074. LinkImplementation const* impl = this->GetLinkImplementation(config, head);
  3075. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3076. li != impl->Languages.end(); ++li)
  3077. {
  3078. languages.insert(*li);
  3079. }
  3080. // Add interface languages from linked targets.
  3081. cmTargetCollectLinkLanguages cll(this, config, languages, head);
  3082. for(std::vector<std::string>::const_iterator li = impl->Libraries.begin();
  3083. li != impl->Libraries.end(); ++li)
  3084. {
  3085. cll.Visit(this->Makefile->FindTargetToUse(li->c_str()));
  3086. }
  3087. // Store the transitive closure of languages.
  3088. for(std::set<cmStdString>::const_iterator li = languages.begin();
  3089. li != languages.end(); ++li)
  3090. {
  3091. lc.Languages.push_back(*li);
  3092. }
  3093. // Choose the language whose linker should be used.
  3094. if(this->GetProperty("HAS_CXX"))
  3095. {
  3096. lc.LinkerLanguage = "CXX";
  3097. }
  3098. else if(const char* linkerLang = this->GetProperty("LINKER_LANGUAGE"))
  3099. {
  3100. lc.LinkerLanguage = linkerLang;
  3101. }
  3102. else
  3103. {
  3104. // Find the language with the highest preference value.
  3105. cmTargetSelectLinker tsl(this);
  3106. // First select from the languages compiled directly in this target.
  3107. for(std::vector<std::string>::const_iterator li = impl->Languages.begin();
  3108. li != impl->Languages.end(); ++li)
  3109. {
  3110. tsl.Consider(li->c_str());
  3111. }
  3112. // Now consider languages that propagate from linked targets.
  3113. for(std::set<cmStdString>::const_iterator sit = languages.begin();
  3114. sit != languages.end(); ++sit)
  3115. {
  3116. std::string propagates = "CMAKE_"+*sit+"_LINKER_PREFERENCE_PROPAGATES";
  3117. if(this->Makefile->IsOn(propagates.c_str()))
  3118. {
  3119. tsl.Consider(sit->c_str());
  3120. }
  3121. }
  3122. lc.LinkerLanguage = tsl.Choose();
  3123. }
  3124. }
  3125. //----------------------------------------------------------------------------
  3126. const char* cmTarget::GetSuffixVariableInternal(bool implib)
  3127. {
  3128. switch(this->GetType())
  3129. {
  3130. case cmTarget::STATIC_LIBRARY:
  3131. return "CMAKE_STATIC_LIBRARY_SUFFIX";
  3132. case cmTarget::SHARED_LIBRARY:
  3133. return (implib
  3134. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3135. : "CMAKE_SHARED_LIBRARY_SUFFIX");
  3136. case cmTarget::MODULE_LIBRARY:
  3137. return (implib
  3138. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3139. : "CMAKE_SHARED_MODULE_SUFFIX");
  3140. case cmTarget::EXECUTABLE:
  3141. return (implib
  3142. ? "CMAKE_IMPORT_LIBRARY_SUFFIX"
  3143. : "CMAKE_EXECUTABLE_SUFFIX");
  3144. default:
  3145. break;
  3146. }
  3147. return "";
  3148. }
  3149. //----------------------------------------------------------------------------
  3150. const char* cmTarget::GetPrefixVariableInternal(bool implib)
  3151. {
  3152. switch(this->GetType())
  3153. {
  3154. case cmTarget::STATIC_LIBRARY:
  3155. return "CMAKE_STATIC_LIBRARY_PREFIX";
  3156. case cmTarget::SHARED_LIBRARY:
  3157. return (implib
  3158. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3159. : "CMAKE_SHARED_LIBRARY_PREFIX");
  3160. case cmTarget::MODULE_LIBRARY:
  3161. return (implib
  3162. ? "CMAKE_IMPORT_LIBRARY_PREFIX"
  3163. : "CMAKE_SHARED_MODULE_PREFIX");
  3164. case cmTarget::EXECUTABLE:
  3165. return (implib? "CMAKE_IMPORT_LIBRARY_PREFIX" : "");
  3166. default:
  3167. break;
  3168. }
  3169. return "";
  3170. }
  3171. //----------------------------------------------------------------------------
  3172. std::string cmTarget::GetPDBName(const char* config)
  3173. {
  3174. std::string prefix;
  3175. std::string base;
  3176. std::string suffix;
  3177. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3178. std::vector<std::string> props;
  3179. std::string configUpper =
  3180. cmSystemTools::UpperCase(config? config : "");
  3181. if(!configUpper.empty())
  3182. {
  3183. // PDB_NAME_<CONFIG>
  3184. props.push_back("PDB_NAME_" + configUpper);
  3185. }
  3186. // PDB_NAME
  3187. props.push_back("PDB_NAME");
  3188. for(std::vector<std::string>::const_iterator i = props.begin();
  3189. i != props.end(); ++i)
  3190. {
  3191. if(const char* outName = this->GetProperty(i->c_str()))
  3192. {
  3193. base = outName;
  3194. break;
  3195. }
  3196. }
  3197. return prefix+base+".pdb";
  3198. }
  3199. //----------------------------------------------------------------------------
  3200. bool cmTarget::HasSOName(const char* config)
  3201. {
  3202. // soname is supported only for shared libraries and modules,
  3203. // and then only when the platform supports an soname flag.
  3204. return ((this->GetType() == cmTarget::SHARED_LIBRARY ||
  3205. this->GetType() == cmTarget::MODULE_LIBRARY) &&
  3206. !this->GetPropertyAsBool("NO_SONAME") &&
  3207. this->Makefile->GetSONameFlag(this->GetLinkerLanguage(config,
  3208. this)));
  3209. }
  3210. //----------------------------------------------------------------------------
  3211. std::string cmTarget::GetSOName(const char* config)
  3212. {
  3213. if(this->IsImported())
  3214. {
  3215. // Lookup the imported soname.
  3216. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3217. {
  3218. if(info->NoSOName)
  3219. {
  3220. // The imported library has no builtin soname so the name
  3221. // searched at runtime will be just the filename.
  3222. return cmSystemTools::GetFilenameName(info->Location);
  3223. }
  3224. else
  3225. {
  3226. // Use the soname given if any.
  3227. return info->SOName;
  3228. }
  3229. }
  3230. else
  3231. {
  3232. return "";
  3233. }
  3234. }
  3235. else
  3236. {
  3237. // Compute the soname that will be built.
  3238. std::string name;
  3239. std::string soName;
  3240. std::string realName;
  3241. std::string impName;
  3242. std::string pdbName;
  3243. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3244. return soName;
  3245. }
  3246. }
  3247. //----------------------------------------------------------------------------
  3248. bool cmTarget::IsImportedSharedLibWithoutSOName(const char* config)
  3249. {
  3250. if(this->IsImported() && this->GetType() == cmTarget::SHARED_LIBRARY)
  3251. {
  3252. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3253. {
  3254. return info->NoSOName;
  3255. }
  3256. }
  3257. return false;
  3258. }
  3259. //----------------------------------------------------------------------------
  3260. std::string cmTarget::NormalGetRealName(const char* config)
  3261. {
  3262. // This should not be called for imported targets.
  3263. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3264. // enforcement of the limited imported target API.
  3265. if(this->IsImported())
  3266. {
  3267. std::string msg = "NormalGetRealName called on imported target: ";
  3268. msg += this->GetName();
  3269. this->GetMakefile()->
  3270. IssueMessage(cmake::INTERNAL_ERROR,
  3271. msg.c_str());
  3272. }
  3273. if(this->GetType() == cmTarget::EXECUTABLE)
  3274. {
  3275. // Compute the real name that will be built.
  3276. std::string name;
  3277. std::string realName;
  3278. std::string impName;
  3279. std::string pdbName;
  3280. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3281. return realName;
  3282. }
  3283. else
  3284. {
  3285. // Compute the real name that will be built.
  3286. std::string name;
  3287. std::string soName;
  3288. std::string realName;
  3289. std::string impName;
  3290. std::string pdbName;
  3291. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3292. return realName;
  3293. }
  3294. }
  3295. //----------------------------------------------------------------------------
  3296. std::string cmTarget::GetFullName(const char* config, bool implib)
  3297. {
  3298. if(this->IsImported())
  3299. {
  3300. return this->GetFullNameImported(config, implib);
  3301. }
  3302. else
  3303. {
  3304. return this->GetFullNameInternal(config, implib);
  3305. }
  3306. }
  3307. //----------------------------------------------------------------------------
  3308. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  3309. {
  3310. return cmSystemTools::GetFilenameName(
  3311. this->ImportedGetFullPath(config, implib));
  3312. }
  3313. //----------------------------------------------------------------------------
  3314. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  3315. std::string& suffix, const char* config,
  3316. bool implib)
  3317. {
  3318. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3319. }
  3320. //----------------------------------------------------------------------------
  3321. std::string cmTarget::GetFullPath(const char* config, bool implib,
  3322. bool realname)
  3323. {
  3324. if(this->IsImported())
  3325. {
  3326. return this->ImportedGetFullPath(config, implib);
  3327. }
  3328. else
  3329. {
  3330. return this->NormalGetFullPath(config, implib, realname);
  3331. }
  3332. }
  3333. //----------------------------------------------------------------------------
  3334. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  3335. bool realname)
  3336. {
  3337. std::string fpath = this->GetMacContentDirectory(config, implib);
  3338. // Add the full name of the target.
  3339. if(implib)
  3340. {
  3341. fpath += this->GetFullName(config, true);
  3342. }
  3343. else if(realname)
  3344. {
  3345. fpath += this->NormalGetRealName(config);
  3346. }
  3347. else
  3348. {
  3349. fpath += this->GetFullName(config, false);
  3350. }
  3351. return fpath;
  3352. }
  3353. //----------------------------------------------------------------------------
  3354. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  3355. {
  3356. std::string result;
  3357. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, this))
  3358. {
  3359. result = implib? info->ImportLibrary : info->Location;
  3360. }
  3361. if(result.empty())
  3362. {
  3363. result = this->GetName();
  3364. result += "-NOTFOUND";
  3365. }
  3366. return result;
  3367. }
  3368. //----------------------------------------------------------------------------
  3369. std::string cmTarget::GetFullNameInternal(const char* config, bool implib)
  3370. {
  3371. std::string prefix;
  3372. std::string base;
  3373. std::string suffix;
  3374. this->GetFullNameInternal(config, implib, prefix, base, suffix);
  3375. return prefix+base+suffix;
  3376. }
  3377. //----------------------------------------------------------------------------
  3378. void cmTarget::GetFullNameInternal(const char* config,
  3379. bool implib,
  3380. std::string& outPrefix,
  3381. std::string& outBase,
  3382. std::string& outSuffix)
  3383. {
  3384. // Use just the target name for non-main target types.
  3385. if(this->GetType() != cmTarget::STATIC_LIBRARY &&
  3386. this->GetType() != cmTarget::SHARED_LIBRARY &&
  3387. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3388. this->GetType() != cmTarget::EXECUTABLE)
  3389. {
  3390. outPrefix = "";
  3391. outBase = this->GetName();
  3392. outSuffix = "";
  3393. return;
  3394. }
  3395. // Return an empty name for the import library if this platform
  3396. // does not support import libraries.
  3397. if(implib &&
  3398. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  3399. {
  3400. outPrefix = "";
  3401. outBase = "";
  3402. outSuffix = "";
  3403. return;
  3404. }
  3405. // The implib option is only allowed for shared libraries, module
  3406. // libraries, and executables.
  3407. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  3408. this->GetType() != cmTarget::MODULE_LIBRARY &&
  3409. this->GetType() != cmTarget::EXECUTABLE)
  3410. {
  3411. implib = false;
  3412. }
  3413. // Compute the full name for main target types.
  3414. const char* targetPrefix = (implib
  3415. ? this->GetProperty("IMPORT_PREFIX")
  3416. : this->GetProperty("PREFIX"));
  3417. const char* targetSuffix = (implib
  3418. ? this->GetProperty("IMPORT_SUFFIX")
  3419. : this->GetProperty("SUFFIX"));
  3420. const char* configPostfix = 0;
  3421. if(config && *config)
  3422. {
  3423. std::string configProp = cmSystemTools::UpperCase(config);
  3424. configProp += "_POSTFIX";
  3425. configPostfix = this->GetProperty(configProp.c_str());
  3426. // Mac application bundles and frameworks have no postfix.
  3427. if(configPostfix &&
  3428. (this->IsAppBundleOnApple() || this->IsFrameworkOnApple()))
  3429. {
  3430. configPostfix = 0;
  3431. }
  3432. }
  3433. const char* prefixVar = this->GetPrefixVariableInternal(implib);
  3434. const char* suffixVar = this->GetSuffixVariableInternal(implib);
  3435. // Check for language-specific default prefix and suffix.
  3436. if(const char* ll = this->GetLinkerLanguage(config, this))
  3437. {
  3438. if(!targetSuffix && suffixVar && *suffixVar)
  3439. {
  3440. std::string langSuff = suffixVar + std::string("_") + ll;
  3441. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  3442. }
  3443. if(!targetPrefix && prefixVar && *prefixVar)
  3444. {
  3445. std::string langPrefix = prefixVar + std::string("_") + ll;
  3446. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  3447. }
  3448. }
  3449. // if there is no prefix on the target use the cmake definition
  3450. if(!targetPrefix && prefixVar)
  3451. {
  3452. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  3453. }
  3454. // if there is no suffix on the target use the cmake definition
  3455. if(!targetSuffix && suffixVar)
  3456. {
  3457. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  3458. }
  3459. // frameworks do not have a prefix or a suffix
  3460. if(this->IsFrameworkOnApple())
  3461. {
  3462. targetPrefix = 0;
  3463. targetSuffix = 0;
  3464. }
  3465. // Begin the final name with the prefix.
  3466. outPrefix = targetPrefix?targetPrefix:"";
  3467. // Append the target name or property-specified name.
  3468. outBase += this->GetOutputName(config, implib);
  3469. // Append the per-configuration postfix.
  3470. outBase += configPostfix?configPostfix:"";
  3471. // Name shared libraries with their version number on some platforms.
  3472. if(const char* soversion = this->GetProperty("SOVERSION"))
  3473. {
  3474. if(this->GetType() == cmTarget::SHARED_LIBRARY && !implib &&
  3475. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  3476. {
  3477. outBase += "-";
  3478. outBase += soversion;
  3479. }
  3480. }
  3481. // Append the suffix.
  3482. outSuffix = targetSuffix?targetSuffix:"";
  3483. }
  3484. //----------------------------------------------------------------------------
  3485. void cmTarget::GetLibraryNames(std::string& name,
  3486. std::string& soName,
  3487. std::string& realName,
  3488. std::string& impName,
  3489. std::string& pdbName,
  3490. const char* config)
  3491. {
  3492. // This should not be called for imported targets.
  3493. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3494. // enforcement of the limited imported target API.
  3495. if(this->IsImported())
  3496. {
  3497. std::string msg = "GetLibraryNames called on imported target: ";
  3498. msg += this->GetName();
  3499. this->Makefile->IssueMessage(cmake::INTERNAL_ERROR,
  3500. msg.c_str());
  3501. return;
  3502. }
  3503. // Check for library version properties.
  3504. const char* version = this->GetProperty("VERSION");
  3505. const char* soversion = this->GetProperty("SOVERSION");
  3506. if(!this->HasSOName(config) ||
  3507. this->IsFrameworkOnApple())
  3508. {
  3509. // Versioning is supported only for shared libraries and modules,
  3510. // and then only when the platform supports an soname flag.
  3511. version = 0;
  3512. soversion = 0;
  3513. }
  3514. if(version && !soversion)
  3515. {
  3516. // The soversion must be set if the library version is set. Use
  3517. // the library version as the soversion.
  3518. soversion = version;
  3519. }
  3520. if(!version && soversion)
  3521. {
  3522. // Use the soversion as the library version.
  3523. version = soversion;
  3524. }
  3525. // Get the components of the library name.
  3526. std::string prefix;
  3527. std::string base;
  3528. std::string suffix;
  3529. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3530. // The library name.
  3531. name = prefix+base+suffix;
  3532. // The library's soname.
  3533. this->ComputeVersionedName(soName, prefix, base, suffix,
  3534. name, soversion);
  3535. // The library's real name on disk.
  3536. this->ComputeVersionedName(realName, prefix, base, suffix,
  3537. name, version);
  3538. // The import library name.
  3539. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  3540. this->GetType() == cmTarget::MODULE_LIBRARY)
  3541. {
  3542. impName = this->GetFullNameInternal(config, true);
  3543. }
  3544. else
  3545. {
  3546. impName = "";
  3547. }
  3548. // The program database file name.
  3549. pdbName = this->GetPDBName(config);
  3550. }
  3551. //----------------------------------------------------------------------------
  3552. void cmTarget::ComputeVersionedName(std::string& vName,
  3553. std::string const& prefix,
  3554. std::string const& base,
  3555. std::string const& suffix,
  3556. std::string const& name,
  3557. const char* version)
  3558. {
  3559. vName = this->IsApple? (prefix+base) : name;
  3560. if(version)
  3561. {
  3562. vName += ".";
  3563. vName += version;
  3564. }
  3565. vName += this->IsApple? suffix : std::string();
  3566. }
  3567. //----------------------------------------------------------------------------
  3568. void cmTarget::GetExecutableNames(std::string& name,
  3569. std::string& realName,
  3570. std::string& impName,
  3571. std::string& pdbName,
  3572. const char* config)
  3573. {
  3574. // This should not be called for imported targets.
  3575. // TODO: Split cmTarget into a class hierarchy to get compile-time
  3576. // enforcement of the limited imported target API.
  3577. if(this->IsImported())
  3578. {
  3579. std::string msg =
  3580. "GetExecutableNames called on imported target: ";
  3581. msg += this->GetName();
  3582. this->GetMakefile()->IssueMessage(cmake::INTERNAL_ERROR, msg.c_str());
  3583. }
  3584. // This versioning is supported only for executables and then only
  3585. // when the platform supports symbolic links.
  3586. #if defined(_WIN32) && !defined(__CYGWIN__)
  3587. const char* version = 0;
  3588. #else
  3589. // Check for executable version properties.
  3590. const char* version = this->GetProperty("VERSION");
  3591. if(this->GetType() != cmTarget::EXECUTABLE || this->Makefile->IsOn("XCODE"))
  3592. {
  3593. version = 0;
  3594. }
  3595. #endif
  3596. // Get the components of the executable name.
  3597. std::string prefix;
  3598. std::string base;
  3599. std::string suffix;
  3600. this->GetFullNameInternal(config, false, prefix, base, suffix);
  3601. // The executable name.
  3602. name = prefix+base+suffix;
  3603. // The executable's real name on disk.
  3604. #if defined(__CYGWIN__)
  3605. realName = prefix+base;
  3606. #else
  3607. realName = name;
  3608. #endif
  3609. if(version)
  3610. {
  3611. realName += "-";
  3612. realName += version;
  3613. }
  3614. #if defined(__CYGWIN__)
  3615. realName += suffix;
  3616. #endif
  3617. // The import library name.
  3618. impName = this->GetFullNameInternal(config, true);
  3619. // The program database file name.
  3620. pdbName = this->GetPDBName(config);
  3621. }
  3622. //----------------------------------------------------------------------------
  3623. bool cmTarget::HasImplibGNUtoMS()
  3624. {
  3625. return this->HasImportLibrary() && this->GetPropertyAsBool("GNUtoMS");
  3626. }
  3627. //----------------------------------------------------------------------------
  3628. bool cmTarget::GetImplibGNUtoMS(std::string const& gnuName,
  3629. std::string& out, const char* newExt)
  3630. {
  3631. if(this->HasImplibGNUtoMS() &&
  3632. gnuName.size() > 6 && gnuName.substr(gnuName.size()-6) == ".dll.a")
  3633. {
  3634. out = gnuName.substr(0, gnuName.size()-6);
  3635. out += newExt? newExt : ".lib";
  3636. return true;
  3637. }
  3638. return false;
  3639. }
  3640. //----------------------------------------------------------------------------
  3641. void cmTarget::GenerateTargetManifest(const char* config)
  3642. {
  3643. cmMakefile* mf = this->Makefile;
  3644. cmLocalGenerator* lg = mf->GetLocalGenerator();
  3645. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  3646. // Get the names.
  3647. std::string name;
  3648. std::string soName;
  3649. std::string realName;
  3650. std::string impName;
  3651. std::string pdbName;
  3652. if(this->GetType() == cmTarget::EXECUTABLE)
  3653. {
  3654. this->GetExecutableNames(name, realName, impName, pdbName, config);
  3655. }
  3656. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3657. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3658. this->GetType() == cmTarget::MODULE_LIBRARY)
  3659. {
  3660. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  3661. }
  3662. else
  3663. {
  3664. return;
  3665. }
  3666. // Get the directory.
  3667. std::string dir = this->GetDirectory(config, false);
  3668. // Add each name.
  3669. std::string f;
  3670. if(!name.empty())
  3671. {
  3672. f = dir;
  3673. f += "/";
  3674. f += name;
  3675. gg->AddToManifest(config? config:"", f);
  3676. }
  3677. if(!soName.empty())
  3678. {
  3679. f = dir;
  3680. f += "/";
  3681. f += soName;
  3682. gg->AddToManifest(config? config:"", f);
  3683. }
  3684. if(!realName.empty())
  3685. {
  3686. f = dir;
  3687. f += "/";
  3688. f += realName;
  3689. gg->AddToManifest(config? config:"", f);
  3690. }
  3691. if(!pdbName.empty())
  3692. {
  3693. f = this->GetPDBDirectory(config);
  3694. f += "/";
  3695. f += pdbName;
  3696. gg->AddToManifest(config? config:"", f);
  3697. }
  3698. if(!impName.empty())
  3699. {
  3700. f = this->GetDirectory(config, true);
  3701. f += "/";
  3702. f += impName;
  3703. gg->AddToManifest(config? config:"", f);
  3704. }
  3705. }
  3706. //----------------------------------------------------------------------------
  3707. void cmTarget::SetPropertyDefault(const char* property,
  3708. const char* default_value)
  3709. {
  3710. // Compute the name of the variable holding the default value.
  3711. std::string var = "CMAKE_";
  3712. var += property;
  3713. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  3714. {
  3715. this->SetProperty(property, value);
  3716. }
  3717. else if(default_value)
  3718. {
  3719. this->SetProperty(property, default_value);
  3720. }
  3721. }
  3722. //----------------------------------------------------------------------------
  3723. bool cmTarget::HaveBuildTreeRPATH()
  3724. {
  3725. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  3726. !this->LinkLibraries.empty());
  3727. }
  3728. //----------------------------------------------------------------------------
  3729. bool cmTarget::HaveInstallTreeRPATH()
  3730. {
  3731. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  3732. return (install_rpath && *install_rpath) &&
  3733. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH");
  3734. }
  3735. //----------------------------------------------------------------------------
  3736. bool cmTarget::NeedRelinkBeforeInstall(const char* config)
  3737. {
  3738. // Only executables and shared libraries can have an rpath and may
  3739. // need relinking.
  3740. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  3741. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  3742. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  3743. {
  3744. return false;
  3745. }
  3746. // If there is no install location this target will not be installed
  3747. // and therefore does not need relinking.
  3748. if(!this->GetHaveInstallRule())
  3749. {
  3750. return false;
  3751. }
  3752. // If skipping all rpaths completely then no relinking is needed.
  3753. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  3754. {
  3755. return false;
  3756. }
  3757. // If building with the install-tree rpath no relinking is needed.
  3758. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3759. {
  3760. return false;
  3761. }
  3762. // If chrpath is going to be used no relinking is needed.
  3763. if(this->IsChrpathUsed(config))
  3764. {
  3765. return false;
  3766. }
  3767. // Check for rpath support on this platform.
  3768. if(const char* ll = this->GetLinkerLanguage(config, this))
  3769. {
  3770. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  3771. flagVar += ll;
  3772. flagVar += "_FLAG";
  3773. if(!this->Makefile->IsSet(flagVar.c_str()))
  3774. {
  3775. // There is no rpath support on this platform so nothing needs
  3776. // relinking.
  3777. return false;
  3778. }
  3779. }
  3780. else
  3781. {
  3782. // No linker language is known. This error will be reported by
  3783. // other code.
  3784. return false;
  3785. }
  3786. // If either a build or install tree rpath is set then the rpath
  3787. // will likely change between the build tree and install tree and
  3788. // this target must be relinked.
  3789. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  3790. }
  3791. //----------------------------------------------------------------------------
  3792. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config,
  3793. bool for_xcode)
  3794. {
  3795. // If building directly for installation then the build tree install_name
  3796. // is the same as the install tree.
  3797. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  3798. {
  3799. return GetInstallNameDirForInstallTree(config, for_xcode);
  3800. }
  3801. // Use the build tree directory for the target.
  3802. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  3803. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3804. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  3805. {
  3806. std::string dir = this->GetDirectory(config);
  3807. dir += "/";
  3808. if(this->IsFrameworkOnApple() && !for_xcode)
  3809. {
  3810. dir += this->GetFrameworkDirectory(config);
  3811. }
  3812. return dir;
  3813. }
  3814. else
  3815. {
  3816. return "";
  3817. }
  3818. }
  3819. //----------------------------------------------------------------------------
  3820. std::string cmTarget::GetInstallNameDirForInstallTree(const char* config,
  3821. bool for_xcode)
  3822. {
  3823. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME"))
  3824. {
  3825. std::string dir;
  3826. if(!this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  3827. !this->Makefile->IsOn("CMAKE_SKIP_INSTALL_RPATH"))
  3828. {
  3829. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  3830. if(install_name_dir && *install_name_dir)
  3831. {
  3832. dir = install_name_dir;
  3833. dir += "/";
  3834. }
  3835. }
  3836. if(this->IsFrameworkOnApple() && !for_xcode)
  3837. {
  3838. dir += this->GetFrameworkDirectory(config);
  3839. }
  3840. return dir;
  3841. }
  3842. else
  3843. {
  3844. return "";
  3845. }
  3846. }
  3847. //----------------------------------------------------------------------------
  3848. const char* cmTarget::GetOutputTargetType(bool implib)
  3849. {
  3850. switch(this->GetType())
  3851. {
  3852. case cmTarget::SHARED_LIBRARY:
  3853. if(this->DLLPlatform)
  3854. {
  3855. if(implib)
  3856. {
  3857. // A DLL import library is treated as an archive target.
  3858. return "ARCHIVE";
  3859. }
  3860. else
  3861. {
  3862. // A DLL shared library is treated as a runtime target.
  3863. return "RUNTIME";
  3864. }
  3865. }
  3866. else
  3867. {
  3868. // For non-DLL platforms shared libraries are treated as
  3869. // library targets.
  3870. return "LIBRARY";
  3871. }
  3872. case cmTarget::STATIC_LIBRARY:
  3873. // Static libraries are always treated as archive targets.
  3874. return "ARCHIVE";
  3875. case cmTarget::MODULE_LIBRARY:
  3876. if(implib)
  3877. {
  3878. // Module libraries are always treated as library targets.
  3879. return "ARCHIVE";
  3880. }
  3881. else
  3882. {
  3883. // Module import libraries are treated as archive targets.
  3884. return "LIBRARY";
  3885. }
  3886. case cmTarget::EXECUTABLE:
  3887. if(implib)
  3888. {
  3889. // Executable import libraries are treated as archive targets.
  3890. return "ARCHIVE";
  3891. }
  3892. else
  3893. {
  3894. // Executables are always treated as runtime targets.
  3895. return "RUNTIME";
  3896. }
  3897. default:
  3898. break;
  3899. }
  3900. return "";
  3901. }
  3902. //----------------------------------------------------------------------------
  3903. bool cmTarget::ComputeOutputDir(const char* config,
  3904. bool implib, std::string& out)
  3905. {
  3906. bool usesDefaultOutputDir = false;
  3907. // Look for a target property defining the target output directory
  3908. // based on the target type.
  3909. std::string targetTypeName = this->GetOutputTargetType(implib);
  3910. const char* propertyName = 0;
  3911. std::string propertyNameStr = targetTypeName;
  3912. if(!propertyNameStr.empty())
  3913. {
  3914. propertyNameStr += "_OUTPUT_DIRECTORY";
  3915. propertyName = propertyNameStr.c_str();
  3916. }
  3917. // Check for a per-configuration output directory target property.
  3918. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3919. const char* configProp = 0;
  3920. std::string configPropStr = targetTypeName;
  3921. if(!configPropStr.empty())
  3922. {
  3923. configPropStr += "_OUTPUT_DIRECTORY_";
  3924. configPropStr += configUpper;
  3925. configProp = configPropStr.c_str();
  3926. }
  3927. // Select an output directory.
  3928. if(const char* config_outdir = this->GetProperty(configProp))
  3929. {
  3930. // Use the user-specified per-configuration output directory.
  3931. out = config_outdir;
  3932. // Skip per-configuration subdirectory.
  3933. config = 0;
  3934. }
  3935. else if(const char* outdir = this->GetProperty(propertyName))
  3936. {
  3937. // Use the user-specified output directory.
  3938. out = outdir;
  3939. }
  3940. else if(this->GetType() == cmTarget::EXECUTABLE)
  3941. {
  3942. // Lookup the output path for executables.
  3943. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  3944. }
  3945. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  3946. this->GetType() == cmTarget::SHARED_LIBRARY ||
  3947. this->GetType() == cmTarget::MODULE_LIBRARY)
  3948. {
  3949. // Lookup the output path for libraries.
  3950. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  3951. }
  3952. if(out.empty())
  3953. {
  3954. // Default to the current output directory.
  3955. usesDefaultOutputDir = true;
  3956. out = ".";
  3957. }
  3958. // Convert the output path to a full path in case it is
  3959. // specified as a relative path. Treat a relative path as
  3960. // relative to the current output directory for this makefile.
  3961. out = (cmSystemTools::CollapseFullPath
  3962. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  3963. // The generator may add the configuration's subdirectory.
  3964. if(config && *config)
  3965. {
  3966. const char *platforms = this->Makefile->GetDefinition(
  3967. "CMAKE_XCODE_EFFECTIVE_PLATFORMS");
  3968. std::string suffix =
  3969. usesDefaultOutputDir && platforms ? "$(EFFECTIVE_PLATFORM_NAME)" : "";
  3970. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  3971. AppendDirectoryForConfig("/", config, suffix.c_str(), out);
  3972. }
  3973. return usesDefaultOutputDir;
  3974. }
  3975. //----------------------------------------------------------------------------
  3976. bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out)
  3977. {
  3978. // Look for a target property defining the target output directory
  3979. // based on the target type.
  3980. std::string targetTypeName = "PDB";
  3981. const char* propertyName = 0;
  3982. std::string propertyNameStr = targetTypeName;
  3983. if(!propertyNameStr.empty())
  3984. {
  3985. propertyNameStr += "_OUTPUT_DIRECTORY";
  3986. propertyName = propertyNameStr.c_str();
  3987. }
  3988. // Check for a per-configuration output directory target property.
  3989. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  3990. const char* configProp = 0;
  3991. std::string configPropStr = targetTypeName;
  3992. if(!configPropStr.empty())
  3993. {
  3994. configPropStr += "_OUTPUT_DIRECTORY_";
  3995. configPropStr += configUpper;
  3996. configProp = configPropStr.c_str();
  3997. }
  3998. // Select an output directory.
  3999. if(const char* config_outdir = this->GetProperty(configProp))
  4000. {
  4001. // Use the user-specified per-configuration output directory.
  4002. out = config_outdir;
  4003. // Skip per-configuration subdirectory.
  4004. config = 0;
  4005. }
  4006. else if(const char* outdir = this->GetProperty(propertyName))
  4007. {
  4008. // Use the user-specified output directory.
  4009. out = outdir;
  4010. }
  4011. if(out.empty())
  4012. {
  4013. return false;
  4014. }
  4015. // Convert the output path to a full path in case it is
  4016. // specified as a relative path. Treat a relative path as
  4017. // relative to the current output directory for this makefile.
  4018. out = (cmSystemTools::CollapseFullPath
  4019. (out.c_str(), this->Makefile->GetStartOutputDirectory()));
  4020. // The generator may add the configuration's subdirectory.
  4021. if(config && *config)
  4022. {
  4023. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
  4024. AppendDirectoryForConfig("/", config, "", out);
  4025. }
  4026. return true;
  4027. }
  4028. //----------------------------------------------------------------------------
  4029. bool cmTarget::UsesDefaultOutputDir(const char* config, bool implib)
  4030. {
  4031. std::string dir;
  4032. return this->ComputeOutputDir(config, implib, dir);
  4033. }
  4034. //----------------------------------------------------------------------------
  4035. std::string cmTarget::GetOutputName(const char* config, bool implib)
  4036. {
  4037. std::vector<std::string> props;
  4038. std::string type = this->GetOutputTargetType(implib);
  4039. std::string configUpper = cmSystemTools::UpperCase(config? config : "");
  4040. if(!type.empty() && !configUpper.empty())
  4041. {
  4042. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME_<CONFIG>
  4043. props.push_back(type + "_OUTPUT_NAME_" + configUpper);
  4044. }
  4045. if(!type.empty())
  4046. {
  4047. // <ARCHIVE|LIBRARY|RUNTIME>_OUTPUT_NAME
  4048. props.push_back(type + "_OUTPUT_NAME");
  4049. }
  4050. if(!configUpper.empty())
  4051. {
  4052. // OUTPUT_NAME_<CONFIG>
  4053. props.push_back("OUTPUT_NAME_" + configUpper);
  4054. // <CONFIG>_OUTPUT_NAME
  4055. props.push_back(configUpper + "_OUTPUT_NAME");
  4056. }
  4057. // OUTPUT_NAME
  4058. props.push_back("OUTPUT_NAME");
  4059. for(std::vector<std::string>::const_iterator i = props.begin();
  4060. i != props.end(); ++i)
  4061. {
  4062. if(const char* outName = this->GetProperty(i->c_str()))
  4063. {
  4064. return outName;
  4065. }
  4066. }
  4067. return this->GetName();
  4068. }
  4069. //----------------------------------------------------------------------------
  4070. std::string cmTarget::GetFrameworkVersion()
  4071. {
  4072. if(const char* fversion = this->GetProperty("FRAMEWORK_VERSION"))
  4073. {
  4074. return fversion;
  4075. }
  4076. else if(const char* tversion = this->GetProperty("VERSION"))
  4077. {
  4078. return tversion;
  4079. }
  4080. else
  4081. {
  4082. return "A";
  4083. }
  4084. }
  4085. //----------------------------------------------------------------------------
  4086. const char* cmTarget::GetExportMacro()
  4087. {
  4088. // Define the symbol for targets that export symbols.
  4089. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4090. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4091. this->IsExecutableWithExports())
  4092. {
  4093. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  4094. {
  4095. this->ExportMacro = custom_export_name;
  4096. }
  4097. else
  4098. {
  4099. std::string in = this->GetName();
  4100. in += "_EXPORTS";
  4101. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  4102. }
  4103. return this->ExportMacro.c_str();
  4104. }
  4105. else
  4106. {
  4107. return 0;
  4108. }
  4109. }
  4110. //----------------------------------------------------------------------------
  4111. void cmTarget::GetLinkDependentTargetsForProperty(const std::string &p,
  4112. std::set<std::string> &targets)
  4113. {
  4114. const std::map<cmStdString, std::set<std::string> >::const_iterator findIt
  4115. = this->LinkDependentProperties.find(p);
  4116. if (findIt != this->LinkDependentProperties.end())
  4117. {
  4118. targets = findIt->second;
  4119. }
  4120. }
  4121. //----------------------------------------------------------------------------
  4122. bool cmTarget::IsNullImpliedByLinkLibraries(const std::string &p)
  4123. {
  4124. return this->LinkImplicitNullProperties.find(p)
  4125. != this->LinkImplicitNullProperties.end();
  4126. }
  4127. //----------------------------------------------------------------------------
  4128. void cmTarget::AddLinkDependentTargetsForProperties(
  4129. const std::map<cmStdString, cmStdString> &map)
  4130. {
  4131. for (std::map<cmStdString, cmStdString>::const_iterator it = map.begin();
  4132. it != map.end(); ++it)
  4133. {
  4134. std::vector<std::string> targets;
  4135. cmSystemTools::ExpandListArgument(it->second.c_str(), targets);
  4136. this->LinkDependentProperties[it->first].insert(targets.begin(),
  4137. targets.end());
  4138. if (!this->GetProperty(it->first.c_str()))
  4139. {
  4140. this->LinkImplicitNullProperties.insert(it->first);
  4141. }
  4142. }
  4143. }
  4144. //----------------------------------------------------------------------------
  4145. template<typename PropertyType>
  4146. PropertyType getTypedProperty(cmTarget *tgt, const char *prop,
  4147. PropertyType *);
  4148. //----------------------------------------------------------------------------
  4149. template<>
  4150. bool getTypedProperty<bool>(cmTarget *tgt, const char *prop, bool *)
  4151. {
  4152. return tgt->GetPropertyAsBool(prop);
  4153. }
  4154. //----------------------------------------------------------------------------
  4155. template<>
  4156. const char *getTypedProperty<const char *>(cmTarget *tgt, const char *prop,
  4157. const char **)
  4158. {
  4159. return tgt->GetProperty(prop);
  4160. }
  4161. //----------------------------------------------------------------------------
  4162. template<typename PropertyType>
  4163. bool consistentProperty(PropertyType lhs, PropertyType rhs);
  4164. //----------------------------------------------------------------------------
  4165. template<>
  4166. bool consistentProperty(bool lhs, bool rhs)
  4167. {
  4168. return lhs == rhs;
  4169. }
  4170. //----------------------------------------------------------------------------
  4171. template<>
  4172. bool consistentProperty(const char *lhs, const char *rhs)
  4173. {
  4174. if (!lhs && !rhs)
  4175. return true;
  4176. if (!lhs || !rhs)
  4177. return false;
  4178. return strcmp(lhs, rhs) == 0;
  4179. }
  4180. //----------------------------------------------------------------------------
  4181. template<typename PropertyType>
  4182. PropertyType checkInterfacePropertyCompatibility(cmTarget *tgt,
  4183. const std::string &p,
  4184. const char *config,
  4185. const char *defaultValue,
  4186. PropertyType *)
  4187. {
  4188. PropertyType propContent = getTypedProperty<PropertyType>(tgt, p.c_str(),
  4189. 0);
  4190. const bool explicitlySet = tgt->GetProperties()
  4191. .find(p.c_str())
  4192. != tgt->GetProperties().end();
  4193. std::set<std::string> dependentTargets;
  4194. tgt->GetLinkDependentTargetsForProperty(p,
  4195. dependentTargets);
  4196. const bool impliedByUse =
  4197. tgt->IsNullImpliedByLinkLibraries(p);
  4198. assert((impliedByUse ^ explicitlySet)
  4199. || (!impliedByUse && !explicitlySet));
  4200. cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
  4201. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  4202. bool propInitialized = explicitlySet;
  4203. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  4204. deps.begin();
  4205. li != deps.end(); ++li)
  4206. {
  4207. // An error should be reported if one dependency
  4208. // has INTERFACE_POSITION_INDEPENDENT_CODE ON and the other
  4209. // has INTERFACE_POSITION_INDEPENDENT_CODE OFF, or if the
  4210. // target itself has a POSITION_INDEPENDENT_CODE which disagrees
  4211. // with a dependency.
  4212. if (!li->Target)
  4213. {
  4214. continue;
  4215. }
  4216. const bool ifaceIsSet = li->Target->GetProperties()
  4217. .find("INTERFACE_" + p)
  4218. != li->Target->GetProperties().end();
  4219. PropertyType ifacePropContent =
  4220. getTypedProperty<PropertyType>(li->Target,
  4221. ("INTERFACE_" + p).c_str(), 0);
  4222. if (explicitlySet)
  4223. {
  4224. if (ifaceIsSet)
  4225. {
  4226. if (!consistentProperty(propContent, ifacePropContent))
  4227. {
  4228. cmOStringStream e;
  4229. e << "Property " << p << " on target \""
  4230. << tgt->GetName() << "\" does\nnot match the "
  4231. "INTERFACE_" << p << " property requirement\nof "
  4232. "dependency \"" << li->Target->GetName() << "\".\n";
  4233. cmSystemTools::Error(e.str().c_str());
  4234. break;
  4235. }
  4236. else
  4237. {
  4238. // Agree
  4239. continue;
  4240. }
  4241. }
  4242. else
  4243. {
  4244. // Explicitly set on target and not set in iface. Can't disagree.
  4245. continue;
  4246. }
  4247. }
  4248. else if (impliedByUse)
  4249. {
  4250. if (ifaceIsSet)
  4251. {
  4252. if (!consistentProperty(propContent, ifacePropContent))
  4253. {
  4254. cmOStringStream e;
  4255. e << "Property " << p << " on target \""
  4256. << tgt->GetName() << "\" is\nimplied to be " << defaultValue
  4257. << " because it was used to determine the link libraries\n"
  4258. "already. The INTERFACE_" << p << " property on\ndependency \""
  4259. << li->Target->GetName() << "\" is in conflict.\n";
  4260. cmSystemTools::Error(e.str().c_str());
  4261. break;
  4262. }
  4263. else
  4264. {
  4265. // Agree
  4266. continue;
  4267. }
  4268. }
  4269. else
  4270. {
  4271. // Implicitly set on target and not set in iface. Can't disagree.
  4272. continue;
  4273. }
  4274. }
  4275. else
  4276. {
  4277. if (ifaceIsSet)
  4278. {
  4279. if (propInitialized)
  4280. {
  4281. if (!consistentProperty(propContent, ifacePropContent))
  4282. {
  4283. cmOStringStream e;
  4284. e << "The INTERFACE_" << p << " property of \""
  4285. << li->Target->GetName() << "\" does\nnot agree with the value "
  4286. "of " << p << " already determined\nfor \""
  4287. << tgt->GetName() << "\".\n";
  4288. cmSystemTools::Error(e.str().c_str());
  4289. break;
  4290. }
  4291. else
  4292. {
  4293. // Agree.
  4294. continue;
  4295. }
  4296. }
  4297. else
  4298. {
  4299. propContent = ifacePropContent;
  4300. propInitialized = true;
  4301. }
  4302. }
  4303. else
  4304. {
  4305. // Not set. Nothing to agree on.
  4306. continue;
  4307. }
  4308. }
  4309. }
  4310. return propContent;
  4311. }
  4312. //----------------------------------------------------------------------------
  4313. bool cmTarget::GetLinkInterfaceDependentBoolProperty(const std::string &p,
  4314. const char *config)
  4315. {
  4316. return checkInterfacePropertyCompatibility<bool>(this, p, config, "FALSE",
  4317. 0);
  4318. }
  4319. //----------------------------------------------------------------------------
  4320. const char * cmTarget::GetLinkInterfaceDependentStringProperty(
  4321. const std::string &p,
  4322. const char *config)
  4323. {
  4324. return checkInterfacePropertyCompatibility<const char *>(this,
  4325. p,
  4326. config,
  4327. "empty", 0);
  4328. }
  4329. //----------------------------------------------------------------------------
  4330. bool isLinkDependentProperty(cmTarget *tgt, const std::string &p,
  4331. const char *interfaceProperty,
  4332. const char *config)
  4333. {
  4334. cmComputeLinkInformation *info = tgt->GetLinkInformation(config);
  4335. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  4336. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  4337. deps.begin();
  4338. li != deps.end(); ++li)
  4339. {
  4340. if (!li->Target)
  4341. {
  4342. continue;
  4343. }
  4344. const char *prop = li->Target->GetProperty(interfaceProperty);
  4345. if (!prop)
  4346. {
  4347. continue;
  4348. }
  4349. std::vector<std::string> props;
  4350. cmSystemTools::ExpandListArgument(prop, props);
  4351. for(std::vector<std::string>::iterator pi = props.begin();
  4352. pi != props.end(); ++pi)
  4353. {
  4354. if (*pi == p)
  4355. {
  4356. return true;
  4357. }
  4358. }
  4359. }
  4360. return false;
  4361. }
  4362. //----------------------------------------------------------------------------
  4363. bool cmTarget::IsLinkInterfaceDependentBoolProperty(const std::string &p,
  4364. const char *config)
  4365. {
  4366. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_BOOL",
  4367. config);
  4368. }
  4369. //----------------------------------------------------------------------------
  4370. bool cmTarget::IsLinkInterfaceDependentStringProperty(const std::string &p,
  4371. const char *config)
  4372. {
  4373. return isLinkDependentProperty(this, p, "COMPATIBLE_INTERFACE_STRING",
  4374. config);
  4375. }
  4376. //----------------------------------------------------------------------------
  4377. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  4378. {
  4379. for(std::vector<cmSourceFile*>::const_iterator
  4380. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  4381. {
  4382. if(const char* lang = (*i)->GetLanguage())
  4383. {
  4384. languages.insert(lang);
  4385. }
  4386. }
  4387. }
  4388. //----------------------------------------------------------------------------
  4389. bool cmTarget::IsChrpathUsed(const char* config)
  4390. {
  4391. #if defined(CMAKE_USE_ELF_PARSER)
  4392. // Only certain target types have an rpath.
  4393. if(!(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4394. this->GetType() == cmTarget::MODULE_LIBRARY ||
  4395. this->GetType() == cmTarget::EXECUTABLE))
  4396. {
  4397. return false;
  4398. }
  4399. // If the target will not be installed we do not need to change its
  4400. // rpath.
  4401. if(!this->GetHaveInstallRule())
  4402. {
  4403. return false;
  4404. }
  4405. // Skip chrpath if skipping rpath altogether.
  4406. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  4407. {
  4408. return false;
  4409. }
  4410. // Skip chrpath if it does not need to be changed at install time.
  4411. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  4412. {
  4413. return false;
  4414. }
  4415. // Allow the user to disable builtin chrpath explicitly.
  4416. if(this->Makefile->IsOn("CMAKE_NO_BUILTIN_CHRPATH"))
  4417. {
  4418. return false;
  4419. }
  4420. // Enable if the rpath flag uses a separator and the target uses ELF
  4421. // binaries.
  4422. if(const char* ll = this->GetLinkerLanguage(config, this))
  4423. {
  4424. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  4425. sepVar += ll;
  4426. sepVar += "_FLAG_SEP";
  4427. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  4428. if(sep && *sep)
  4429. {
  4430. // TODO: Add ELF check to ABI detection and get rid of
  4431. // CMAKE_EXECUTABLE_FORMAT.
  4432. if(const char* fmt =
  4433. this->Makefile->GetDefinition("CMAKE_EXECUTABLE_FORMAT"))
  4434. {
  4435. return strcmp(fmt, "ELF") == 0;
  4436. }
  4437. }
  4438. }
  4439. #endif
  4440. static_cast<void>(config);
  4441. return false;
  4442. }
  4443. //----------------------------------------------------------------------------
  4444. cmTarget::ImportInfo const*
  4445. cmTarget::GetImportInfo(const char* config, cmTarget *headTarget)
  4446. {
  4447. // There is no imported information for non-imported targets.
  4448. if(!this->IsImported())
  4449. {
  4450. return 0;
  4451. }
  4452. // Lookup/compute/cache the import information for this
  4453. // configuration.
  4454. std::string config_upper;
  4455. if(config && *config)
  4456. {
  4457. config_upper = cmSystemTools::UpperCase(config);
  4458. }
  4459. else
  4460. {
  4461. config_upper = "NOCONFIG";
  4462. }
  4463. TargetConfigPair key(headTarget, config_upper);
  4464. typedef cmTargetInternals::ImportInfoMapType ImportInfoMapType;
  4465. ImportInfoMapType::const_iterator i =
  4466. this->Internal->ImportInfoMap.find(key);
  4467. if(i == this->Internal->ImportInfoMap.end())
  4468. {
  4469. ImportInfo info;
  4470. this->ComputeImportInfo(config_upper, info, headTarget);
  4471. ImportInfoMapType::value_type entry(key, info);
  4472. i = this->Internal->ImportInfoMap.insert(entry).first;
  4473. }
  4474. // If the location is empty then the target is not available for
  4475. // this configuration.
  4476. if(i->second.Location.empty() && i->second.ImportLibrary.empty())
  4477. {
  4478. return 0;
  4479. }
  4480. // Return the import information.
  4481. return &i->second;
  4482. }
  4483. bool cmTarget::GetMappedConfig(std::string const& desired_config,
  4484. const char** loc,
  4485. const char** imp,
  4486. std::string& suffix)
  4487. {
  4488. // Track the configuration-specific property suffix.
  4489. suffix = "_";
  4490. suffix += desired_config;
  4491. std::vector<std::string> mappedConfigs;
  4492. {
  4493. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  4494. mapProp += desired_config;
  4495. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  4496. {
  4497. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  4498. }
  4499. }
  4500. // If we needed to find one of the mapped configurations but did not
  4501. // On a DLL platform there may be only IMPORTED_IMPLIB for a shared
  4502. // library or an executable with exports.
  4503. bool allowImp = this->HasImportLibrary();
  4504. // If a mapping was found, check its configurations.
  4505. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  4506. !*loc && !*imp && mci != mappedConfigs.end(); ++mci)
  4507. {
  4508. // Look for this configuration.
  4509. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  4510. std::string locProp = "IMPORTED_LOCATION_";
  4511. locProp += mcUpper;
  4512. *loc = this->GetProperty(locProp.c_str());
  4513. if(allowImp)
  4514. {
  4515. std::string impProp = "IMPORTED_IMPLIB_";
  4516. impProp += mcUpper;
  4517. *imp = this->GetProperty(impProp.c_str());
  4518. }
  4519. // If it was found, use it for all properties below.
  4520. if(*loc || *imp)
  4521. {
  4522. suffix = "_";
  4523. suffix += mcUpper;
  4524. }
  4525. }
  4526. // If we needed to find one of the mapped configurations but did not
  4527. // then the target is not found. The project does not want any
  4528. // other configuration.
  4529. if(!mappedConfigs.empty() && !*loc && !*imp)
  4530. {
  4531. return false;
  4532. }
  4533. // If we have not yet found it then there are no mapped
  4534. // configurations. Look for an exact-match.
  4535. if(!*loc && !*imp)
  4536. {
  4537. std::string locProp = "IMPORTED_LOCATION";
  4538. locProp += suffix;
  4539. *loc = this->GetProperty(locProp.c_str());
  4540. if(allowImp)
  4541. {
  4542. std::string impProp = "IMPORTED_IMPLIB";
  4543. impProp += suffix;
  4544. *imp = this->GetProperty(impProp.c_str());
  4545. }
  4546. }
  4547. // If we have not yet found it then there are no mapped
  4548. // configurations and no exact match.
  4549. if(!*loc && !*imp)
  4550. {
  4551. // The suffix computed above is not useful.
  4552. suffix = "";
  4553. // Look for a configuration-less location. This may be set by
  4554. // manually-written code.
  4555. *loc = this->GetProperty("IMPORTED_LOCATION");
  4556. if(allowImp)
  4557. {
  4558. *imp = this->GetProperty("IMPORTED_IMPLIB");
  4559. }
  4560. }
  4561. // If we have not yet found it then the project is willing to try
  4562. // any available configuration.
  4563. if(!*loc && !*imp)
  4564. {
  4565. std::vector<std::string> availableConfigs;
  4566. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  4567. {
  4568. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  4569. }
  4570. for(std::vector<std::string>::const_iterator
  4571. aci = availableConfigs.begin();
  4572. !*loc && !*imp && aci != availableConfigs.end(); ++aci)
  4573. {
  4574. suffix = "_";
  4575. suffix += cmSystemTools::UpperCase(*aci);
  4576. std::string locProp = "IMPORTED_LOCATION";
  4577. locProp += suffix;
  4578. *loc = this->GetProperty(locProp.c_str());
  4579. if(allowImp)
  4580. {
  4581. std::string impProp = "IMPORTED_IMPLIB";
  4582. impProp += suffix;
  4583. *imp = this->GetProperty(impProp.c_str());
  4584. }
  4585. }
  4586. }
  4587. // If we have not yet found it then the target is not available.
  4588. if(!*loc && !*imp)
  4589. {
  4590. return false;
  4591. }
  4592. return true;
  4593. }
  4594. //----------------------------------------------------------------------------
  4595. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  4596. ImportInfo& info,
  4597. cmTarget *headTarget)
  4598. {
  4599. (void)headTarget;
  4600. // This method finds information about an imported target from its
  4601. // properties. The "IMPORTED_" namespace is reserved for properties
  4602. // defined by the project exporting the target.
  4603. // Initialize members.
  4604. info.NoSOName = false;
  4605. const char* loc = 0;
  4606. const char* imp = 0;
  4607. std::string suffix;
  4608. if (!this->GetMappedConfig(desired_config, &loc, &imp, suffix))
  4609. {
  4610. return;
  4611. }
  4612. // A provided configuration has been chosen. Load the
  4613. // configuration's properties.
  4614. // Get the location.
  4615. if(loc)
  4616. {
  4617. info.Location = loc;
  4618. }
  4619. else
  4620. {
  4621. std::string impProp = "IMPORTED_LOCATION";
  4622. impProp += suffix;
  4623. if(const char* config_location = this->GetProperty(impProp.c_str()))
  4624. {
  4625. info.Location = config_location;
  4626. }
  4627. else if(const char* location = this->GetProperty("IMPORTED_LOCATION"))
  4628. {
  4629. info.Location = location;
  4630. }
  4631. }
  4632. // Get the soname.
  4633. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4634. {
  4635. std::string soProp = "IMPORTED_SONAME";
  4636. soProp += suffix;
  4637. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  4638. {
  4639. info.SOName = config_soname;
  4640. }
  4641. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  4642. {
  4643. info.SOName = soname;
  4644. }
  4645. }
  4646. // Get the "no-soname" mark.
  4647. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4648. {
  4649. std::string soProp = "IMPORTED_NO_SONAME";
  4650. soProp += suffix;
  4651. if(const char* config_no_soname = this->GetProperty(soProp.c_str()))
  4652. {
  4653. info.NoSOName = cmSystemTools::IsOn(config_no_soname);
  4654. }
  4655. else if(const char* no_soname = this->GetProperty("IMPORTED_NO_SONAME"))
  4656. {
  4657. info.NoSOName = cmSystemTools::IsOn(no_soname);
  4658. }
  4659. }
  4660. // Get the import library.
  4661. if(imp)
  4662. {
  4663. info.ImportLibrary = imp;
  4664. }
  4665. else if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4666. this->IsExecutableWithExports())
  4667. {
  4668. std::string impProp = "IMPORTED_IMPLIB";
  4669. impProp += suffix;
  4670. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  4671. {
  4672. info.ImportLibrary = config_implib;
  4673. }
  4674. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  4675. {
  4676. info.ImportLibrary = implib;
  4677. }
  4678. }
  4679. // Get the link interface.
  4680. {
  4681. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4682. linkProp += suffix;
  4683. const char *propertyLibs = this->GetProperty(linkProp.c_str());
  4684. if(!propertyLibs)
  4685. {
  4686. linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  4687. propertyLibs = this->GetProperty(linkProp.c_str());
  4688. }
  4689. if(propertyLibs)
  4690. {
  4691. cmListFileBacktrace lfbt;
  4692. cmGeneratorExpression ge(lfbt);
  4693. cmGeneratorExpressionDAGChecker dagChecker(lfbt,
  4694. this->GetName(),
  4695. linkProp, 0, 0);
  4696. cmSystemTools::ExpandListArgument(ge.Parse(propertyLibs)
  4697. ->Evaluate(this->Makefile,
  4698. desired_config.c_str(),
  4699. false,
  4700. headTarget,
  4701. this,
  4702. &dagChecker),
  4703. info.LinkInterface.Libraries);
  4704. }
  4705. }
  4706. // Get the link dependencies.
  4707. {
  4708. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  4709. linkProp += suffix;
  4710. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4711. {
  4712. cmSystemTools::ExpandListArgument(config_libs,
  4713. info.LinkInterface.SharedDeps);
  4714. }
  4715. else if(const char* libs =
  4716. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  4717. {
  4718. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  4719. }
  4720. }
  4721. // Get the link languages.
  4722. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4723. {
  4724. std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES";
  4725. linkProp += suffix;
  4726. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  4727. {
  4728. cmSystemTools::ExpandListArgument(config_libs,
  4729. info.LinkInterface.Languages);
  4730. }
  4731. else if(const char* libs =
  4732. this->GetProperty("IMPORTED_LINK_INTERFACE_LANGUAGES"))
  4733. {
  4734. cmSystemTools::ExpandListArgument(libs,
  4735. info.LinkInterface.Languages);
  4736. }
  4737. }
  4738. // Get the cyclic repetition count.
  4739. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4740. {
  4741. std::string linkProp = "IMPORTED_LINK_INTERFACE_MULTIPLICITY";
  4742. linkProp += suffix;
  4743. if(const char* config_reps = this->GetProperty(linkProp.c_str()))
  4744. {
  4745. sscanf(config_reps, "%u", &info.LinkInterface.Multiplicity);
  4746. }
  4747. else if(const char* reps =
  4748. this->GetProperty("IMPORTED_LINK_INTERFACE_MULTIPLICITY"))
  4749. {
  4750. sscanf(reps, "%u", &info.LinkInterface.Multiplicity);
  4751. }
  4752. }
  4753. }
  4754. //----------------------------------------------------------------------------
  4755. cmTarget::LinkInterface const* cmTarget::GetLinkInterface(const char* config,
  4756. cmTarget *head)
  4757. {
  4758. // Imported targets have their own link interface.
  4759. if(this->IsImported())
  4760. {
  4761. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config, head))
  4762. {
  4763. return &info->LinkInterface;
  4764. }
  4765. return 0;
  4766. }
  4767. // Link interfaces are not supported for executables that do not
  4768. // export symbols.
  4769. if(this->GetType() == cmTarget::EXECUTABLE &&
  4770. !this->IsExecutableWithExports())
  4771. {
  4772. return 0;
  4773. }
  4774. // Lookup any existing link interface for this configuration.
  4775. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4776. cmTargetInternals::LinkInterfaceMapType::iterator
  4777. i = this->Internal->LinkInterfaceMap.find(key);
  4778. if(i == this->Internal->LinkInterfaceMap.end())
  4779. {
  4780. // Compute the link interface for this configuration.
  4781. cmTargetInternals::OptionalLinkInterface iface;
  4782. iface.Exists = this->ComputeLinkInterface(config, iface, head);
  4783. // Store the information for this configuration.
  4784. cmTargetInternals::LinkInterfaceMapType::value_type entry(key, iface);
  4785. i = this->Internal->LinkInterfaceMap.insert(entry).first;
  4786. }
  4787. return i->second.Exists? &i->second : 0;
  4788. }
  4789. //----------------------------------------------------------------------------
  4790. bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface,
  4791. cmTarget *headTarget)
  4792. {
  4793. // Construct the property name suffix for this configuration.
  4794. std::string suffix = "_";
  4795. if(config && *config)
  4796. {
  4797. suffix += cmSystemTools::UpperCase(config);
  4798. }
  4799. else
  4800. {
  4801. suffix += "NOCONFIG";
  4802. }
  4803. // An explicit list of interface libraries may be set for shared
  4804. // libraries and executables that export symbols.
  4805. const char* explicitLibraries = 0;
  4806. std::string linkIfaceProp;
  4807. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  4808. this->IsExecutableWithExports())
  4809. {
  4810. // Lookup the per-configuration property.
  4811. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4812. linkIfaceProp += suffix;
  4813. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  4814. // If not set, try the generic property.
  4815. if(!explicitLibraries)
  4816. {
  4817. linkIfaceProp = "LINK_INTERFACE_LIBRARIES";
  4818. explicitLibraries = this->GetProperty(linkIfaceProp.c_str());
  4819. }
  4820. }
  4821. // There is no implicit link interface for executables or modules
  4822. // so if none was explicitly set then there is no link interface.
  4823. // Note that CMake versions 2.2 and below allowed linking to modules.
  4824. bool canLinkModules = this->Makefile->NeedBackwardsCompatibility(2,2);
  4825. if(!explicitLibraries &&
  4826. (this->GetType() == cmTarget::EXECUTABLE ||
  4827. (this->GetType() == cmTarget::MODULE_LIBRARY && !canLinkModules)))
  4828. {
  4829. return false;
  4830. }
  4831. if(explicitLibraries)
  4832. {
  4833. // The interface libraries have been explicitly set.
  4834. cmListFileBacktrace lfbt;
  4835. cmGeneratorExpression ge(lfbt);
  4836. cmGeneratorExpressionDAGChecker dagChecker(lfbt, this->GetName(),
  4837. linkIfaceProp, 0, 0);
  4838. cmSystemTools::ExpandListArgument(ge.Parse(explicitLibraries)->Evaluate(
  4839. this->Makefile,
  4840. config,
  4841. false,
  4842. headTarget,
  4843. this, &dagChecker), iface.Libraries);
  4844. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  4845. {
  4846. // Shared libraries may have runtime implementation dependencies
  4847. // on other shared libraries that are not in the interface.
  4848. std::set<cmStdString> emitted;
  4849. for(std::vector<std::string>::const_iterator
  4850. li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li)
  4851. {
  4852. emitted.insert(*li);
  4853. }
  4854. LinkImplementation const* impl = this->GetLinkImplementation(config,
  4855. headTarget);
  4856. for(std::vector<std::string>::const_iterator
  4857. li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li)
  4858. {
  4859. if(emitted.insert(*li).second)
  4860. {
  4861. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->c_str()))
  4862. {
  4863. // This is a runtime dependency on another shared library.
  4864. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  4865. {
  4866. iface.SharedDeps.push_back(*li);
  4867. }
  4868. }
  4869. else
  4870. {
  4871. // TODO: Recognize shared library file names. Perhaps this
  4872. // should be moved to cmComputeLinkInformation, but that creates
  4873. // a chicken-and-egg problem since this list is needed for its
  4874. // construction.
  4875. }
  4876. }
  4877. }
  4878. }
  4879. }
  4880. else
  4881. {
  4882. // The link implementation is the default link interface.
  4883. LinkImplementation const* impl = this->GetLinkImplementation(config,
  4884. headTarget);
  4885. iface.ImplementationIsInterface = true;
  4886. iface.Libraries = impl->Libraries;
  4887. iface.WrongConfigLibraries = impl->WrongConfigLibraries;
  4888. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4889. {
  4890. // Targets using this archive need its language runtime libraries.
  4891. iface.Languages = impl->Languages;
  4892. }
  4893. }
  4894. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  4895. {
  4896. // How many repetitions are needed if this library has cyclic
  4897. // dependencies?
  4898. std::string propName = "LINK_INTERFACE_MULTIPLICITY";
  4899. propName += suffix;
  4900. if(const char* config_reps = this->GetProperty(propName.c_str()))
  4901. {
  4902. sscanf(config_reps, "%u", &iface.Multiplicity);
  4903. }
  4904. else if(const char* reps =
  4905. this->GetProperty("LINK_INTERFACE_MULTIPLICITY"))
  4906. {
  4907. sscanf(reps, "%u", &iface.Multiplicity);
  4908. }
  4909. }
  4910. return true;
  4911. }
  4912. //----------------------------------------------------------------------------
  4913. cmTarget::LinkImplementation const*
  4914. cmTarget::GetLinkImplementation(const char* config, cmTarget *head)
  4915. {
  4916. // There is no link implementation for imported targets.
  4917. if(this->IsImported())
  4918. {
  4919. return 0;
  4920. }
  4921. // Lookup any existing link implementation for this configuration.
  4922. TargetConfigPair key(head, cmSystemTools::UpperCase(config? config : ""));
  4923. cmTargetInternals::LinkImplMapType::iterator
  4924. i = this->Internal->LinkImplMap.find(key);
  4925. if(i == this->Internal->LinkImplMap.end())
  4926. {
  4927. // Compute the link implementation for this configuration.
  4928. LinkImplementation impl;
  4929. this->ComputeLinkImplementation(config, impl, head);
  4930. // Store the information for this configuration.
  4931. cmTargetInternals::LinkImplMapType::value_type entry(key, impl);
  4932. i = this->Internal->LinkImplMap.insert(entry).first;
  4933. }
  4934. return &i->second;
  4935. }
  4936. //----------------------------------------------------------------------------
  4937. void cmTarget::ComputeLinkImplementation(const char* config,
  4938. LinkImplementation& impl,
  4939. cmTarget *head)
  4940. {
  4941. // Compute which library configuration to link.
  4942. cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config);
  4943. // Collect libraries directly linked in this configuration.
  4944. std::vector<std::string> llibs;
  4945. this->GetDirectLinkLibraries(config, llibs, head);
  4946. for(std::vector<std::string>::const_iterator li = llibs.begin();
  4947. li != llibs.end(); ++li)
  4948. {
  4949. // Skip entries that resolve to the target itself or are empty.
  4950. std::string item = this->CheckCMP0004(*li);
  4951. if(item == this->GetName() || item.empty())
  4952. {
  4953. continue;
  4954. }
  4955. // The entry is meant for this configuration.
  4956. impl.Libraries.push_back(item);
  4957. }
  4958. LinkLibraryVectorType const& oldllibs = this->GetOriginalLinkLibraries();
  4959. for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin();
  4960. li != oldllibs.end(); ++li)
  4961. {
  4962. if(li->second != cmTarget::GENERAL && li->second != linkType)
  4963. {
  4964. std::string item = this->CheckCMP0004(li->first);
  4965. if(item == this->GetName() || item.empty())
  4966. {
  4967. continue;
  4968. }
  4969. // Support OLD behavior for CMP0003.
  4970. impl.WrongConfigLibraries.push_back(item);
  4971. }
  4972. }
  4973. // This target needs runtime libraries for its source languages.
  4974. std::set<cmStdString> languages;
  4975. // Get languages used in our source files.
  4976. this->GetLanguages(languages);
  4977. // Get languages used in object library sources.
  4978. for(std::vector<std::string>::iterator i = this->ObjectLibraries.begin();
  4979. i != this->ObjectLibraries.end(); ++i)
  4980. {
  4981. if(cmTarget* objLib = this->Makefile->FindTargetToUse(i->c_str()))
  4982. {
  4983. if(objLib->GetType() == cmTarget::OBJECT_LIBRARY)
  4984. {
  4985. objLib->GetLanguages(languages);
  4986. }
  4987. }
  4988. }
  4989. // Copy the set of langauges to the link implementation.
  4990. for(std::set<cmStdString>::iterator li = languages.begin();
  4991. li != languages.end(); ++li)
  4992. {
  4993. impl.Languages.push_back(*li);
  4994. }
  4995. }
  4996. //----------------------------------------------------------------------------
  4997. std::string cmTarget::CheckCMP0004(std::string const& item)
  4998. {
  4999. // Strip whitespace off the library names because we used to do this
  5000. // in case variables were expanded at generate time. We no longer
  5001. // do the expansion but users link to libraries like " ${VAR} ".
  5002. std::string lib = item;
  5003. std::string::size_type pos = lib.find_first_not_of(" \t\r\n");
  5004. if(pos != lib.npos)
  5005. {
  5006. lib = lib.substr(pos, lib.npos);
  5007. }
  5008. pos = lib.find_last_not_of(" \t\r\n");
  5009. if(pos != lib.npos)
  5010. {
  5011. lib = lib.substr(0, pos+1);
  5012. }
  5013. if(lib != item)
  5014. {
  5015. cmake* cm = this->Makefile->GetCMakeInstance();
  5016. switch(this->PolicyStatusCMP0004)
  5017. {
  5018. case cmPolicies::WARN:
  5019. {
  5020. cmOStringStream w;
  5021. w << (this->Makefile->GetPolicies()
  5022. ->GetPolicyWarning(cmPolicies::CMP0004)) << "\n"
  5023. << "Target \"" << this->GetName() << "\" links to item \""
  5024. << item << "\" which has leading or trailing whitespace.";
  5025. cm->IssueMessage(cmake::AUTHOR_WARNING, w.str(),
  5026. this->GetBacktrace());
  5027. }
  5028. case cmPolicies::OLD:
  5029. break;
  5030. case cmPolicies::NEW:
  5031. {
  5032. cmOStringStream e;
  5033. e << "Target \"" << this->GetName() << "\" links to item \""
  5034. << item << "\" which has leading or trailing whitespace. "
  5035. << "This is now an error according to policy CMP0004.";
  5036. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5037. }
  5038. break;
  5039. case cmPolicies::REQUIRED_IF_USED:
  5040. case cmPolicies::REQUIRED_ALWAYS:
  5041. {
  5042. cmOStringStream e;
  5043. e << (this->Makefile->GetPolicies()
  5044. ->GetRequiredPolicyError(cmPolicies::CMP0004)) << "\n"
  5045. << "Target \"" << this->GetName() << "\" links to item \""
  5046. << item << "\" which has leading or trailing whitespace.";
  5047. cm->IssueMessage(cmake::FATAL_ERROR, e.str(), this->GetBacktrace());
  5048. }
  5049. break;
  5050. }
  5051. }
  5052. return lib;
  5053. }
  5054. template<typename PropertyType>
  5055. PropertyType getLinkInterfaceDependentProperty(cmTarget *tgt,
  5056. const std::string prop,
  5057. const char *config,
  5058. PropertyType *);
  5059. template<>
  5060. bool getLinkInterfaceDependentProperty(cmTarget *tgt,
  5061. const std::string prop,
  5062. const char *config, bool *)
  5063. {
  5064. return tgt->GetLinkInterfaceDependentBoolProperty(prop, config);
  5065. }
  5066. template<>
  5067. const char * getLinkInterfaceDependentProperty(cmTarget *tgt,
  5068. const std::string prop,
  5069. const char *config,
  5070. const char **)
  5071. {
  5072. return tgt->GetLinkInterfaceDependentStringProperty(prop, config);
  5073. }
  5074. //----------------------------------------------------------------------------
  5075. template<typename PropertyType>
  5076. void checkPropertyConsistency(cmTarget *depender, cmTarget *dependee,
  5077. const char *propName,
  5078. std::set<cmStdString> &emitted,
  5079. const char *config,
  5080. PropertyType *)
  5081. {
  5082. const char *prop = dependee->GetProperty(propName);
  5083. if (!prop)
  5084. {
  5085. return;
  5086. }
  5087. std::vector<std::string> props;
  5088. cmSystemTools::ExpandListArgument(prop, props);
  5089. for(std::vector<std::string>::iterator pi = props.begin();
  5090. pi != props.end(); ++pi)
  5091. {
  5092. if (depender->GetMakefile()->GetCMakeInstance()
  5093. ->GetIsPropertyDefined(pi->c_str(),
  5094. cmProperty::TARGET))
  5095. {
  5096. cmOStringStream e;
  5097. e << "Target \"" << dependee->GetName() << "\" has property \""
  5098. << *pi << "\" listed in its " << propName << " property. "
  5099. "This is not allowed. Only user-defined properties may appear "
  5100. "listed in the " << propName << " property.";
  5101. depender->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
  5102. return;
  5103. }
  5104. if(emitted.insert(*pi).second)
  5105. {
  5106. getLinkInterfaceDependentProperty<PropertyType>(depender, *pi, config,
  5107. 0);
  5108. if (cmSystemTools::GetErrorOccuredFlag())
  5109. {
  5110. return;
  5111. }
  5112. }
  5113. }
  5114. }
  5115. //----------------------------------------------------------------------------
  5116. void cmTarget::CheckPropertyCompatibility(cmComputeLinkInformation *info,
  5117. const char* config)
  5118. {
  5119. const cmComputeLinkInformation::ItemVector &deps = info->GetItems();
  5120. std::set<cmStdString> emitted;
  5121. for(cmComputeLinkInformation::ItemVector::const_iterator li =
  5122. deps.begin();
  5123. li != deps.end(); ++li)
  5124. {
  5125. if (!li->Target)
  5126. {
  5127. continue;
  5128. }
  5129. checkPropertyConsistency<bool>(this, li->Target,
  5130. "COMPATIBLE_INTERFACE_BOOL",
  5131. emitted, config, 0);
  5132. if (cmSystemTools::GetErrorOccuredFlag())
  5133. {
  5134. return;
  5135. }
  5136. checkPropertyConsistency<const char *>(this, li->Target,
  5137. "COMPATIBLE_INTERFACE_STRING",
  5138. emitted, config, 0);
  5139. if (cmSystemTools::GetErrorOccuredFlag())
  5140. {
  5141. return;
  5142. }
  5143. }
  5144. }
  5145. //----------------------------------------------------------------------------
  5146. cmComputeLinkInformation*
  5147. cmTarget::GetLinkInformation(const char* config, cmTarget *head)
  5148. {
  5149. cmTarget *headTarget = head ? head : this;
  5150. // Lookup any existing information for this configuration.
  5151. TargetConfigPair key(headTarget,
  5152. cmSystemTools::UpperCase(config?config:""));
  5153. cmTargetLinkInformationMap::iterator
  5154. i = this->LinkInformation.find(key);
  5155. if(i == this->LinkInformation.end())
  5156. {
  5157. // Compute information for this configuration.
  5158. cmComputeLinkInformation* info =
  5159. new cmComputeLinkInformation(this, config, headTarget);
  5160. if(!info || !info->Compute())
  5161. {
  5162. delete info;
  5163. info = 0;
  5164. }
  5165. // Store the information for this configuration.
  5166. cmTargetLinkInformationMap::value_type entry(key, info);
  5167. i = this->LinkInformation.insert(entry).first;
  5168. if (info)
  5169. {
  5170. this->CheckPropertyCompatibility(info, config);
  5171. }
  5172. }
  5173. return i->second;
  5174. }
  5175. //----------------------------------------------------------------------------
  5176. std::string cmTarget::GetFrameworkDirectory(const char* config)
  5177. {
  5178. std::string fpath;
  5179. fpath += this->GetFullName(config, false);
  5180. fpath += ".framework/Versions/";
  5181. fpath += this->GetFrameworkVersion();
  5182. fpath += "/";
  5183. return fpath;
  5184. }
  5185. //----------------------------------------------------------------------------
  5186. std::string cmTarget::BuildMacContentDirectory(const std::string& base,
  5187. const char* config,
  5188. bool includeMacOS)
  5189. {
  5190. std::string fpath = base;
  5191. if(this->IsAppBundleOnApple())
  5192. {
  5193. fpath += this->GetFullName(config, false);
  5194. fpath += ".app/Contents/";
  5195. if(includeMacOS)
  5196. fpath += "MacOS/";
  5197. }
  5198. if(this->IsFrameworkOnApple())
  5199. {
  5200. fpath += this->GetFrameworkDirectory(config);
  5201. }
  5202. if(this->IsCFBundleOnApple())
  5203. {
  5204. fpath += this->GetFullName(config, false);
  5205. fpath += ".";
  5206. const char *ext = this->GetProperty("BUNDLE_EXTENSION");
  5207. if (!ext)
  5208. {
  5209. ext = "bundle";
  5210. }
  5211. fpath += ext;
  5212. fpath += "/Contents/";
  5213. if(includeMacOS)
  5214. fpath += "MacOS/";
  5215. }
  5216. return fpath;
  5217. }
  5218. //----------------------------------------------------------------------------
  5219. std::string cmTarget::GetMacContentDirectory(const char* config,
  5220. bool implib,
  5221. bool includeMacOS)
  5222. {
  5223. // Start with the output directory for the target.
  5224. std::string fpath = this->GetDirectory(config, implib);
  5225. fpath += "/";
  5226. fpath = this->BuildMacContentDirectory(fpath, config, includeMacOS);
  5227. return fpath;
  5228. }
  5229. //----------------------------------------------------------------------------
  5230. cmTargetLinkInformationMap
  5231. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  5232. {
  5233. // Ideally cmTarget instances should never be copied. However until
  5234. // we can make a sweep to remove that, this copy constructor avoids
  5235. // allowing the resources (LinkInformation) from getting copied. In
  5236. // the worst case this will lead to extra cmComputeLinkInformation
  5237. // instances. We also enforce in debug mode that the map be emptied
  5238. // when copied.
  5239. static_cast<void>(r);
  5240. assert(r.empty());
  5241. }
  5242. //----------------------------------------------------------------------------
  5243. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  5244. {
  5245. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  5246. {
  5247. delete i->second;
  5248. }
  5249. }
  5250. //----------------------------------------------------------------------------
  5251. cmTargetInternalPointer::cmTargetInternalPointer()
  5252. {
  5253. this->Pointer = new cmTargetInternals;
  5254. }
  5255. //----------------------------------------------------------------------------
  5256. cmTargetInternalPointer
  5257. ::cmTargetInternalPointer(cmTargetInternalPointer const& r)
  5258. {
  5259. // Ideally cmTarget instances should never be copied. However until
  5260. // we can make a sweep to remove that, this copy constructor avoids
  5261. // allowing the resources (Internals) to be copied.
  5262. this->Pointer = new cmTargetInternals(*r.Pointer);
  5263. }
  5264. //----------------------------------------------------------------------------
  5265. cmTargetInternalPointer::~cmTargetInternalPointer()
  5266. {
  5267. deleteAndClear(this->Pointer->IncludeDirectoriesEntries);
  5268. delete this->Pointer;
  5269. }
  5270. //----------------------------------------------------------------------------
  5271. cmTargetInternalPointer&
  5272. cmTargetInternalPointer::operator=(cmTargetInternalPointer const& r)
  5273. {
  5274. if(this == &r) { return *this; } // avoid warning on HP about self check
  5275. // Ideally cmTarget instances should never be copied. However until
  5276. // we can make a sweep to remove that, this copy constructor avoids
  5277. // allowing the resources (Internals) to be copied.
  5278. cmTargetInternals* oldPointer = this->Pointer;
  5279. this->Pointer = new cmTargetInternals(*r.Pointer);
  5280. delete oldPointer;
  5281. return *this;
  5282. }