• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1project('openh264', ['c', 'cpp'],
2  version : '2.2.0',
3  meson_version : '>= 0.52',
4  default_options : [ 'warning_level=1',
5                      'buildtype=debugoptimized' ])
6
7major_version = '6'
8
9cpp = meson.get_compiler('cpp')
10
11inc = include_directories([
12  join_paths('codec', 'api', 'svc'),
13  join_paths('codec', 'common', 'inc'),
14])
15
16processing_inc = include_directories([
17  join_paths('codec', 'processing', 'interface'),
18  join_paths('codec', 'processing', 'src', 'common'),
19  join_paths('codec', 'processing', 'src', 'adaptivequantization'),
20  join_paths('codec', 'processing', 'src', 'downsample'),
21  join_paths('codec', 'processing', 'src', 'scrolldetection'),
22  join_paths('codec', 'processing', 'src', 'vaacalc'),
23])
24
25console_common_inc = include_directories([
26  join_paths('codec', 'console', 'common', 'inc')
27])
28
29decoder_inc = include_directories([
30  join_paths('codec', 'decoder', 'core', 'inc'),
31  join_paths('codec', 'decoder', 'plus', 'inc'),
32])
33
34encoder_inc = include_directories([
35  join_paths('codec', 'encoder', 'core', 'inc'),
36  join_paths('codec', 'encoder', 'plus', 'inc'),
37])
38
39system = host_machine.system()
40cpu_family = host_machine.cpu_family()
41
42supported_arguments = cpp.get_supported_arguments([
43  '-Wno-non-virtual-dtor',
44  '-Wno-class-memaccess',
45  '-Wno-strict-aliasing'])
46
47add_project_arguments(supported_arguments, language: 'cpp')
48
49deps = [dependency('threads')]
50c_args = []
51cpp_args = []
52asm_args = []
53asm_inc = []
54casm_inc = []
55cpp_lib = '-lstdc++'
56
57# TODO: should rely on dependency('threads') instead and change the pkg-config
58# generator below
59pthread_dep = cpp.find_library('pthread', required : false)
60libm_dep = cpp.find_library('libm', required : false)
61deps += [libm_dep]
62
63if ['linux', 'android', 'ios', 'darwin'].contains(system)
64  asm_format32 = 'elf'
65  asm_format64 = 'elf64'
66  if ['ios', 'darwin'].contains(system)
67    asm_format32 = 'macho32'
68    asm_format64 = 'macho64'
69  endif
70  if cpu_family == 'x86'
71    asm_format = asm_format32
72    asm_args += ['-DX86_32', '-DHAVE_AVX2']
73    add_project_arguments('-DHAVE_AVX2', language: 'cpp')
74    add_project_arguments('-DHAVE_AVX2', '-DX86_ASM', '-DX86_32_ASM', language: 'c')
75    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
76  elif cpu_family == 'x86_64'
77    asm_format = asm_format64
78    asm_args += ['-DUNIX64', '-DHAVE_AVX2']
79    add_project_arguments('-DHAVE_AVX2', language: 'cpp')
80    add_project_arguments('-DHAVE_AVX2', '-DX86_ASM', language: 'c')
81    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
82  elif cpu_family == 'arm'
83    asm_format = asm_format32
84    add_project_arguments('-DHAVE_NEON', language: 'c')
85    add_project_arguments('-DHAVE_NEON', language: 'c')
86    casm_inc = include_directories(join_paths('codec', 'common', 'arm'))
87  elif cpu_family == 'aarch64'
88    asm_format = asm_format64
89    add_project_arguments('-DHAVE_NEON_ARM64', language: 'c')
90    add_project_arguments('-DHAVE_NEON_ARM64', language: 'cpp')
91    casm_inc = include_directories(join_paths('codec', 'common', 'arm64'))
92  else
93    error('FIXME: unhandled CPU family @0@ for @1@'.format(cpu_family, system))
94  endif
95
96  if ['ios', 'darwin', 'android'].contains(system)
97    cpp_lib = '-lc++'
98  endif
99elif system == 'windows'
100  if cpu_family == 'x86'
101    asm_format = 'win32'
102    asm_args += ['-DPREFIX', '-DX86_32']
103    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
104  elif cpu_family == 'x86_64'
105    asm_format = 'win64'
106    asm_args += ['-DWIN64']
107    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
108  elif cpu_family == 'arm'
109    if cpp.get_argument_syntax() == 'msvc'
110      asm_format = 'armasm'
111      asm_args += ['-nologo', '-DHAVE_NEON', '-ignore', '4509']
112      asm_cmds = ['armasm']
113    else
114      asm_format = 'clang'
115      asm_args += ['-DHAVE_NEON', '-mimplicit-it=always']
116      asm_cmds = cpp.cmd_array()
117    endif
118    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm', '')
119  elif cpu_family == 'aarch64'
120    asm_format = 'armasm'
121    asm_args += ['-nologo', '-DHAVE_NEON_AARCH64']
122    asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm64', '')
123  else
124    error('FIXME: unhandled CPU family @0@ for Windows'.format(cpu_family))
125  endif
126else
127  error('FIXME: Unhandled system @0@'.format(system))
128endif
129
130use_asm_gen = false
131if cpu_family in ['x86', 'x86_64']
132  nasm = find_program('nasm')
133
134  use_asm_gen = true
135  asm_gen = generator(nasm,
136    output : '@BASENAME@.o',
137    arguments : [
138      '-f', asm_format,
139      '-i', asm_inc,
140      '@INPUT@',
141      '-o', '@OUTPUT@'] + asm_args)
142elif system == 'windows'
143  if  cpu_family == 'arm'
144    # For ARM, gas-preprocessor is needed for converting the asm to be
145    # buildable as thumb even with Clang.
146    use_asm_gen = true
147    gasprep = find_program('gas-preprocessor.pl')
148    asm_gen = generator(gasprep,
149      output : '@BASENAME@.obj',
150      arguments : [
151        '-as-type', asm_format,
152        '-force-thumb',
153        '--'
154        ] + asm_cmds + [
155        '-I' + asm_inc] + asm_args + [
156        '@INPUT@',
157        '-c', '-o', '@OUTPUT@'])
158  elif cpu_family == 'aarch64'
159    # For ARM64, Clang can build the assembly as-is without needing to use
160    # either gas-preprocessor or armasm64.
161    if cpp.get_argument_syntax() == 'msvc'
162      use_asm_gen = true
163      gasprep = find_program('gas-preprocessor.pl')
164      asm_gen = generator(gasprep,
165        output : '@BASENAME@.obj',
166        arguments : [
167          '-as-type', asm_format,
168          '-arch', 'aarch64',
169          '--',
170          'armasm64',
171          '-I' + asm_inc] + asm_args + [
172          '@INPUT@',
173          '-c', '-o', '@OUTPUT@'])
174    endif
175  else
176    # Windows only supports x86, x86_64, arm, arm64
177    error('unreachable code')
178  endif
179endif
180
181api_headers = []
182api_header_deps = []
183
184subdir ('codec')
185subdir ('test')
186
187libopenh264_shared = library('openh264',
188  link_with: [libcommon, libprocessing, libencoder, libdecoder],
189  install: true,
190  soversion: major_version,
191  version: meson.project_version(),
192  vs_module_defs: 'openh264.def',
193  dependencies: deps)
194
195pkg_install_dir = '@0@/pkgconfig'.format(get_option('libdir'))
196
197foreach t : ['', '-static']
198  pkgconf = configuration_data()
199  pkgconf.set('prefix', join_paths(get_option('prefix')))
200  pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir')))
201  pkgconf.set('VERSION', meson.project_version())
202  pkglibs = cpp_lib
203  if libm_dep.found()
204    pkglibs += ' -lm'
205  endif
206  if pthread_dep.found()
207    pkglibs += ' -lpthread'
208  endif
209  if t == '-static'
210    pkgconf.set('LIBS', pkglibs)
211    pkgconf.set('LIBS_PRIVATE', '')
212  else
213    pkgconf.set('LIBS', '')
214    pkgconf.set('LIBS_PRIVATE', pkglibs)
215  endif
216
217  configure_file(
218    input: 'openh264.pc.in',
219    output: 'openh264@0@.pc'.format(t),
220    install: t == '-static' ? false : true,
221    install_dir: t == '-static' ? '' : pkg_install_dir,
222    configuration: pkgconf)
223endforeach
224
225openh264_dep = declare_dependency(
226  link_with: libopenh264_shared,
227  include_directories: include_directories('include'),
228  dependencies: deps + api_header_deps)
229
230subdir ('include')
231