cmTarget.cxx 166 KB

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