cmTarget.cxx 128 KB

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