cmTarget.cxx 155 KB

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