cmTarget.cxx 118 KB

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