cmTarget.cxx 165 KB

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