project('faac', 'c',
    version: '2.0.0',
    default_options: [
        'default_library=both',
        'buildtype=release',
        'warning_level=3',
        'c_std=gnu11,c11',
    ])

add_global_arguments('-DHAVE_CONFIG_H', language: 'c')

config_h = configuration_data()
config_h.set_quoted('PACKAGE', meson.project_name())
config_h.set_quoted('PACKAGE_VERSION', meson.project_version())

cc = meson.get_compiler('c')
foreach h: ['getopt.h', 'immintrin.h']
    config_h.set('HAVE_' + h.underscorify().to_upper(), cc.has_header(h))
endforeach

config_h.set('WORDS_BIGENDIAN', host_machine.endian() == 'big')


libm = cc.find_library('m', required: false)

cpu_family = target_machine.cpu_family()

config_h.set('HAVE_SSE2', (cpu_family in ['x86', 'x86_64']) and config_h.get('HAVE_IMMINTRIN_H'))

config_h.set('FAAC_SBR_DECIMATION', get_option('sbr-decimation'))

config_h.set('MAX_CHANNELS', get_option('max-channels'))

c_args = []
if cc.get_argument_syntax() == 'msvc'
    c_args += ['-DWIN32', '-DNDEBUG', '-D_WINDOWS', '-D_USRDLL', '-DLIBFAAC_DLL_EXPORTS']
endif

configure_file(
    output: 'config.h',
    configuration: config_h
)


subdir('docs')
subdir('include')
subdir('libfaac')

if get_option('frontend')
    subdir('frontend')
endif
