1 inc_conf = include_directories('include')
3 cdata = configuration_data()
5 cdata.set_quoted('PACKAGE', meson.project_name())
6 cdata.set_quoted('VERSION', meson.project_version())
7 cdata.set_quoted('CONFDIR', dir_sysconf)
8 cdata.set_quoted('RUNSTATEDIR', dir_run_state)
9 cdata.set_quoted('LOCALSTATEDIR', dir_local_state)
10 cdata.set_quoted('SBINDIR', dir_sbin)
12 cdata.set('HAVE_' + os_name.to_upper(), 1)
14 foreach attr : ['malloc', 'nonnull', 'warn_unused_result', 'packed', 'format']
15 if cc.has_function_attribute(attr)
16 cdata.set('HAVE_ATTR_' + attr.to_upper(), 1,
17 description: '__attribute__((__@0@__))'.format(attr))
23 extern void *make() __attribute__((malloc(free)));
24 int main(void) { return 0; }
26 cdata.set('HAVE_ATTR_MALLOC_WITH_ARG', 1,
27 description: 'support for __attribute__((malloc(deallocator)))')
31 _Static_assert(1, "ok");
32 int main(void) { return 0; }
34 cdata.set('HAVE_STATIC_ASSERT', 1,
35 description: 'C11 _Static_assert()')
78 # 'struct msghdr' misses some required fields
80 check_headers += 'sys/un.h'
98 # Broken definition, fails to link
99 if os_name != 'windows'
100 check_functions += 'fork'
106 'struct ether_header',
111 'struct nd_neighbor_solicit',
116 subdir('chacha-poly1305')
158 'multicast_device.c',
172 'raw_socket_device.c',
177 cc_flags_tinc = cc_flags
178 cc_flags_tincd = cc_flags
182 deps_tincd = [cc.find_library('m', required: false)]
184 if os_name != 'windows'
185 src_lib_common += 'random.c'
188 if os_name in ['linux', 'android']
190 elif os_name.endswith('bsd') or os_name in ['dragonfly', 'darwin']
192 elif os_name == 'sunos'
194 elif os_name == 'windows'
198 foreach h : check_headers
200 cdata.set('HAVE_' + h.to_upper().underscorify(),
202 description: '#include <' + h + '>')
206 if cdata.has('HAVE_SYS_UN_H')
207 src_tincd += 'fd_device.c'
210 confdata = configuration_data()
211 confdata.merge_from(cdata)
212 configure_file(output: 'meson_config.h', configuration: confdata)
215 #include "@0@/src/meson_config.h"
216 #include "@1@/have.h"
217 '''.format(build_root, meson.current_source_dir())
219 foreach f : check_functions
220 if cc.has_function(f, prefix: have_prefix, args: cc_defs)
221 cdata.set('HAVE_' + f.to_upper(),
223 description: 'function ' + f)
227 if cc.has_function('res_init', prefix: '''
228 #include <netinet/in.h>
231 cdata.set('HAVE_DECL_RES_INIT', 1)
234 foreach type : check_types
235 if cc.has_type(type, prefix: have_prefix, args: cc_defs)
236 name = 'HAVE_' + type.to_upper().underscorify()
237 cdata.set(name, 1, description: type)
242 if not cdata.has('HAVE_GETOPT_H') or not cc.has_function('getopt_long', prefix: have_prefix, args: cc_defs)
243 src_getopt = ['getopt.c', 'getopt1.c']
244 src_lib_common += src_getopt
247 if not opt_miniupnpc.disabled()
248 dep_miniupnpc = dependency('miniupnpc', required: false, static: static)
249 if not dep_miniupnpc.found()
250 # No pkg-config files on MinGW
251 dep_miniupnpc = cc.find_library('miniupnpc', required: opt_miniupnpc, static: static)
253 if dep_miniupnpc.found()
254 src_tincd += 'upnp.c'
256 dependency('threads', static: static),
260 cc_flags_tincd += '-DMINIUPNP_STATICLIB'
262 cdata.set('HAVE_MINIUPNPC', 1)
266 if not opt_curses.disabled()
267 # The meta-dependency covers more alternatives, but is only available in 0.54+
268 curses_name = meson_version.version_compare('>=0.54') ? 'curses' : 'ncurses'
269 dep_curses = dependency(curses_name, required: opt_curses, static: static)
270 if dep_curses.found()
271 cdata.set('HAVE_CURSES', 1)
272 deps_tinc += dep_curses
274 cc_flags_tinc += '-DNCURSES_STATIC'
279 # Some distributions do not supply pkg-config files for readline
280 if opt_readline.auto() and os_name == 'windows'
281 message('readline not available on Windows')
283 dep_readline = dependency('readline', required: opt_readline, static: static)
284 if not dep_readline.found()
285 dep_readline = cc.find_library('readline', required: opt_readline, static: static)
287 if not dep_readline.found()
288 dep_readline = cc.find_library('libedit', required: opt_readline, static: static)
290 if dep_readline.found() and \
291 cc.has_header('readline/readline.h', dependencies: dep_readline) and \
292 cc.has_header('readline/history.h', dependencies: dep_readline)
293 cdata.set('HAVE_READLINE', 1)
294 deps_tinc += dep_readline
298 dep_zlib = dependency('zlib',
301 fallback: ['zlib', 'zlib_dep'])
303 cdata.set('HAVE_ZLIB', 1)
304 deps_tincd += dep_zlib
307 if not opt_lzo.disabled()
308 dep_lzo = dependency('lzo2', required: false, static: static)
309 if not dep_lzo.found()
310 dep_lzo = cc.find_library('lzo2', required: opt_lzo, static: static)
312 if not dep_lzo.found()
313 dep_lzo = dependency('lzo2',
316 fallback: ['lzo2', 'lzo2_dep'])
319 if dep_lzo.type_name() == 'internal' or cc.has_header('lzo/lzo1x.h', dependencies: dep_lzo)
320 cdata.set('LZO1X_H', '<lzo/lzo1x.h>')
321 elif cc.has_header('lzo1x.h', dependencies: dep_lzo)
322 cdata.set('LZO1X_H', '<lzo1x.h>')
324 msg = 'lzo1x.h not found'
331 if cdata.has('LZO1X_H')
332 cdata.set('HAVE_LZO', 1)
333 deps_tincd += dep_lzo
338 dep_lz4 = dependency('liblz4',
341 fallback: ['lz4', 'liblz4_dep'])
343 deps_tincd += dep_lz4
344 cdata.set('HAVE_LZ4', 1)
347 dep_vde = dependency('vdeplug', required: opt_vde, static: static)
348 dep_dl = cc.find_library('dl', required: opt_vde)
349 if dep_vde.found() and dep_dl.found()
350 cdata.set('ENABLE_VDE', 1)
351 src_tincd += 'vde_device.c'
352 deps_tincd += [dep_dl, dep_vde]
356 cdata.set('ENABLE_JUMBOGRAMS', 1)
361 if opt_crypto != 'nolegacy'
362 src_lib_crypto += ['cipher.c', 'digest.c']
367 have_sandbox = cdata.has('HAVE_SANDBOX')
369 src_lib_common += 'sandbox.c'
372 lib_crypto = static_library(
374 sources: src_lib_crypto,
375 dependencies: dep_crypto,
376 implicit_include_directories: false,
377 include_directories: inc_conf,
378 build_by_default: false,
381 deps_lib_common = [deps_common, dep_crypto]
382 deps_tinc += deps_lib_common
383 deps_tincd += deps_lib_common
385 lib_common = static_library(
387 sources: src_lib_common,
388 dependencies: deps_lib_common,
389 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
390 implicit_include_directories: false,
391 include_directories: inc_conf,
392 build_by_default: false,
395 lib_tinc = static_library(
398 dependencies: deps_tinc,
399 link_with: lib_common,
400 c_args: cc_flags_tinc,
401 implicit_include_directories: false,
402 include_directories: inc_conf,
403 build_by_default: false,
406 lib_tincd = static_library(
409 dependencies: deps_tincd,
410 link_with: lib_common,
411 c_args: cc_flags_tincd,
412 implicit_include_directories: false,
413 include_directories: inc_conf,
414 build_by_default: false,
417 exe_tinc = executable(
419 sources: 'tincctl.c',
420 dependencies: deps_tinc,
422 implicit_include_directories: false,
423 include_directories: inc_conf,
425 install_dir: dir_sbin,
428 exe_tincd = executable(
431 dependencies: deps_tincd,
432 link_with: lib_tincd,
433 c_args: cc_flags_tincd,
434 implicit_include_directories: false,
435 include_directories: inc_conf,
437 install_dir: dir_sbin,
440 exe_sptps_test = executable(
442 sources: [src_getopt, 'sptps_test.c'],
443 dependencies: deps_lib_common,
444 link_with: lib_common,
445 implicit_include_directories: false,
446 include_directories: inc_conf,
447 build_by_default: false,
450 exe_sptps_keypair = executable(
452 sources: [src_getopt, 'sptps_keypair.c'],
453 dependencies: deps_lib_common,
454 link_with: lib_common,
455 implicit_include_directories: false,
456 include_directories: inc_conf,
457 build_by_default: false,
460 if os_name == 'linux'
461 dep_rt = cc.find_library('rt')
463 exe_sptps_speed = executable(
465 sources: 'sptps_speed.c',
466 dependencies: [deps_lib_common, dep_rt],
467 link_with: lib_common,
468 implicit_include_directories: false,
469 include_directories: inc_conf,
470 build_by_default: false,
473 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)