Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 1 | project('openh264', ['c', 'cpp'], |
Michael Catanzaro | 4a51b79 | 2020-04-06 19:20:30 -0500 | [diff] [blame] | 2 | version : '2.1.0', |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 3 | meson_version : '>= 0.50', |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 4 | default_options : [ 'warning_level=1', |
| 5 | 'buildtype=debugoptimized' ]) |
| 6 | |
Michael Catanzaro | d644364 | 2020-04-07 15:24:54 -0500 | [diff] [blame] | 7 | major_version = '6' |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 8 | |
| 9 | cpp = meson.get_compiler('cpp') |
| 10 | |
| 11 | inc = include_directories([ |
| 12 | join_paths('codec', 'api', 'svc'), |
| 13 | join_paths('codec', 'common', 'inc'), |
| 14 | ]) |
| 15 | |
| 16 | processing_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 | |
| 25 | console_common_inc = include_directories([ |
| 26 | join_paths('codec', 'console', 'common', 'inc') |
| 27 | ]) |
| 28 | |
| 29 | decoder_inc = include_directories([ |
| 30 | join_paths('codec', 'decoder', 'core', 'inc'), |
| 31 | join_paths('codec', 'decoder', 'plus', 'inc'), |
| 32 | ]) |
| 33 | |
| 34 | encoder_inc = include_directories([ |
| 35 | join_paths('codec', 'encoder', 'core', 'inc'), |
| 36 | join_paths('codec', 'encoder', 'plus', 'inc'), |
| 37 | ]) |
| 38 | |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 39 | system = host_machine.system() |
| 40 | cpu_family = host_machine.cpu_family() |
| 41 | |
| 42 | supported_arguments = cpp.get_supported_arguments([ |
| 43 | '-Wno-non-virtual-dtor', |
Thibault Saunier | b09e4ee | 2018-06-28 15:30:37 -0400 | [diff] [blame] | 44 | '-Wno-class-memaccess', |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 45 | '-Wno-strict-aliasing']) |
| 46 | |
| 47 | add_project_arguments(supported_arguments, language: 'cpp') |
| 48 | |
| 49 | deps = [dependency('threads')] |
| 50 | c_args = [] |
| 51 | cpp_args = [] |
| 52 | asm_args = [] |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 53 | asm_inc = [] |
| 54 | casm_inc = [] |
| 55 | cpp_lib = '-lstdc++' |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 56 | |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 57 | # TODO: should rely on dependency('threads') instead and change the pkg-config |
| 58 | # generator below |
| 59 | pthread_dep = cpp.find_library('pthread', required : false) |
| 60 | libm_dep = cpp.find_library('libm', required : false) |
| 61 | deps += [libm_dep] |
| 62 | |
| 63 | if ['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 Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 70 | if cpu_family == 'x86' |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 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', '') |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 76 | elif cpu_family == 'x86_64' |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 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')) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 92 | else |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 93 | error('FIXME: unhandled CPU family @0@ for @1@'.format(cpu_family, system)) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 94 | endif |
| 95 | |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 96 | if ['ios', 'darwin', 'android'].contains(system) |
| 97 | cpp_lib = '-lc++' |
| 98 | endif |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 99 | elif system == 'windows' |
| 100 | if cpu_family == 'x86' |
| 101 | asm_format = 'win32' |
| 102 | asm_args += ['-DPREFIX', '-DX86_32'] |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 103 | asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '') |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 104 | elif cpu_family == 'x86_64' |
| 105 | asm_format = 'win64' |
| 106 | asm_args += ['-DWIN64'] |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 107 | asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'x86', '') |
| 108 | elif cpu_family == 'arm' |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 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() |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 117 | endif |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 118 | asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm', '') |
| 119 | elif cpu_family == 'aarch64' |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 120 | asm_format = 'armasm' |
| 121 | asm_args += ['-nologo', '-DHAVE_NEON_AARCH64'] |
| 122 | asm_inc = join_paths(meson.current_source_dir(), 'codec', 'common', 'arm64', '') |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 123 | else |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 124 | error('FIXME: unhandled CPU family @0@ for Windows'.format(cpu_family)) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 125 | endif |
| 126 | else |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 127 | error('FIXME: Unhandled system @0@'.format(system)) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 128 | endif |
| 129 | |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 130 | use_asm_gen = false |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 131 | if cpu_family in ['x86', 'x86_64'] |
| 132 | nasm = find_program('nasm') |
| 133 | |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 134 | use_asm_gen = true |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 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) |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 142 | elif system == 'windows' |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 143 | if cpu_family == 'arm' |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 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') |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 148 | asm_gen = generator(gasprep, |
| 149 | output : '@BASENAME@.obj', |
| 150 | arguments : [ |
| 151 | '-as-type', asm_format, |
| 152 | '-force-thumb', |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 153 | '--' |
| 154 | ] + asm_cmds + [ |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 155 | '-I' + asm_inc] + asm_args + [ |
| 156 | '@INPUT@', |
| 157 | '-c', '-o', '@OUTPUT@']) |
| 158 | elif cpu_family == 'aarch64' |
Martin Storsjö | 35a956a | 2020-09-16 23:53:11 +0300 | [diff] [blame] | 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 |
Nirbheek Chauhan | 013c456 | 2020-06-17 21:35:33 +0530 | [diff] [blame] | 175 | else |
| 176 | # Windows only supports x86, x86_64, arm, arm64 |
| 177 | error('unreachable code') |
| 178 | endif |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 179 | endif |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 180 | |
| 181 | api_headers = [] |
| 182 | api_header_deps = [] |
| 183 | |
| 184 | subdir ('codec') |
| 185 | subdir ('test') |
| 186 | |
| 187 | all_objects = [ |
| 188 | libcommon.extract_all_objects(), |
| 189 | libprocessing.extract_all_objects(), |
| 190 | libencoder.extract_all_objects(), |
| 191 | libdecoder.extract_all_objects() |
| 192 | ] |
| 193 | |
| 194 | libopenh264_shared = shared_library('openh264', |
| 195 | objects: all_objects, |
| 196 | install: true, |
Aleksey Filippov | a77c284 | 2018-04-21 21:48:36 +0100 | [diff] [blame] | 197 | soversion: major_version, |
| 198 | version: meson.project_version(), |
Nirbheek Chauhan | e0917df | 2019-02-05 22:28:41 +0530 | [diff] [blame] | 199 | vs_module_defs: 'openh264.def', |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 200 | dependencies: deps) |
| 201 | |
| 202 | libopenh264_static = static_library('openh264', |
| 203 | objects: all_objects, |
| 204 | install: true, |
| 205 | dependencies: deps) |
| 206 | |
| 207 | pkg_install_dir = '@0@/pkgconfig'.format(get_option('libdir')) |
| 208 | |
| 209 | foreach t : ['', '-static'] |
| 210 | pkgconf = configuration_data() |
| 211 | pkgconf.set('prefix', join_paths(get_option('prefix'))) |
Julien Isorce | d6a3614 | 2020-01-28 14:08:02 -0800 | [diff] [blame] | 212 | pkgconf.set('libdir', '${prefix}/@0@'.format(get_option('libdir'))) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 213 | pkgconf.set('VERSION', meson.project_version()) |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 214 | pkglibs = cpp_lib |
| 215 | if libm_dep.found() |
| 216 | pkglibs += ' -lm' |
| 217 | endif |
| 218 | if pthread_dep.found() |
| 219 | pkglibs += ' -lpthread' |
| 220 | endif |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 221 | if t == '-static' |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 222 | pkgconf.set('LIBS', pkglibs) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 223 | pkgconf.set('LIBS_PRIVATE', '') |
| 224 | else |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 225 | pkgconf.set('LIBS', '') |
Matthew Waters | a396835 | 2020-03-10 12:06:56 +1100 | [diff] [blame] | 226 | pkgconf.set('LIBS_PRIVATE', pkglibs) |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 227 | endif |
| 228 | |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 229 | 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) |
| 235 | endforeach |
| 236 | |
| 237 | openh264_dep = declare_dependency( |
| 238 | link_with: libopenh264_shared, |
| 239 | include_directories: include_directories('include'), |
| 240 | dependencies: deps + api_header_deps) |
| 241 | |
Mathieu Duponchelle | bb896db | 2018-04-14 23:03:33 +0200 | [diff] [blame] | 242 | subdir ('include') |