xref: /aosp_15_r20/external/libdav1d/meson.build (revision c09093415860a1c2373dacd84c4fde00c507cdfd)
1*c0909341SAndroid Build Coastguard Worker# Copyright © 2018-2024, VideoLAN and dav1d authors
2*c0909341SAndroid Build Coastguard Worker# All rights reserved.
3*c0909341SAndroid Build Coastguard Worker#
4*c0909341SAndroid Build Coastguard Worker# Redistribution and use in source and binary forms, with or without
5*c0909341SAndroid Build Coastguard Worker# modification, are permitted provided that the following conditions are met:
6*c0909341SAndroid Build Coastguard Worker#
7*c0909341SAndroid Build Coastguard Worker# 1. Redistributions of source code must retain the above copyright notice, this
8*c0909341SAndroid Build Coastguard Worker#    list of conditions and the following disclaimer.
9*c0909341SAndroid Build Coastguard Worker#
10*c0909341SAndroid Build Coastguard Worker# 2. Redistributions in binary form must reproduce the above copyright notice,
11*c0909341SAndroid Build Coastguard Worker#    this list of conditions and the following disclaimer in the documentation
12*c0909341SAndroid Build Coastguard Worker#    and/or other materials provided with the distribution.
13*c0909341SAndroid Build Coastguard Worker#
14*c0909341SAndroid Build Coastguard Worker# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15*c0909341SAndroid Build Coastguard Worker# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16*c0909341SAndroid Build Coastguard Worker# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17*c0909341SAndroid Build Coastguard Worker# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18*c0909341SAndroid Build Coastguard Worker# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19*c0909341SAndroid Build Coastguard Worker# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20*c0909341SAndroid Build Coastguard Worker# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21*c0909341SAndroid Build Coastguard Worker# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22*c0909341SAndroid Build Coastguard Worker# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23*c0909341SAndroid Build Coastguard Worker# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*c0909341SAndroid Build Coastguard Worker
25*c0909341SAndroid Build Coastguard Workerproject('dav1d', ['c'],
26*c0909341SAndroid Build Coastguard Worker    version: '1.5.0',
27*c0909341SAndroid Build Coastguard Worker    default_options: ['c_std=c99',
28*c0909341SAndroid Build Coastguard Worker                      'warning_level=2',
29*c0909341SAndroid Build Coastguard Worker                      'buildtype=release',
30*c0909341SAndroid Build Coastguard Worker                      'b_ndebug=if-release'],
31*c0909341SAndroid Build Coastguard Worker    meson_version: '>= 0.49.0')
32*c0909341SAndroid Build Coastguard Worker
33*c0909341SAndroid Build Coastguard Workerdav1d_src_root = meson.current_source_dir()
34*c0909341SAndroid Build Coastguard Workercc = meson.get_compiler('c')
35*c0909341SAndroid Build Coastguard Worker
36*c0909341SAndroid Build Coastguard Worker# Configuratin data for config.h
37*c0909341SAndroid Build Coastguard Workercdata = configuration_data()
38*c0909341SAndroid Build Coastguard Worker
39*c0909341SAndroid Build Coastguard Worker# Configuration data for config.asm
40*c0909341SAndroid Build Coastguard Workercdata_asm = configuration_data()
41*c0909341SAndroid Build Coastguard Worker
42*c0909341SAndroid Build Coastguard Worker# Include directories
43*c0909341SAndroid Build Coastguard Workerdav1d_inc_dirs = include_directories(['.', 'include/dav1d', 'include'])
44*c0909341SAndroid Build Coastguard Worker
45*c0909341SAndroid Build Coastguard Workerdav1d_api_version_major    = cc.get_define('DAV1D_API_VERSION_MAJOR',
46*c0909341SAndroid Build Coastguard Worker                                           prefix: '#include "dav1d/version.h"',
47*c0909341SAndroid Build Coastguard Worker                                           include_directories: dav1d_inc_dirs).strip()
48*c0909341SAndroid Build Coastguard Workerdav1d_api_version_minor    = cc.get_define('DAV1D_API_VERSION_MINOR',
49*c0909341SAndroid Build Coastguard Worker                                           prefix: '#include "dav1d/version.h"',
50*c0909341SAndroid Build Coastguard Worker                                           include_directories: dav1d_inc_dirs).strip()
51*c0909341SAndroid Build Coastguard Workerdav1d_api_version_revision = cc.get_define('DAV1D_API_VERSION_PATCH',
52*c0909341SAndroid Build Coastguard Worker                                           prefix: '#include "dav1d/version.h"',
53*c0909341SAndroid Build Coastguard Worker                                           include_directories: dav1d_inc_dirs).strip()
54*c0909341SAndroid Build Coastguard Workerdav1d_soname_version       = '@0@.@1@.@2@'.format(dav1d_api_version_major,
55*c0909341SAndroid Build Coastguard Worker                                                  dav1d_api_version_minor,
56*c0909341SAndroid Build Coastguard Worker                                                  dav1d_api_version_revision)
57*c0909341SAndroid Build Coastguard Worker
58*c0909341SAndroid Build Coastguard Worker#
59*c0909341SAndroid Build Coastguard Worker# Option handling
60*c0909341SAndroid Build Coastguard Worker#
61*c0909341SAndroid Build Coastguard Worker
62*c0909341SAndroid Build Coastguard Worker# Bitdepth option
63*c0909341SAndroid Build Coastguard Workerdav1d_bitdepths = get_option('bitdepths')
64*c0909341SAndroid Build Coastguard Workerforeach bitdepth : ['8', '16']
65*c0909341SAndroid Build Coastguard Worker    cdata.set10('CONFIG_@0@BPC'.format(bitdepth), dav1d_bitdepths.contains(bitdepth))
66*c0909341SAndroid Build Coastguard Workerendforeach
67*c0909341SAndroid Build Coastguard Worker
68*c0909341SAndroid Build Coastguard Worker# ASM option
69*c0909341SAndroid Build Coastguard Workeris_asm_enabled = (get_option('enable_asm') == true and
70*c0909341SAndroid Build Coastguard Worker    (host_machine.cpu_family() == 'aarch64' or
71*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family().startswith('arm') or
72*c0909341SAndroid Build Coastguard Worker     host_machine.cpu() == 'ppc64le' or
73*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family().startswith('riscv') or
74*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family().startswith('loongarch') or
75*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family() == 'x86' or
76*c0909341SAndroid Build Coastguard Worker     (host_machine.cpu_family() == 'x86_64' and cc.get_define('__ILP32__').strip() == '')))
77*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_ASM', is_asm_enabled)
78*c0909341SAndroid Build Coastguard Worker
79*c0909341SAndroid Build Coastguard Workerif is_asm_enabled and get_option('b_sanitize') == 'memory'
80*c0909341SAndroid Build Coastguard Worker    error('asm causes false positive with memory sanitizer. Use \'-Denable_asm=false\'.')
81*c0909341SAndroid Build Coastguard Workerendif
82*c0909341SAndroid Build Coastguard Worker
83*c0909341SAndroid Build Coastguard Workercdata.set10('TRIM_DSP_FUNCTIONS', get_option('trim_dsp') == 'true' or
84*c0909341SAndroid Build Coastguard Worker    (get_option('trim_dsp') == 'if-release' and get_option('buildtype') == 'release'))
85*c0909341SAndroid Build Coastguard Worker
86*c0909341SAndroid Build Coastguard Worker# Logging option
87*c0909341SAndroid Build Coastguard Workercdata.set10('CONFIG_LOG', get_option('logging'))
88*c0909341SAndroid Build Coastguard Worker
89*c0909341SAndroid Build Coastguard Workercdata.set10('CONFIG_MACOS_KPERF', get_option('macos_kperf'))
90*c0909341SAndroid Build Coastguard Worker
91*c0909341SAndroid Build Coastguard Worker#
92*c0909341SAndroid Build Coastguard Worker# OS/Compiler checks and defines
93*c0909341SAndroid Build Coastguard Worker#
94*c0909341SAndroid Build Coastguard Worker
95*c0909341SAndroid Build Coastguard Worker# Arguments in test_args will be used even on feature tests
96*c0909341SAndroid Build Coastguard Workertest_args = []
97*c0909341SAndroid Build Coastguard Worker
98*c0909341SAndroid Build Coastguard Workeroptional_arguments = []
99*c0909341SAndroid Build Coastguard Workeroptional_link_arguments = []
100*c0909341SAndroid Build Coastguard Worker
101*c0909341SAndroid Build Coastguard Workerif host_machine.system() in ['linux', 'gnu', 'emscripten']
102*c0909341SAndroid Build Coastguard Worker    test_args += '-D_GNU_SOURCE'
103*c0909341SAndroid Build Coastguard Worker    add_project_arguments('-D_GNU_SOURCE', language: 'c')
104*c0909341SAndroid Build Coastguard Workerendif
105*c0909341SAndroid Build Coastguard Worker
106*c0909341SAndroid Build Coastguard Workerhave_clock_gettime = false
107*c0909341SAndroid Build Coastguard Workerhave_posix_memalign = false
108*c0909341SAndroid Build Coastguard Workerhave_memalign = false
109*c0909341SAndroid Build Coastguard Workerhave_aligned_alloc = false
110*c0909341SAndroid Build Coastguard Workerif host_machine.system() == 'windows'
111*c0909341SAndroid Build Coastguard Worker    cdata.set('_WIN32_WINNT',           '0x0601')
112*c0909341SAndroid Build Coastguard Worker    cdata.set('UNICODE',                1) # Define to 1 for Unicode (Wide Chars) APIs
113*c0909341SAndroid Build Coastguard Worker    cdata.set('_UNICODE',               1) # Define to 1 for Unicode (Wide Chars) APIs
114*c0909341SAndroid Build Coastguard Worker    cdata.set('__USE_MINGW_ANSI_STDIO', 1) # Define to force use of MinGW printf
115*c0909341SAndroid Build Coastguard Worker    cdata.set('_CRT_DECLARE_NONSTDC_NAMES', 1) # Define to get off_t from sys/types.h on MSVC
116*c0909341SAndroid Build Coastguard Worker    if cc.has_function('fseeko', prefix : '#include <stdio.h>', args : test_args)
117*c0909341SAndroid Build Coastguard Worker        cdata.set('_FILE_OFFSET_BITS', 64) # Not set by default by Meson on Windows
118*c0909341SAndroid Build Coastguard Worker    else
119*c0909341SAndroid Build Coastguard Worker        cdata.set('fseeko', '_fseeki64')
120*c0909341SAndroid Build Coastguard Worker        cdata.set('ftello', '_ftelli64')
121*c0909341SAndroid Build Coastguard Worker    endif
122*c0909341SAndroid Build Coastguard Worker
123*c0909341SAndroid Build Coastguard Worker    if host_machine.cpu_family() == 'x86_64'
124*c0909341SAndroid Build Coastguard Worker        if cc.get_argument_syntax() != 'msvc'
125*c0909341SAndroid Build Coastguard Worker            optional_link_arguments += '-Wl,--dynamicbase,--nxcompat,--tsaware,--high-entropy-va'
126*c0909341SAndroid Build Coastguard Worker        endif
127*c0909341SAndroid Build Coastguard Worker    elif host_machine.cpu_family() == 'x86' or host_machine.cpu_family() == 'arm'
128*c0909341SAndroid Build Coastguard Worker        if cc.get_argument_syntax() == 'msvc'
129*c0909341SAndroid Build Coastguard Worker            optional_link_arguments += '/largeaddressaware'
130*c0909341SAndroid Build Coastguard Worker        else
131*c0909341SAndroid Build Coastguard Worker            optional_link_arguments += '-Wl,--dynamicbase,--nxcompat,--tsaware,--large-address-aware'
132*c0909341SAndroid Build Coastguard Worker        endif
133*c0909341SAndroid Build Coastguard Worker    endif
134*c0909341SAndroid Build Coastguard Worker
135*c0909341SAndroid Build Coastguard Worker    # On Windows, we use a compatibility layer to emulate pthread
136*c0909341SAndroid Build Coastguard Worker    thread_dependency = []
137*c0909341SAndroid Build Coastguard Worker    thread_compat_dep = declare_dependency(sources : files('src/win32/thread.c'))
138*c0909341SAndroid Build Coastguard Worker
139*c0909341SAndroid Build Coastguard Worker    rt_dependency = []
140*c0909341SAndroid Build Coastguard Worker
141*c0909341SAndroid Build Coastguard Worker    rc_version_array = meson.project_version().split('.')
142*c0909341SAndroid Build Coastguard Worker    winmod = import('windows')
143*c0909341SAndroid Build Coastguard Worker    rc_data = configuration_data()
144*c0909341SAndroid Build Coastguard Worker    rc_data.set('PROJECT_VERSION_MAJOR', rc_version_array[0])
145*c0909341SAndroid Build Coastguard Worker    rc_data.set('PROJECT_VERSION_MINOR', rc_version_array[1])
146*c0909341SAndroid Build Coastguard Worker    rc_data.set('PROJECT_VERSION_REVISION', rc_version_array[2])
147*c0909341SAndroid Build Coastguard Worker    rc_data.set('API_VERSION_MAJOR', dav1d_api_version_major)
148*c0909341SAndroid Build Coastguard Worker    rc_data.set('API_VERSION_MINOR', dav1d_api_version_minor)
149*c0909341SAndroid Build Coastguard Worker    rc_data.set('API_VERSION_REVISION', dav1d_api_version_revision)
150*c0909341SAndroid Build Coastguard Worker    rc_data.set('COPYRIGHT_YEARS', '2018-2024')
151*c0909341SAndroid Build Coastguard Workerelse
152*c0909341SAndroid Build Coastguard Worker    thread_dependency = dependency('threads')
153*c0909341SAndroid Build Coastguard Worker    thread_compat_dep = []
154*c0909341SAndroid Build Coastguard Worker
155*c0909341SAndroid Build Coastguard Worker    rt_dependency = []
156*c0909341SAndroid Build Coastguard Worker    if cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args)
157*c0909341SAndroid Build Coastguard Worker        have_clock_gettime = true
158*c0909341SAndroid Build Coastguard Worker    elif host_machine.system() not in ['darwin', 'ios', 'tvos']
159*c0909341SAndroid Build Coastguard Worker        rt_dependency = cc.find_library('rt', required: false)
160*c0909341SAndroid Build Coastguard Worker        if not cc.has_function('clock_gettime', prefix : '#include <time.h>', args : test_args, dependencies : rt_dependency)
161*c0909341SAndroid Build Coastguard Worker            error('clock_gettime not found')
162*c0909341SAndroid Build Coastguard Worker        endif
163*c0909341SAndroid Build Coastguard Worker        have_clock_gettime = true
164*c0909341SAndroid Build Coastguard Worker    endif
165*c0909341SAndroid Build Coastguard Worker
166*c0909341SAndroid Build Coastguard Worker    have_posix_memalign = cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args)
167*c0909341SAndroid Build Coastguard Worker    have_memalign = cc.has_function('memalign', prefix : '#include <malloc.h>', args : test_args)
168*c0909341SAndroid Build Coastguard Worker    have_aligned_alloc = cc.has_function('aligned_alloc', prefix : '#include <stdlib.h>', args : test_args)
169*c0909341SAndroid Build Coastguard Workerendif
170*c0909341SAndroid Build Coastguard Worker
171*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_CLOCK_GETTIME', have_clock_gettime)
172*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_POSIX_MEMALIGN', have_posix_memalign)
173*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_MEMALIGN', have_memalign)
174*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_ALIGNED_ALLOC', have_aligned_alloc)
175*c0909341SAndroid Build Coastguard Worker
176*c0909341SAndroid Build Coastguard Worker# check for fseeko on android. It is not always available if _FILE_OFFSET_BITS is defined to 64
177*c0909341SAndroid Build Coastguard Workerhave_fseeko = true
178*c0909341SAndroid Build Coastguard Workerif host_machine.system() == 'android'
179*c0909341SAndroid Build Coastguard Worker    if not cc.has_function('fseeko', prefix : '#include <stdio.h>', args : test_args)
180*c0909341SAndroid Build Coastguard Worker        if cc.has_function('fseeko', prefix : '#include <stdio.h>', args : test_args + ['-U_FILE_OFFSET_BITS'])
181*c0909341SAndroid Build Coastguard Worker            warning('Files larger than 2 gigabytes might not be supported in the dav1d CLI tool.')
182*c0909341SAndroid Build Coastguard Worker            add_project_arguments('-U_FILE_OFFSET_BITS', language: 'c')
183*c0909341SAndroid Build Coastguard Worker        elif get_option('enable_tools')
184*c0909341SAndroid Build Coastguard Worker            error('dav1d CLI tool needs fseeko()')
185*c0909341SAndroid Build Coastguard Worker        else
186*c0909341SAndroid Build Coastguard Worker            have_fseeko = false
187*c0909341SAndroid Build Coastguard Worker        endif
188*c0909341SAndroid Build Coastguard Worker    endif
189*c0909341SAndroid Build Coastguard Workerendif
190*c0909341SAndroid Build Coastguard Worker
191*c0909341SAndroid Build Coastguard Workerlibdl_dependency = []
192*c0909341SAndroid Build Coastguard Workerhave_dlsym = false
193*c0909341SAndroid Build Coastguard Workerif host_machine.system() == 'linux'
194*c0909341SAndroid Build Coastguard Worker    libdl_dependency = cc.find_library('dl', required : false)
195*c0909341SAndroid Build Coastguard Worker    have_dlsym = cc.has_function('dlsym', prefix : '#include <dlfcn.h>', args : test_args, dependencies : libdl_dependency)
196*c0909341SAndroid Build Coastguard Workerendif
197*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_DLSYM', have_dlsym)
198*c0909341SAndroid Build Coastguard Worker
199*c0909341SAndroid Build Coastguard Workerlibm_dependency = cc.find_library('m', required: false)
200*c0909341SAndroid Build Coastguard Worker
201*c0909341SAndroid Build Coastguard Worker
202*c0909341SAndroid Build Coastguard Worker# Header checks
203*c0909341SAndroid Build Coastguard Worker
204*c0909341SAndroid Build Coastguard Workerstdatomic_dependencies = []
205*c0909341SAndroid Build Coastguard Workerif not cc.check_header('stdatomic.h')
206*c0909341SAndroid Build Coastguard Worker    if cc.get_id() == 'msvc'
207*c0909341SAndroid Build Coastguard Worker        # we have a custom replacement for MSVC
208*c0909341SAndroid Build Coastguard Worker        stdatomic_dependencies += declare_dependency(
209*c0909341SAndroid Build Coastguard Worker            include_directories : include_directories('include/compat/msvc'),
210*c0909341SAndroid Build Coastguard Worker        )
211*c0909341SAndroid Build Coastguard Worker    elif cc.compiles('''int main() { int v = 0; return __atomic_fetch_add(&v, 1, __ATOMIC_SEQ_CST); }''',
212*c0909341SAndroid Build Coastguard Worker                     name : 'GCC-style atomics', args : test_args)
213*c0909341SAndroid Build Coastguard Worker        stdatomic_dependencies += declare_dependency(
214*c0909341SAndroid Build Coastguard Worker            include_directories : include_directories('include/compat/gcc'),
215*c0909341SAndroid Build Coastguard Worker        )
216*c0909341SAndroid Build Coastguard Worker    else
217*c0909341SAndroid Build Coastguard Worker        error('Atomics not supported')
218*c0909341SAndroid Build Coastguard Worker    endif
219*c0909341SAndroid Build Coastguard Workerendif
220*c0909341SAndroid Build Coastguard Worker
221*c0909341SAndroid Build Coastguard Workerif host_machine.cpu_family().startswith('wasm')
222*c0909341SAndroid Build Coastguard Worker    # enable atomics + bulk-memory features
223*c0909341SAndroid Build Coastguard Worker    stdatomic_dependencies += thread_dependency.partial_dependency(compile_args: true)
224*c0909341SAndroid Build Coastguard Workerendif
225*c0909341SAndroid Build Coastguard Worker
226*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_SYS_TYPES_H', cc.check_header('sys/types.h'))
227*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_UNISTD_H', cc.check_header('unistd.h'))
228*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_IO_H', cc.check_header('io.h'))
229*c0909341SAndroid Build Coastguard Worker
230*c0909341SAndroid Build Coastguard Workerhave_pthread_np = cc.check_header('pthread_np.h')
231*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_PTHREAD_NP_H', have_pthread_np)
232*c0909341SAndroid Build Coastguard Workertest_args += '-DHAVE_PTHREAD_NP_H=' + (have_pthread_np ? '1' : '0')
233*c0909341SAndroid Build Coastguard Worker
234*c0909341SAndroid Build Coastguard Worker# Function checks
235*c0909341SAndroid Build Coastguard Worker
236*c0909341SAndroid Build Coastguard Workerif not cc.has_function('getopt_long', prefix : '#include <getopt.h>', args : test_args)
237*c0909341SAndroid Build Coastguard Worker    getopt_dependency = declare_dependency(
238*c0909341SAndroid Build Coastguard Worker        sources: files('tools/compat/getopt.c'),
239*c0909341SAndroid Build Coastguard Worker        include_directories : include_directories('include/compat'),
240*c0909341SAndroid Build Coastguard Worker    )
241*c0909341SAndroid Build Coastguard Workerelse
242*c0909341SAndroid Build Coastguard Worker    getopt_dependency = []
243*c0909341SAndroid Build Coastguard Workerendif
244*c0909341SAndroid Build Coastguard Worker
245*c0909341SAndroid Build Coastguard Workerhave_getauxval = false
246*c0909341SAndroid Build Coastguard Workerhave_elf_aux_info = false
247*c0909341SAndroid Build Coastguard Workerif (host_machine.cpu_family() == 'aarch64' or
248*c0909341SAndroid Build Coastguard Worker    host_machine.cpu_family().startswith('arm') or
249*c0909341SAndroid Build Coastguard Worker    host_machine.cpu_family().startswith('loongarch') or
250*c0909341SAndroid Build Coastguard Worker    host_machine.cpu() == 'ppc64le' or
251*c0909341SAndroid Build Coastguard Worker    host_machine.cpu_family().startswith('riscv'))
252*c0909341SAndroid Build Coastguard Worker    have_getauxval = cc.has_function('getauxval', prefix : '#include <sys/auxv.h>', args : test_args)
253*c0909341SAndroid Build Coastguard Worker    have_elf_aux_info = cc.has_function('elf_aux_info', prefix : '#include <sys/auxv.h>', args : test_args)
254*c0909341SAndroid Build Coastguard Workerendif
255*c0909341SAndroid Build Coastguard Worker
256*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_GETAUXVAL', have_getauxval)
257*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_ELF_AUX_INFO', have_elf_aux_info)
258*c0909341SAndroid Build Coastguard Worker
259*c0909341SAndroid Build Coastguard Workerpthread_np_prefix = '''
260*c0909341SAndroid Build Coastguard Worker#include <pthread.h>
261*c0909341SAndroid Build Coastguard Worker#if HAVE_PTHREAD_NP_H
262*c0909341SAndroid Build Coastguard Worker#include <pthread_np.h>
263*c0909341SAndroid Build Coastguard Worker#endif
264*c0909341SAndroid Build Coastguard Worker'''
265*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_PTHREAD_GETAFFINITY_NP', cc.has_function('pthread_getaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency))
266*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_PTHREAD_SETAFFINITY_NP', cc.has_function('pthread_setaffinity_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency))
267*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_PTHREAD_SETNAME_NP', cc.has_function('pthread_setname_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency))
268*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_PTHREAD_SET_NAME_NP', cc.has_function('pthread_set_name_np', prefix : pthread_np_prefix, args : test_args, dependencies : thread_dependency))
269*c0909341SAndroid Build Coastguard Worker
270*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_C11_GENERIC', cc.compiles('int x = _Generic(0, default: 0);', name: '_Generic', args: test_args))
271*c0909341SAndroid Build Coastguard Worker
272*c0909341SAndroid Build Coastguard Worker# Compiler flag tests
273*c0909341SAndroid Build Coastguard Worker
274*c0909341SAndroid Build Coastguard Workerif cc.has_argument('-fvisibility=hidden')
275*c0909341SAndroid Build Coastguard Worker    add_project_arguments('-fvisibility=hidden', language: 'c')
276*c0909341SAndroid Build Coastguard Workerelse
277*c0909341SAndroid Build Coastguard Worker    warning('Compiler does not support -fvisibility=hidden, all symbols will be public!')
278*c0909341SAndroid Build Coastguard Workerendif
279*c0909341SAndroid Build Coastguard Worker
280*c0909341SAndroid Build Coastguard Worker# Compiler flags that should be set
281*c0909341SAndroid Build Coastguard Worker# But when the compiler does not supports them
282*c0909341SAndroid Build Coastguard Worker# it is not an error and silently tolerated
283*c0909341SAndroid Build Coastguard Workerif cc.get_argument_syntax() != 'msvc'
284*c0909341SAndroid Build Coastguard Worker    optional_arguments += [
285*c0909341SAndroid Build Coastguard Worker      '-Wundef',
286*c0909341SAndroid Build Coastguard Worker      '-Werror=vla',
287*c0909341SAndroid Build Coastguard Worker      '-Wno-maybe-uninitialized',
288*c0909341SAndroid Build Coastguard Worker      '-Wno-missing-field-initializers',
289*c0909341SAndroid Build Coastguard Worker      '-Wno-unused-parameter',
290*c0909341SAndroid Build Coastguard Worker      '-Wstrict-prototypes',
291*c0909341SAndroid Build Coastguard Worker      '-Werror=missing-prototypes',
292*c0909341SAndroid Build Coastguard Worker      '-Wshorten-64-to-32',
293*c0909341SAndroid Build Coastguard Worker    ]
294*c0909341SAndroid Build Coastguard Worker    if host_machine.cpu_family() == 'x86'
295*c0909341SAndroid Build Coastguard Worker        optional_arguments += [
296*c0909341SAndroid Build Coastguard Worker          '-msse2',
297*c0909341SAndroid Build Coastguard Worker          '-mfpmath=sse',
298*c0909341SAndroid Build Coastguard Worker        ]
299*c0909341SAndroid Build Coastguard Worker    endif
300*c0909341SAndroid Build Coastguard Workerelse
301*c0909341SAndroid Build Coastguard Worker    optional_arguments += [
302*c0909341SAndroid Build Coastguard Worker      '-wd4028', # parameter different from declaration
303*c0909341SAndroid Build Coastguard Worker      '-wd4090', # broken with arrays of pointers
304*c0909341SAndroid Build Coastguard Worker      '-wd4996'  # use of POSIX functions
305*c0909341SAndroid Build Coastguard Worker    ]
306*c0909341SAndroid Build Coastguard Workerendif
307*c0909341SAndroid Build Coastguard Worker
308*c0909341SAndroid Build Coastguard Workerif (get_option('buildtype') != 'debug' and get_option('buildtype') != 'plain')
309*c0909341SAndroid Build Coastguard Worker    optional_arguments += '-fomit-frame-pointer'
310*c0909341SAndroid Build Coastguard Worker    optional_arguments += '-ffast-math'
311*c0909341SAndroid Build Coastguard Workerendif
312*c0909341SAndroid Build Coastguard Worker
313*c0909341SAndroid Build Coastguard Workerif (host_machine.system() in ['darwin', 'ios', 'tvos'] and cc.get_id() == 'clang' and
314*c0909341SAndroid Build Coastguard Worker    cc.version().startswith('11'))
315*c0909341SAndroid Build Coastguard Worker    # Workaround for Xcode 11 -fstack-check bug, see #301
316*c0909341SAndroid Build Coastguard Worker    optional_arguments += '-fno-stack-check'
317*c0909341SAndroid Build Coastguard Workerendif
318*c0909341SAndroid Build Coastguard Worker
319*c0909341SAndroid Build Coastguard Workerif (host_machine.cpu_family() == 'aarch64' or host_machine.cpu_family().startswith('arm'))
320*c0909341SAndroid Build Coastguard Worker    optional_arguments += '-fno-align-functions'
321*c0909341SAndroid Build Coastguard Workerendif
322*c0909341SAndroid Build Coastguard Worker
323*c0909341SAndroid Build Coastguard Workeradd_project_arguments(cc.get_supported_arguments(optional_arguments), language : 'c')
324*c0909341SAndroid Build Coastguard Workeradd_project_link_arguments(cc.get_supported_link_arguments(optional_link_arguments), language : 'c')
325*c0909341SAndroid Build Coastguard Worker
326*c0909341SAndroid Build Coastguard Worker# libFuzzer related things
327*c0909341SAndroid Build Coastguard Workerfuzzing_engine = get_option('fuzzing_engine')
328*c0909341SAndroid Build Coastguard Workerif fuzzing_engine == 'libfuzzer'
329*c0909341SAndroid Build Coastguard Worker    if not cc.has_argument('-fsanitize=fuzzer')
330*c0909341SAndroid Build Coastguard Worker        error('fuzzing_engine libfuzzer requires "-fsanitize=fuzzer"')
331*c0909341SAndroid Build Coastguard Worker    endif
332*c0909341SAndroid Build Coastguard Worker    fuzzer_args = ['-fsanitize=fuzzer-no-link', '-fsanitize=fuzzer']
333*c0909341SAndroid Build Coastguard Worker    add_project_arguments(cc.first_supported_argument(fuzzer_args), language : 'c')
334*c0909341SAndroid Build Coastguard Workerendif
335*c0909341SAndroid Build Coastguard Worker
336*c0909341SAndroid Build Coastguard Workercdata.set10('ENDIANNESS_BIG', host_machine.endian() == 'big')
337*c0909341SAndroid Build Coastguard Worker
338*c0909341SAndroid Build Coastguard Workerif host_machine.cpu_family().startswith('x86')
339*c0909341SAndroid Build Coastguard Worker    if get_option('stack_alignment') > 0
340*c0909341SAndroid Build Coastguard Worker        stack_alignment = get_option('stack_alignment')
341*c0909341SAndroid Build Coastguard Worker    elif host_machine.cpu_family() == 'x86_64' or host_machine.system() in ['linux', 'darwin', 'ios', 'tvos']
342*c0909341SAndroid Build Coastguard Worker        stack_alignment = 16
343*c0909341SAndroid Build Coastguard Worker    else
344*c0909341SAndroid Build Coastguard Worker        stack_alignment = 4
345*c0909341SAndroid Build Coastguard Worker    endif
346*c0909341SAndroid Build Coastguard Worker    cdata_asm.set('STACK_ALIGNMENT', stack_alignment)
347*c0909341SAndroid Build Coastguard Workerendif
348*c0909341SAndroid Build Coastguard Worker
349*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_AARCH64', host_machine.cpu_family() == 'aarch64' or host_machine.cpu() == 'arm64')
350*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_ARM',     host_machine.cpu_family().startswith('arm') and host_machine.cpu() != 'arm64')
351*c0909341SAndroid Build Coastguard Worker
352*c0909341SAndroid Build Coastguard Workerhave_as_func = false
353*c0909341SAndroid Build Coastguard Workerhave_as_arch = false
354*c0909341SAndroid Build Coastguard Workeraarch64_extensions = {
355*c0909341SAndroid Build Coastguard Worker    'dotprod': 'udot v0.4s, v0.16b, v0.16b',
356*c0909341SAndroid Build Coastguard Worker    'i8mm':    'usdot v0.4s, v0.16b, v0.16b',
357*c0909341SAndroid Build Coastguard Worker    'sve':     'whilelt p0.s, x0, x1',
358*c0909341SAndroid Build Coastguard Worker    'sve2':    'sqrdmulh z0.s, z0.s, z0.s',
359*c0909341SAndroid Build Coastguard Worker}
360*c0909341SAndroid Build Coastguard Workersupported_aarch64_archexts = []
361*c0909341SAndroid Build Coastguard Workersupported_aarch64_instructions = []
362*c0909341SAndroid Build Coastguard Workerif (is_asm_enabled and
363*c0909341SAndroid Build Coastguard Worker    (host_machine.cpu_family() == 'aarch64' or
364*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family().startswith('arm')))
365*c0909341SAndroid Build Coastguard Worker
366*c0909341SAndroid Build Coastguard Worker   as_func_code = '''__asm__ (
367*c0909341SAndroid Build Coastguard Worker".func meson_test"
368*c0909341SAndroid Build Coastguard Worker".endfunc"
369*c0909341SAndroid Build Coastguard Worker);
370*c0909341SAndroid Build Coastguard Worker'''
371*c0909341SAndroid Build Coastguard Worker    have_as_func = cc.compiles(as_func_code)
372*c0909341SAndroid Build Coastguard Worker
373*c0909341SAndroid Build Coastguard Worker    # fedora package build infrastructure uses a gcc specs file to enable
374*c0909341SAndroid Build Coastguard Worker    # '-fPIE' by default. The chosen way only adds '-fPIE' to the C compiler
375*c0909341SAndroid Build Coastguard Worker    # with integrated preprocessor. It is not added to the standalone
376*c0909341SAndroid Build Coastguard Worker    # preprocessor or the preprocessing stage of '.S' files. So we have to
377*c0909341SAndroid Build Coastguard Worker    # compile code to check if we have to define PIC for the arm asm to
378*c0909341SAndroid Build Coastguard Worker    # avoid absolute relocations when building for example checkasm.
379*c0909341SAndroid Build Coastguard Worker    check_pic_code = '''
380*c0909341SAndroid Build Coastguard Worker#if defined(PIC)
381*c0909341SAndroid Build Coastguard Worker#error "PIC already defined"
382*c0909341SAndroid Build Coastguard Worker#elif !(defined(__PIC__) || defined(__pic__))
383*c0909341SAndroid Build Coastguard Worker#error "no pic"
384*c0909341SAndroid Build Coastguard Worker#endif
385*c0909341SAndroid Build Coastguard Worker'''
386*c0909341SAndroid Build Coastguard Worker    if cc.compiles(check_pic_code)
387*c0909341SAndroid Build Coastguard Worker        cdata.set('PIC', '3')
388*c0909341SAndroid Build Coastguard Worker    endif
389*c0909341SAndroid Build Coastguard Worker
390*c0909341SAndroid Build Coastguard Worker    if host_machine.cpu_family() == 'aarch64'
391*c0909341SAndroid Build Coastguard Worker        have_as_arch = cc.compiles('''__asm__ (".arch armv8-a");''')
392*c0909341SAndroid Build Coastguard Worker        as_arch_str = ''
393*c0909341SAndroid Build Coastguard Worker        if have_as_arch
394*c0909341SAndroid Build Coastguard Worker            as_arch_level = 'armv8-a'
395*c0909341SAndroid Build Coastguard Worker            # Check what .arch levels are supported. In principle, we only
396*c0909341SAndroid Build Coastguard Worker            # want to detect up to armv8.2-a here (binutils requires that
397*c0909341SAndroid Build Coastguard Worker            # in order to enable i8mm). However, older Clang versions
398*c0909341SAndroid Build Coastguard Worker            # (before Clang 17, and Xcode versions up to and including 15.0)
399*c0909341SAndroid Build Coastguard Worker            # didn't support controlling dotprod/i8mm extensions via
400*c0909341SAndroid Build Coastguard Worker            # .arch_extension, therefore try to enable a high enough .arch
401*c0909341SAndroid Build Coastguard Worker            # level as well, to implicitly make them available via that.
402*c0909341SAndroid Build Coastguard Worker            foreach arch : ['armv8.2-a', 'armv8.4-a', 'armv8.6-a']
403*c0909341SAndroid Build Coastguard Worker                if cc.compiles('__asm__ (".arch ' + arch + '\\n");')
404*c0909341SAndroid Build Coastguard Worker                    as_arch_level = arch
405*c0909341SAndroid Build Coastguard Worker                endif
406*c0909341SAndroid Build Coastguard Worker            endforeach
407*c0909341SAndroid Build Coastguard Worker            # Clang versions before 17 also had a bug
408*c0909341SAndroid Build Coastguard Worker            # (https://github.com/llvm/llvm-project/issues/32220)
409*c0909341SAndroid Build Coastguard Worker            # causing a plain ".arch <level>" to not have any effect unless it
410*c0909341SAndroid Build Coastguard Worker            # had an extra "+<feature>" included - but it was activated on the
411*c0909341SAndroid Build Coastguard Worker            # next ".arch_extension" directive instead. Check if we can include
412*c0909341SAndroid Build Coastguard Worker            # "+crc" as dummy feature to make the .arch directive behave as
413*c0909341SAndroid Build Coastguard Worker            # expected and take effect right away.
414*c0909341SAndroid Build Coastguard Worker            if cc.compiles('__asm__ (".arch ' + as_arch_level + '+crc\\n");')
415*c0909341SAndroid Build Coastguard Worker                as_arch_level = as_arch_level + '+crc'
416*c0909341SAndroid Build Coastguard Worker            endif
417*c0909341SAndroid Build Coastguard Worker            cdata.set('AS_ARCH_LEVEL', as_arch_level)
418*c0909341SAndroid Build Coastguard Worker            as_arch_str = '".arch ' + as_arch_level + '\\n"'
419*c0909341SAndroid Build Coastguard Worker        endif
420*c0909341SAndroid Build Coastguard Worker        foreach name, instr : aarch64_extensions
421*c0909341SAndroid Build Coastguard Worker            # Test for support for the various extensions. First test if
422*c0909341SAndroid Build Coastguard Worker            # the assembler supports the .arch_extension directive for
423*c0909341SAndroid Build Coastguard Worker            # enabling/disabling the extension, then separately check whether
424*c0909341SAndroid Build Coastguard Worker            # the instructions themselves are supported. Even if .arch_extension
425*c0909341SAndroid Build Coastguard Worker            # isn't supported, we may be able to assemble the instructions
426*c0909341SAndroid Build Coastguard Worker            # if the .arch level includes support for them.
427*c0909341SAndroid Build Coastguard Worker            code = '__asm__ (' + as_arch_str
428*c0909341SAndroid Build Coastguard Worker            code += '".arch_extension ' + name + '\\n"'
429*c0909341SAndroid Build Coastguard Worker            code += ');'
430*c0909341SAndroid Build Coastguard Worker            supports_archext = cc.compiles(code)
431*c0909341SAndroid Build Coastguard Worker            code = '__asm__ (' + as_arch_str
432*c0909341SAndroid Build Coastguard Worker            if supports_archext
433*c0909341SAndroid Build Coastguard Worker                supported_aarch64_archexts += name
434*c0909341SAndroid Build Coastguard Worker                code += '".arch_extension ' + name + '\\n"'
435*c0909341SAndroid Build Coastguard Worker            endif
436*c0909341SAndroid Build Coastguard Worker            code += '"' + instr + '\\n"'
437*c0909341SAndroid Build Coastguard Worker            code += ');'
438*c0909341SAndroid Build Coastguard Worker            if cc.compiles(code, name: name.to_upper())
439*c0909341SAndroid Build Coastguard Worker                supported_aarch64_instructions += name
440*c0909341SAndroid Build Coastguard Worker            endif
441*c0909341SAndroid Build Coastguard Worker        endforeach
442*c0909341SAndroid Build Coastguard Worker    endif
443*c0909341SAndroid Build Coastguard Workerendif
444*c0909341SAndroid Build Coastguard Worker
445*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_AS_FUNC', have_as_func)
446*c0909341SAndroid Build Coastguard Workercdata.set10('HAVE_AS_ARCH_DIRECTIVE', have_as_arch)
447*c0909341SAndroid Build Coastguard Workerforeach name, _ : aarch64_extensions
448*c0909341SAndroid Build Coastguard Worker    cdata.set10('HAVE_AS_ARCHEXT_' + name.to_upper() + '_DIRECTIVE', name in supported_aarch64_archexts)
449*c0909341SAndroid Build Coastguard Worker    cdata.set10('HAVE_' + name.to_upper(), name in supported_aarch64_instructions)
450*c0909341SAndroid Build Coastguard Workerendforeach
451*c0909341SAndroid Build Coastguard Worker
452*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_X86', host_machine.cpu_family().startswith('x86'))
453*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_X86_64', host_machine.cpu_family() == 'x86_64')
454*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_X86_32', host_machine.cpu_family() == 'x86')
455*c0909341SAndroid Build Coastguard Worker
456*c0909341SAndroid Build Coastguard Workerif host_machine.cpu_family().startswith('x86')
457*c0909341SAndroid Build Coastguard Worker    cdata_asm.set('private_prefix', 'dav1d')
458*c0909341SAndroid Build Coastguard Worker    cdata_asm.set10('ARCH_X86_64', host_machine.cpu_family() == 'x86_64')
459*c0909341SAndroid Build Coastguard Worker    cdata_asm.set10('ARCH_X86_32', host_machine.cpu_family() == 'x86')
460*c0909341SAndroid Build Coastguard Worker    cdata_asm.set10('PIC', true)
461*c0909341SAndroid Build Coastguard Worker
462*c0909341SAndroid Build Coastguard Worker    # Convert SSE asm into (128-bit) AVX when compiler flags are set to use AVX instructions
463*c0909341SAndroid Build Coastguard Worker    cdata_asm.set10('FORCE_VEX_ENCODING', cc.get_define('__AVX__').strip() != '')
464*c0909341SAndroid Build Coastguard Workerendif
465*c0909341SAndroid Build Coastguard Worker
466*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_PPC64LE', host_machine.cpu() == 'ppc64le')
467*c0909341SAndroid Build Coastguard Worker
468*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_RISCV', host_machine.cpu_family().startswith('riscv'))
469*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_RV32', host_machine.cpu_family() == 'riscv32')
470*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_RV64', host_machine.cpu_family() == 'riscv64')
471*c0909341SAndroid Build Coastguard Worker
472*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_LOONGARCH', host_machine.cpu_family().startswith('loongarch'))
473*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_LOONGARCH32', host_machine.cpu_family() == 'loongarch32')
474*c0909341SAndroid Build Coastguard Workercdata.set10('ARCH_LOONGARCH64', host_machine.cpu_family() == 'loongarch64')
475*c0909341SAndroid Build Coastguard Worker
476*c0909341SAndroid Build Coastguard Worker# meson's cc.symbols_have_underscore_prefix() is unfortunately unrelieably
477*c0909341SAndroid Build Coastguard Worker# when additional flags like '-fprofile-instr-generate' are passed via CFLAGS
478*c0909341SAndroid Build Coastguard Worker# see following meson issue https://github.com/mesonbuild/meson/issues/5482
479*c0909341SAndroid Build Coastguard Workerif (host_machine.system() in ['darwin', 'ios', 'tvos'] or
480*c0909341SAndroid Build Coastguard Worker   (host_machine.system() == 'windows' and host_machine.cpu_family() == 'x86'))
481*c0909341SAndroid Build Coastguard Worker    cdata.set10('PREFIX', true)
482*c0909341SAndroid Build Coastguard Worker    cdata_asm.set10('PREFIX', true)
483*c0909341SAndroid Build Coastguard Workerendif
484*c0909341SAndroid Build Coastguard Worker
485*c0909341SAndroid Build Coastguard Worker#
486*c0909341SAndroid Build Coastguard Worker# ASM specific stuff
487*c0909341SAndroid Build Coastguard Worker#
488*c0909341SAndroid Build Coastguard Workerif is_asm_enabled and host_machine.cpu_family().startswith('x86')
489*c0909341SAndroid Build Coastguard Worker
490*c0909341SAndroid Build Coastguard Worker    # NASM compiler support
491*c0909341SAndroid Build Coastguard Worker
492*c0909341SAndroid Build Coastguard Worker    nasm = find_program('nasm')
493*c0909341SAndroid Build Coastguard Worker
494*c0909341SAndroid Build Coastguard Worker    # check NASM version
495*c0909341SAndroid Build Coastguard Worker    if nasm.found()
496*c0909341SAndroid Build Coastguard Worker        nasm_r = run_command(nasm, '-v', check: true)
497*c0909341SAndroid Build Coastguard Worker
498*c0909341SAndroid Build Coastguard Worker        out = nasm_r.stdout().strip().split()
499*c0909341SAndroid Build Coastguard Worker        if out[1].to_lower() == 'version'
500*c0909341SAndroid Build Coastguard Worker            if out[2].version_compare('<2.14')
501*c0909341SAndroid Build Coastguard Worker                error('nasm 2.14 or later is required, found nasm @0@'.format(out[2]))
502*c0909341SAndroid Build Coastguard Worker            endif
503*c0909341SAndroid Build Coastguard Worker        else
504*c0909341SAndroid Build Coastguard Worker            error('unexpected nasm version string: @0@'.format(nasm_r.stdout()))
505*c0909341SAndroid Build Coastguard Worker        endif
506*c0909341SAndroid Build Coastguard Worker    endif
507*c0909341SAndroid Build Coastguard Worker
508*c0909341SAndroid Build Coastguard Worker    # Generate config.asm
509*c0909341SAndroid Build Coastguard Worker    config_asm_target = configure_file(output: 'config.asm', output_format: 'nasm', configuration: cdata_asm)
510*c0909341SAndroid Build Coastguard Worker
511*c0909341SAndroid Build Coastguard Worker    if host_machine.system() == 'windows'
512*c0909341SAndroid Build Coastguard Worker        nasm_format = 'win'
513*c0909341SAndroid Build Coastguard Worker    elif host_machine.system() in ['darwin', 'ios', 'tvos']
514*c0909341SAndroid Build Coastguard Worker        nasm_format = 'macho'
515*c0909341SAndroid Build Coastguard Worker    else
516*c0909341SAndroid Build Coastguard Worker        nasm_format = 'elf'
517*c0909341SAndroid Build Coastguard Worker    endif
518*c0909341SAndroid Build Coastguard Worker    if host_machine.cpu_family() == 'x86_64'
519*c0909341SAndroid Build Coastguard Worker        nasm_format += '64'
520*c0909341SAndroid Build Coastguard Worker    else
521*c0909341SAndroid Build Coastguard Worker        nasm_format += '32'
522*c0909341SAndroid Build Coastguard Worker    endif
523*c0909341SAndroid Build Coastguard Worker
524*c0909341SAndroid Build Coastguard Worker    nasm_gen = generator(nasm,
525*c0909341SAndroid Build Coastguard Worker        output: '@[email protected]',
526*c0909341SAndroid Build Coastguard Worker        depfile: '@[email protected]',
527*c0909341SAndroid Build Coastguard Worker        arguments: [
528*c0909341SAndroid Build Coastguard Worker            '-f', nasm_format,
529*c0909341SAndroid Build Coastguard Worker            '-I', '@0@/src/'.format(dav1d_src_root),
530*c0909341SAndroid Build Coastguard Worker            '-I', '@0@/'.format(meson.current_build_dir()),
531*c0909341SAndroid Build Coastguard Worker            '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@',
532*c0909341SAndroid Build Coastguard Worker            '@EXTRA_ARGS@',
533*c0909341SAndroid Build Coastguard Worker            '@INPUT@',
534*c0909341SAndroid Build Coastguard Worker            '-o', '@OUTPUT@'
535*c0909341SAndroid Build Coastguard Worker        ])
536*c0909341SAndroid Build Coastguard Workerendif
537*c0909341SAndroid Build Coastguard Worker
538*c0909341SAndroid Build Coastguard Workeruse_gaspp = false
539*c0909341SAndroid Build Coastguard Workerif (is_asm_enabled and
540*c0909341SAndroid Build Coastguard Worker    (host_machine.cpu_family() == 'aarch64' or
541*c0909341SAndroid Build Coastguard Worker     host_machine.cpu_family().startswith('arm')) and
542*c0909341SAndroid Build Coastguard Worker    cc.get_argument_syntax() == 'msvc' and
543*c0909341SAndroid Build Coastguard Worker    (cc.get_id() != 'clang-cl' or meson.version().version_compare('<0.58.0')))
544*c0909341SAndroid Build Coastguard Worker    gaspp = find_program('gas-preprocessor.pl')
545*c0909341SAndroid Build Coastguard Worker    use_gaspp = true
546*c0909341SAndroid Build Coastguard Worker    gaspp_gen = generator(gaspp,
547*c0909341SAndroid Build Coastguard Worker        output: '@[email protected]',
548*c0909341SAndroid Build Coastguard Worker        arguments: [
549*c0909341SAndroid Build Coastguard Worker            '-as-type', 'armasm',
550*c0909341SAndroid Build Coastguard Worker            '-arch', host_machine.cpu_family(),
551*c0909341SAndroid Build Coastguard Worker            '--',
552*c0909341SAndroid Build Coastguard Worker            host_machine.cpu_family() == 'aarch64' ? 'armasm64' : 'armasm',
553*c0909341SAndroid Build Coastguard Worker            '-nologo',
554*c0909341SAndroid Build Coastguard Worker            '-I@0@'.format(dav1d_src_root),
555*c0909341SAndroid Build Coastguard Worker            '-I@0@/'.format(meson.current_build_dir()),
556*c0909341SAndroid Build Coastguard Worker            '@INPUT@',
557*c0909341SAndroid Build Coastguard Worker            '-c',
558*c0909341SAndroid Build Coastguard Worker            '-o', '@OUTPUT@'
559*c0909341SAndroid Build Coastguard Worker        ])
560*c0909341SAndroid Build Coastguard Workerendif
561*c0909341SAndroid Build Coastguard Worker
562*c0909341SAndroid Build Coastguard Workerif is_asm_enabled and host_machine.cpu_family().startswith('riscv')
563*c0909341SAndroid Build Coastguard Worker    as_option_code = '''__asm__ (
564*c0909341SAndroid Build Coastguard Worker".option arch, +v\n"
565*c0909341SAndroid Build Coastguard Worker"vsetivli zero, 0, e8, m1, ta, ma"
566*c0909341SAndroid Build Coastguard Worker);
567*c0909341SAndroid Build Coastguard Worker'''
568*c0909341SAndroid Build Coastguard Worker    if not cc.compiles(as_option_code, name : 'RISC-V Vector')
569*c0909341SAndroid Build Coastguard Worker        error('Compiler doesn\'t support \'.option arch\' asm directive. Update to binutils>=2.38 or clang>=17 or use \'-Denable_asm=false\'.')
570*c0909341SAndroid Build Coastguard Worker    endif
571*c0909341SAndroid Build Coastguard Workerendif
572*c0909341SAndroid Build Coastguard Worker
573*c0909341SAndroid Build Coastguard Worker# Generate config.h
574*c0909341SAndroid Build Coastguard Workerconfig_h_target = configure_file(output: 'config.h', configuration: cdata)
575*c0909341SAndroid Build Coastguard Worker
576*c0909341SAndroid Build Coastguard Worker
577*c0909341SAndroid Build Coastguard Worker
578*c0909341SAndroid Build Coastguard Worker#
579*c0909341SAndroid Build Coastguard Worker# Include subdir meson.build files
580*c0909341SAndroid Build Coastguard Worker# The order is important!
581*c0909341SAndroid Build Coastguard Worker
582*c0909341SAndroid Build Coastguard Workersubdir('include')
583*c0909341SAndroid Build Coastguard Worker
584*c0909341SAndroid Build Coastguard Workersubdir('doc')
585*c0909341SAndroid Build Coastguard Worker
586*c0909341SAndroid Build Coastguard Workersubdir('src')
587*c0909341SAndroid Build Coastguard Worker
588*c0909341SAndroid Build Coastguard Workersubdir('tools')
589*c0909341SAndroid Build Coastguard Worker
590*c0909341SAndroid Build Coastguard Workersubdir('examples')
591*c0909341SAndroid Build Coastguard Worker
592*c0909341SAndroid Build Coastguard Workersubdir('tests')
593