cmTarget.cxx 127 KB

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