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 != 'openssl'
362 src_lib_crypto += 'crypto.c'
365 if opt_crypto != 'nolegacy'
366 src_lib_crypto += ['cipher.c', 'digest.c']
371 have_sandbox = cdata.has('HAVE_SANDBOX')
373 src_lib_common += 'sandbox.c'
376 lib_crypto = static_library(
378 sources: src_lib_crypto,
379 dependencies: dep_crypto,
380 implicit_include_directories: false,
381 include_directories: inc_conf,
382 build_by_default: false,
385 deps_lib_common = [deps_common, dep_crypto]
386 deps_tinc += deps_lib_common
387 deps_tincd += deps_lib_common
389 lib_common = static_library(
391 sources: src_lib_common,
392 dependencies: deps_lib_common,
393 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
394 implicit_include_directories: false,
395 include_directories: inc_conf,
396 build_by_default: false,
399 lib_tinc = static_library(
402 dependencies: deps_tinc,
403 link_with: lib_common,
404 c_args: cc_flags_tinc,
405 implicit_include_directories: false,
406 include_directories: inc_conf,
407 build_by_default: false,
410 lib_tincd = static_library(
413 dependencies: deps_tincd,
414 link_with: lib_common,
415 c_args: cc_flags_tincd,
416 implicit_include_directories: false,
417 include_directories: inc_conf,
418 build_by_default: false,
421 exe_tinc = executable(
423 sources: 'tincctl.c',
424 dependencies: deps_tinc,
426 implicit_include_directories: false,
427 include_directories: inc_conf,
429 install_dir: dir_sbin,
432 exe_tincd = executable(
435 dependencies: deps_tincd,
436 link_with: lib_tincd,
437 c_args: cc_flags_tincd,
438 implicit_include_directories: false,
439 include_directories: inc_conf,
441 install_dir: dir_sbin,
444 exe_sptps_test = executable(
446 sources: [src_getopt, 'sptps_test.c'],
447 dependencies: deps_lib_common,
448 link_with: lib_common,
449 implicit_include_directories: false,
450 include_directories: inc_conf,
451 build_by_default: false,
454 exe_sptps_keypair = executable(
456 sources: [src_getopt, 'sptps_keypair.c'],
457 dependencies: deps_lib_common,
458 link_with: lib_common,
459 implicit_include_directories: false,
460 include_directories: inc_conf,
461 build_by_default: false,
464 if os_name == 'linux'
465 dep_rt = cc.find_library('rt')
467 exe_sptps_speed = executable(
469 sources: 'sptps_speed.c',
470 dependencies: [deps_lib_common, dep_rt],
471 link_with: lib_common,
472 implicit_include_directories: false,
473 include_directories: inc_conf,
474 build_by_default: false,
477 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)