cmTarget.cxx 114 KB

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