cmTarget.cxx 88 KB

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