cmTarget.cxx 161 KB

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