cmTarget.cxx 161 KB

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