cmTarget.cxx 149 KB

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