-
Notifications
You must be signed in to change notification settings - Fork 24
/
meson.build
232 lines (197 loc) · 6.17 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
# Project definition
project('cffi-lua', ['cpp'],
version: '0.2.3',
default_options: [
'buildtype=debugoptimized', 'b_ndebug=if-release', 'cpp_std=c++14',
'warning_level=3', 'cpp_rtti=false', 'cpp_eh=none'
],
meson_version: '>=0.56'
)
# Extra compiler warnings for gcc/clang
cxx = meson.get_compiler('cpp')
extra_cxxflags = []
if get_option('buildtype') != 'plain'
if cxx.has_argument('-Wshadow')
extra_cxxflags += '-Wshadow'
endif
if cxx.has_argument('-Wold-style-cast')
extra_cxxflags += '-Wold-style-cast'
endif
endif
# Endianness specification is mandatory
if host_machine.endian() == 'big'
extra_cxxflags += '-DFFI_BIG_ENDIAN'
else
extra_cxxflags += '-DFFI_LITTLE_ENDIAN'
endif
# Vendor library path; used to find libs and also added to PATH for Windows
deps_path = get_option('deps_dir')
deps_libs = [
join_paths(meson.project_source_root(), deps_path),
join_paths(meson.project_build_root(), deps_path)
]
extra_inc = []
# Lua dependency checks
luaver = get_option('lua_version')
if luaver == 'luajit'
lua_dep = dependency('luajit')
elif luaver != 'auto' and luaver != 'custom' and luaver != 'vendor'
lua_dep = dependency('lua' + luaver, required: false)
if not lua_dep.found()
lua_dep = dependency('lua-' + luaver, required: false)
endif
if not lua_dep.found()
lua_dep = dependency('lua' + ''.join(luaver.split('.')), required: false)
endif
if not lua_dep.found()
lua_dep = dependency('lua')
endif
if not lua_dep.version().startswith(luaver)
error('required lua version not found (got @0@)'
.format(lua_dep.version()))
endif
elif luaver == 'custom'
lua_dep = dependency('', required: false)
elif luaver == 'vendor'
lua_dep = dependency('', required: false)
extra_inc += include_directories(join_paths(deps_path, 'include'))
else
lua_dep = dependency('lua')
endif
# Libffi dependency checks
ffiver = get_option('libffi')
if ffiver == 'custom'
ffi_dep = dependency('', required: false)
elif ffiver == 'vendor'
ffi_dep = cxx.find_library('ffi', dirs: deps_libs)
extra_inc += include_directories(join_paths(deps_path, 'include'))
else
# use static lib if subproject
ffi_dep = dependency('libffi',
default_options: ['default_library=static', 'tests=false']
)
endif
# Needed on Linux
dl_lib = cxx.find_library('dl', required: false)
# These are Windows only
if get_option('shared_libffi')
extra_cxxflags += '-DHAVE_LIBFFI_DLLIMPORT'
endif
# Module build definition
luaver_maj = '5'
luaver_num = cxx.compute_int(
'LUA_VERSION_NUM', prefix: '#include <lua.hpp>',
dependencies: lua_dep, include_directories: extra_inc
)
luaver_min = luaver_num - 500
luaver_str = '@0@.@1@'.format(luaver_maj, luaver_min)
if luaver_min < 1
error('Lua 5.1 or newer is required')
endif
# follow what lua does, i.e. .so everywhere except windows
plugin_suffix = 'so'
if host_machine.system() == 'windows'
plugin_suffix = 'dll'
endif
cffi_src = [
'src/util.cc',
'src/ffilib.cc',
'src/parser.cc',
'src/ast.cc',
'src/lib.cc',
'src/ffi.cc',
'src/main.cc'
]
# on windows, we need to link to the dll, the dll has a specific name that
# follows the lua version we depend on; on unix-likes we on the other hand
# do not need the library at all, so skip it
if host_machine.system() == 'windows'
# msys2, etc
lua_adep = cxx.find_library('lua', dirs: deps_libs, required: false)
if not lua_adep.found()
# lua 5.1 uses lua5.1.dll/lib
lua_adep = cxx.find_library(
'lua@0@.@1@'.format(luaver_maj, luaver_min),
dirs: deps_libs, required: false
)
endif
if not lua_adep.found()
# lua 5.2 onwards uses lua5.2.dll/lib
lua_adep = cxx.find_library(
'lua@0@@1@'.format(luaver_maj, luaver_min), dirs: deps_libs
)
endif
else
lua_adep = lua_dep.partial_dependency(compile_args: true, includes: true)
endif
cffi_deps = [dl_lib, ffi_dep, lua_adep]
if get_option('static')
cffi = static_library('cffi-lua-@0@'.format(luaver_str),
cffi_src,
install: true,
pic: true,
dependencies: cffi_deps,
include_directories: extra_inc,
cpp_args: extra_cxxflags,
gnu_symbol_visibility: 'hidden'
)
cffi_dep = declare_dependency(
link_with: cffi,
include_directories: extra_inc
)
else
lua_modpath = get_option('lua_install_path')
if lua_modpath == 'auto'
lua_modpath = join_paths(get_option('libdir'), 'lua', '@0@')
endif
cffi = shared_module('cffi',
cffi_src,
install: true,
install_dir: lua_modpath.format(luaver_str),
name_prefix: '',
name_suffix: plugin_suffix,
dependencies: cffi_deps,
cpp_args: ['-DCFFI_LUA_DLL'] + extra_cxxflags,
include_directories: extra_inc,
gnu_symbol_visibility: 'hidden'
)
endif
# Tests
if meson.is_cross_build() and get_option('tests')
build_tests = get_option('tests_cross')
else
build_tests = get_option('tests')
endif
if build_tests and not get_option('static')
# get lua path for the runner
lua_pathopt = get_option('lua_path')
if lua_pathopt == 'auto' and luaver == 'vendor'
lua_exe = find_program(
join_paths(deps_path, 'lua@0@'.format(luaver_str)),
join_paths(deps_path, 'lua@0@@1@'.format(luaver_maj, luaver_min)),
join_paths(deps_path, 'lua'),
required: true
)
elif lua_pathopt == 'auto'
lua_exe = find_program(
'lua@0@'.format(luaver_str),
'lua@0@@1@'.format(luaver_maj, luaver_min),
'lua',
required: true
)
else
lua_exe = find_program(lua_pathopt, required: true)
endif
# check the lua version matches the library version
# also checks if it's actually runnable (cross-compiling?)
ret = run_command(lua_exe, [
'-e',
'io.write(_VERSION:match("5.+"))'
])
if ret.stdout() != luaver_str
error('Lua executable does not match version (@0@ vs @1@)'.format(
ret.stdout(), luaver_str
))
endif
subdir('tests')
endif