🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
11 KiB

  1. #
  2. # Meson project file for FreeType 2
  3. #
  4. # Copyright (C) 2020-2021 by
  5. # David Turner, Robert Wilhelm, and Werner Lemberg.
  6. #
  7. # This file is part of the FreeType project, and may only be used, modified,
  8. # and distributed under the terms of the FreeType project license,
  9. # LICENSE.TXT. By continuing to use, modify, or distribute this file you
  10. # indicate that you have read the license and understand and accept it
  11. # fully.
  12. #
  13. # Say
  14. #
  15. # meson configure
  16. #
  17. # to see all configuration options and their default values. For example,
  18. # to build only a shared version of FreeType, override the default value
  19. # with
  20. #
  21. # meson setup -Ddefault_library=shared
  22. #
  23. project('freetype2', 'c',
  24. meson_version: '>= 0.55.0',
  25. default_options: ['default_library=both'],
  26. version: run_command('builds/meson/extract_freetype_version.py',
  27. 'include/freetype/freetype.h').stdout().strip(),
  28. )
  29. # Only meson >= 0.57 can read a file and assign its contents to a
  30. # variable; we thus use an external command to have this functionality
  31. # with older versions, too.
  32. python = import('python')
  33. python_exe = python.find_installation(required: true)
  34. ft2_so_version = run_command(python_exe,
  35. files('builds/meson/extract_libtool_version.py'),
  36. '--soversion',
  37. files('builds/unix/configure.raw')).stdout().strip()
  38. ft2_pkgconfig_version = run_command(python_exe,
  39. files('builds/meson/extract_libtool_version.py'),
  40. files('builds/unix/configure.raw')).stdout().strip()
  41. ft2_includes = include_directories('include')
  42. # Generate a custom `ftmodule.h` version based on the content of
  43. # `modules.cfg`.
  44. ftmodule_h = custom_target('ftmodule.h',
  45. output: 'ftmodule.h',
  46. input: 'modules.cfg',
  47. command: [python_exe, files('builds/meson/parse_modules_cfg.py'),
  48. '--format=ftmodule.h', '@INPUT@', '--output', '@OUTPUT@'],
  49. install: true,
  50. install_dir: 'include/freetype2/freetype/config',
  51. )
  52. ft2_sources = [ftmodule_h]
  53. # FreeType 2 modules.
  54. ft_main_modules = run_command(python_exe,
  55. files('builds/meson/parse_modules_cfg.py'),
  56. '--format=main-modules',
  57. files('modules.cfg')).stdout().strip().split()
  58. ft2_sources += files([
  59. 'src/base/ftbase.c',
  60. 'src/base/ftinit.c',
  61. ])
  62. foreach mod: ft_main_modules
  63. source = mod
  64. if mod == 'winfonts'
  65. source = 'winfnt'
  66. elif mod == 'cid'
  67. source = 'type1cid'
  68. endif
  69. ft2_sources += 'src/@0@/@1@.c'.format(mod, source)
  70. endforeach
  71. # NOTE: The `gzip` and `bzip2` aux modules are handled through options.
  72. ft_aux_modules = run_command(python_exe,
  73. files('builds/meson/parse_modules_cfg.py'),
  74. '--format=aux-modules',
  75. files('modules.cfg')).stdout().strip().split()
  76. foreach auxmod: ft_aux_modules
  77. source = auxmod
  78. # Most sources are named `src/<module>/<module>.c`, but there are a few
  79. # exceptions handled here.
  80. if auxmod == 'cache'
  81. source = 'ftcache'
  82. elif auxmod == 'lzw'
  83. source = 'ftlzw'
  84. elif auxmod == 'gzip' or auxmod == 'bzip2'
  85. # Handled through options instead, see below.
  86. continue
  87. endif
  88. ft2_sources += 'src/@0@/@1@.c'.format(auxmod, source)
  89. endforeach
  90. # FreeType 2 base extensions.
  91. # To be configured in `modules.cfg`.
  92. base_extensions = run_command(python_exe,
  93. files('builds/meson/parse_modules_cfg.py'),
  94. '--format=base-extensions-list',
  95. files('modules.cfg')).stdout().split()
  96. foreach ext: base_extensions
  97. ft2_sources += files('src/base/' + ext)
  98. endforeach
  99. # Header files.
  100. ft2_public_headers = files([
  101. 'include/freetype/freetype.h',
  102. 'include/freetype/ftadvanc.h',
  103. 'include/freetype/ftbbox.h',
  104. 'include/freetype/ftbdf.h',
  105. 'include/freetype/ftbitmap.h',
  106. 'include/freetype/ftbzip2.h',
  107. 'include/freetype/ftcache.h',
  108. 'include/freetype/ftchapters.h',
  109. 'include/freetype/ftcid.h',
  110. 'include/freetype/ftcolor.h',
  111. 'include/freetype/ftdriver.h',
  112. 'include/freetype/fterrdef.h',
  113. 'include/freetype/fterrors.h',
  114. 'include/freetype/ftfntfmt.h',
  115. 'include/freetype/ftgasp.h',
  116. 'include/freetype/ftglyph.h',
  117. 'include/freetype/ftgxval.h',
  118. 'include/freetype/ftgzip.h',
  119. 'include/freetype/ftimage.h',
  120. 'include/freetype/ftincrem.h',
  121. 'include/freetype/ftlcdfil.h',
  122. 'include/freetype/ftlist.h',
  123. 'include/freetype/ftlzw.h',
  124. 'include/freetype/ftmac.h',
  125. 'include/freetype/ftmm.h',
  126. 'include/freetype/ftmodapi.h',
  127. 'include/freetype/ftmoderr.h',
  128. 'include/freetype/ftotval.h',
  129. 'include/freetype/ftoutln.h',
  130. 'include/freetype/ftparams.h',
  131. 'include/freetype/ftpfr.h',
  132. 'include/freetype/ftrender.h',
  133. 'include/freetype/ftsizes.h',
  134. 'include/freetype/ftsnames.h',
  135. 'include/freetype/ftstroke.h',
  136. 'include/freetype/ftsynth.h',
  137. 'include/freetype/ftsystem.h',
  138. 'include/freetype/fttrigon.h',
  139. 'include/freetype/fttypes.h',
  140. 'include/freetype/ftwinfnt.h',
  141. 'include/freetype/t1tables.h',
  142. 'include/freetype/ttnameid.h',
  143. 'include/freetype/tttables.h',
  144. 'include/freetype/tttags.h',
  145. ])
  146. ft2_config_headers = files([
  147. 'include/freetype/config/ftconfig.h',
  148. 'include/freetype/config/ftheader.h',
  149. 'include/freetype/config/ftstdlib.h',
  150. 'include/freetype/config/integer-types.h',
  151. 'include/freetype/config/mac-support.h',
  152. 'include/freetype/config/public-macros.h',
  153. ])
  154. ft2_defines = ['-DFT2_BUILD_LIBRARY=1']
  155. # System support file.
  156. cc = meson.get_compiler('c')
  157. # NOTE: msys2 on Windows has `unistd.h` and `fcntl.h` but not `sys/mman.h`!
  158. has_unistd_h = cc.has_header('unistd.h')
  159. has_fcntl_h = cc.has_header('fcntl.h')
  160. has_sys_mman_h = cc.has_header('sys/mman.h')
  161. mmap_option = get_option('mmap')
  162. use_unix_ftsystem_c = false
  163. if mmap_option.disabled()
  164. ft2_sources += files(['src/base/ftsystem.c',])
  165. elif host_machine.system() == 'windows'
  166. ft2_sources += files(['builds/windows/ftsystem.c',])
  167. else
  168. if has_unistd_h and has_fcntl_h and has_sys_mman_h
  169. # This version of `ftsystem.c` uses `mmap` to read input font files.
  170. ft2_sources += files(['builds/unix/ftsystem.c',])
  171. use_unix_ftsystem_c = true
  172. elif mmap_option.enabled()
  173. error('mmap was enabled via options but is not available,'
  174. + ' required headers were not found!')
  175. else
  176. ft2_sources += files(['src/base/ftsystem.c',])
  177. endif
  178. endif
  179. # Debug support file
  180. #
  181. # NOTE: Some specialized versions exist for other platforms not supported by
  182. # Meson. Most implementation differences are extremely minor, i.e., in the
  183. # implementation of `FT_Message` and `FT_Panic`, and getting the `FT2_DEBUG`
  184. # value from the environment, when this is supported. A smaller refactor
  185. # might make these platform-specific files much smaller, and could be moved
  186. # into `ftsystem.c` as well.
  187. #
  188. if host_machine.system() == 'windows'
  189. winmod = import('windows')
  190. ft2_sources += [
  191. 'builds/windows/ftdebug.c',
  192. winmod.compile_resources('src/base/ftver.rc'),
  193. ]
  194. else
  195. ft2_sources += 'src/base/ftdebug.c'
  196. endif
  197. ft2_deps = []
  198. # Generate `ftoption.h` based on available dependencies.
  199. process_header_command = [python_exe,
  200. files('builds/meson/process_ftoption_h.py'),
  201. '@INPUT@', '--output=@OUTPUT@']
  202. ftoption_command = process_header_command
  203. # GZip support
  204. zlib_dep = dependency('zlib',
  205. required: get_option('zlib'),
  206. fallback: 'zlib')
  207. if zlib_dep.found()
  208. ftoption_command += [
  209. '--enable=FT_CONFIG_OPTION_USE_ZLIB',
  210. '--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB',
  211. ]
  212. ft2_sources += files(['src/gzip/ftgzip.c',])
  213. ft2_deps += [zlib_dep]
  214. else
  215. ftoption_command += ['--disable=FT_CONFIG_OPTION_USE_ZLIB']
  216. endif
  217. # BZip2 support
  218. bzip2_dep = cc.find_library('bz2',
  219. required: get_option('bzip2'))
  220. if bzip2_dep.found()
  221. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BZIP2']
  222. ft2_sources += files(['src/bzip2/ftbzip2.c',])
  223. ft2_deps += [bzip2_dep]
  224. endif
  225. # PNG support
  226. libpng_dep = dependency('libpng',
  227. required: get_option('png'),
  228. fallback: 'libpng')
  229. if libpng_dep.found()
  230. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_PNG']
  231. ft2_deps += [libpng_dep]
  232. endif
  233. # Harfbuzz support
  234. harfbuzz_dep = dependency('harfbuzz',
  235. version: '>= 2.0.0',
  236. required: get_option('harfbuzz'))
  237. if harfbuzz_dep.found()
  238. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ']
  239. ft2_deps += [harfbuzz_dep]
  240. endif
  241. # Brotli decompression support
  242. brotli_dep = dependency('libbrotlidec',
  243. required: get_option('brotli'))
  244. if brotli_dep.found()
  245. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BROTLI']
  246. ft2_deps += [brotli_dep]
  247. endif
  248. # We can now generate `ftoption.h`.
  249. ftoption_h = custom_target('ftoption.h',
  250. input: 'include/freetype/config/ftoption.h',
  251. output: 'ftoption.h',
  252. command: ftoption_command,
  253. install: true,
  254. install_dir: 'include/freetype2/freetype/config',
  255. )
  256. ft2_sources += ftoption_h
  257. ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>']
  258. if host_machine.system() == 'windows'
  259. ft2_defines += ['-DDLL_EXPORT=1']
  260. endif
  261. # Generate `ftconfig.h`.
  262. ftconfig_command = process_header_command
  263. if has_unistd_h
  264. ftconfig_command += '--enable=HAVE_UNISTD_H'
  265. endif
  266. if has_fcntl_h
  267. ftconfig_command += '--enable=HAVE_FCNTL_H'
  268. endif
  269. if use_unix_ftsystem_c
  270. ftconfig_h_in = files('builds/unix/ftconfig.h.in')
  271. ftconfig_h = custom_target('ftconfig.h',
  272. input: ftconfig_h_in,
  273. output: 'ftconfig.h',
  274. command: ftconfig_command,
  275. install: true,
  276. install_dir: 'include/freetype2/freetype/config',
  277. )
  278. ft2_sources += ftconfig_h
  279. ft2_defines += ['-DFT_CONFIG_CONFIG_H=<ftconfig.h>']
  280. endif
  281. ft2_lib = library('freetype',
  282. sources: ft2_sources + [ftmodule_h],
  283. c_args: ft2_defines,
  284. gnu_symbol_visibility: 'hidden',
  285. include_directories: ft2_includes,
  286. dependencies: ft2_deps,
  287. install: true,
  288. version: ft2_so_version,
  289. )
  290. # To be used by other projects including this one through `subproject`.
  291. freetype_dep = declare_dependency(
  292. include_directories: ft2_includes,
  293. link_with: ft2_lib,
  294. version: ft2_pkgconfig_version)
  295. meson.override_dependency('freetype2', freetype_dep)
  296. # NOTE: Using both `install_dir` and `subdir` doesn't seem to work below,
  297. # i.e., the subdir value seems to be ignored, contrary to examples in the
  298. # Meson documentation.
  299. install_headers('include/ft2build.h',
  300. install_dir: 'include/freetype2')
  301. install_headers(ft2_public_headers,
  302. install_dir: 'include/freetype2/freetype')
  303. install_headers(ft2_config_headers,
  304. install_dir: 'include/freetype2/freetype/config')
  305. pkgconfig = import('pkgconfig')
  306. pkgconfig.generate(ft2_lib,
  307. filebase: 'freetype2',
  308. name: 'FreeType 2',
  309. description: 'A free, high-quality, and portable font engine.',
  310. url: 'https://freetype.org',
  311. subdirs: 'freetype2',
  312. version: ft2_pkgconfig_version,
  313. )
  314. if get_option('tests').enabled()
  315. subdir('tests')
  316. endif
  317. # NOTE: Unlike the old `make refdoc` command, this generates the
  318. # documentation under `$BUILD/docs/` since Meson doesn't support modifying
  319. # the source root directory (which is a good thing).
  320. gen_docs = custom_target('freetype2 reference documentation',
  321. output: 'docs',
  322. input: ft2_public_headers + ft2_config_headers,
  323. command: [python_exe,
  324. files('builds/meson/generate_reference_docs.py'),
  325. '--version=' + meson.project_version(),
  326. '--input-dir=' + meson.source_root(),
  327. '--output-dir=@OUTPUT@'
  328. ],
  329. )
  330. summary({'OS': host_machine.system(),
  331. 'Zlib': zlib_dep.found() ? 'yes' : 'no',
  332. 'Bzip2': bzip2_dep.found() ? 'yes' : 'no',
  333. 'Png': libpng_dep.found() ? 'yes' : 'no',
  334. 'Harfbuzz': harfbuzz_dep.found() ? 'yes' : 'no',
  335. 'Brotli': brotli_dep.found() ? 'yes' : 'no',
  336. }, section: 'Configuration Options Summary:')
  337. # EOF