cmTarget.cxx 100 KB

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