🛠️🐜 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.

466 lines
13 KiB

  1. #
  2. # Meson project file for FreeType 2
  3. #
  4. # Copyright (C) 2020-2022 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. version: run_command('builds/meson/extract_freetype_version.py',
  26. 'include/freetype/freetype.h',
  27. check: true).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_exe = find_program('python3')
  33. ft2_so_version = run_command(python_exe,
  34. files('builds/meson/extract_libtool_version.py'),
  35. '--soversion',
  36. files('builds/unix/configure.raw'),
  37. check: true).stdout().strip()
  38. ft2_pkgconfig_version = run_command(python_exe,
  39. files('builds/meson/extract_libtool_version.py'),
  40. files('builds/unix/configure.raw'),
  41. check: true).stdout().strip()
  42. ft2_includes = include_directories('include')
  43. freetype_includedir = join_paths(get_option('includedir'), 'freetype2')
  44. # Generate a custom `ftmodule.h` version based on the content of
  45. # `modules.cfg`.
  46. ftmodule_h = custom_target('ftmodule.h',
  47. output: 'ftmodule.h',
  48. input: 'modules.cfg',
  49. command: [python_exe, files('builds/meson/parse_modules_cfg.py'),
  50. '--format=ftmodule.h', '@INPUT@', '--output', '@OUTPUT@'],
  51. install: true,
  52. install_dir: join_paths(freetype_includedir, 'freetype/config'),
  53. )
  54. ft2_sources = [ftmodule_h]
  55. # FreeType 2 modules.
  56. ft_main_modules = run_command(python_exe,
  57. files('builds/meson/parse_modules_cfg.py'),
  58. '--format=main-modules',
  59. files('modules.cfg'),
  60. check: true).stdout().strip().split()
  61. ft2_sources += files([
  62. 'src/base/ftbase.c',
  63. 'src/base/ftinit.c',
  64. ])
  65. foreach mod: ft_main_modules
  66. source = mod
  67. if mod == 'winfonts'
  68. source = 'winfnt'
  69. elif mod == 'cid'
  70. source = 'type1cid'
  71. endif
  72. ft2_sources += 'src/@0@/@1@.c'.format(mod, source)
  73. endforeach
  74. # NOTE: The `bzip2` aux module is handled through options.
  75. ft_aux_modules = run_command(python_exe,
  76. files('builds/meson/parse_modules_cfg.py'),
  77. '--format=aux-modules',
  78. files('modules.cfg'),
  79. check: true).stdout().strip().split()
  80. foreach auxmod: ft_aux_modules
  81. source = auxmod
  82. # Most sources are named `src/<module>/<module>.c`, but there are a few
  83. # exceptions handled here.
  84. if auxmod == 'cache'
  85. source = 'ftcache'
  86. elif auxmod == 'lzw'
  87. source = 'ftlzw'
  88. elif auxmod == 'gzip'
  89. source = 'ftgzip'
  90. elif auxmod == 'bzip2'
  91. # Handled through options instead, see below.
  92. continue
  93. endif
  94. ft2_sources += 'src/@0@/@1@.c'.format(auxmod, source)
  95. endforeach
  96. # FreeType 2 base extensions.
  97. # To be configured in `modules.cfg`.
  98. base_extensions = run_command(python_exe,
  99. files('builds/meson/parse_modules_cfg.py'),
  100. '--format=base-extensions-list',
  101. files('modules.cfg'),
  102. check: true).stdout().split()
  103. foreach ext: base_extensions
  104. ft2_sources += files('src/base/' + ext)
  105. endforeach
  106. # Header files.
  107. ft2_public_headers = files([
  108. 'include/freetype/freetype.h',
  109. 'include/freetype/ftadvanc.h',
  110. 'include/freetype/ftbbox.h',
  111. 'include/freetype/ftbdf.h',
  112. 'include/freetype/ftbitmap.h',
  113. 'include/freetype/ftbzip2.h',
  114. 'include/freetype/ftcache.h',
  115. 'include/freetype/ftchapters.h',
  116. 'include/freetype/ftcid.h',
  117. 'include/freetype/ftcolor.h',
  118. 'include/freetype/ftdriver.h',
  119. 'include/freetype/fterrdef.h',
  120. 'include/freetype/fterrors.h',
  121. 'include/freetype/ftfntfmt.h',
  122. 'include/freetype/ftgasp.h',
  123. 'include/freetype/ftglyph.h',
  124. 'include/freetype/ftgxval.h',
  125. 'include/freetype/ftgzip.h',
  126. 'include/freetype/ftimage.h',
  127. 'include/freetype/ftincrem.h',
  128. 'include/freetype/ftlcdfil.h',
  129. 'include/freetype/ftlist.h',
  130. 'include/freetype/ftlzw.h',
  131. 'include/freetype/ftmac.h',
  132. 'include/freetype/ftmm.h',
  133. 'include/freetype/ftmodapi.h',
  134. 'include/freetype/ftmoderr.h',
  135. 'include/freetype/ftotval.h',
  136. 'include/freetype/ftoutln.h',
  137. 'include/freetype/ftparams.h',
  138. 'include/freetype/ftpfr.h',
  139. 'include/freetype/ftrender.h',
  140. 'include/freetype/ftsizes.h',
  141. 'include/freetype/ftsnames.h',
  142. 'include/freetype/ftstroke.h',
  143. 'include/freetype/ftsynth.h',
  144. 'include/freetype/ftsystem.h',
  145. 'include/freetype/fttrigon.h',
  146. 'include/freetype/fttypes.h',
  147. 'include/freetype/ftwinfnt.h',
  148. 'include/freetype/otsvg.h',
  149. 'include/freetype/t1tables.h',
  150. 'include/freetype/ttnameid.h',
  151. 'include/freetype/tttables.h',
  152. 'include/freetype/tttags.h',
  153. ])
  154. ft2_config_headers = files([
  155. 'include/freetype/config/ftconfig.h',
  156. 'include/freetype/config/ftheader.h',
  157. 'include/freetype/config/ftstdlib.h',
  158. 'include/freetype/config/integer-types.h',
  159. 'include/freetype/config/mac-support.h',
  160. 'include/freetype/config/public-macros.h',
  161. ])
  162. ft2_defines = ['-DFT2_BUILD_LIBRARY=1']
  163. # System support file.
  164. cc = meson.get_compiler('c')
  165. # NOTE: msys2 on Windows has `unistd.h` and `fcntl.h` but not `sys/mman.h`!
  166. has_unistd_h = cc.has_header('unistd.h')
  167. has_fcntl_h = cc.has_header('fcntl.h')
  168. has_sys_mman_h = cc.has_header('sys/mman.h')
  169. mmap_option = get_option('mmap')
  170. use_unix_ftsystem_c = false
  171. if mmap_option.disabled()
  172. ft2_sources += files(['src/base/ftsystem.c',])
  173. elif host_machine.system() == 'windows'
  174. ft2_sources += files(['builds/windows/ftsystem.c',])
  175. else
  176. if has_unistd_h and has_fcntl_h and has_sys_mman_h
  177. # This version of `ftsystem.c` uses `mmap` to read input font files.
  178. ft2_sources += files(['builds/unix/ftsystem.c',])
  179. use_unix_ftsystem_c = true
  180. elif mmap_option.enabled()
  181. error('mmap was enabled via options but is not available,'
  182. + ' required headers were not found!')
  183. else
  184. ft2_sources += files(['src/base/ftsystem.c',])
  185. endif
  186. endif
  187. # Debug support file
  188. #
  189. # NOTE: Some specialized versions exist for other platforms not supported by
  190. # Meson. Most implementation differences are extremely minor, i.e., in the
  191. # implementation of `FT_Message` and `FT_Panic`, and getting the `FT2_DEBUG`
  192. # value from the environment, when this is supported. A smaller refactor
  193. # might make these platform-specific files much smaller, and could be moved
  194. # into `ftsystem.c` as well.
  195. #
  196. if host_machine.system() == 'windows'
  197. winmod = import('windows')
  198. ft2_sources += [
  199. 'builds/windows/ftdebug.c',
  200. winmod.compile_resources('src/base/ftver.rc'),
  201. ]
  202. else
  203. ft2_sources += 'src/base/ftdebug.c'
  204. endif
  205. ft2_deps = []
  206. common_ldflags = []
  207. # Correct compatibility version for OS x.
  208. #
  209. # OSX sets the compatibility_version (aka libtools version) differently from
  210. # the library name.
  211. #
  212. if host_machine.system() == 'darwin'
  213. # maintain compatibility with autotools on macOS
  214. common_ldflags = [
  215. '-compatibility_version', ft2_pkgconfig_version.split('.')[0],
  216. '-current_version', ft2_pkgconfig_version
  217. ]
  218. endif
  219. # Generate `ftoption.h` based on available dependencies.
  220. process_header_command = [python_exe,
  221. files('builds/meson/process_ftoption_h.py'),
  222. '@INPUT@', '--output=@OUTPUT@']
  223. ftoption_command = process_header_command
  224. # external GZip support
  225. zlib_option = get_option('zlib')
  226. # Backwards-compatible aliases.
  227. if zlib_option == 'disabled'
  228. zlib_option = 'none'
  229. elif zlib_option == 'enabled'
  230. zlib_option = 'auto'
  231. endif
  232. if zlib_option == 'auto'
  233. # First try to find a system installation, otherwise fall back to
  234. # the subproject.
  235. zlib_dep = dependency('zlib',
  236. required: false)
  237. if zlib_dep.found()
  238. zlib_option = 'system'
  239. else
  240. zlib_option = 'external'
  241. endif
  242. endif
  243. if zlib_option == 'none'
  244. ftoption_command += [ '--disable=FT_CONFIG_OPTION_USE_ZLIB' ]
  245. elif zlib_option == 'internal'
  246. ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ]
  247. elif zlib_option == 'external'
  248. ftoption_command += [ '--enable=FT_CONFIG_OPTION_USE_ZLIB' ]
  249. zlib_project = subproject('zlib',
  250. required: true,
  251. default_options: 'default_library=static')
  252. zlib_dep = zlib_project.get_variable('zlib_dep')
  253. ft2_deps += [zlib_dep]
  254. elif zlib_option == 'system'
  255. zlib_dep = dependency('zlib',
  256. required: true)
  257. assert(zlib_dep.found(), 'Could not find system zlib installation!')
  258. ftoption_command += [
  259. '--enable=FT_CONFIG_OPTION_USE_ZLIB',
  260. '--enable=FT_CONFIG_OPTION_SYSTEM_ZLIB',
  261. ]
  262. ft2_deps += [zlib_dep]
  263. else
  264. assert(false, 'Invalid zlib option ' + zlib_option)
  265. endif
  266. # BZip2 support
  267. bzip2_dep = cc.find_library('bz2',
  268. required: get_option('bzip2'))
  269. if bzip2_dep.found()
  270. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BZIP2']
  271. ft2_sources += files(['src/bzip2/ftbzip2.c',])
  272. ft2_deps += [bzip2_dep]
  273. endif
  274. # PNG support
  275. libpng_dep = dependency('libpng',
  276. required: get_option('png'),
  277. fallback: 'libpng')
  278. if libpng_dep.found()
  279. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_PNG']
  280. ft2_deps += [libpng_dep]
  281. endif
  282. # Harfbuzz support
  283. harfbuzz_dep = dependency('harfbuzz',
  284. version: '>= 2.0.0',
  285. required: get_option('harfbuzz'))
  286. if harfbuzz_dep.found()
  287. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_HARFBUZZ']
  288. ft2_deps += [harfbuzz_dep]
  289. endif
  290. # Brotli decompression support
  291. brotli_dep = dependency('libbrotlidec',
  292. required: get_option('brotli'))
  293. if brotli_dep.found()
  294. ftoption_command += ['--enable=FT_CONFIG_OPTION_USE_BROTLI']
  295. ft2_deps += [brotli_dep]
  296. endif
  297. # We can now generate `ftoption.h`.
  298. ftoption_h = custom_target('ftoption.h',
  299. input: 'include/freetype/config/ftoption.h',
  300. output: 'ftoption.h',
  301. command: ftoption_command,
  302. install: true,
  303. install_dir: join_paths(freetype_includedir, 'freetype/config'),
  304. )
  305. ft2_sources += ftoption_h
  306. ft2_defines += ['-DFT_CONFIG_OPTIONS_H=<ftoption.h>']
  307. if host_machine.system() == 'windows'
  308. ft2_defines += ['-DDLL_EXPORT=1']
  309. endif
  310. # Generate `ftconfig.h`.
  311. ftconfig_command = process_header_command
  312. if has_unistd_h
  313. ftconfig_command += '--enable=HAVE_UNISTD_H'
  314. endif
  315. if has_fcntl_h
  316. ftconfig_command += '--enable=HAVE_FCNTL_H'
  317. endif
  318. if use_unix_ftsystem_c
  319. ftconfig_h_in = files('builds/unix/ftconfig.h.in')
  320. ftconfig_h = custom_target('ftconfig.h',
  321. input: ftconfig_h_in,
  322. output: 'ftconfig.h',
  323. command: ftconfig_command,
  324. install: true,
  325. install_dir: join_paths(freetype_includedir, 'freetype/config'),
  326. )
  327. ft2_sources += ftconfig_h
  328. ft2_defines += ['-DFT_CONFIG_CONFIG_H=<ftconfig.h>']
  329. endif
  330. ft2_lib = library('freetype',
  331. sources: ft2_sources + [ftmodule_h],
  332. c_args: ft2_defines,
  333. gnu_symbol_visibility: 'hidden',
  334. include_directories: ft2_includes,
  335. dependencies: ft2_deps,
  336. install: true,
  337. version: ft2_so_version,
  338. link_args: common_ldflags,
  339. )
  340. # To be used by other projects including this one through `subproject`.
  341. freetype_dep = declare_dependency(
  342. include_directories: ft2_includes,
  343. link_with: ft2_lib,
  344. version: ft2_pkgconfig_version)
  345. meson.override_dependency('freetype2', freetype_dep)
  346. # NOTE: Using both `install_dir` and `subdir` doesn't seem to work below,
  347. # i.e., the subdir value seems to be ignored, contrary to examples in the
  348. # Meson documentation.
  349. install_headers('include/ft2build.h',
  350. install_dir: freetype_includedir)
  351. install_headers(ft2_public_headers,
  352. install_dir: join_paths(freetype_includedir, 'freetype'))
  353. install_headers(ft2_config_headers,
  354. install_dir: join_paths(freetype_includedir, 'freetype/config'))
  355. pkgconfig = import('pkgconfig')
  356. pkgconfig.generate(ft2_lib,
  357. filebase: 'freetype2',
  358. name: 'FreeType 2',
  359. description: 'A free, high-quality, and portable font engine.',
  360. url: 'https://freetype.org',
  361. subdirs: 'freetype2',
  362. version: ft2_pkgconfig_version,
  363. )
  364. if get_option('tests').enabled()
  365. subdir('tests')
  366. endif
  367. # NOTE: Unlike the old `make refdoc` command, this generates the
  368. # documentation under `$BUILD/docs/` since Meson doesn't support modifying
  369. # the source root directory (which is a good thing).
  370. gen_docs = custom_target('freetype2 reference documentation',
  371. output: 'docs',
  372. input: ft2_public_headers + ft2_config_headers,
  373. command: [python_exe,
  374. files('builds/meson/generate_reference_docs.py'),
  375. '--version=' + meson.project_version(),
  376. '--input-dir=' + meson.current_source_dir(),
  377. '--output-dir=@OUTPUT@'
  378. ],
  379. )
  380. summary({'OS': host_machine.system(),
  381. }, section: 'Operating System')
  382. summary({'Zlib': zlib_option,
  383. 'Bzip2': bzip2_dep.found() ? 'yes' : 'no',
  384. 'Png': libpng_dep.found() ? 'yes' : 'no',
  385. 'Harfbuzz': harfbuzz_dep.found() ? 'yes' : 'no',
  386. 'Brotli': brotli_dep.found() ? 'yes' : 'no',
  387. }, section: 'Used Libraries')
  388. # EOF