• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    'data.c',
34    'decode.c',
35    'dequant_tables.c',
36    'getbits.c',
37    'intra_edge.c',
38    'itx_1d.c',
39    'lf_mask.c',
40    'lib.c',
41    'log.c',
42    'mem.c',
43    'msac.c',
44    'obu.c',
45    'pal.c',
46    'picture.c',
47    'qm.c',
48    'ref.c',
49    'refmvs.c',
50    'scan.c',
51    'tables.c',
52    'thread_task.c',
53    'warpmv.c',
54    'wedge.c',
55)
56
57# libdav1d bitdepth source files
58# These files are compiled for each bitdepth with
59# `BITDEPTH` defined to the currently built bitdepth.
60libdav1d_tmpl_sources = files(
61    'cdef_apply_tmpl.c',
62    'cdef_tmpl.c',
63    'fg_apply_tmpl.c',
64    'filmgrain_tmpl.c',
65    'ipred_prepare_tmpl.c',
66    'ipred_tmpl.c',
67    'itx_tmpl.c',
68    'lf_apply_tmpl.c',
69    'loopfilter_tmpl.c',
70    'looprestoration_tmpl.c',
71    'lr_apply_tmpl.c',
72    'mc_tmpl.c',
73    'recon_tmpl.c',
74)
75
76libdav1d_arch_tmpl_sources = {}
77
78libdav1d_bitdepth_objs = []
79
80# ASM specific sources
81libdav1d_asm_objs = []
82# Arch-specific flags
83arch_flags = {}
84if is_asm_enabled
85    if (host_machine.cpu_family() == 'aarch64' or
86        host_machine.cpu_family().startswith('arm'))
87
88        libdav1d_sources += files(
89            'arm/cpu.c',
90        )
91        if (host_machine.cpu_family() == 'aarch64' or
92            host_machine.cpu() == 'arm64')
93            libdav1d_sources_asm = files(
94                # itx.S is used for both 8 and 16 bpc.
95                'arm/64/itx.S',
96                'arm/64/looprestoration_common.S',
97                'arm/64/msac.S',
98                'arm/64/refmvs.S',
99            )
100
101            if dav1d_bitdepths.contains('8')
102                libdav1d_sources_asm += files(
103                    'arm/64/cdef.S',
104                    'arm/64/filmgrain.S',
105                    'arm/64/ipred.S',
106                    'arm/64/loopfilter.S',
107                    'arm/64/looprestoration.S',
108                    'arm/64/mc.S',
109                    'arm/64/mc_dotprod.S',
110                )
111            endif
112
113            if dav1d_bitdepths.contains('16')
114                libdav1d_sources_asm += files(
115                    'arm/64/cdef16.S',
116                    'arm/64/filmgrain16.S',
117                    'arm/64/ipred16.S',
118                    'arm/64/itx16.S',
119                    'arm/64/loopfilter16.S',
120                    'arm/64/looprestoration16.S',
121                    'arm/64/mc16.S',
122                )
123            endif
124        elif host_machine.cpu_family().startswith('arm')
125            libdav1d_sources_asm = files(
126                # itx.S is used for both 8 and 16 bpc.
127                'arm/32/itx.S',
128                'arm/32/looprestoration_common.S',
129                'arm/32/msac.S',
130                'arm/32/refmvs.S',
131            )
132
133            if dav1d_bitdepths.contains('8')
134                libdav1d_sources_asm += files(
135                    'arm/32/cdef.S',
136                    'arm/32/filmgrain.S',
137                    'arm/32/ipred.S',
138                    'arm/32/loopfilter.S',
139                    'arm/32/looprestoration.S',
140                    'arm/32/mc.S',
141                )
142            endif
143
144            if dav1d_bitdepths.contains('16')
145                libdav1d_sources_asm += files(
146                    'arm/32/cdef16.S',
147                    'arm/32/filmgrain16.S',
148                    'arm/32/ipred16.S',
149                    'arm/32/itx16.S',
150                    'arm/32/loopfilter16.S',
151                    'arm/32/looprestoration16.S',
152                    'arm/32/mc16.S',
153                )
154            endif
155        endif
156
157        if use_gaspp
158            libdav1d_asm_objs = gaspp_gen.process(libdav1d_sources_asm)
159        else
160            libdav1d_sources += libdav1d_sources_asm
161        endif
162    elif host_machine.cpu_family().startswith('x86')
163
164        libdav1d_sources += files(
165            'x86/cpu.c',
166        )
167
168        # NASM source files
169        libdav1d_sources_asm = files(
170            'x86/cpuid.asm',
171            'x86/msac.asm',
172            'x86/pal.asm',
173            'x86/refmvs.asm',
174            'x86/itx_avx512.asm',
175            'x86/cdef_avx2.asm',
176            'x86/itx_avx2.asm',
177            'x86/looprestoration_avx2.asm',
178            'x86/cdef_sse.asm',
179            'x86/itx_sse.asm',
180        )
181
182        if dav1d_bitdepths.contains('8')
183            libdav1d_sources_asm += files(
184                'x86/cdef_avx512.asm',
185                'x86/filmgrain_avx512.asm',
186                'x86/ipred_avx512.asm',
187                'x86/loopfilter_avx512.asm',
188                'x86/looprestoration_avx512.asm',
189                'x86/mc_avx512.asm',
190                'x86/filmgrain_avx2.asm',
191                'x86/ipred_avx2.asm',
192                'x86/loopfilter_avx2.asm',
193                'x86/mc_avx2.asm',
194                'x86/filmgrain_sse.asm',
195                'x86/ipred_sse.asm',
196                'x86/loopfilter_sse.asm',
197                'x86/looprestoration_sse.asm',
198                'x86/mc_sse.asm',
199            )
200        endif
201
202        if dav1d_bitdepths.contains('16')
203            libdav1d_sources_asm += files(
204                'x86/cdef16_avx512.asm',
205                'x86/filmgrain16_avx512.asm',
206                'x86/ipred16_avx512.asm',
207                'x86/itx16_avx512.asm',
208                'x86/loopfilter16_avx512.asm',
209                'x86/looprestoration16_avx512.asm',
210                'x86/mc16_avx512.asm',
211                'x86/cdef16_avx2.asm',
212                'x86/filmgrain16_avx2.asm',
213                'x86/ipred16_avx2.asm',
214                'x86/itx16_avx2.asm',
215                'x86/loopfilter16_avx2.asm',
216                'x86/looprestoration16_avx2.asm',
217                'x86/mc16_avx2.asm',
218                'x86/cdef16_sse.asm',
219                'x86/filmgrain16_sse.asm',
220                'x86/ipred16_sse.asm',
221                'x86/itx16_sse.asm',
222                'x86/loopfilter16_sse.asm',
223                'x86/looprestoration16_sse.asm',
224                'x86/mc16_sse.asm',
225            )
226        endif
227
228        # Compile the ASM sources with NASM
229        libdav1d_asm_objs = nasm_gen.process(libdav1d_sources_asm)
230    elif host_machine.cpu_family().startswith('loongarch')
231        libdav1d_sources += files(
232            'loongarch/cpu.c',
233        )
234
235        libdav1d_arch_tmpl_sources += {'default': files(
236            'loongarch/looprestoration_tmpl.c',
237        )}
238
239        libdav1d_sources_asm = files(
240            'loongarch/mc.S',
241            'loongarch/loopfilter.S',
242            'loongarch/looprestoration.S',
243            'loongarch/msac.S',
244            'loongarch/refmvs.S',
245            'loongarch/itx.S',
246        )
247        libdav1d_asm_objs += libdav1d_sources_asm
248    elif host_machine.cpu() == 'ppc64le'
249        arch_flags += {'vsx': ['-maltivec', '-mvsx', '-DDAV1D_VSX']}
250        libdav1d_sources += files(
251            'ppc/cpu.c',
252        )
253        libdav1d_arch_tmpl_sources += {'vsx': files(
254            'ppc/cdef_tmpl.c',
255            'ppc/looprestoration_tmpl.c',
256        )}
257        arch_flags += {'pwr9': ['-mcpu=power9', '-DDAV1D_PWR9']}
258        libdav1d_arch_tmpl_sources += {'pwr9': files(
259            'ppc/loopfilter_tmpl.c',
260        )}
261    elif host_machine.cpu_family().startswith('riscv')
262        libdav1d_sources += files(
263            'riscv/cpu.c',
264        )
265        if host_machine.cpu_family() == 'riscv64'
266            libdav1d_sources += files(
267                'riscv/64/cpu.S',
268                'riscv/64/itx.S',
269            )
270        endif
271    endif
272endif
273
274
275
276libdav1d_rc_obj = []
277libdav1d_flags = []
278api_export_flags = []
279
280#
281# Windows .rc file and API export flags
282#
283
284if host_machine.system() == 'windows'
285    if get_option('default_library') != 'static'
286        rc_file = configure_file(
287            input : 'dav1d.rc.in',
288            output : 'dav1d.rc',
289            configuration : rc_data
290        )
291
292        libdav1d_rc_obj = winmod.compile_resources(rc_file)
293
294        api_export_flags = ['-DDAV1D_BUILDING_DLL']
295    endif
296
297    if (host_machine.cpu_family() == 'x86_64' and cc.get_id() == 'gcc')
298        # We don't expect to reference data members from other DLLs without
299        # dllimport attributes. Set the -mcmodel=small flag, which avoids
300        # generating indirection via .refptr.<symname> for all potentially
301        # dllimported variable references.
302        libdav1d_flags += '-mcmodel=small'
303    endif
304endif
305
306
307
308#
309# Library definitions
310#
311
312# Helper library for each bitdepth
313libdav1d_bitdepth_objs = []
314foreach bitdepth : dav1d_bitdepths
315    libdav1d_bitdepth_objs += static_library(
316        'dav1d_bitdepth_@0@'.format(bitdepth),
317        libdav1d_tmpl_sources, config_h_target,
318        include_directories: dav1d_inc_dirs,
319        dependencies : [stdatomic_dependencies],
320        c_args : ['-DBITDEPTH=@0@'.format(bitdepth)] + libdav1d_flags,
321        install : false,
322        build_by_default : false,
323    ).extract_all_objects(recursive: true)
324endforeach
325
326# Helper library for each bitdepth and architecture-specific flags
327foreach bitdepth : dav1d_bitdepths
328    foreach subarch : libdav1d_arch_tmpl_sources.keys()
329        libdav1d_bitdepth_objs += static_library(
330            'dav1d_arch_bitdepth_@0@_@1@'.format(bitdepth,subarch),
331            libdav1d_arch_tmpl_sources[subarch], config_h_target,
332            include_directories: dav1d_inc_dirs,
333            dependencies : [stdatomic_dependencies],
334            c_args : ['-DBITDEPTH=@0@'.format(bitdepth)] + libdav1d_flags + arch_flags.get(subarch, []),
335            install : false,
336            build_by_default : false,
337        ).extract_all_objects(recursive: true)
338    endforeach
339endforeach
340
341# The final dav1d library
342if host_machine.system() == 'windows'
343    dav1d_soversion = ''
344else
345    dav1d_soversion = dav1d_api_version_major
346endif
347
348libdav1d = library('dav1d',
349    libdav1d_sources,
350    libdav1d_asm_objs,
351    libdav1d_rc_obj,
352    rev_target,
353    config_h_target,
354
355    objects : [
356        libdav1d_bitdepth_objs,
357        ],
358
359    include_directories : dav1d_inc_dirs,
360    dependencies : [
361        stdatomic_dependencies,
362        thread_dependency,
363        thread_compat_dep,
364        libdl_dependency,
365        ],
366    c_args : [libdav1d_flags, api_export_flags],
367    version : dav1d_soname_version,
368    soversion : dav1d_soversion,
369    install : true,
370)
371
372dav1d_dep = declare_dependency(link_with: libdav1d,
373    include_directories : include_directories('../include/dav1d')
374)
375
376#
377# Generate pkg-config .pc file
378#
379pkg_mod = import('pkgconfig')
380pkg_mod.generate(libraries: libdav1d,
381    version: meson.project_version(),
382    name: 'libdav1d',
383    filebase: 'dav1d',
384    description: 'AV1 decoding library'
385)
386