tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

meson.build (24150B)


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