1 | project('libslirp', 'c',
|
---|
2 | version : '4.8.0',
|
---|
3 | license : 'BSD-3-Clause',
|
---|
4 | default_options : ['warning_level=1', 'c_std=gnu99'],
|
---|
5 | meson_version : '>= 0.50',
|
---|
6 | )
|
---|
7 |
|
---|
8 | version = meson.project_version()
|
---|
9 | varr = version.split('.')
|
---|
10 | major_version = varr[0]
|
---|
11 | minor_version = varr[1]
|
---|
12 | micro_version = varr[2]
|
---|
13 |
|
---|
14 | conf = configuration_data()
|
---|
15 | conf.set('SLIRP_MAJOR_VERSION', major_version)
|
---|
16 | conf.set('SLIRP_MINOR_VERSION', minor_version)
|
---|
17 | conf.set('SLIRP_MICRO_VERSION', micro_version)
|
---|
18 |
|
---|
19 | want_ossfuzz = get_option('oss-fuzz')
|
---|
20 | want_libfuzzer = get_option('llvm-fuzz')
|
---|
21 | fuzz_reproduce = get_option('fuzz-reproduce')
|
---|
22 | if want_ossfuzz and want_libfuzzer
|
---|
23 | error('only one of oss-fuzz and llvm-fuzz can be specified')
|
---|
24 | endif
|
---|
25 | fuzzer_build = want_ossfuzz or want_libfuzzer
|
---|
26 | if fuzzer_build and fuzz_reproduce
|
---|
27 | error('fuzzer build and reproducer build are mutually exclusive')
|
---|
28 | endif
|
---|
29 |
|
---|
30 | cc = meson.get_compiler('c')
|
---|
31 | add_languages('cpp', required : fuzzer_build)
|
---|
32 |
|
---|
33 | if get_option('static') == true
|
---|
34 | add_global_arguments('-static', language : 'c')
|
---|
35 | endif
|
---|
36 |
|
---|
37 | if cc.get_argument_syntax() != 'msvc'
|
---|
38 | r = run_command('build-aux/git-version-gen',
|
---|
39 | '@0@/.tarball-version'.format(meson.current_source_dir()),
|
---|
40 | check : false)
|
---|
41 |
|
---|
42 | full_version = r.stdout().strip()
|
---|
43 | if r.returncode() != 0 or full_version.startswith('UNKNOWN')
|
---|
44 | full_version = meson.project_version()
|
---|
45 | elif not full_version.startswith(meson.project_version())
|
---|
46 | error('meson.build project version @0@ does not match git-describe output @1@'
|
---|
47 | .format(meson.project_version(), full_version))
|
---|
48 | endif
|
---|
49 | else
|
---|
50 | full_version = meson.project_version()
|
---|
51 | endif
|
---|
52 | conf.set_quoted('SLIRP_VERSION_STRING', full_version + get_option('version_suffix'))
|
---|
53 |
|
---|
54 | # libtool versioning - this applies to libslirp
|
---|
55 | #
|
---|
56 | # See http://sources.redhat.com/autobook/autobook/autobook_91.html#SEC91 for details
|
---|
57 | #
|
---|
58 | # - If interfaces have been changed or added, but binary compatibility
|
---|
59 | # has been preserved, change:
|
---|
60 | # CURRENT += 1
|
---|
61 | # REVISION = 0
|
---|
62 | # AGE += 1
|
---|
63 | # - If binary compatibility has been broken (eg removed or changed
|
---|
64 | # interfaces), change:
|
---|
65 | # CURRENT += 1
|
---|
66 | # REVISION = 0
|
---|
67 | # AGE = 0
|
---|
68 | # - If the interface is the same as the previous version, but bugs are
|
---|
69 | # fixed, change:
|
---|
70 | # REVISION += 1
|
---|
71 | lt_current = 4
|
---|
72 | lt_revision = 0
|
---|
73 | lt_age = 4
|
---|
74 | lt_version = '@0@.@1@.@2@'.format(lt_current - lt_age, lt_age, lt_revision)
|
---|
75 |
|
---|
76 | host_system = host_machine.system()
|
---|
77 |
|
---|
78 | glib_dep = dependency('glib-2.0', static : get_option('static'))
|
---|
79 |
|
---|
80 | add_project_arguments(cc.get_supported_arguments('-Wmissing-prototypes', '-Wstrict-prototypes',
|
---|
81 | '-Wredundant-decls', '-Wundef', '-Wwrite-strings'),
|
---|
82 | language: 'c', native: false)
|
---|
83 |
|
---|
84 | platform_deps = []
|
---|
85 |
|
---|
86 | if host_system == 'windows'
|
---|
87 | platform_deps += [
|
---|
88 | cc.find_library('ws2_32'),
|
---|
89 | cc.find_library('iphlpapi')
|
---|
90 | ]
|
---|
91 | elif host_system == 'darwin'
|
---|
92 | platform_deps += [
|
---|
93 | cc.find_library('resolv')
|
---|
94 | ]
|
---|
95 | elif host_system == 'haiku'
|
---|
96 | platform_deps += [
|
---|
97 | cc.find_library('network')
|
---|
98 | ]
|
---|
99 | endif
|
---|
100 |
|
---|
101 | cargs = [
|
---|
102 | '-DG_LOG_DOMAIN="Slirp"',
|
---|
103 | '-DBUILDING_LIBSLIRP',
|
---|
104 | ]
|
---|
105 |
|
---|
106 | if cc.check_header('valgrind/valgrind.h')
|
---|
107 | cargs += [ '-DHAVE_VALGRIND=1' ]
|
---|
108 | endif
|
---|
109 |
|
---|
110 | sources = [
|
---|
111 | 'src/arp_table.c',
|
---|
112 | 'src/bootp.c',
|
---|
113 | 'src/cksum.c',
|
---|
114 | 'src/dhcpv6.c',
|
---|
115 | 'src/dnssearch.c',
|
---|
116 | 'src/if.c',
|
---|
117 | 'src/ip6_icmp.c',
|
---|
118 | 'src/ip6_input.c',
|
---|
119 | 'src/ip6_output.c',
|
---|
120 | 'src/ip_icmp.c',
|
---|
121 | 'src/ip_input.c',
|
---|
122 | 'src/ip_output.c',
|
---|
123 | 'src/mbuf.c',
|
---|
124 | 'src/misc.c',
|
---|
125 | 'src/ncsi.c',
|
---|
126 | 'src/ndp_table.c',
|
---|
127 | 'src/sbuf.c',
|
---|
128 | 'src/slirp.c',
|
---|
129 | 'src/socket.c',
|
---|
130 | 'src/state.c',
|
---|
131 | 'src/stream.c',
|
---|
132 | 'src/tcp_input.c',
|
---|
133 | 'src/tcp_output.c',
|
---|
134 | 'src/tcp_subr.c',
|
---|
135 | 'src/tcp_timer.c',
|
---|
136 | 'src/tftp.c',
|
---|
137 | 'src/udp.c',
|
---|
138 | 'src/udp6.c',
|
---|
139 | 'src/util.c',
|
---|
140 | 'src/version.c',
|
---|
141 | 'src/vmstate.c',
|
---|
142 | ]
|
---|
143 |
|
---|
144 | mapfile = 'src/libslirp.map'
|
---|
145 | vflag = []
|
---|
146 | vflag_test = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
|
---|
147 | if cc.has_link_argument(vflag_test)
|
---|
148 | vflag += vflag_test
|
---|
149 | endif
|
---|
150 |
|
---|
151 | if fuzzer_build
|
---|
152 | cargs += '-fsanitize-coverage=edge,indirect-calls,trace-cmp'
|
---|
153 | cargs += '-fsanitize=fuzzer-no-link,address'
|
---|
154 | cargs += '-fprofile-instr-generate'
|
---|
155 | cargs += '-fcoverage-mapping'
|
---|
156 | cargs += '-g'
|
---|
157 | cargs += '-DSLIRP_DEBUG'
|
---|
158 | vflag += '-fsanitize=fuzzer-no-link,address'
|
---|
159 | vflag += '-fsanitize-coverage=edge,indirect-calls,trace-cmp'
|
---|
160 | vflag += '-fprofile-instr-generate'
|
---|
161 | vflag += '-fcoverage-mapping'
|
---|
162 | endif
|
---|
163 | if fuzz_reproduce
|
---|
164 | cargs += '-DSLIRP_DEBUG'
|
---|
165 | cargs += '-g'
|
---|
166 | endif
|
---|
167 |
|
---|
168 | install_devel = not meson.is_subproject()
|
---|
169 |
|
---|
170 | configure_file(
|
---|
171 | input : 'src/libslirp-version.h.in',
|
---|
172 | output : 'libslirp-version.h',
|
---|
173 | install : install_devel,
|
---|
174 | install_dir : join_paths(get_option('includedir'), 'slirp'),
|
---|
175 | configuration : conf
|
---|
176 | )
|
---|
177 |
|
---|
178 | if fuzzer_build or fuzz_reproduce
|
---|
179 | lib = static_library('slirp', sources,
|
---|
180 | c_args : cargs,
|
---|
181 | link_args : vflag,
|
---|
182 | link_depends : mapfile,
|
---|
183 | dependencies : [glib_dep, platform_deps],
|
---|
184 | )
|
---|
185 | else
|
---|
186 | lib = library('slirp', sources,
|
---|
187 | version : lt_version,
|
---|
188 | c_args : cargs,
|
---|
189 | link_args : vflag,
|
---|
190 | link_depends : mapfile,
|
---|
191 | dependencies : [glib_dep, platform_deps],
|
---|
192 | install : install_devel or get_option('default_library') == 'shared',
|
---|
193 | )
|
---|
194 | endif
|
---|
195 |
|
---|
196 | pingtest = executable('pingtest', 'test/pingtest.c',
|
---|
197 | link_with: [ lib ],
|
---|
198 | c_args : cargs,
|
---|
199 | link_args : vflag,
|
---|
200 | include_directories: [ 'src' ],
|
---|
201 | dependencies : [ platform_deps ]
|
---|
202 | )
|
---|
203 |
|
---|
204 | test('ping', pingtest)
|
---|
205 |
|
---|
206 | ncsitest = executable('ncsitest', 'test/ncsitest.c',
|
---|
207 | link_with: [lib],
|
---|
208 | c_args : cargs,
|
---|
209 | link_args : vflag,
|
---|
210 | include_directories: ['src'],
|
---|
211 | dependencies: [glib_dep, platform_deps]
|
---|
212 | )
|
---|
213 |
|
---|
214 | test('ncsi', ncsitest)
|
---|
215 |
|
---|
216 | if install_devel
|
---|
217 | install_headers(['src/libslirp.h'], subdir : 'slirp')
|
---|
218 |
|
---|
219 | pkg = import('pkgconfig')
|
---|
220 |
|
---|
221 | pkg.generate(
|
---|
222 | version : version,
|
---|
223 | libraries : lib,
|
---|
224 | requires : [
|
---|
225 | 'glib-2.0',
|
---|
226 | ],
|
---|
227 | name : 'slirp',
|
---|
228 | description : 'User-space network stack',
|
---|
229 | filebase : 'slirp',
|
---|
230 | subdirs : 'slirp',
|
---|
231 | )
|
---|
232 | else
|
---|
233 | if get_option('default_library') == 'both'
|
---|
234 | lib = lib.get_static_lib()
|
---|
235 | endif
|
---|
236 | endif
|
---|
237 |
|
---|
238 | libslirp_dep = declare_dependency(
|
---|
239 | link_with : lib,
|
---|
240 | include_directories : [include_directories('src'), include_directories('.')],
|
---|
241 | )
|
---|
242 |
|
---|
243 | subdir('fuzzing')
|
---|