cmTarget.cxx 168 KB

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