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')
159 'multicast_device.c',
173 'raw_socket_device.c',
178 src_event_select = files('event_select.c')
180 if os_name != 'windows'
181 src_tincd += 'signal.c'
184 cc_flags_tinc = cc_flags
185 cc_flags_tincd = cc_flags
189 deps_tincd = [cc.find_library('m', required: false)]
191 if os_name != 'windows'
192 src_lib_common += 'random.c'
195 if os_name in ['linux', 'android']
197 elif os_name.endswith('bsd') or os_name in ['dragonfly', 'darwin']
199 elif os_name == 'sunos'
201 elif os_name == 'windows'
205 foreach h : check_headers
207 cdata.set('HAVE_' + h.to_upper().underscorify(),
209 description: '#include <' + h + '>')
213 if cdata.has('HAVE_SYS_UN_H')
214 src_tincd += 'fd_device.c'
217 confdata = configuration_data()
218 confdata.merge_from(cdata)
219 configure_file(output: 'meson_config.h', configuration: confdata)
222 #include "@0@/src/meson_config.h"
223 #include "@1@/have.h"
224 '''.format(build_root, meson.current_source_dir())
226 foreach f : check_functions
227 if cc.has_function(f, prefix: have_prefix, args: cc_defs)
228 cdata.set('HAVE_' + f.to_upper(),
230 description: 'function ' + f)
234 if cc.has_function('res_init', prefix: '''
235 #include <netinet/in.h>
238 cdata.set('HAVE_DECL_RES_INIT', 1)
241 foreach type : check_types
242 if cc.has_type(type, prefix: have_prefix, args: cc_defs)
243 name = 'HAVE_' + type.to_upper().underscorify()
244 cdata.set(name, 1, description: type)
249 if not cdata.has('HAVE_GETOPT_H') or not cc.has_function('getopt_long', prefix: have_prefix, args: cc_defs)
250 src_getopt = ['getopt.c', 'getopt1.c']
251 src_lib_common += src_getopt
254 if not opt_miniupnpc.disabled()
255 dep_miniupnpc = dependency('miniupnpc', required: false, static: static)
256 if not dep_miniupnpc.found()
257 # No pkg-config files on MinGW
258 dep_miniupnpc = cc.find_library('miniupnpc', required: opt_miniupnpc, static: static)
260 if dep_miniupnpc.found()
261 src_tincd += 'upnp.c'
263 dependency('threads', static: static),
267 cc_flags_tincd += '-DMINIUPNP_STATICLIB'
269 cdata.set('HAVE_MINIUPNPC', 1)
273 if not opt_curses.disabled()
274 # The meta-dependency covers more alternatives, but is only available in 0.54+
275 curses_name = meson_version.version_compare('>=0.54') ? 'curses' : 'ncurses'
276 dep_curses = dependency(curses_name, required: opt_curses, static: static)
277 if dep_curses.found()
278 cdata.set('HAVE_CURSES', 1)
279 deps_tinc += dep_curses
281 cc_flags_tinc += '-DNCURSES_STATIC'
286 # Some distributions do not supply pkg-config files for readline
287 if opt_readline.auto() and os_name == 'windows'
288 message('readline not available on Windows')
290 dep_readline = dependency('readline', required: opt_readline, static: static)
291 if not dep_readline.found()
292 dep_readline = cc.find_library('readline', required: opt_readline, static: static)
294 if not dep_readline.found()
295 dep_readline = cc.find_library('libedit', required: opt_readline, static: static)
297 if dep_readline.found() and \
298 cc.has_header('readline/readline.h', dependencies: dep_readline) and \
299 cc.has_header('readline/history.h', dependencies: dep_readline)
300 cdata.set('HAVE_READLINE', 1)
301 deps_tinc += dep_readline
305 dep_zlib = dependency('zlib',
308 fallback: ['zlib', 'zlib_dep'])
310 cdata.set('HAVE_ZLIB', 1)
311 deps_tincd += dep_zlib
314 if not opt_lzo.disabled()
315 dep_lzo = dependency('lzo2', required: false, static: static)
316 if not dep_lzo.found()
317 dep_lzo = cc.find_library('lzo2', required: opt_lzo, static: static)
319 if not dep_lzo.found()
320 dep_lzo = dependency('lzo2',
323 fallback: ['lzo2', 'lzo2_dep'])
326 if dep_lzo.type_name() == 'internal' or cc.has_header('lzo/lzo1x.h', dependencies: dep_lzo)
327 cdata.set('LZO1X_H', '<lzo/lzo1x.h>')
328 elif cc.has_header('lzo1x.h', dependencies: dep_lzo)
329 cdata.set('LZO1X_H', '<lzo1x.h>')
331 msg = 'lzo1x.h not found'
338 if cdata.has('LZO1X_H')
339 cdata.set('HAVE_LZO', 1)
340 deps_tincd += dep_lzo
345 dep_lz4 = dependency('liblz4',
348 fallback: ['lz4', 'liblz4_dep'])
350 deps_tincd += dep_lz4
351 cdata.set('HAVE_LZ4', 1)
354 dep_vde = dependency('vdeplug', required: opt_vde, static: static)
355 dep_dl = cc.find_library('dl', required: opt_vde)
356 if dep_vde.found() and dep_dl.found()
357 cdata.set('ENABLE_VDE', 1)
358 src_tincd += 'vde_device.c'
359 deps_tincd += [dep_dl, dep_vde]
363 cdata.set('ENABLE_JUMBOGRAMS', 1)
368 if opt_crypto != 'nolegacy'
369 src_lib_crypto += ['cipher.c', 'digest.c']
374 have_sandbox = cdata.has('HAVE_SANDBOX')
376 src_lib_common += 'sandbox.c'
379 lib_crypto = static_library(
381 sources: src_lib_crypto,
382 dependencies: dep_crypto,
383 implicit_include_directories: false,
384 include_directories: inc_conf,
385 build_by_default: false,
388 deps_lib_common = [deps_common, dep_crypto]
389 deps_tinc += deps_lib_common
390 deps_tincd += deps_lib_common
392 lib_common = static_library(
394 sources: src_lib_common,
395 dependencies: deps_lib_common,
396 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
397 implicit_include_directories: false,
398 include_directories: inc_conf,
399 build_by_default: false,
402 lib_tinc = static_library(
405 dependencies: deps_tinc,
406 link_with: lib_common,
407 c_args: cc_flags_tinc,
408 implicit_include_directories: false,
409 include_directories: inc_conf,
410 build_by_default: false,
413 lib_tincd = static_library(
416 dependencies: deps_tincd,
417 link_with: lib_common,
418 c_args: cc_flags_tincd,
419 implicit_include_directories: false,
420 include_directories: inc_conf,
421 build_by_default: false,
424 exe_tinc = executable(
426 sources: 'tincctl.c',
427 dependencies: deps_tinc,
429 implicit_include_directories: false,
430 include_directories: inc_conf,
432 install_dir: dir_sbin,
435 exe_tincd = executable(
438 dependencies: deps_tincd,
439 link_with: lib_tincd,
440 c_args: cc_flags_tincd,
441 implicit_include_directories: false,
442 include_directories: inc_conf,
444 install_dir: dir_sbin,
447 exe_sptps_test = executable(
449 sources: [src_getopt, 'sptps_test.c'],
450 dependencies: deps_lib_common,
451 link_with: lib_common,
452 implicit_include_directories: false,
453 include_directories: inc_conf,
454 build_by_default: false,
457 exe_sptps_keypair = executable(
459 sources: [src_getopt, 'sptps_keypair.c'],
460 dependencies: deps_lib_common,
461 link_with: lib_common,
462 implicit_include_directories: false,
463 include_directories: inc_conf,
464 build_by_default: false,
467 if os_name == 'linux'
468 dep_rt = cc.find_library('rt')
470 exe_sptps_speed = executable(
472 sources: 'sptps_speed.c',
473 dependencies: [deps_lib_common, dep_rt],
474 link_with: lib_common,
475 implicit_include_directories: false,
476 include_directories: inc_conf,
477 build_by_default: false,
480 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)