-
Notifications
You must be signed in to change notification settings - Fork 16
/
meson.build
236 lines (198 loc) · 5.31 KB
/
meson.build
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
project('boxfort', 'c',
meson_version : '>= 0.48.0',
license : 'MIT',
version : '0.0.1',
default_options : ['c_std=c99', 'warning_level=3', 'b_lundef=false', 'default_library=static'])
# standard install directories
prefix = get_option('prefix')
samples = get_option('samples')
tests = get_option('tests')
# Helper scripts
auxdir = join_paths(meson.current_source_dir(), 'ci')
isdir = join_paths(auxdir, 'isdir.py')
python3 = find_program('python3')
git = find_program('git', required: false)
# Get the right version
is_git_repo = run_command([isdir, '.git'], check: false).returncode() == 0
version = 'v' + meson.project_version()
if git.found() and is_git_repo
version = run_command([git.path(), 'describe', '--dirty', '--tags'], check: false).stdout().strip()
branch = run_command([git.path(), 'rev-parse', '--abbrev-ref', 'HEAD'], check: false).stdout().strip()
if branch != 'master'
version = '@0@ (@1@)'.format(version, branch)
endif
endif
cc = meson.get_compiler('c')
add_project_arguments(
cc.get_supported_arguments([
'-Wno-unused-parameter',
'-Wno-unused-value',
'-fvisibility=hidden',
# MSVC-specific stuff
'/SAFESEH:NO',
'/source-charset:utf-8',
]),
'-DBXF_BUILDING_LIB',
'-D_GNU_SOURCE',
language: ['c', 'cpp'])
if host_machine.system() == 'windows'
add_project_arguments(
'-DVC_EXTRALEAN',
'-DWIN32_LEAN_AND_MEAN',
'-D_CRT_SECURE_NO_WARNINGS',
'-D_WIN32_WINNT=0x600',
language: ['c', 'cpp'])
endif
boxfort_includedir = include_directories(
'include',
'src',
)
threads = dependency('threads')
# optional platform-dependent standard libs
librt = cc.find_library('rt', required: false)
libm = cc.find_library('m', required: false)
config = configuration_data()
config.set('package', meson.project_name())
config.set('version', version)
os = host_machine.system()
arch = host_machine.cpu_family()
mangling = 'none'
if cc.symbols_have_underscore_prefix()
mangling = 'leading-underscore'
endif
if arch == 'x86'
bitness = 32
elif arch == 'x86_64'
bitness = 64
elif arch == 'arm'
bitness = 32
elif arch == 'aarch64'
bitness = 64
elif arch == 'riscv64'
bitness = 64
else
error('Architecture "@0@" is not supported.'.format(arch))
endif
if get_option('arena_reopen_shm')
config.set('BXF_ARENA_REOPEN_SHM', 1)
endif
if get_option('arena_file_backed')
config.set('BXF_ARENA_FILE_BACKED', 1)
endif
binfmt = 'elf'
os_family = 'posix'
if os == 'windows'
binfmt = 'pe'
os_family = 'windows'
elif os == 'darwin'
binfmt = 'mach-o'
# This is mandatory because OS X fails silently when mmap'ing an inherited
# shm file descriptor
config.set('BXF_ARENA_REOPEN_SHM', 1)
config.set('BXF_ARENA_FILE_BACKED', 1)
endif
config.set('BXF_EXE_FORMAT', binfmt)
config.set('BXF_EXE_FMT_@0@'.format(binfmt.to_upper().underscorify()), 1)
config.set('BXF_OS_FAMILY', os_family)
config.set('BXF_ARCH', '"' + arch + '"')
config.set('BXF_ARCH_@0@'.format(arch.to_upper()), 1)
config.set('BXF_MANGLING', mangling)
config.set('BXF_BITS', bitness)
checks = [
{'fn': 'clock_gettime'},
{'fn': 'gettimeofday'},
{'fn': 'mincore'},
{'fn': 'prctl'},
{'fn': 'procctl'},
{'fn': 'shm_open'},
{'fn': 'mach_vm_protect'},
{'fn': '__builtin___clear_cache'},
# some platforms define mincore with an unsigned vector
{
'fn': 'mincore',
'proto': 'int _(void *, size_t, unsigned char *)',
'headers': ['unistd.h', 'sys/mman.h'],
'var': 'HAVE_UNSIGNED_MINCORE_VEC',
},
{'sym': 'PR_SET_PDEATHSIG', 'header': 'sys/prctl.h'},
{'sym': 'PROC_PDEATHSIG_CTL', 'header': 'sys/procctl.h'},
{'sym': 'CLOCK_MONOTONIC_RAW', 'header': 'time.h'},
{'sym': 'environ', 'header': 'unistd.h'},
]
if binfmt == 'elf'
checks += [
{'sym': '_r_debug', 'header': 'link.h'},
{'sym': '_DYNAMIC', 'header': 'link.h'},
]
endif
check_prelude = '''
#define _GNU_SOURCE
'''
prototype_check = check_prelude + '''
@0@
typedef @1@;
static _ *check = @2@;
'''
foreach check : checks
chk_prefix = check.get('prefix', '')
if chk_prefix != ''
chk_prefix = chk_prefix + '_'
endif
result = false
if check.has_key('proto')
includes = ''
foreach hdr : check.get('headers')
includes += '#include <@0@>\n'.format(hdr)
endforeach
result = cc.compiles(prototype_check.format(includes, check.get('proto'), check.get('fn')))
elif check.has_key('fn')
name = check.get('fn')
libs = ['c']
if librt.found()
libs += 'rt'
endif
if libm.found()
libs += 'm'
endif
if check.has_key('libs')
libs += check.get('libs')
endif
args = []
foreach lib : libs
args += '-l' + lib
endforeach
result = cc.has_function(name, prefix: check_prelude, args: args)
elif check.has_key('sym')
name = check.get('sym')
result = cc.has_header_symbol(check.get('header'), name, prefix: check_prelude)
elif check.has_key('hdr')
name = check.get('hdr')
result = cc.has_header(name)
endif
if check.has_key('var')
name = check.get('var')
else
name = 'HAVE_@1@@0@'.format(name.to_upper(), chk_prefix.to_upper())
endif
config.set(name, result)
endforeach
api = files('include/boxfort.h')
if not meson.is_subproject()
install_headers(api)
endif
includedir = include_directories(
'include',
'src',
)
if target_machine.system() == 'windows'
config.set10('HAVE_WIN32_THREADS', true)
else
config.set10('HAVE_PTHREADS', true)
endif
subdir('src')
if samples
subdir('sample')
endif
if tests
subdir('test')
endif