cmTarget.cxx 112 KB

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