meson.build 8.71 KB
Newer Older
Marvin Scholz's avatar
Marvin Scholz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# Copyright © 2018, VideoLAN and dav1d authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
#    list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

project('dav1d', ['c'],
    version: '0.0.1',
27 28
    default_options: ['c_std=c99',
                      'warning_level=2'],
Marvin Scholz's avatar
Marvin Scholz committed
29 30
    meson_version: '>= 0.47.0')

31 32 33 34 35
dav1d_version_array    = meson.project_version().split('.')
dav1d_version_major    = dav1d_version_array[0]
dav1d_version_minor    = dav1d_version_array[1]
dav1d_version_revision = dav1d_version_array[2]

Marvin Scholz's avatar
Marvin Scholz committed
36
dav1d_src_root = meson.current_source_dir()
37 38 39
cc = meson.get_compiler('c')

# Configuratin data for config.h
Marvin Scholz's avatar
Marvin Scholz committed
40
cdata = configuration_data()
41 42

# Configuration data for config.asm
Marvin Scholz's avatar
Marvin Scholz committed
43
cdata_asm = configuration_data()
Marvin Scholz's avatar
Marvin Scholz committed
44

45 46 47
# Include directories
dav1d_inc_dirs = include_directories(['.', 'include', 'include/dav1d'])

Marvin Scholz's avatar
Marvin Scholz committed
48

49 50 51 52

#
# Option handling
#
53 54

# Bitdepth option
55 56 57 58
dav1d_bitdepths = get_option('bitdepths')
foreach bitdepth : dav1d_bitdepths
    cdata.set('CONFIG_@0@BPC'.format(bitdepth), 1)
endforeach
Marvin Scholz's avatar
Marvin Scholz committed
59

60 61
# ASM option
is_asm_enabled = (get_option('build_asm') == true and
62 63 64
    (host_machine.cpu_family().startswith('x86')) or
     host_machine.cpu_family() == 'aarch64'       or
     host_machine.cpu_family().startswith('arm'))
65 66 67 68
cdata.set10('HAVE_ASM', is_asm_enabled)



Marvin Scholz's avatar
Marvin Scholz committed
69
#
70
# OS/Compiler checks and defines
Marvin Scholz's avatar
Marvin Scholz committed
71 72
#

73 74 75 76 77 78 79 80 81 82 83 84 85
# Arguments in test_args will be used even on feature tests
test_args = []

# Define _POSIX_C_SOURCE to POSIX.1–2001 (IEEE Std 1003.1-2001)
test_args  += '-D_POSIX_C_SOURCE=200112L'
add_project_arguments('-D_POSIX_C_SOURCE=200112L', language: 'c')

if host_machine.system() == 'windows'
    cdata.set('_WIN32_WINNT',           '0x0601')
    cdata.set('UNICODE',                1) # Define to 1 for Unicode (Wide Chars) APIs
    cdata.set('_UNICODE',               1) # Define to 1 for Unicode (Wide Chars) APIs
    cdata.set('__USE_MINGW_ANSI_STDIO', 1) # Define to force use of MinGW printf
endif
Marvin Scholz's avatar
Marvin Scholz committed
86

87
# On Windows, we use a compatibility layer to emulate pthread
Marvin Scholz's avatar
Marvin Scholz committed
88
if host_machine.system() == 'windows'
89 90
    thread_dependency = []
    thread_compat_dep = declare_dependency(sources : files('src/win32/thread.c'))
91 92
else
    thread_dependency = dependency('threads')
93
    thread_compat_dep = []
Marvin Scholz's avatar
Marvin Scholz committed
94 95
endif

96 97 98

# Header checks

99
stdatomic_dependency = []
Marvin Scholz's avatar
Marvin Scholz committed
100
if not cc.check_header('stdatomic.h')
101 102 103 104 105 106 107 108
    if cc.get_id() == 'msvc'
        # we have a custom replacement for MSVC
        stdatomic_dependency = declare_dependency(
            include_directories : include_directories('include/compat'),
        )
    else
        error('Atomics not supported')
    endif
Marvin Scholz's avatar
Marvin Scholz committed
109 110
endif

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
if cc.check_header('unistd.h')
    cdata.set('HAVE_UNISTD_H', 1)
endif


# Function checks

if not cc.has_function('getopt_long', prefix : '#include <getopt.h>', args : test_args)
    getopt_dependency = declare_dependency(
        sources: files('tools/compat/getopt.c'),
        include_directories : include_directories('include/compat'),
    )
else
    getopt_dependency = []
endif

if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test_args)
    cdata.set('HAVE_POSIX_MEMALIGN', 1)
elif cc.has_function('_aligned_malloc', prefix : '#include <malloc.h>', args : test_args)
    cdata.set('HAVE_ALIGNED_MALLOC', 1)
endif


# Compiler flag tests

if cc.has_argument('-fvisibility=hidden')
    add_project_arguments('-fvisibility=hidden', language: 'c')
else
    warning('Compiler does not support -fvisibility=hidden, all symbols will be public!')
endif

# Compiler flags that should be set
# But when the compiler does not supports them
# it is not an error and silently tolerated
optional_arguments = [
  '-Wundef',
147
  '-Werror=vla',
148 149 150 151 152 153 154 155 156 157 158 159
]

if (get_option('buildtype') != 'debug' and get_option('buildtype') != 'plain')
    optional_arguments += '-fomit-frame-pointer'
    optional_arguments += '-ffast-math'
endif

add_project_arguments(cc.get_supported_arguments(optional_arguments), language : 'c')


# Stack alignments flags

160 161 162
stackalign_flag = []
stackrealign_flag = []

163 164 165 166
if host_machine.cpu_family().startswith('x86')
    if cc.has_argument('-mpreferred-stack-boundary=5')
        stackalign_flag = ['-mpreferred-stack-boundary=5']
        stackrealign_flag = ['-mincoming-stack-boundary=4']
Marvin Scholz's avatar
Marvin Scholz committed
167 168 169
        cdata_asm.set('STACK_ALIGNMENT', 32)
        cdata.set('STACK_ALIGNMENT', 32)
    elif cc.has_argument('-mpreferred-stack-boundary=4')
170 171
        stackalign_flag = ['-mpreferred-stack-boundary=4']
        stackrealign_flag = ['-mincoming-stack-boundary=4']
Marvin Scholz's avatar
Marvin Scholz committed
172 173
        cdata_asm.set('STACK_ALIGNMENT', 16)
        cdata.set('STACK_ALIGNMENT', 16)
174 175 176
    elif cc.has_argument('-mstack-alignment=32')
        stackalign_flag = ['-mstack-alignment=32']
        stackrealign_flag = ['-mstackrealign']
Marvin Scholz's avatar
Marvin Scholz committed
177 178
        cdata_asm.set('STACK_ALIGNMENT', 32)
        cdata.set('STACK_ALIGNMENT', 32)
179
    else
Marvin Scholz's avatar
Marvin Scholz committed
180 181 182 183 184 185 186
        if host_machine.cpu_family() == 'x86_64'
            cdata_asm.set('STACK_ALIGNMENT', 16)
            cdata.set('STACK_ALIGNMENT', 16)
        else
            cdata_asm.set('STACK_ALIGNMENT', 4)
            cdata.set('STACK_ALIGNMENT', 4)
        endif
187
    endif
Marvin Scholz's avatar
Marvin Scholz committed
188 189
endif

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
cdata.set10('ARCH_AARCH64', host_machine.cpu_family() == 'aarch64')
cdata.set10('ARCH_ARM',     host_machine.cpu_family().startswith('arm'))
if (is_asm_enabled and
    (host_machine.cpu_family() == 'aarch64' or
     host_machine.cpu_family().startswith('arm')))

   as_func_code = '''__asm__ (
".func meson_test"
".endfunc"
);
'''
    have_as_func = cc.compiles(as_func_code)
    cdata.set10('HAVE_AS_FUNC', have_as_func)
endif

Marvin Scholz's avatar
Marvin Scholz committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
if host_machine.cpu_family().startswith('x86')
    cdata.set10('ARCH_X86', true)
    if host_machine.cpu_family() == 'x86_64'
        cdata_asm.set10('ARCH_X86_64', true)
        cdata.set10('ARCH_X86_64', true)
        cdata_asm.set10('ARCH_X86_32', false)
        cdata.set10('ARCH_X86_32', false)

        cdata_asm.set10('PIC', true)
    else
        cdata_asm.set10('ARCH_X86_64', false)
        cdata.set10('ARCH_X86_64', false)
        cdata_asm.set10('ARCH_X86_32', true)
        cdata.set10('ARCH_X86_32', true)
    endif
else
    cdata.set10('ARCH_X86', false)
    cdata.set10('ARCH_X86_64', false)
    cdata.set10('ARCH_X86_32', false)
endif

if cc.symbols_have_underscore_prefix()
227
    cdata.set10('PREFIX', true)
Marvin Scholz's avatar
Marvin Scholz committed
228 229 230
    cdata_asm.set10('PREFIX', true)
endif

231 232
# Generate config.h
config_h_target = configure_file(output: 'config.h', configuration: cdata)
Marvin Scholz's avatar
Marvin Scholz committed
233 234


Marvin Scholz's avatar
Marvin Scholz committed
235

Marvin Scholz's avatar
Marvin Scholz committed
236
#
237
# ASM specific stuff
Marvin Scholz's avatar
Marvin Scholz committed
238
#
239
if is_asm_enabled and host_machine.cpu_family().startswith('x86')
Marvin Scholz's avatar
Marvin Scholz committed
240

241 242
    # Generate config.asm
    config_asm_target = configure_file(output: 'config.asm', output_format: 'nasm', configuration: cdata_asm)
243 244


245
    # NASM compiler support
Marvin Scholz's avatar
Marvin Scholz committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

    nasm = find_program('nasm')

    if host_machine.system() == 'windows'
        nasm_format = 'win'
    elif host_machine.system() == 'darwin'
        nasm_format = 'macho'
    else
        nasm_format = 'elf'
    endif
    if host_machine.cpu_family() == 'x86_64'
        nasm_format += '64'
    else
        nasm_format += '32'
    endif

    nasm_gen = generator(nasm,
        output: '@BASENAME@.obj',
        depfile: '@BASENAME@.obj.ndep',
        arguments: [
            '-f', nasm_format,
267
            '-I', '@SOURCE_DIR@/src/',
268
            '-I', '@0@/'.format(meson.current_build_dir()),
Marvin Scholz's avatar
Marvin Scholz committed
269 270 271 272 273 274 275
            '-MQ', '@OUTPUT@', '-MF', '@DEPFILE@',
            '@EXTRA_ARGS@',
            '@INPUT@',
            '-o', '@OUTPUT@'
        ])
endif

Henrik Gramner's avatar
Henrik Gramner committed
276

277

278 279 280
#
# Include subdir meson.build files
# The order is important!
Marvin Scholz's avatar
Marvin Scholz committed
281

282
subdir('include')
Marvin Scholz's avatar
Marvin Scholz committed
283

284
subdir('src')
285

286
subdir('tools')
287

288
subdir('tests')
289

290

Marvin Scholz's avatar
Marvin Scholz committed
291

Marvin Scholz's avatar
Marvin Scholz committed
292
#
293
# Generate pkg-config .pc file
Marvin Scholz's avatar
Marvin Scholz committed
294 295 296
#
pkg_mod = import('pkgconfig')
pkg_mod.generate(libraries: libdav1d,
297
    version: meson.project_version(),
Marvin Scholz's avatar
Marvin Scholz committed
298 299 300 301
    name: 'libdav1d',
    filebase: 'dav1d',
    description: 'AV1 decoding library'
)