cmTarget.cxx 157 KB

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