xref: /aosp_15_r20/external/libdav1d/src/meson.build (revision c09093415860a1c2373dacd84c4fde00c507cdfd)
1# Copyright © 2018-2019, VideoLAN and dav1d authors
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are met:
6#
7# 1. Redistributions of source code must retain the above copyright notice, this
8#    list of conditions and the following disclaimer.
9#
10# 2. Redistributions in binary form must reproduce the above copyright notice,
11#    this list of conditions and the following disclaimer in the documentation
12#    and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
25#
26# Build definition for the dav1d library
27#
28
29# libdav1d source files
30libdav1d_sources = files(
31    'cdf.c',
32    'cpu.c',
33    'ctx.c',
34    'data.c',
35    'decode.c',
36    'dequant_tables.c',
37    'getbits.c',
38    'intra_edge.c',
39    'itx_1d.c',
40    'lf_mask.c',
41    'lib.c',
42    'log.c',
43    'mem.c',
44    'msac.c',
45    'obu.c',
46    'pal.c',
47    'picture.c',
48    'qm.c',
49    'ref.c',
50    'refmvs.c',
51    'scan.c',
52    'tables.c',
53    'thread_task.c',
54    'warpmv.c',
55    'wedge.c',
56)
57
58# libdav1d bitdepth source files
59# These files are compiled for each bitdepth with
60# `BITDEPTH` defined to the currently built bitdepth.
61libdav1d_tmpl_sources = files(
62    'cdef_apply_tmpl.c',
63    'cdef_tmpl.c',
64    'fg_apply_tmpl.c',
65    'filmgrain_tmpl.c',
66    'ipred_prepare_tmpl.c',
67    'ipred_tmpl.c',
68    'itx_tmpl.c',
69    'lf_apply_tmpl.c',
70    'loopfilter_tmpl.c',
71    'looprestoration_tmpl.c',
72    'lr_apply_tmpl.c',
73    'mc_tmpl.c',
74    'recon_tmpl.c',
75)
76
77libdav1d_arch_tmpl_sources = {}
78
79libdav1d_bitdepth_objs = []
80
81# ASM specific sources
82libdav1d_asm_objs = []
83# Arch-specific flags
84arch_flags = {}
85if is_asm_enabled
86    if (host_machine.cpu_family() == 'aarch64' or
87        host_machine.cpu_family().startswith('arm'))
88
89        libdav1d_sources += files(
90            'arm/cpu.c',
91        )
92        if (host_machine.cpu_family() == 'aarch64' or
93            host_machine.cpu() == 'arm64')
94            libdav1d_sources_asm = files(
95                # itx.S is used for both 8 and 16 bpc.
96                'arm/64/itx.S',
97                'arm/64/looprestoration_common.S',
98                'arm/64/msac.S',
99                'arm/64/refmvs.S',
100            )
101
102            if dav1d_bitdepths.contains('8')
103                libdav1d_sources_asm += files(
104                    'arm/64/cdef.S',
105                    'arm/64/filmgrain.S',
106                    'arm/64/ipred.S',
107                    'arm/64/loopfilter.S',
108                    'arm/64/looprestoration.S',
109                    'arm/64/mc.S',
110                    'arm/64/mc_dotprod.S',
111                )
112            endif
113
114            if dav1d_bitdepths.contains('16')
115                libdav1d_sources_asm += files(
116                    'arm/64/cdef16.S',
117                    'arm/64/filmgrain16.S',
118                    'arm/64/ipred16.S',
119                    'arm/64/itx16.S',
120                    'arm/64/loopfilter16.S',
121                    'arm/64/looprestoration16.S',
122                    'arm/64/mc16.S',
123                    'arm/64/mc16_sve.S',
124                )
125            endif
126        elif host_machine.cpu_family().startswith('arm')
127            libdav1d_sources_asm = files(
128                # itx.S is used for both 8 and 16 bpc.
129                'arm/32/itx.S',
130                'arm/32/looprestoration_common.S',
131                'arm/32/msac.S',
132                'arm/32/refmvs.S',
133            )
134
135            if dav1d_bitdepths.contains('8')
136                libdav1d_sources_asm += files(
137                    'arm/32/cdef.S',
138                    'arm/32/filmgrain.S',
139                    'arm/32/ipred.S',
140                    'arm/32/loopfilter.S',
141                    'arm/32/looprestoration.S',
142                    'arm/32/mc.S',
143                )
144            endif
145
146            if dav1d_bitdepths.contains('16')
147                libdav1d_sources_asm += files(
148                    'arm/32/cdef16.S',
149                    'arm/32/filmgrain16.S',
150                    'arm/32/ipred16.S',
151                    'arm/32/itx16.S',
152                    'arm/32/loopfilter16.S',
153                    'arm/32/looprestoration16.S',
154                    'arm/32/mc16.S',
155                )
156            endif
157        endif
158
159        if use_gaspp
160            libdav1d_asm_objs = gaspp_gen.process(libdav1d_sources_asm)
161        else
162            libdav1d_sources += libdav1d_sources_asm
163        endif
164    elif host_machine.cpu_family().startswith('x86')
165
166        libdav1d_sources += files(
167            'x86/cpu.c',
168        )
169
170        # NASM source files
171        libdav1d_sources_asm = files(
172            'x86/cpuid.asm',
173            'x86/msac.asm',
174            'x86/pal.asm',
175            'x86/refmvs.asm',
176            'x86/itx_avx512.asm',
177            'x86/cdef_avx2.asm',
178            'x86/itx_avx2.asm',
179            'x86/cdef_sse.asm',
180            'x86/itx_sse.asm',
181        )
182
183        if dav1d_bitdepths.contains('8')
184            libdav1d_sources_asm += files(
185                'x86/cdef_avx512.asm',
186                'x86/filmgrain_avx512.asm',
187                'x86/ipred_avx512.asm',
188                'x86/loopfilter_avx512.asm',
189                'x86/looprestoration_avx512.asm',
190                'x86/mc_avx512.asm',
191                'x86/filmgrain_avx2.asm',
192                'x86/ipred_avx2.asm',
193                'x86/loopfilter_avx2.asm',
194                'x86/looprestoration_avx2.asm',
195                'x86/mc_avx2.asm',
196                'x86/filmgrain_sse.asm',
197                'x86/ipred_sse.asm',
198                'x86/loopfilter_sse.asm',
199                'x86/looprestoration_sse.asm',
200                'x86/mc_sse.asm',
201            )
202        endif
203
204        if dav1d_bitdepths.contains('16')
205            libdav1d_sources_asm += files(
206                'x86/cdef16_avx512.asm',
207                'x86/filmgrain16_avx512.asm',
208                'x86/ipred16_avx512.asm',
209                'x86/itx16_avx512.asm',
210                'x86/loopfilter16_avx512.asm',
211                'x86/looprestoration16_avx512.asm',
212                'x86/mc16_avx512.asm',
213                'x86/cdef16_avx2.asm',
214                'x86/filmgrain16_avx2.asm',
215                'x86/ipred16_avx2.asm',
216                'x86/itx16_avx2.asm',
217                'x86/loopfilter16_avx2.asm',
218                'x86/looprestoration16_avx2.asm',
219                'x86/mc16_avx2.asm',
220                'x86/cdef16_sse.asm',
221                'x86/filmgrain16_sse.asm',
222                'x86/ipred16_sse.asm',
223                'x86/itx16_sse.asm',
224                'x86/loopfilter16_sse.asm',
225                'x86/looprestoration16_sse.asm',
226                'x86/mc16_sse.asm',
227            )
228        endif
229
230        # Compile the ASM sources with NASM
231        libdav1d_asm_objs = nasm_gen.process(libdav1d_sources_asm)
232    elif host_machine.cpu_family().startswith('loongarch')
233        libdav1d_sources += files(
234            'loongarch/cpu.c',
235        )
236
237        libdav1d_arch_tmpl_sources += {'default': files(
238            'loongarch/looprestoration_tmpl.c',
239        )}
240
241        libdav1d_sources_asm = files(
242            'loongarch/cdef.S',
243            'loongarch/ipred.S',
244            'loongarch/mc.S',
245            'loongarch/loopfilter.S',
246            'loongarch/looprestoration.S',
247            'loongarch/msac.S',
248            'loongarch/refmvs.S',
249            'loongarch/itx.S',
250        )
251        libdav1d_asm_objs += libdav1d_sources_asm
252    elif host_machine.cpu() == 'ppc64le'
253        arch_flags += {'vsx': ['-maltivec', '-mvsx', '-DDAV1D_VSX']}
254        libdav1d_sources += files(
255            'ppc/cpu.c',
256        )
257        libdav1d_arch_tmpl_sources += {'vsx': files(
258            'ppc/cdef_tmpl.c',
259            'ppc/looprestoration_tmpl.c',
260        )}
261        arch_flags += {'pwr9': ['-mcpu=power9', '-DDAV1D_PWR9']}
262        libdav1d_arch_tmpl_sources += {'pwr9': files(
263            'ppc/itx_tmpl.c',
264            'ppc/loopfilter_tmpl.c',
265        )}
266    elif host_machine.cpu_family().startswith('riscv')
267        libdav1d_sources += files(
268            'riscv/cpu.c',
269        )
270        if host_machine.cpu_family() == 'riscv64'
271            libdav1d_sources += files(
272                'riscv/64/cdef.S',
273                'riscv/64/cpu.S',
274                'riscv/64/itx.S',
275                'riscv/64/pal.S',
276                'riscv/64/mc.S',
277            )
278
279            if dav1d_bitdepths.contains('8')
280                libdav1d_sources += files(
281                    'riscv/64/cdef.S',
282                    'riscv/64/ipred.S',
283                )
284            endif
285
286            if dav1d_bitdepths.contains('16')
287                libdav1d_sources += files(
288                    'riscv/64/cdef16.S',
289                    'riscv/64/ipred16.S',
290                )
291            endif
292        endif
293    endif
294endif
295
296
297
298libdav1d_rc_obj = []
299libdav1d_flags = []
300api_export_flags = []
301
302#
303# Windows .rc file and API export flags
304#
305
306if host_machine.system() == 'windows'
307    if get_option('default_library') != 'static'
308        rc_file = configure_file(
309            input : 'dav1d.rc.in',
310            output : 'dav1d.rc',
311            configuration : rc_data
312        )
313
314        libdav1d_rc_obj = winmod.compile_resources(rc_file)
315
316        api_export_flags = ['-DDAV1D_BUILDING_DLL']
317    endif
318
319    if (host_machine.cpu_family() == 'x86_64' and cc.get_id() == 'gcc')
320        # We don't expect to reference data members from other DLLs without
321        # dllimport attributes. Set the -mcmodel=small flag, which avoids
322        # generating indirection via .refptr.<symname> for all potentially
323        # dllimported variable references.
324        libdav1d_flags += '-mcmodel=small'
325    endif
326endif
327
328
329
330#
331# Library definitions
332#
333
334# Helper library for each bitdepth
335libdav1d_bitdepth_objs = []
336foreach bitdepth : dav1d_bitdepths
337    libdav1d_bitdepth_objs += static_library(
338        'dav1d_bitdepth_@0@'.format(bitdepth),
339        libdav1d_tmpl_sources, config_h_target,
340        include_directories: dav1d_inc_dirs,
341        dependencies : [stdatomic_dependencies],
342        c_args : ['-DBITDEPTH=@0@'.format(bitdepth)] + libdav1d_flags,
343        install : false,
344        build_by_default : false,
345    ).extract_all_objects(recursive: true)
346endforeach
347
348# Helper library for each bitdepth and architecture-specific flags
349foreach bitdepth : dav1d_bitdepths
350    foreach subarch : libdav1d_arch_tmpl_sources.keys()
351        libdav1d_bitdepth_objs += static_library(
352            'dav1d_arch_bitdepth_@0@_@1@'.format(bitdepth,subarch),
353            libdav1d_arch_tmpl_sources[subarch], config_h_target,
354            include_directories: dav1d_inc_dirs,
355            dependencies : [stdatomic_dependencies],
356            c_args : ['-DBITDEPTH=@0@'.format(bitdepth)] + libdav1d_flags + arch_flags.get(subarch, []),
357            install : false,
358            build_by_default : false,
359        ).extract_all_objects(recursive: true)
360    endforeach
361endforeach
362
363# The final dav1d library
364if host_machine.system() == 'windows'
365    dav1d_soversion = ''
366else
367    dav1d_soversion = dav1d_api_version_major
368endif
369
370libdav1d = library('dav1d',
371    libdav1d_sources,
372    libdav1d_asm_objs,
373    libdav1d_rc_obj,
374    rev_target,
375    config_h_target,
376
377    objects : [
378        libdav1d_bitdepth_objs,
379        ],
380
381    include_directories : dav1d_inc_dirs,
382    dependencies : [
383        stdatomic_dependencies,
384        thread_dependency,
385        thread_compat_dep,
386        libdl_dependency,
387        ],
388    c_args : [libdav1d_flags, api_export_flags],
389    version : dav1d_soname_version,
390    soversion : dav1d_soversion,
391    install : true,
392)
393
394dav1d_dep = declare_dependency(link_with: libdav1d,
395    include_directories : include_directories('../include')
396)
397
398#
399# Generate pkg-config .pc file
400#
401pkg_mod = import('pkgconfig')
402pkg_mod.generate(libraries: libdav1d,
403    version: meson.project_version(),
404    name: 'libdav1d',
405    filebase: 'dav1d',
406    description: 'AV1 decoding library'
407)
408