cmTarget.cxx 154 KB

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