blob: 283413375b76d6cbad79a5da3367f883b42ac23d [file] [log] [blame]
Mathieu Duponchellebb896db2018-04-14 23:03:33 +02001project('openh264', ['c', 'cpp'],
Michael Catanzaro4a51b792020-04-06 19:20:30 -05002 version : '2.1.0',
Nirbheek Chauhan013c4562020-06-17 21:35:33 +05303 meson_version : '>= 0.50',
Mathieu Duponchellebb896db2018-04-14 23:03:33 +02004 default_options : [ 'warning_level=1',
5 'buildtype=debugoptimized' ])
6
Michael Catanzarod6443642020-04-07 15:24:54 -05007major_version = '6'
Mathieu Duponchellebb896db2018-04-14 23:03:33 +02008
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
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020039system = host_machine.system()
40cpu_family = host_machine.cpu_family()
41
42supported_arguments = cpp.get_supported_arguments([
43 '-Wno-non-virtual-dtor',
Thibault Saunierb09e4ee2018-06-28 15:30:37 -040044 '-Wno-class-memaccess',
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020045 '-Wno-strict-aliasing'])
46
47add_project_arguments(supported_arguments, language: 'cpp')
48
49deps = [dependency('threads')]
50c_args = []
51cpp_args = []
52asm_args = []
Matthew Watersa3968352020-03-10 12:06:56 +110053asm_inc = []
54casm_inc = []
55cpp_lib = '-lstdc++'
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020056
Matthew Watersa3968352020-03-10 12:06:56 +110057# 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
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020070 if cpu_family == 'x86'
Matthew Watersa3968352020-03-10 12:06:56 +110071 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', '')
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020076 elif cpu_family == 'x86_64'
Matthew Watersa3968352020-03-10 12:06:56 +110077 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'))
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020092 else
Nirbheek Chauhan013c4562020-06-17 21:35:33 +053093 error('FIXME: unhandled CPU family @0@ for @1@'.format(cpu_family, system))
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020094 endif
95
Matthew Watersa3968352020-03-10 12:06:56 +110096 if ['ios', 'darwin', 'android'].contains(system)
97 cpp_lib = '-lc++'
98 endif
Mathieu Duponchellebb896db2018-04-14 23:03:33 +020099elif system == 'windows'
100 if cpu_family == 'x86'
101 asm_format = 'win32'
102 asm_args += ['-DPREFIX', '-DX86_32']
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530103 asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200104 elif cpu_family == 'x86_64'
105 asm_format = 'win64'
106 asm_args += ['-DWIN64']
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530107 asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '')
108 elif cpu_family == 'arm'
Martin Storsjö35a956a2020-09-16 23:53:11 +0300109 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()
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530117 endif
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530118 asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm', '')
119 elif cpu_family == 'aarch64'
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530120 asm_format = 'armasm'
121 asm_args += ['-nologo', '-DHAVE_NEON_AARCH64']
122 asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm64', '')
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200123 else
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530124 error('FIXME: unhandled CPU family @0@ for Windows'.format(cpu_family))
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200125 endif
126else
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530127 error('FIXME: Unhandled system @0@'.format(system))
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200128endif
129
Martin Storsjö35a956a2020-09-16 23:53:11 +0300130use_asm_gen = false
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530131if cpu_family in ['x86', 'x86_64']
132 nasm = find_program('nasm')
133
Martin Storsjö35a956a2020-09-16 23:53:11 +0300134 use_asm_gen = true
Matthew Watersa3968352020-03-10 12:06:56 +1100135 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)
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530142elif system == 'windows'
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530143 if cpu_family == 'arm'
Martin Storsjö35a956a2020-09-16 23:53:11 +0300144 # 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')
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530148 asm_gen = generator(gasprep,
149 output : '@BASENAME@.obj',
150 arguments : [
151 '-as-type', asm_format,
152 '-force-thumb',
Martin Storsjö35a956a2020-09-16 23:53:11 +0300153 '--'
154 ] + asm_cmds + [
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530155 '-I' + asm_inc] + asm_args + [
156 '@INPUT@',
157 '-c', '-o', '@OUTPUT@'])
158 elif cpu_family == 'aarch64'
Martin Storsjö35a956a2020-09-16 23:53:11 +0300159 # 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
Nirbheek Chauhan013c4562020-06-17 21:35:33 +0530175 else
176 # Windows only supports x86, x86_64, arm, arm64
177 error('unreachable code')
178 endif
Matthew Watersa3968352020-03-10 12:06:56 +1100179endif
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200180
181api_headers = []
182api_header_deps = []
183
184subdir ('codec')
185subdir ('test')
186
187all_objects = [
188 libcommon.extract_all_objects(),
189 libprocessing.extract_all_objects(),
190 libencoder.extract_all_objects(),
191 libdecoder.extract_all_objects()
192]
193
194libopenh264_shared = shared_library('openh264',
195 objects: all_objects,
196 install: true,
Aleksey Filippova77c2842018-04-21 21:48:36 +0100197 soversion: major_version,
198 version: meson.project_version(),
Nirbheek Chauhane0917df2019-02-05 22:28:41 +0530199 vs_module_defs: 'openh264.def',
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200200 dependencies: deps)
201
202libopenh264_static = static_library('openh264',
203 objects: all_objects,
204 install: true,
205 dependencies: deps)
206
207pkg_install_dir = '@0@/pkgconfig'.format(get_option('libdir'))
208
209foreach t : ['', '-static']
210 pkgconf = configuration_data()
211 pkgconf.set('prefix', join_paths(get_option('prefix')))
Julien Isorced6a36142020-01-28 14:08:02 -0800212 pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir')))
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200213 pkgconf.set('VERSION', meson.project_version())
Matthew Watersa3968352020-03-10 12:06:56 +1100214 pkglibs = cpp_lib
215 if libm_dep.found()
216 pkglibs += ' -lm'
217 endif
218 if pthread_dep.found()
219 pkglibs += ' -lpthread'
220 endif
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200221 if t == '-static'
Matthew Watersa3968352020-03-10 12:06:56 +1100222 pkgconf.set('LIBS', pkglibs)
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200223 pkgconf.set('LIBS_PRIVATE', '')
224 else
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200225 pkgconf.set('LIBS', '')
Matthew Watersa3968352020-03-10 12:06:56 +1100226 pkgconf.set('LIBS_PRIVATE', pkglibs)
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200227 endif
228
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200229 configure_file(
230 input: 'openh264.pc.in',
231 output: 'openh264@0@.pc'.format(t),
232 install: t == '-static' ? false : true,
233 install_dir: t == '-static' ? '' : pkg_install_dir,
234 configuration: pkgconf)
235endforeach
236
237openh264_dep = declare_dependency(
238 link_with: libopenh264_shared,
239 include_directories: include_directories('include'),
240 dependencies: deps + api_header_deps)
241
Mathieu Duponchellebb896db2018-04-14 23:03:33 +0200242subdir ('include')