meson.build 6.92 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
    default_options: ['c_std=c99'],
Marvin Scholz's avatar
Marvin Scholz committed
28
29
30
31
32
33
34
35
36
    meson_version: '>= 0.47.0')

dav1d_src_root = meson.current_source_dir()
cdata = configuration_data()
cc = meson.get_compiler('c')

if not meson.is_cross_build() 
    thread_dependency = dependency('threads')
else
37
38
39
40
    thread_dependency = cc.find_library('pthread', required: false)
endif
if thread_dependency.found()
    cdata.set('HAVE_PTHREAD_H', 1)
Marvin Scholz's avatar
Marvin Scholz committed
41
42
endif

43
44
45
46
47
48
49
50
51
dav1d_inc_dirs = include_directories(['include', 'include/dav1d'])

#
# Option handling
#
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
52
53
54
55
56
57
58

#
# OS/Compiler feature detection
#

feature_defines = [
    ['_GNU_SOURCE',                 1], # Enable GNU extensions on systems that have them
59
    ['_POSIX_C_SOURCE',             '200112L'], # POSIX.1–2001 (IEEE Std 1003.1-2001)
Marvin Scholz's avatar
Marvin Scholz committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
]

if host_machine.system() == 'windows'
    feature_defines += [
            ['_WIN32_WINNT',                0x0601],
            ['UNICODE',                     1], # Define to 1 for Unicode (Wide Chars) APIs
            ['_UNICODE',                    1], # Define to 1 for Unicode (Wide Chars) APIs
            ['__USE_MINGW_ANSI_STDIO',      1], # Define to force use of MinGW printf
    ]
endif

if not cc.check_header('stdatomic.h')
    error('Atomics not supported')
endif

75
76
77
78
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
79
80
81
# When cross compiling for win64 gcc refuses to use -mpreferred-stack-boundary
# with a value which isn't 3 or 4. However, when cross compiling with clang, 5 is
# accepted.
82
83
84
85
86
87
88
89
90
91
    elif (host_machine.system() == 'windows' and host_machine.cpu_family() == 'x86_64'
    and cc.has_argument('-mpreferred-stack-boundary=4'))
        stackalign_flag = ['-mpreferred-stack-boundary=4']
        stackrealign_flag = ['-mincoming-stack-boundary=4']
    elif cc.has_argument('-mstack-alignment=32')
        stackalign_flag = ['-mstack-alignment=32']
        stackrealign_flag = ['-mstackrealign']
    else
        error('Failed to specify stack alignment')
    endif
Marvin Scholz's avatar
Marvin Scholz committed
92
else
93
94
    stackalign_flag = []
    stackrealign_flag = []
Marvin Scholz's avatar
Marvin Scholz committed
95
96
97
98
99
100
101
102
endif

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

103
if cc.has_function('posix_memalign', prefix: '#include <stdlib.h>', args: ['-D_POSIX_C_SOURCE=200112L'])
Marvin Scholz's avatar
Marvin Scholz committed
104
105
106
107
108
    cdata.set('HAVE_POSIX_MEMALIGN', 1)
elif cc.has_function('_aligned_malloc', prefix: '#include <malloc.h>')
    cdata.set('HAVE_ALIGNED_MALLOC', 1)
endif

109
110
if (get_option('buildtype') != 'debug' and
    get_option('buildtype') != 'plain')
111
112
113
    add_project_arguments('-fomit-frame-pointer', '-ffast-math',
        language: 'c')
endif
Marvin Scholz's avatar
Marvin Scholz committed
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

add_project_arguments('-Wall', '-Wundef',
    language: 'c')

foreach f : feature_defines
   cdata.set(f.get(0), f.get(1))
endforeach

#
# Generate config headers
#

config_h_target = configure_file(output: 'config.h', configuration: cdata)

subdir('include')

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
# dav1d library
#
libdav1d_tmpl_sources = files(
    'src/ipred.c',
    'src/itx.c',
    'src/ipred_prepare.c',
    'src/lf_apply.c',
    'src/loopfilter.c',
    'src/mc.c',
    'src/cdef_apply.c',
    'src/cdef.c',
    'src/lr_apply.c',
    'src/looprestoration.c',
    'src/recon.c'
)

# Build a helper library for each bitdepth
bitdepth_objs = []
foreach bitdepth : dav1d_bitdepths
    bitdepth_lib = static_library(
        'dav1d_bitdepth_@0@'.format(bitdepth),
        libdav1d_tmpl_sources, config_h_target,
        include_directories: dav1d_inc_dirs,
154
        c_args: ['-DBITDEPTH=@0@'.format(bitdepth)] + stackalign_flag,
155
156
157
158
159
160
161
162
163
164
165
166
167
168
        install: false,
        build_by_default: false,
    )
    bitdepth_objs += bitdepth_lib.extract_all_objects()
endforeach

entrypoints_src = files(
    'src/lib.c',
    'src/thread_task.c'
)
entrypoints_lib = static_library(
    'libdav1dentrypoint',
    entrypoints_src,
    include_directories: dav1d_inc_dirs,
169
    c_args: stackrealign_flag,
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
    install: false,
)
entrypoints_objs = entrypoints_lib.extract_all_objects()

libdav1d_sources = files(
    'src/picture.c',
    'src/data.c',
    'src/ref.c',
    'src/getbits.c',
    'src/obu.c',
    'src/decode.c',
    'src/cdf.c',
    'src/msac.c',
    'src/tables.c',
    'src/scan.c',
    'src/dequant_tables.c',
    'src/intra_edge.c',
    'src/lf_mask.c',
    'src/ref_mvs.c',
    'src/warpmv.c',
    'src/wedge.c',
    'src/qm.c',
)

194
195
196
197
if host_machine.system() == 'windows'
    libdav1d_sources += files('src/win32/thread.c')
endif

Marvin Scholz's avatar
Marvin Scholz committed
198
libdav1d = library('dav1d',
199
    libdav1d_sources, rev_target,
Marvin Scholz's avatar
Marvin Scholz committed
200
    version: '0.0.1',
201
    objects: [bitdepth_objs, entrypoints_objs],
Marvin Scholz's avatar
Marvin Scholz committed
202
203
204
205
206
207
    include_directories: dav1d_inc_dirs,
    c_args: [stackalign_flag],
    dependencies: thread_dependency,
    install: true
)

208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
install_subdir('include/dav1d/', install_dir: 'include')

#
# dav1d cli tool
#
dav1d_sources = files(
    'tools/dav1d.c',
    'tools/dav1d_cli_parse.c',
    'tools/input/input.c',
    'tools/input/ivf.c',
    'tools/output/md5.c',
    'tools/output/output.c',
    'tools/output/y4m2.c',
    'tools/output/yuv.c'
)

dav1d = executable('dav1d',
    dav1d_sources, rev_target,
    link_with: libdav1d,
227
228
    include_directories: [dav1d_inc_dirs, include_directories('tools')],
    install: true,
229
230
)

Marvin Scholz's avatar
Marvin Scholz committed
231
232
233
234
235
236
237
238
239
240
#
# pkg-config boilerplate
#
pkg_mod = import('pkgconfig')
pkg_mod.generate(libraries: libdav1d,
    version: '0.0.1',
    name: 'libdav1d',
    filebase: 'dav1d',
    description: 'AV1 decoding library'
)