cmTarget.cxx 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364
  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::NormalGetRealName(const char* config)
  1837. {
  1838. // This should not be called for imported targets.
  1839. // TODO: Split cmTarget into a class hierarchy to get compile-time
  1840. // enforcement of the limited imported target API.
  1841. if(this->IsImported())
  1842. {
  1843. abort();
  1844. }
  1845. if(this->GetType() == cmTarget::EXECUTABLE)
  1846. {
  1847. // Compute the real name that will be built.
  1848. std::string name;
  1849. std::string realName;
  1850. std::string impName;
  1851. std::string pdbName;
  1852. this->GetExecutableNames(name, realName, impName, pdbName, config);
  1853. return realName;
  1854. }
  1855. else
  1856. {
  1857. // Compute the real name that will be built.
  1858. std::string name;
  1859. std::string soName;
  1860. std::string realName;
  1861. std::string impName;
  1862. std::string pdbName;
  1863. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  1864. return realName;
  1865. }
  1866. }
  1867. //----------------------------------------------------------------------------
  1868. std::string cmTarget::GetFullName(const char* config, bool implib)
  1869. {
  1870. if(this->IsImported())
  1871. {
  1872. return this->GetFullNameImported(config, implib);
  1873. }
  1874. else
  1875. {
  1876. return this->GetFullNameInternal(this->GetType(), config, implib);
  1877. }
  1878. }
  1879. //----------------------------------------------------------------------------
  1880. std::string cmTarget::GetFullNameImported(const char* config, bool implib)
  1881. {
  1882. return cmSystemTools::GetFilenameName(
  1883. this->ImportedGetFullPath(config, implib));
  1884. }
  1885. //----------------------------------------------------------------------------
  1886. void cmTarget::GetFullNameComponents(std::string& prefix, std::string& base,
  1887. std::string& suffix, const char* config,
  1888. bool implib)
  1889. {
  1890. this->GetFullNameInternal(this->GetType(), config, implib,
  1891. prefix, base, suffix);
  1892. }
  1893. //----------------------------------------------------------------------------
  1894. std::string cmTarget::GetFullPath(const char* config, bool implib,
  1895. bool realname)
  1896. {
  1897. if(this->IsImported())
  1898. {
  1899. return this->ImportedGetFullPath(config, implib);
  1900. }
  1901. else
  1902. {
  1903. return this->NormalGetFullPath(config, implib, realname);
  1904. }
  1905. }
  1906. //----------------------------------------------------------------------------
  1907. std::string cmTarget::NormalGetFullPath(const char* config, bool implib,
  1908. bool realname)
  1909. {
  1910. // Start with the output directory for the target.
  1911. std::string fpath = this->GetDirectory(config, implib);
  1912. fpath += "/";
  1913. // Add the full name of the target.
  1914. if(realname)
  1915. {
  1916. fpath += this->NormalGetRealName(config);
  1917. }
  1918. else
  1919. {
  1920. fpath += this->GetFullName(config, implib);
  1921. }
  1922. return fpath;
  1923. }
  1924. //----------------------------------------------------------------------------
  1925. std::string cmTarget::ImportedGetFullPath(const char* config, bool implib)
  1926. {
  1927. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  1928. {
  1929. if(implib)
  1930. {
  1931. return info->ImportLibrary;
  1932. }
  1933. else
  1934. {
  1935. return info->Location;
  1936. }
  1937. }
  1938. else
  1939. {
  1940. std::string result = this->GetName();
  1941. result += "-NOTFOUND";
  1942. return result;
  1943. }
  1944. }
  1945. //----------------------------------------------------------------------------
  1946. std::string
  1947. cmTarget::GetFullNameInternal(TargetType type, const char* config,
  1948. bool implib)
  1949. {
  1950. std::string prefix;
  1951. std::string base;
  1952. std::string suffix;
  1953. this->GetFullNameInternal(type, config, implib, prefix, base, suffix);
  1954. return prefix+base+suffix;
  1955. }
  1956. //----------------------------------------------------------------------------
  1957. void cmTarget::GetFullNameInternal(TargetType type,
  1958. const char* config,
  1959. bool implib,
  1960. std::string& outPrefix,
  1961. std::string& outBase,
  1962. std::string& outSuffix)
  1963. {
  1964. // Use just the target name for non-main target types.
  1965. if(type != cmTarget::STATIC_LIBRARY &&
  1966. type != cmTarget::SHARED_LIBRARY &&
  1967. type != cmTarget::MODULE_LIBRARY &&
  1968. type != cmTarget::EXECUTABLE)
  1969. {
  1970. outPrefix = "";
  1971. outBase = this->GetName();
  1972. outSuffix = "";
  1973. return;
  1974. }
  1975. // Return an empty name for the import library if this platform
  1976. // does not support import libraries.
  1977. if(implib &&
  1978. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  1979. {
  1980. outPrefix = "";
  1981. outBase = "";
  1982. outSuffix = "";
  1983. return;
  1984. }
  1985. // The implib option is only allowed for shared libraries, module
  1986. // libraries, and executables.
  1987. if(type != cmTarget::SHARED_LIBRARY &&
  1988. type != cmTarget::MODULE_LIBRARY &&
  1989. type != cmTarget::EXECUTABLE)
  1990. {
  1991. implib = false;
  1992. }
  1993. // Compute the full name for main target types.
  1994. const char* targetPrefix = (implib
  1995. ? this->GetProperty("IMPORT_PREFIX")
  1996. : this->GetProperty("PREFIX"));
  1997. const char* targetSuffix = (implib
  1998. ? this->GetProperty("IMPORT_SUFFIX")
  1999. : this->GetProperty("SUFFIX"));
  2000. const char* configPostfix = 0;
  2001. if(config && *config)
  2002. {
  2003. std::string configProp = cmSystemTools::UpperCase(config);
  2004. configProp += "_POSTFIX";
  2005. configPostfix = this->GetProperty(configProp.c_str());
  2006. }
  2007. const char* prefixVar = this->GetPrefixVariableInternal(type, implib);
  2008. const char* suffixVar = this->GetSuffixVariableInternal(type, implib);
  2009. const char* ll =
  2010. this->GetLinkerLanguage(
  2011. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  2012. // first try language specific suffix
  2013. if(ll)
  2014. {
  2015. if(!targetSuffix && suffixVar && *suffixVar)
  2016. {
  2017. std::string langSuff = suffixVar + std::string("_") + ll;
  2018. targetSuffix = this->Makefile->GetDefinition(langSuff.c_str());
  2019. }
  2020. if(!targetPrefix && prefixVar && *prefixVar)
  2021. {
  2022. std::string langPrefix = prefixVar + std::string("_") + ll;
  2023. targetPrefix = this->Makefile->GetDefinition(langPrefix.c_str());
  2024. }
  2025. }
  2026. // if there is no prefix on the target use the cmake definition
  2027. if(!targetPrefix && prefixVar)
  2028. {
  2029. targetPrefix = this->Makefile->GetSafeDefinition(prefixVar);
  2030. }
  2031. // if there is no suffix on the target use the cmake definition
  2032. if(!targetSuffix && suffixVar)
  2033. {
  2034. targetSuffix = this->Makefile->GetSafeDefinition(suffixVar);
  2035. }
  2036. // frameworks do not have a prefix or a suffix
  2037. if(this->IsFrameworkOnApple())
  2038. {
  2039. targetPrefix = 0;
  2040. targetSuffix = 0;
  2041. }
  2042. // Begin the final name with the prefix.
  2043. outPrefix = targetPrefix?targetPrefix:"";
  2044. // Append the target name or property-specified name.
  2045. const char* outName = 0;
  2046. if(config && *config)
  2047. {
  2048. std::string configProp = cmSystemTools::UpperCase(config);
  2049. configProp += "_OUTPUT_NAME";
  2050. outName = this->GetProperty(configProp.c_str());
  2051. }
  2052. if(!outName)
  2053. {
  2054. outName = this->GetProperty("OUTPUT_NAME");
  2055. }
  2056. if(outName)
  2057. {
  2058. outBase = outName;
  2059. }
  2060. else
  2061. {
  2062. outBase = this->GetName();
  2063. }
  2064. // Append the per-configuration postfix.
  2065. outBase += configPostfix?configPostfix:"";
  2066. // Name shared libraries with their version number on some platforms.
  2067. if(const char* version = this->GetProperty("VERSION"))
  2068. {
  2069. if(type == cmTarget::SHARED_LIBRARY && !implib &&
  2070. this->Makefile->IsOn("CMAKE_SHARED_LIBRARY_NAME_WITH_VERSION"))
  2071. {
  2072. outBase += "-";
  2073. outBase += version;
  2074. }
  2075. }
  2076. // Append the suffix.
  2077. outSuffix = targetSuffix?targetSuffix:"";
  2078. }
  2079. //----------------------------------------------------------------------------
  2080. void cmTarget::GetLibraryNames(std::string& name,
  2081. std::string& soName,
  2082. std::string& realName,
  2083. std::string& impName,
  2084. std::string& pdbName,
  2085. const char* config)
  2086. {
  2087. // Get the names based on the real type of the library.
  2088. this->GetLibraryNamesInternal(name, soName, realName, impName, pdbName,
  2089. this->GetType(), config);
  2090. }
  2091. //----------------------------------------------------------------------------
  2092. void cmTarget::GetLibraryCleanNames(std::string& staticName,
  2093. std::string& sharedName,
  2094. std::string& sharedSOName,
  2095. std::string& sharedRealName,
  2096. std::string& importName,
  2097. std::string& pdbName,
  2098. const char* config)
  2099. {
  2100. // Get the name as if this were a static library.
  2101. std::string soName;
  2102. std::string realName;
  2103. std::string impName;
  2104. this->GetLibraryNamesInternal(staticName, soName, realName, impName,
  2105. pdbName, cmTarget::STATIC_LIBRARY, config);
  2106. // Get the names as if this were a shared library.
  2107. if(this->GetType() == cmTarget::STATIC_LIBRARY)
  2108. {
  2109. // Since the real type is static then the user either specified
  2110. // STATIC or did not specify a type. In the former case the
  2111. // shared library will never be present. In the latter case the
  2112. // type will never be MODULE. Either way the only names that
  2113. // might have to be cleaned are the shared library names.
  2114. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  2115. importName, pdbName,
  2116. cmTarget::SHARED_LIBRARY, config);
  2117. }
  2118. else
  2119. {
  2120. // Use the name of the real type of the library (shared or module).
  2121. this->GetLibraryNamesInternal(sharedName, sharedSOName, sharedRealName,
  2122. importName, pdbName, this->GetType(),
  2123. config);
  2124. }
  2125. }
  2126. //----------------------------------------------------------------------------
  2127. void cmTarget::GetLibraryNamesInternal(std::string& name,
  2128. std::string& soName,
  2129. std::string& realName,
  2130. std::string& impName,
  2131. std::string& pdbName,
  2132. TargetType type,
  2133. const char* config)
  2134. {
  2135. // This should not be called for imported targets.
  2136. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2137. // enforcement of the limited imported target API.
  2138. if(this->IsImported())
  2139. {
  2140. abort();
  2141. }
  2142. // Construct the name of the soname flag variable for this language.
  2143. const char* ll =
  2144. this->GetLinkerLanguage(
  2145. this->Makefile->GetLocalGenerator()->GetGlobalGenerator());
  2146. std::string sonameFlag = "CMAKE_SHARED_LIBRARY_SONAME";
  2147. if(ll)
  2148. {
  2149. sonameFlag += "_";
  2150. sonameFlag += ll;
  2151. }
  2152. sonameFlag += "_FLAG";
  2153. // Check for library version properties.
  2154. const char* version = this->GetProperty("VERSION");
  2155. const char* soversion = this->GetProperty("SOVERSION");
  2156. if((type != cmTarget::SHARED_LIBRARY && type != cmTarget::MODULE_LIBRARY) ||
  2157. !this->Makefile->GetDefinition(sonameFlag.c_str()))
  2158. {
  2159. // Versioning is supported only for shared libraries and modules,
  2160. // and then only when the platform supports an soname flag.
  2161. version = 0;
  2162. soversion = 0;
  2163. }
  2164. if(version && !soversion)
  2165. {
  2166. // The soversion must be set if the library version is set. Use
  2167. // the library version as the soversion.
  2168. soversion = version;
  2169. }
  2170. // Get the components of the library name.
  2171. std::string prefix;
  2172. std::string base;
  2173. std::string suffix;
  2174. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  2175. // The library name.
  2176. name = prefix+base+suffix;
  2177. // The library's soname.
  2178. #if defined(__APPLE__)
  2179. soName = prefix+base;
  2180. #else
  2181. soName = name;
  2182. #endif
  2183. if(soversion)
  2184. {
  2185. soName += ".";
  2186. soName += soversion;
  2187. }
  2188. #if defined(__APPLE__)
  2189. soName += suffix;
  2190. #endif
  2191. // The library's real name on disk.
  2192. #if defined(__APPLE__)
  2193. realName = prefix+base;
  2194. #else
  2195. realName = name;
  2196. #endif
  2197. if(version)
  2198. {
  2199. realName += ".";
  2200. realName += version;
  2201. }
  2202. else if(soversion)
  2203. {
  2204. realName += ".";
  2205. realName += soversion;
  2206. }
  2207. #if defined(__APPLE__)
  2208. realName += suffix;
  2209. #endif
  2210. // The import library name.
  2211. if(type == cmTarget::SHARED_LIBRARY ||
  2212. type == cmTarget::MODULE_LIBRARY)
  2213. {
  2214. impName = this->GetFullNameInternal(type, config, true);
  2215. }
  2216. else
  2217. {
  2218. impName = "";
  2219. }
  2220. // The program database file name.
  2221. pdbName = prefix+base+".pdb";
  2222. }
  2223. //----------------------------------------------------------------------------
  2224. void cmTarget::GetExecutableNames(std::string& name,
  2225. std::string& realName,
  2226. std::string& impName,
  2227. std::string& pdbName,
  2228. const char* config)
  2229. {
  2230. // Get the names based on the real type of the executable.
  2231. this->GetExecutableNamesInternal(name, realName, impName, pdbName,
  2232. this->GetType(), config);
  2233. }
  2234. //----------------------------------------------------------------------------
  2235. void cmTarget::GetExecutableCleanNames(std::string& name,
  2236. std::string& realName,
  2237. std::string& impName,
  2238. std::string& pdbName,
  2239. const char* config)
  2240. {
  2241. // Get the name and versioned name of this executable.
  2242. this->GetExecutableNamesInternal(name, realName, impName, pdbName,
  2243. cmTarget::EXECUTABLE, config);
  2244. }
  2245. //----------------------------------------------------------------------------
  2246. void cmTarget::GetExecutableNamesInternal(std::string& name,
  2247. std::string& realName,
  2248. std::string& impName,
  2249. std::string& pdbName,
  2250. TargetType type,
  2251. const char* config)
  2252. {
  2253. // This should not be called for imported targets.
  2254. // TODO: Split cmTarget into a class hierarchy to get compile-time
  2255. // enforcement of the limited imported target API.
  2256. if(this->IsImported())
  2257. {
  2258. abort();
  2259. }
  2260. // This versioning is supported only for executables and then only
  2261. // when the platform supports symbolic links.
  2262. #if defined(_WIN32) && !defined(__CYGWIN__)
  2263. const char* version = 0;
  2264. #else
  2265. // Check for executable version properties.
  2266. const char* version = this->GetProperty("VERSION");
  2267. if(type != cmTarget::EXECUTABLE)
  2268. {
  2269. version = 0;
  2270. }
  2271. #endif
  2272. // Get the components of the executable name.
  2273. std::string prefix;
  2274. std::string base;
  2275. std::string suffix;
  2276. this->GetFullNameInternal(type, config, false, prefix, base, suffix);
  2277. // The executable name.
  2278. name = prefix+base+suffix;
  2279. // The executable's real name on disk.
  2280. #if defined(__CYGWIN__)
  2281. realName = prefix+base;
  2282. #else
  2283. realName = name;
  2284. #endif
  2285. if(version)
  2286. {
  2287. realName += "-";
  2288. realName += version;
  2289. }
  2290. #if defined(__CYGWIN__)
  2291. realName += suffix;
  2292. #endif
  2293. // The import library name.
  2294. impName = this->GetFullNameInternal(type, config, true);
  2295. // The program database file name.
  2296. pdbName = prefix+base+".pdb";
  2297. }
  2298. //----------------------------------------------------------------------------
  2299. void cmTarget::GenerateTargetManifest(const char* config)
  2300. {
  2301. cmMakefile* mf = this->Makefile;
  2302. cmLocalGenerator* lg = mf->GetLocalGenerator();
  2303. cmGlobalGenerator* gg = lg->GetGlobalGenerator();
  2304. // Get the names.
  2305. std::string name;
  2306. std::string soName;
  2307. std::string realName;
  2308. std::string impName;
  2309. std::string pdbName;
  2310. if(this->GetType() == cmTarget::EXECUTABLE)
  2311. {
  2312. this->GetExecutableNames(name, realName, impName, pdbName, config);
  2313. }
  2314. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2315. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2316. this->GetType() == cmTarget::MODULE_LIBRARY)
  2317. {
  2318. this->GetLibraryNames(name, soName, realName, impName, pdbName, config);
  2319. }
  2320. else
  2321. {
  2322. return;
  2323. }
  2324. // Get the directory.
  2325. std::string dir = this->GetDirectory(config, false);
  2326. // Add each name.
  2327. std::string f;
  2328. if(!name.empty())
  2329. {
  2330. f = dir;
  2331. f += "/";
  2332. f += name;
  2333. gg->AddToManifest(config? config:"", f);
  2334. }
  2335. if(!soName.empty())
  2336. {
  2337. f = dir;
  2338. f += "/";
  2339. f += soName;
  2340. gg->AddToManifest(config? config:"", f);
  2341. }
  2342. if(!realName.empty())
  2343. {
  2344. f = dir;
  2345. f += "/";
  2346. f += realName;
  2347. gg->AddToManifest(config? config:"", f);
  2348. }
  2349. if(!pdbName.empty())
  2350. {
  2351. f = dir;
  2352. f += "/";
  2353. f += pdbName;
  2354. gg->AddToManifest(config? config:"", f);
  2355. }
  2356. if(!impName.empty())
  2357. {
  2358. f = this->GetDirectory(config, true);
  2359. f += "/";
  2360. f += impName;
  2361. gg->AddToManifest(config? config:"", f);
  2362. }
  2363. }
  2364. //----------------------------------------------------------------------------
  2365. void cmTarget::SetPropertyDefault(const char* property,
  2366. const char* default_value)
  2367. {
  2368. // Compute the name of the variable holding the default value.
  2369. std::string var = "CMAKE_";
  2370. var += property;
  2371. if(const char* value = this->Makefile->GetDefinition(var.c_str()))
  2372. {
  2373. this->SetProperty(property, value);
  2374. }
  2375. else if(default_value)
  2376. {
  2377. this->SetProperty(property, default_value);
  2378. }
  2379. }
  2380. //----------------------------------------------------------------------------
  2381. bool cmTarget::HaveBuildTreeRPATH()
  2382. {
  2383. return (!this->GetPropertyAsBool("SKIP_BUILD_RPATH") &&
  2384. !this->LinkLibraries.empty());
  2385. }
  2386. //----------------------------------------------------------------------------
  2387. bool cmTarget::HaveInstallTreeRPATH()
  2388. {
  2389. const char* install_rpath = this->GetProperty("INSTALL_RPATH");
  2390. return install_rpath && *install_rpath;
  2391. }
  2392. //----------------------------------------------------------------------------
  2393. bool cmTarget::NeedRelinkBeforeInstall()
  2394. {
  2395. // Only executables and shared libraries can have an rpath and may
  2396. // need relinking.
  2397. if(this->TargetTypeValue != cmTarget::EXECUTABLE &&
  2398. this->TargetTypeValue != cmTarget::SHARED_LIBRARY &&
  2399. this->TargetTypeValue != cmTarget::MODULE_LIBRARY)
  2400. {
  2401. return false;
  2402. }
  2403. // If there is no install location this target will not be installed
  2404. // and therefore does not need relinking.
  2405. if(!this->GetHaveInstallRule())
  2406. {
  2407. return false;
  2408. }
  2409. // If skipping all rpaths completely then no relinking is needed.
  2410. if(this->Makefile->IsOn("CMAKE_SKIP_RPATH"))
  2411. {
  2412. return false;
  2413. }
  2414. // If building with the install-tree rpath no relinking is needed.
  2415. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  2416. {
  2417. return false;
  2418. }
  2419. // If chrpath is going to be used no relinking is needed.
  2420. if(this->IsChrpathUsed())
  2421. {
  2422. return false;
  2423. }
  2424. // Check for rpath support on this platform.
  2425. if(const char* ll = this->GetLinkerLanguage(
  2426. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
  2427. {
  2428. std::string flagVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  2429. flagVar += ll;
  2430. flagVar += "_FLAG";
  2431. if(!this->Makefile->IsSet(flagVar.c_str()))
  2432. {
  2433. // There is no rpath support on this platform so nothing needs
  2434. // relinking.
  2435. return false;
  2436. }
  2437. }
  2438. else
  2439. {
  2440. // No linker language is known. This error will be reported by
  2441. // other code.
  2442. return false;
  2443. }
  2444. // If either a build or install tree rpath is set then the rpath
  2445. // will likely change between the build tree and install tree and
  2446. // this target must be relinked.
  2447. return this->HaveBuildTreeRPATH() || this->HaveInstallTreeRPATH();
  2448. }
  2449. //----------------------------------------------------------------------------
  2450. std::string cmTarget::GetInstallNameDirForBuildTree(const char* config)
  2451. {
  2452. // If building directly for installation then the build tree install_name
  2453. // is the same as the install tree.
  2454. if(this->GetPropertyAsBool("BUILD_WITH_INSTALL_RPATH"))
  2455. {
  2456. return GetInstallNameDirForInstallTree(config);
  2457. }
  2458. // Use the build tree directory for the target.
  2459. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  2460. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  2461. !this->GetPropertyAsBool("SKIP_BUILD_RPATH"))
  2462. {
  2463. std::string dir = this->GetDirectory(config);
  2464. dir += "/";
  2465. return dir;
  2466. }
  2467. else
  2468. {
  2469. return "";
  2470. }
  2471. }
  2472. //----------------------------------------------------------------------------
  2473. std::string cmTarget::GetInstallNameDirForInstallTree(const char*)
  2474. {
  2475. // Lookup the target property.
  2476. const char* install_name_dir = this->GetProperty("INSTALL_NAME_DIR");
  2477. if(this->Makefile->IsOn("CMAKE_PLATFORM_HAS_INSTALLNAME") &&
  2478. !this->Makefile->IsOn("CMAKE_SKIP_RPATH") &&
  2479. install_name_dir && *install_name_dir)
  2480. {
  2481. std::string dir = install_name_dir;
  2482. dir += "/";
  2483. return dir;
  2484. }
  2485. else
  2486. {
  2487. return "";
  2488. }
  2489. }
  2490. //----------------------------------------------------------------------------
  2491. const char* cmTarget::GetAndCreateOutputDir(bool implib, bool create)
  2492. {
  2493. // The implib option is only allowed for shared libraries, module
  2494. // libraries, and executables.
  2495. if(this->GetType() != cmTarget::SHARED_LIBRARY &&
  2496. this->GetType() != cmTarget::MODULE_LIBRARY &&
  2497. this->GetType() != cmTarget::EXECUTABLE)
  2498. {
  2499. implib = false;
  2500. }
  2501. // Sanity check. Only generators on platforms supporting import
  2502. // libraries should be asking for the import library output
  2503. // directory.
  2504. if(implib &&
  2505. !this->Makefile->GetDefinition("CMAKE_IMPORT_LIBRARY_SUFFIX"))
  2506. {
  2507. abort();
  2508. }
  2509. if(implib && !this->DLLPlatform)
  2510. {
  2511. abort();
  2512. }
  2513. // Select whether we are constructing the directory for the main
  2514. // target or the import library.
  2515. std::string& out = implib? this->OutputDirImplib : this->OutputDir;
  2516. if(out.empty())
  2517. {
  2518. // Look for a target property defining the target output directory
  2519. // based on the target type.
  2520. const char* propertyName = 0;
  2521. switch(this->GetType())
  2522. {
  2523. case cmTarget::SHARED_LIBRARY:
  2524. {
  2525. // For non-DLL platforms shared libraries are treated as
  2526. // library targets. For DLL platforms the DLL part of a
  2527. // shared library is treated as a runtime target and the
  2528. // corresponding import library is treated as an archive
  2529. // target.
  2530. if(this->DLLPlatform)
  2531. {
  2532. if(implib)
  2533. {
  2534. propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
  2535. }
  2536. else
  2537. {
  2538. propertyName = "RUNTIME_OUTPUT_DIRECTORY";
  2539. }
  2540. }
  2541. else
  2542. {
  2543. propertyName = "LIBRARY_OUTPUT_DIRECTORY";
  2544. }
  2545. } break;
  2546. case cmTarget::STATIC_LIBRARY:
  2547. {
  2548. // Static libraries are always treated as archive targets.
  2549. propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
  2550. } break;
  2551. case cmTarget::MODULE_LIBRARY:
  2552. {
  2553. // Module libraries are always treated as library targets.
  2554. // Module import libraries are treated as archive targets.
  2555. if(implib)
  2556. {
  2557. propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
  2558. }
  2559. else
  2560. {
  2561. propertyName = "LIBRARY_OUTPUT_DIRECTORY";
  2562. }
  2563. } break;
  2564. case cmTarget::EXECUTABLE:
  2565. {
  2566. // Executables are always treated as runtime targets.
  2567. // Executable import libraries are treated as archive targets.
  2568. if(implib)
  2569. {
  2570. propertyName = "ARCHIVE_OUTPUT_DIRECTORY";
  2571. }
  2572. else
  2573. {
  2574. propertyName = "RUNTIME_OUTPUT_DIRECTORY";
  2575. }
  2576. } break;
  2577. default: break;
  2578. }
  2579. // Select an output directory.
  2580. if(const char* outdir = this->GetProperty(propertyName))
  2581. {
  2582. // Use the user-specified output directory.
  2583. out = outdir;
  2584. }
  2585. else if(this->GetType() == cmTarget::EXECUTABLE)
  2586. {
  2587. // Lookup the output path for executables.
  2588. out = this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2589. }
  2590. else if(this->GetType() == cmTarget::STATIC_LIBRARY ||
  2591. this->GetType() == cmTarget::SHARED_LIBRARY ||
  2592. this->GetType() == cmTarget::MODULE_LIBRARY)
  2593. {
  2594. // Lookup the output path for libraries.
  2595. out = this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
  2596. }
  2597. if(out.empty())
  2598. {
  2599. // Default to the current output directory.
  2600. out = ".";
  2601. }
  2602. // Convert the output path to a full path in case it is
  2603. // specified as a relative path. Treat a relative path as
  2604. // relative to the current output directory for this makefile.
  2605. out =
  2606. cmSystemTools::CollapseFullPath
  2607. (out.c_str(), this->Makefile->GetStartOutputDirectory());
  2608. if(this->IsFrameworkOnApple())
  2609. {
  2610. out += "/";
  2611. out += this->GetFullName(0, implib);
  2612. out += ".framework";
  2613. }
  2614. // Optionally make sure the output path exists on disk.
  2615. if(create)
  2616. {
  2617. if(!cmSystemTools::MakeDirectory(out.c_str()))
  2618. {
  2619. cmSystemTools::Error("Error failed to create output directory: ",
  2620. out.c_str());
  2621. }
  2622. }
  2623. }
  2624. return out.c_str();
  2625. }
  2626. //----------------------------------------------------------------------------
  2627. const char* cmTarget::GetOutputDir(bool implib)
  2628. {
  2629. return this->GetAndCreateOutputDir(implib, true);
  2630. }
  2631. //----------------------------------------------------------------------------
  2632. const char* cmTarget::GetExportMacro()
  2633. {
  2634. // Define the symbol for targets that export symbols.
  2635. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2636. this->GetType() == cmTarget::MODULE_LIBRARY ||
  2637. this->IsExecutableWithExports())
  2638. {
  2639. if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
  2640. {
  2641. this->ExportMacro = custom_export_name;
  2642. }
  2643. else
  2644. {
  2645. std::string in = this->GetName();
  2646. in += "_EXPORTS";
  2647. this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
  2648. }
  2649. return this->ExportMacro.c_str();
  2650. }
  2651. else
  2652. {
  2653. return 0;
  2654. }
  2655. }
  2656. //----------------------------------------------------------------------------
  2657. void cmTarget::GetLanguages(std::set<cmStdString>& languages) const
  2658. {
  2659. for(std::vector<cmSourceFile*>::const_iterator
  2660. i = this->SourceFiles.begin(); i != this->SourceFiles.end(); ++i)
  2661. {
  2662. if(const char* lang = (*i)->GetLanguage())
  2663. {
  2664. languages.insert(lang);
  2665. }
  2666. }
  2667. }
  2668. //----------------------------------------------------------------------------
  2669. bool cmTarget::IsChrpathUsed()
  2670. {
  2671. // Enable use of "chrpath" if it is available, the user has turned
  2672. // on the feature, and the rpath flag uses a separator.
  2673. if(const char* ll = this->GetLinkerLanguage(
  2674. this->Makefile->GetLocalGenerator()->GetGlobalGenerator()))
  2675. {
  2676. std::string sepVar = "CMAKE_SHARED_LIBRARY_RUNTIME_";
  2677. sepVar += ll;
  2678. sepVar += "_FLAG_SEP";
  2679. const char* sep = this->Makefile->GetDefinition(sepVar.c_str());
  2680. if(sep && *sep)
  2681. {
  2682. if(this->Makefile->IsSet("CMAKE_CHRPATH") &&
  2683. this->Makefile->IsOn("CMAKE_USE_CHRPATH"))
  2684. {
  2685. return true;
  2686. }
  2687. }
  2688. }
  2689. return false;
  2690. }
  2691. //----------------------------------------------------------------------------
  2692. cmTarget::ImportInfo const*
  2693. cmTarget::GetImportInfo(const char* config)
  2694. {
  2695. // There is no imported information for non-imported targets.
  2696. if(!this->IsImported())
  2697. {
  2698. return 0;
  2699. }
  2700. // Lookup/compute/cache the import information for this
  2701. // configuration.
  2702. std::string config_upper;
  2703. if(config && *config)
  2704. {
  2705. config_upper = cmSystemTools::UpperCase(config);
  2706. }
  2707. else
  2708. {
  2709. config_upper = "NOCONFIG";
  2710. }
  2711. ImportInfoMapType::const_iterator i =
  2712. this->ImportInfoMap.find(config_upper);
  2713. if(i == this->ImportInfoMap.end())
  2714. {
  2715. ImportInfo info;
  2716. this->ComputeImportInfo(config_upper, info);
  2717. ImportInfoMapType::value_type entry(config_upper, info);
  2718. i = this->ImportInfoMap.insert(entry).first;
  2719. }
  2720. // If the location is empty then the target is not available for
  2721. // this configuration.
  2722. if(i->second.Location.empty())
  2723. {
  2724. return 0;
  2725. }
  2726. // Return the import information.
  2727. return &i->second;
  2728. }
  2729. //----------------------------------------------------------------------------
  2730. void cmTarget::ComputeImportInfo(std::string const& desired_config,
  2731. ImportInfo& info)
  2732. {
  2733. // This method finds information about an imported target from its
  2734. // properties. The "IMPORTED_" namespace is reserved for properties
  2735. // defined by the project exporting the target.
  2736. // Track the configuration-specific property suffix.
  2737. std::string suffix = "_";
  2738. suffix += desired_config;
  2739. // Look for a mapping from the current project's configuration to
  2740. // the imported project's configuration.
  2741. std::vector<std::string> mappedConfigs;
  2742. {
  2743. std::string mapProp = "MAP_IMPORTED_CONFIG_";
  2744. mapProp += desired_config;
  2745. if(const char* mapValue = this->GetProperty(mapProp.c_str()))
  2746. {
  2747. cmSystemTools::ExpandListArgument(mapValue, mappedConfigs);
  2748. }
  2749. }
  2750. // If a mapping was found, check its configurations.
  2751. const char* loc = 0;
  2752. for(std::vector<std::string>::const_iterator mci = mappedConfigs.begin();
  2753. !loc && mci != mappedConfigs.end(); ++mci)
  2754. {
  2755. // Look for this configuration.
  2756. std::string mcUpper = cmSystemTools::UpperCase(mci->c_str());
  2757. std::string locProp = "IMPORTED_LOCATION_";
  2758. locProp += mcUpper;
  2759. loc = this->GetProperty(locProp.c_str());
  2760. // If it was found, use it for all properties below.
  2761. if(loc)
  2762. {
  2763. suffix = "_";
  2764. suffix += mcUpper;
  2765. }
  2766. }
  2767. // If we needed to find one of the mapped configurations but did not
  2768. // then the target is not found. The project does not want any
  2769. // other configuration.
  2770. if(!mappedConfigs.empty() && !loc)
  2771. {
  2772. return;
  2773. }
  2774. // If we have not yet found it then there are no mapped
  2775. // configurations. Look for an exact-match.
  2776. if(!loc)
  2777. {
  2778. std::string locProp = "IMPORTED_LOCATION";
  2779. locProp += suffix;
  2780. loc = this->GetProperty(locProp.c_str());
  2781. }
  2782. // If we have not yet found it then there are no mapped
  2783. // configurations and no exact match.
  2784. if(!loc)
  2785. {
  2786. // The suffix computed above is not useful.
  2787. suffix = "";
  2788. // Look for a configuration-less location. This may be set by
  2789. // manually-written code.
  2790. loc = this->GetProperty("IMPORTED_LOCATION");
  2791. }
  2792. // If we have not yet found it then the project is willing to try
  2793. // any available configuration.
  2794. if(!loc)
  2795. {
  2796. std::vector<std::string> availableConfigs;
  2797. if(const char* iconfigs = this->GetProperty("IMPORTED_CONFIGURATIONS"))
  2798. {
  2799. cmSystemTools::ExpandListArgument(iconfigs, availableConfigs);
  2800. }
  2801. for(std::vector<std::string>::const_iterator
  2802. aci = availableConfigs.begin();
  2803. !loc && aci != availableConfigs.end(); ++aci)
  2804. {
  2805. suffix = "_";
  2806. suffix += cmSystemTools::UpperCase(availableConfigs[0]);
  2807. std::string locProp = "IMPORTED_LOCATION";
  2808. locProp += suffix;
  2809. loc = this->GetProperty(locProp.c_str());
  2810. }
  2811. }
  2812. // If we have not yet found it then the target is not available.
  2813. if(!loc)
  2814. {
  2815. return;
  2816. }
  2817. // A provided configuration has been chosen. Load the
  2818. // configuration's properties.
  2819. info.Location = loc;
  2820. // Get the soname.
  2821. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  2822. {
  2823. std::string soProp = "IMPORTED_SONAME";
  2824. soProp += suffix;
  2825. if(const char* config_soname = this->GetProperty(soProp.c_str()))
  2826. {
  2827. info.SOName = config_soname;
  2828. }
  2829. else if(const char* soname = this->GetProperty("IMPORTED_SONAME"))
  2830. {
  2831. info.SOName = soname;
  2832. }
  2833. }
  2834. // Get the import library.
  2835. if(this->GetType() == cmTarget::SHARED_LIBRARY ||
  2836. this->IsExecutableWithExports())
  2837. {
  2838. std::string impProp = "IMPORTED_IMPLIB";
  2839. impProp += suffix;
  2840. if(const char* config_implib = this->GetProperty(impProp.c_str()))
  2841. {
  2842. info.ImportLibrary = config_implib;
  2843. }
  2844. else if(const char* implib = this->GetProperty("IMPORTED_IMPLIB"))
  2845. {
  2846. info.ImportLibrary = implib;
  2847. }
  2848. }
  2849. // Get the link interface.
  2850. {
  2851. std::string linkProp = "IMPORTED_LINK_INTERFACE_LIBRARIES";
  2852. linkProp += suffix;
  2853. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  2854. {
  2855. cmSystemTools::ExpandListArgument(config_libs,
  2856. info.LinkInterface.Libraries);
  2857. }
  2858. else if(const char* libs =
  2859. this->GetProperty("IMPORTED_LINK_INTERFACE_LIBRARIES"))
  2860. {
  2861. cmSystemTools::ExpandListArgument(libs,
  2862. info.LinkInterface.Libraries);
  2863. }
  2864. }
  2865. // Get the link dependencies.
  2866. {
  2867. std::string linkProp = "IMPORTED_LINK_DEPENDENT_LIBRARIES";
  2868. linkProp += suffix;
  2869. if(const char* config_libs = this->GetProperty(linkProp.c_str()))
  2870. {
  2871. cmSystemTools::ExpandListArgument(config_libs,
  2872. info.LinkInterface.SharedDeps);
  2873. }
  2874. else if(const char* libs =
  2875. this->GetProperty("IMPORTED_LINK_DEPENDENT_LIBRARIES"))
  2876. {
  2877. cmSystemTools::ExpandListArgument(libs, info.LinkInterface.SharedDeps);
  2878. }
  2879. }
  2880. }
  2881. //----------------------------------------------------------------------------
  2882. cmTargetLinkInterface const* cmTarget::GetLinkInterface(const char* config)
  2883. {
  2884. // Imported targets have their own link interface.
  2885. if(this->IsImported())
  2886. {
  2887. if(cmTarget::ImportInfo const* info = this->GetImportInfo(config))
  2888. {
  2889. return &info->LinkInterface;
  2890. }
  2891. return 0;
  2892. }
  2893. // Link interfaces are supported only for shared libraries and
  2894. // executables that export symbols.
  2895. if((this->GetType() != cmTarget::SHARED_LIBRARY &&
  2896. !this->IsExecutableWithExports()))
  2897. {
  2898. return 0;
  2899. }
  2900. // Lookup any existing link interface for this configuration.
  2901. std::map<cmStdString, cmTargetLinkInterface*>::iterator
  2902. i = this->LinkInterface.find(config?config:"");
  2903. if(i == this->LinkInterface.end())
  2904. {
  2905. // Compute the link interface for this configuration.
  2906. cmTargetLinkInterface* interface = this->ComputeLinkInterface(config);
  2907. // Store the information for this configuration.
  2908. std::map<cmStdString, cmTargetLinkInterface*>::value_type
  2909. entry(config?config:"", interface);
  2910. i = this->LinkInterface.insert(entry).first;
  2911. }
  2912. return i->second;
  2913. }
  2914. //----------------------------------------------------------------------------
  2915. cmTargetLinkInterface* cmTarget::ComputeLinkInterface(const char* config)
  2916. {
  2917. // Construct the property name suffix for this configuration.
  2918. std::string suffix = "_";
  2919. if(config && *config)
  2920. {
  2921. suffix += cmSystemTools::UpperCase(config);
  2922. }
  2923. else
  2924. {
  2925. suffix += "NOCONFIG";
  2926. }
  2927. // Lookup the link interface libraries.
  2928. const char* libs = 0;
  2929. {
  2930. // Lookup the per-configuration property.
  2931. std::string propName = "LINK_INTERFACE_LIBRARIES";
  2932. propName += suffix;
  2933. libs = this->GetProperty(propName.c_str());
  2934. // If not set, try the generic property.
  2935. if(!libs)
  2936. {
  2937. libs = this->GetProperty("LINK_INTERFACE_LIBRARIES");
  2938. }
  2939. }
  2940. // If still not set, there is no link interface.
  2941. if(!libs)
  2942. {
  2943. return 0;
  2944. }
  2945. // Allocate the interface.
  2946. cmTargetLinkInterface* interface = new cmTargetLinkInterface;
  2947. if(!interface)
  2948. {
  2949. return 0;
  2950. }
  2951. // Expand the list of libraries in the interface.
  2952. cmSystemTools::ExpandListArgument(libs, interface->Libraries);
  2953. // Now we need to construct a list of shared library dependencies
  2954. // not included in the interface.
  2955. if(this->GetType() == cmTarget::SHARED_LIBRARY)
  2956. {
  2957. // Use a set to keep track of what libraries have been emitted to
  2958. // either list.
  2959. std::set<cmStdString> emitted;
  2960. for(std::vector<std::string>::const_iterator
  2961. li = interface->Libraries.begin();
  2962. li != interface->Libraries.end(); ++li)
  2963. {
  2964. emitted.insert(*li);
  2965. }
  2966. // Compute which library configuration to link.
  2967. cmTarget::LinkLibraryType linkType = cmTarget::OPTIMIZED;
  2968. if(config && cmSystemTools::UpperCase(config) == "DEBUG")
  2969. {
  2970. linkType = cmTarget::DEBUG;
  2971. }
  2972. // Construct the list of libs linked for this configuration.
  2973. cmTarget::LinkLibraryVectorType const& llibs =
  2974. this->GetOriginalLinkLibraries();
  2975. for(cmTarget::LinkLibraryVectorType::const_iterator li = llibs.begin();
  2976. li != llibs.end(); ++li)
  2977. {
  2978. // Skip entries that will resolve to the target itself, are empty,
  2979. // or are not meant for this configuration.
  2980. if(li->first == this->GetName() || li->first.empty() ||
  2981. !(li->second == cmTarget::GENERAL || li->second == linkType))
  2982. {
  2983. continue;
  2984. }
  2985. // Skip entries that have already been emitted into either list.
  2986. if(!emitted.insert(li->first).second)
  2987. {
  2988. continue;
  2989. }
  2990. // Add this entry if it is a shared library.
  2991. if(cmTarget* tgt = this->Makefile->FindTargetToUse(li->first.c_str()))
  2992. {
  2993. if(tgt->GetType() == cmTarget::SHARED_LIBRARY)
  2994. {
  2995. interface->SharedDeps.push_back(li->first);
  2996. }
  2997. }
  2998. else
  2999. {
  3000. // TODO: Recognize shared library file names. Perhaps this
  3001. // should be moved to cmComputeLinkInformation, but that creates
  3002. // a chicken-and-egg problem since this list is needed for its
  3003. // construction.
  3004. }
  3005. }
  3006. }
  3007. // Return the completed interface.
  3008. return interface;
  3009. }
  3010. //----------------------------------------------------------------------------
  3011. cmComputeLinkInformation*
  3012. cmTarget::GetLinkInformation(const char* config)
  3013. {
  3014. // Lookup any existing information for this configuration.
  3015. std::map<cmStdString, cmComputeLinkInformation*>::iterator
  3016. i = this->LinkInformation.find(config?config:"");
  3017. if(i == this->LinkInformation.end())
  3018. {
  3019. // Compute information for this configuration.
  3020. cmComputeLinkInformation* info =
  3021. new cmComputeLinkInformation(this, config);
  3022. if(!info || !info->Compute())
  3023. {
  3024. delete info;
  3025. info = 0;
  3026. }
  3027. // Store the information for this configuration.
  3028. std::map<cmStdString, cmComputeLinkInformation*>::value_type
  3029. entry(config?config:"", info);
  3030. i = this->LinkInformation.insert(entry).first;
  3031. }
  3032. return i->second;
  3033. }
  3034. //----------------------------------------------------------------------------
  3035. cmTargetLinkInformationMap
  3036. ::cmTargetLinkInformationMap(cmTargetLinkInformationMap const& r): derived()
  3037. {
  3038. // Ideally cmTarget instances should never be copied. However until
  3039. // we can make a sweep to remove that, this copy constructor avoids
  3040. // allowing the resources (LinkInformation) from getting copied. In
  3041. // the worst case this will lead to extra cmComputeLinkInformation
  3042. // instances. We also enforce in debug mode that the map be emptied
  3043. // when copied.
  3044. static_cast<void>(r);
  3045. assert(r.empty());
  3046. }
  3047. //----------------------------------------------------------------------------
  3048. cmTargetLinkInformationMap::~cmTargetLinkInformationMap()
  3049. {
  3050. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  3051. {
  3052. delete i->second;
  3053. }
  3054. }
  3055. //----------------------------------------------------------------------------
  3056. cmTargetLinkInterfaceMap
  3057. ::cmTargetLinkInterfaceMap(cmTargetLinkInterfaceMap const& r): derived()
  3058. {
  3059. // Ideally cmTarget instances should never be copied. However until
  3060. // we can make a sweep to remove that, this copy constructor avoids
  3061. // allowing the resources (LinkInterface) from getting copied. In
  3062. // the worst case this will lead to extra cmTargetLinkInterface
  3063. // instances. We also enforce in debug mode that the map be emptied
  3064. // when copied.
  3065. static_cast<void>(r);
  3066. assert(r.empty());
  3067. }
  3068. //----------------------------------------------------------------------------
  3069. cmTargetLinkInterfaceMap::~cmTargetLinkInterfaceMap()
  3070. {
  3071. for(derived::iterator i = this->begin(); i != this->end(); ++i)
  3072. {
  3073. delete i->second;
  3074. }
  3075. }