forked from frida/frida-gum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
244 lines (206 loc) · 5.53 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
237
238
239
240
241
242
243
244
project('frida-gum', 'c', 'cpp',
version: '1.0.0',
default_options: ['c_std=gnu99', 'cpp_std=c++11'],
)
gum_version = meson.project_version()
api_version = '1.0'
host_os_family = host_machine.system()
host_os = host_os_family
languages = ['c', 'cpp']
if host_os_family == 'darwin'
languages += ['objc', 'objcpp']
add_languages('objc', 'objcpp')
endif
cc = meson.get_compiler('c')
target_conditionals_prefix = '#include <TargetConditionals.h>'
is_macos_src = target_conditionals_prefix + '''
#if !TARGET_OS_OSX
# error Not macOS
#endif
'''
if cc.compiles(is_macos_src, name: 'compiling for macOS')
host_os = 'macos'
endif
is_ios_src = target_conditionals_prefix + '''
#if !TARGET_OS_IOS
# error Not iOS
#endif
'''
if cc.compiles(is_ios_src, name: 'compiling for iOS')
host_os = 'ios'
endif
if cc.has_header('android/api-level.h')
host_os = 'android'
endif
cdata = configuration_data()
cdata.set('HAVE_' + host_os_family.to_upper(), 1)
if host_os != host_os_family
cdata.set('HAVE_' + host_os.to_upper(), 1)
endif
cpu_defines = [
['x86', 'HAVE_I386'],
['x86_64', 'HAVE_I386'],
['arm', 'HAVE_ARM'],
['arm64', 'HAVE_ARM64'],
['mips', 'HAVE_MIPS'],
]
foreach d : cpu_defines
if d.get(0) == host_machine.cpu_family()
cdata.set(d.get(1), 1)
endif
endforeach
headers = [
'elf.h',
'stdint.h',
'sys/elf.h',
'sys/user.h',
]
foreach h : headers
if cc.has_header(h)
cdata.set('HAVE_' + h.underscorify().to_upper(), 1)
endif
endforeach
types = [
'long double',
'long long int',
'unsigned long long int'
]
foreach t : types
if cc.has_type(t)
cdata.set('HAVE_' + t.underscorify().to_upper(), 1)
endif
endforeach
glibc_src = '''
#include <features.h>
#if defined (__GLIBC__) && !defined (__UCLIBC__)
#else
# error Not glibc
#endif
'''
if cc.compiles(glibc_src, name: 'compiling for glibc')
cdata.set('HAVE_GLIBC', 1)
endif
if cc.has_function('log2') and host_os != 'android'
cdata.set('HAVE_LOG2', 1)
endif
if cc.has_member('struct mallinfo', 'arena', prefix: '#include <malloc.h>')
cdata.set('HAVE_LIBC_MALLINFO', 1)
endif
asan_src = '''
#ifndef __SANITIZE_ADDRESS__
# ifdef __clang__
# if __has_feature(address_sanitizer)
# define __SANITIZE_ADDRESS__
# endif
# endif
#endif
#ifndef __SANITIZE_ADDRESS__
# error ASAN disabled
#endif
'''
if cc.compiles(asan_src, name: 'compiling with ASan')
cdata.set('HAVE_ASAN', 1)
endif
glib_dep = dependency('glib-2.0', version: '>=2.53')
gobject_dep = dependency('gobject-2.0')
gmodule_dep = dependency('gmodule-2.0')
gio_dep = dependency('gio-2.0')
capstone_dep = dependency('capstone')
ffi_dep = dependency('libffi')
extra_deps = []
extra_requires_private = []
extra_libs_private = []
gumjs_extra_deps = []
gumjs_extra_requires = []
gumjs_extra_libraries = []
if host_os == 'android'
extra_libs_private += ['-llog']
endif
unwind_dep = dependency('libunwind', required: false)
unwind_requires = []
if unwind_dep.found()
cdata.set('HAVE_LIBUNWIND', 1)
extra_deps += [unwind_dep]
extra_requires_private += ['libunwind']
elif host_os_family == 'linux' or host_os_family == 'qnx'
error('libunwind is required')
endif
have_bfd = cc.has_header('bfd.h')
if have_bfd
if host_os_family == 'linux'
extra_libs_private += ['-lbfd', '-ldl', '-lz']
else
extra_libs_private += ['-lbfd', '-lz']
endif
elif host_os_family == 'linux' or host_os_family == 'qnx'
error('libbfd is required')
endif
if get_option('enable_gumpp')
cdata.set('HAVE_GUMPP', 1)
endif
if get_option('enable_gumjs')
cdata.set('HAVE_GUMJS', 1)
json_glib_dep = dependency('json-glib-1.0')
if host_os_family == 'windows'
gio_os_package_name = 'gio-windows-2.0'
else
gio_os_package_name = 'gio-unix-2.0'
endif
gio_os_package_dep = dependency(gio_os_package_name)
gumjs_extra_deps += [gio_os_package_dep]
gumjs_extra_requires += [gio_os_package_name]
if host_os_family == 'linux' or host_os_family == 'qnx'
gumjs_extra_libraries += ['-lm']
endif
enable_diet_value = get_option('enable_diet')
if enable_diet_value == 'auto'
cpu = host_machine.cpu_family()
is_embedded_linux = host_os == 'linux' and (cpu == 'arm' or cpu == 'arm64' or cpu == 'mips')
is_arm_hardfloat_linux = host_os == 'linux' and cpu == 'arm' and host_machine.cpu().endswith('hf')
enable_diet = host_os == 'ios' or (is_embedded_linux and not is_arm_hardfloat_linux) or host_os == 'qnx'
else
enable_diet = enable_diet_value == 'yes'
endif
if not enable_diet
v8_dep = dependency('v8', version: '>=6.0.124', required: false)
have_v8 = v8_dep.found()
else
have_v8 = false
endif
if have_v8
cdata.set('HAVE_V8', 1)
gumjs_extra_deps += [v8_dep]
gumjs_extra_requires += ['v8']
endif
endif
configure_file(input: 'config.h.in',
output: 'config.h',
configuration: cdata)
add_project_arguments(
'-include', 'config.h',
'-DG_LOG_DOMAIN="Frida"',
language: languages)
if host_os_family == 'linux'
add_project_arguments('-D_GNU_SOURCE=1', language: languages)
endif
if host_os_family == 'qnx'
add_project_arguments('-D_QNX_SOURCE=1', language: languages)
endif
gum_incdirs = [
include_directories('.'),
include_directories('gum'),
include_directories('gum/arch-x86'),
include_directories('gum/arch-arm'),
include_directories('gum/arch-arm64'),
include_directories('gum/arch-mips'),
include_directories('libs'),
include_directories('libs/gum/heap'),
include_directories('libs/gum/prof'),
]
install_header_basedir = 'frida-' + api_version
install_header_subdir = install_header_basedir + '/gum'
subdir('gum')
subdir('libs')
subdir('bindings')
subdir('vapi')
subdir('tests')