meson.build 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. project('harfbuzz', 'c', 'cpp',
  2. meson_version: '>= 0.55.0',
  3. version: '6.0.0',
  4. default_options: [
  5. 'cpp_rtti=false', # Just to support msvc, we are passing -fno-exceptions also anyway
  6. 'cpp_std=c++11',
  7. 'wrap_mode=nofallback', # Use --wrap-mode=default to revert, https://github.com/harfbuzz/harfbuzz/pull/2548
  8. ],
  9. )
  10. hb_version_arr = meson.project_version().split('.')
  11. hb_version_major = hb_version_arr[0].to_int()
  12. hb_version_minor = hb_version_arr[1].to_int()
  13. hb_version_micro = hb_version_arr[2].to_int()
  14. # libtool versioning
  15. hb_version_int = hb_version_major*10000 + hb_version_minor*100 + hb_version_micro
  16. hb_libtool_version_info = '@0@:0:@0@'.format(hb_version_int)
  17. pkgmod = import('pkgconfig')
  18. cpp = meson.get_compiler('cpp')
  19. null_dep = dependency('', required: false)
  20. if cpp.get_argument_syntax() == 'msvc'
  21. # Ignore several spurious warnings for things HarfBuzz does very commonly.
  22. # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it
  23. # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once
  24. # NOTE: Only add warnings here if you are sure they're spurious
  25. msvc_args = [
  26. '/wd4018', # implicit signed/unsigned conversion
  27. '/wd4146', # unary minus on unsigned (beware INT_MIN)
  28. '/wd4244', # lossy type conversion (e.g. double -> int)
  29. '/wd4305', # truncating type conversion (e.g. double -> float)
  30. cpp.get_supported_arguments(['/utf-8']), # set the input encoding to utf-8
  31. ]
  32. add_project_arguments(msvc_args, language: ['c', 'cpp'])
  33. # Disable SAFESEH with MSVC for libs that use external deps that are built with MinGW
  34. # noseh_link_args = ['/SAFESEH:NO']
  35. # disable exception handling
  36. add_project_arguments(['/EHs-', '/EHc-'], language: 'cpp')
  37. endif
  38. add_project_link_arguments(cpp.get_supported_link_arguments([
  39. '-Bsymbolic-functions'
  40. ]), language: 'c')
  41. add_project_arguments(cpp.get_supported_arguments([
  42. '-fno-exceptions',
  43. '-fno-rtti',
  44. '-fno-threadsafe-statics',
  45. '-fvisibility-inlines-hidden',
  46. ]), language: 'cpp')
  47. if host_machine.cpu_family() == 'arm' and cpp.alignment('struct { char c; }') != 1
  48. if cpp.has_argument('-mstructure-size-boundary=8')
  49. add_project_arguments('-mstructure-size-boundary=8', language: 'cpp')
  50. endif
  51. endif
  52. if host_machine.system() == 'windows'
  53. add_project_arguments(cpp.get_supported_arguments([
  54. '-Wa,-mbig-obj'
  55. ]), language : 'cpp')
  56. endif
  57. check_headers = [
  58. ['unistd.h'],
  59. ['sys/mman.h'],
  60. ['stdbool.h'],
  61. ['xlocale.h'],
  62. ]
  63. check_funcs = [
  64. ['atexit'],
  65. ['mprotect'],
  66. ['sysconf'],
  67. ['getpagesize'],
  68. ['mmap'],
  69. ['isatty'],
  70. ['uselocale'],
  71. ['newlocale'],
  72. ]
  73. m_dep = cpp.find_library('m', required: false)
  74. if meson.version().version_compare('>=0.60.0')
  75. # pkg-config: freetype2, cmake: Freetype
  76. freetype_dep = dependency('freetype2', 'Freetype',
  77. required: get_option('freetype'),
  78. default_options: ['harfbuzz=disabled'],
  79. allow_fallback: true)
  80. else
  81. # painful hack to handle multiple dependencies but also respect options
  82. freetype_opt = get_option('freetype')
  83. # we want to handle enabled manually after fallbacks, but also handle disabled normally
  84. if freetype_opt.enabled()
  85. freetype_opt = false
  86. endif
  87. # try pkg-config name
  88. freetype_dep = dependency('freetype2', method: 'pkg-config', required: freetype_opt)
  89. # when disabled, leave it not-found
  90. if not freetype_dep.found() and not get_option('freetype').disabled()
  91. # Try cmake name
  92. freetype_dep = dependency('Freetype', method: 'cmake', required: false)
  93. # Subproject fallback, `allow_fallback: true` means the fallback will be
  94. # tried even if the freetype option is set to `auto`.
  95. if not freetype_dep.found()
  96. freetype_dep = dependency('freetype2',
  97. method: 'pkg-config',
  98. required: get_option('freetype'),
  99. default_options: ['harfbuzz=disabled'],
  100. allow_fallback: true)
  101. endif
  102. endif
  103. endif
  104. glib_dep = dependency('glib-2.0', required: get_option('glib'))
  105. gobject_dep = dependency('gobject-2.0', required: get_option('gobject'))
  106. graphite2_dep = dependency('graphite2', required: get_option('graphite2'))
  107. graphite_dep = dependency('graphite2', required: get_option('graphite'))
  108. if meson.version().version_compare('>=0.60.0')
  109. # pkg-config: icu-uc, cmake: ICU but with components
  110. icu_dep = dependency('icu-uc', 'ICU',
  111. components: 'uc',
  112. required: get_option('icu'),
  113. default_options: ['harfbuzz=disabled'],
  114. allow_fallback: true)
  115. else
  116. # painful hack to handle multiple dependencies but also respect options
  117. icu_opt = get_option('icu')
  118. # we want to handle enabled manually after fallbacks, but also handle disabled normally
  119. if icu_opt.enabled()
  120. icu_opt = false
  121. endif
  122. # try pkg-config name
  123. icu_dep = dependency('icu-uc', method: 'pkg-config', required: icu_opt)
  124. # when disabled, leave it not-found
  125. if not icu_dep.found() and not get_option('icu').disabled()
  126. # Try cmake name
  127. icu_dep = dependency('ICU', method: 'cmake', components: 'uc', required: false)
  128. # Try again with subproject fallback. `allow_fallback: true` means the
  129. # fallback will be tried even if the icu option is set to `auto`, but
  130. # we cannot pass this option until Meson 0.59.0, because no wrap file
  131. # is checked into git.
  132. if not icu_dep.found()
  133. icu_dep = dependency('icu-uc',
  134. method: 'pkg-config',
  135. required: get_option('icu'))
  136. endif
  137. endif
  138. endif
  139. if icu_dep.found() and icu_dep.type_name() == 'pkgconfig'
  140. icu_defs = icu_dep.get_variable(pkgconfig: 'DEFS', default_value: '').split()
  141. if icu_defs.length() > 0
  142. add_project_arguments(icu_defs, language: ['c', 'cpp'])
  143. endif
  144. endif
  145. cairo_dep = null_dep
  146. cairo_ft_dep = null_dep
  147. if not get_option('cairo').disabled()
  148. cairo_dep = dependency('cairo', required: false)
  149. cairo_ft_dep = dependency('cairo-ft', required: false)
  150. if (not cairo_dep.found() and
  151. cpp.get_argument_syntax() == 'msvc' and
  152. cpp.has_header('cairo.h'))
  153. cairo_dep = cpp.find_library('cairo', required: false)
  154. if cairo_dep.found() and cpp.has_function('cairo_ft_font_face_create_for_ft_face',
  155. prefix: '#include <cairo-ft.h>',
  156. dependencies: cairo_dep)
  157. cairo_ft_dep = cairo_dep
  158. endif
  159. endif
  160. if not cairo_dep.found()
  161. # Note that we don't have harfbuzz -> cairo -> freetype2 -> harfbuzz fallback
  162. # dependency cycle here because we have configured freetype2 above with
  163. # harfbuzz support disabled, so when cairo will lookup freetype2 dependency
  164. # it will be forced to use that one.
  165. cairo_dep = dependency('cairo', required: get_option('cairo'))
  166. cairo_ft_required = get_option('cairo').enabled() and get_option('freetype').enabled()
  167. cairo_ft_dep = dependency('cairo-ft', required: cairo_ft_required)
  168. endif
  169. endif
  170. chafa_dep = dependency('chafa', version: '>= 1.6.0', required: get_option('chafa'))
  171. conf = configuration_data()
  172. incconfig = include_directories('.')
  173. add_project_arguments('-DHAVE_CONFIG_H', language: ['c', 'cpp'])
  174. warn_cflags = [
  175. '-Wno-non-virtual-dtor',
  176. ]
  177. cpp_args = cpp.get_supported_arguments(warn_cflags)
  178. if glib_dep.found()
  179. conf.set('HAVE_GLIB', 1)
  180. endif
  181. if gobject_dep.found()
  182. conf.set('HAVE_GOBJECT', 1)
  183. endif
  184. if cairo_dep.found()
  185. conf.set('HAVE_CAIRO', 1)
  186. if cairo_dep.type_name() == 'internal'
  187. conf.set('HAVE_CAIRO_USER_FONT_FACE_SET_RENDER_COLOR_GLYPH_FUNC', 1)
  188. else
  189. check_funcs += [['cairo_user_font_face_set_render_color_glyph_func', {'deps': cairo_dep}]]
  190. endif
  191. endif
  192. if cairo_ft_dep.found()
  193. conf.set('HAVE_CAIRO_FT', 1)
  194. endif
  195. if chafa_dep.found()
  196. conf.set('HAVE_CHAFA', 1)
  197. endif
  198. if graphite2_dep.found() or graphite_dep.found()
  199. conf.set('HAVE_GRAPHITE2', 1)
  200. endif
  201. if icu_dep.found()
  202. conf.set('HAVE_ICU', 1)
  203. endif
  204. if get_option('icu_builtin')
  205. conf.set('HAVE_ICU_BUILTIN', 1)
  206. endif
  207. if get_option('experimental_api')
  208. conf.set('HB_EXPERIMENTAL_API', 1)
  209. endif
  210. if freetype_dep.found()
  211. conf.set('HAVE_FREETYPE', 1)
  212. check_freetype_funcs = [
  213. ['FT_Get_Var_Blend_Coordinates', {'deps': freetype_dep}],
  214. ['FT_Set_Var_Blend_Coordinates', {'deps': freetype_dep}],
  215. ['FT_Done_MM_Var', {'deps': freetype_dep}],
  216. ['FT_Get_Transform', {'deps': freetype_dep}],
  217. ]
  218. if freetype_dep.type_name() == 'internal'
  219. foreach func: check_freetype_funcs
  220. name = func[0]
  221. conf.set('HAVE_@0@'.format(name.to_upper()), 1)
  222. endforeach
  223. else
  224. check_funcs += check_freetype_funcs
  225. endif
  226. endif
  227. gdi_uniscribe_deps = []
  228. # GDI (Uniscribe) (Windows)
  229. if host_machine.system() == 'windows' and not get_option('gdi').disabled()
  230. if (get_option('directwrite').enabled() and
  231. not (cpp.has_header('usp10.h') and cpp.has_header('windows.h')))
  232. error('GDI/Uniscribe was enabled explicitly, but required headers are missing.')
  233. endif
  234. gdi_deps_found = true
  235. foreach usplib : ['usp10', 'gdi32', 'rpcrt4']
  236. dep = cpp.find_library(usplib, required: get_option('gdi'))
  237. gdi_deps_found = gdi_deps_found and dep.found()
  238. gdi_uniscribe_deps += dep
  239. endforeach
  240. if gdi_deps_found
  241. conf.set('HAVE_UNISCRIBE', 1)
  242. conf.set('HAVE_GDI', 1)
  243. endif
  244. endif
  245. # DirectWrite (Windows)
  246. if host_machine.system() == 'windows' and not get_option('directwrite').disabled()
  247. if get_option('directwrite').enabled() and not cpp.has_header('dwrite_1.h')
  248. error('DirectWrite was enabled explicitly, but required header is missing.')
  249. endif
  250. conf.set('HAVE_DIRECTWRITE', 1)
  251. endif
  252. # CoreText (macOS)
  253. coretext_deps = []
  254. if host_machine.system() == 'darwin' and not get_option('coretext').disabled()
  255. app_services_dep = dependency('appleframeworks', modules: ['ApplicationServices'], required: false)
  256. if cpp.has_type('CTFontRef', prefix: '#include <ApplicationServices/ApplicationServices.h>', dependencies: app_services_dep)
  257. coretext_deps += [app_services_dep]
  258. conf.set('HAVE_CORETEXT', 1)
  259. # On iOS CoreText and CoreGraphics are stand-alone frameworks
  260. # Check for a different symbol to avoid getting cached result
  261. else
  262. coretext_dep = dependency('appleframeworks', modules: ['CoreText'], required: false)
  263. coregraphics_dep = dependency('appleframeworks', modules: ['CoreGraphics'], required: false)
  264. corefoundation_dep = dependency('appleframeworks', modules: ['CoreFoundation'], required: false)
  265. if cpp.has_type('CTRunRef', prefix: '#include <CoreText/CoreText.h>', dependencies: [coretext_dep, coregraphics_dep, corefoundation_dep])
  266. coretext_deps += [coretext_dep, coregraphics_dep, corefoundation_dep]
  267. conf.set('HAVE_CORETEXT', 1)
  268. elif get_option('coretext').enabled()
  269. error('CoreText was enabled explicitly, but required headers or frameworks are missing.')
  270. endif
  271. endif
  272. endif
  273. # threads
  274. thread_dep = null_dep
  275. if host_machine.system() != 'windows'
  276. thread_dep = dependency('threads', required: false)
  277. if thread_dep.found()
  278. conf.set('HAVE_PTHREAD', 1)
  279. endif
  280. endif
  281. conf.set_quoted('PACKAGE_NAME', 'HarfBuzz')
  282. conf.set_quoted('PACKAGE_VERSION', meson.project_version())
  283. foreach check : check_headers
  284. name = check[0]
  285. if cpp.has_header(name)
  286. conf.set('HAVE_@0@'.format(name.to_upper().underscorify()), 1)
  287. endif
  288. endforeach
  289. harfbuzz_extra_deps = []
  290. foreach check : check_funcs
  291. name = check[0]
  292. opts = check.get(1, {})
  293. link_withs = opts.get('link_with', [])
  294. check_deps = opts.get('deps', [])
  295. extra_deps = []
  296. found = true
  297. # First try without linking
  298. found = cpp.has_function(name, dependencies: check_deps)
  299. if not found and link_withs.length() > 0
  300. found = true
  301. foreach link_with : link_withs
  302. dep = cpp.find_library(link_with, required: false)
  303. if dep.found()
  304. extra_deps += dep
  305. else
  306. found = false
  307. endif
  308. endforeach
  309. if found
  310. found = cpp.has_function(name, dependencies: check_deps + extra_deps)
  311. endif
  312. endif
  313. if found
  314. harfbuzz_extra_deps += extra_deps
  315. conf.set('HAVE_@0@'.format(name.to_upper()), 1)
  316. endif
  317. endforeach
  318. subdir('src')
  319. subdir('util')
  320. if not get_option('tests').disabled()
  321. subdir('test')
  322. endif
  323. if not get_option('benchmark').disabled()
  324. subdir('perf')
  325. endif
  326. if not get_option('docs').disabled()
  327. subdir('docs')
  328. endif
  329. configure_file(output: 'config.h', configuration: conf)
  330. build_summary = {
  331. 'Directories':
  332. {'prefix': get_option('prefix'),
  333. 'bindir': get_option('bindir'),
  334. 'libdir': get_option('libdir'),
  335. 'includedir': get_option('includedir'),
  336. 'datadir': get_option('datadir'),
  337. },
  338. 'Unicode callbacks (you want at least one)':
  339. {'Builtin': true,
  340. 'Glib': conf.get('HAVE_GLIB', 0) == 1,
  341. 'ICU': conf.get('HAVE_ICU', 0) == 1,
  342. },
  343. 'Font callbacks (the more the merrier)':
  344. {'FreeType': conf.get('HAVE_FREETYPE', 0) == 1,
  345. },
  346. 'Dependencies used for command-line utilities':
  347. {'Cairo': conf.get('HAVE_CAIRO', 0) == 1,
  348. 'Chafa': conf.get('HAVE_CHAFA', 0) == 1,
  349. },
  350. 'Additional shapers':
  351. {'Graphite2': conf.get('HAVE_GRAPHITE2', 0) == 1,
  352. },
  353. 'Platform shapers (not normally needed)':
  354. {'CoreText': conf.get('HAVE_CORETEXT', 0) == 1,
  355. 'DirectWrite': conf.get('HAVE_DIRECTWRITE', 0) == 1,
  356. 'GDI/Uniscribe': (conf.get('HAVE_GDI', 0) == 1) and (conf.get('HAVE_UNISCRIBE', 0) == 1),
  357. },
  358. 'Other features':
  359. {'Documentation': conf.get('HAVE_GTK_DOC', 0) == 1,
  360. 'GObject bindings': conf.get('HAVE_GOBJECT', 0) == 1,
  361. 'Introspection': conf.get('HAVE_INTROSPECTION', 0) == 1,
  362. 'Experimental APIs': conf.get('HB_EXPERIMENTAL_API', 0) == 1,
  363. },
  364. 'Testing':
  365. {'Tests': get_option('tests').enabled(),
  366. 'Benchmark': get_option('benchmark').enabled(),
  367. },
  368. }
  369. foreach section_title, section : build_summary
  370. summary(section, bool_yn: true, section: section_title)
  371. endforeach