cmTarget.cxx 148 KB

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