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'
215 cdata.set('HAVE_FD_DEVICE', 1)
218 confdata = configuration_data()
219 confdata.merge_from(cdata)
220 configure_file(output: 'meson_config.h', configuration: confdata)
223 #include "@0@/src/meson_config.h"
224 #include "@1@/have.h"
225 '''.format(build_root, meson.current_source_dir())
227 foreach f : check_functions
228 if cc.has_function(f, prefix: have_prefix, args: cc_defs)
229 cdata.set('HAVE_' + f.to_upper(),
231 description: 'function ' + f)
235 if cc.has_function('res_init', prefix: '''
236 #include <netinet/in.h>
239 cdata.set('HAVE_DECL_RES_INIT', 1)
242 foreach type : check_types
243 if cc.has_type(type, prefix: have_prefix, args: cc_defs)
244 name = 'HAVE_' + type.to_upper().underscorify()
245 cdata.set(name, 1, description: type)
250 if not cdata.has('HAVE_GETOPT_H') or not cc.has_function('getopt_long', prefix: have_prefix, args: cc_defs)
251 src_getopt = ['getopt.c', 'getopt1.c']
252 src_lib_common += src_getopt
255 if not opt_miniupnpc.disabled()
256 dep_miniupnpc = dependency('miniupnpc', required: false, static: static)
257 if not dep_miniupnpc.found()
258 # No pkg-config files on MinGW
259 dep_miniupnpc = cc.find_library('miniupnpc', required: opt_miniupnpc, static: static)
261 if dep_miniupnpc.found()
262 src_tincd += 'upnp.c'
264 dependency('threads', static: static),
268 cc_flags_tincd += '-DMINIUPNP_STATICLIB'
270 cdata.set('HAVE_MINIUPNPC', 1)
274 if not opt_curses.disabled()
275 # The meta-dependency covers more alternatives, but is only available in 0.54+
276 curses_name = meson_version.version_compare('>=0.54') ? 'curses' : 'ncurses'
277 dep_curses = dependency(curses_name, required: opt_curses, static: static)
278 if dep_curses.found()
279 cdata.set('HAVE_CURSES', 1)
280 deps_tinc += dep_curses
282 cc_flags_tinc += '-DNCURSES_STATIC'
287 # Some distributions do not supply pkg-config files for readline
288 if opt_readline.auto() and os_name == 'windows'
289 message('readline not available on Windows')
291 dep_readline = dependency('readline', required: opt_readline, static: static)
292 if not dep_readline.found()
293 dep_readline = cc.find_library('readline', required: opt_readline, static: static)
295 if not dep_readline.found()
296 dep_readline = cc.find_library('libedit', required: opt_readline, static: static)
298 if dep_readline.found() and \
299 cc.has_header('readline/readline.h', dependencies: dep_readline) and \
300 cc.has_header('readline/history.h', dependencies: dep_readline)
301 cdata.set('HAVE_READLINE', 1)
302 deps_tinc += dep_readline
306 dep_zlib = dependency('zlib',
309 fallback: ['zlib', 'zlib_dep'])
311 cdata.set('HAVE_ZLIB', 1)
312 deps_tincd += dep_zlib
315 if not opt_lzo.disabled()
316 dep_lzo = dependency('lzo2', required: false, static: static)
317 if not dep_lzo.found()
318 dep_lzo = cc.find_library('lzo2', required: opt_lzo, static: static)
320 if not dep_lzo.found()
321 dep_lzo = dependency('lzo2',
324 fallback: ['lzo2', 'lzo2_dep'])
327 if dep_lzo.type_name() == 'internal' or cc.has_header('lzo/lzo1x.h', dependencies: dep_lzo)
328 cdata.set('LZO1X_H', '<lzo/lzo1x.h>')
329 elif cc.has_header('lzo1x.h', dependencies: dep_lzo)
330 cdata.set('LZO1X_H', '<lzo1x.h>')
332 msg = 'lzo1x.h not found'
339 if cdata.has('LZO1X_H')
340 cdata.set('HAVE_LZO', 1)
341 deps_tincd += dep_lzo
346 dep_lz4 = dependency('liblz4',
349 fallback: ['lz4', 'liblz4_dep'])
351 deps_tincd += dep_lz4
352 cdata.set('HAVE_LZ4', 1)
355 dep_vde = dependency('vdeplug', required: opt_vde, static: static)
356 dep_dl = cc.find_library('dl', required: opt_vde)
357 if dep_vde.found() and dep_dl.found()
358 cdata.set('ENABLE_VDE', 1)
359 src_tincd += 'vde_device.c'
360 deps_tincd += [dep_dl, dep_vde]
364 cdata.set('ENABLE_JUMBOGRAMS', 1)
369 if opt_crypto != 'nolegacy'
370 src_lib_crypto += ['cipher.c', 'digest.c']
375 have_sandbox = cdata.has('HAVE_SANDBOX')
377 src_lib_common += 'sandbox.c'
380 lib_crypto = static_library(
382 sources: src_lib_crypto,
383 dependencies: dep_crypto,
384 implicit_include_directories: false,
385 include_directories: inc_conf,
386 build_by_default: false,
389 deps_lib_common = [deps_common, dep_crypto]
390 deps_tinc += deps_lib_common
391 deps_tincd += deps_lib_common
393 lib_common = static_library(
395 sources: src_lib_common,
396 dependencies: deps_lib_common,
397 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
398 implicit_include_directories: false,
399 include_directories: inc_conf,
400 build_by_default: false,
403 lib_tinc = static_library(
406 dependencies: deps_tinc,
407 link_with: lib_common,
408 c_args: cc_flags_tinc,
409 implicit_include_directories: false,
410 include_directories: inc_conf,
411 build_by_default: false,
414 lib_tincd = static_library(
417 dependencies: deps_tincd,
418 link_with: lib_common,
419 c_args: cc_flags_tincd,
420 implicit_include_directories: false,
421 include_directories: inc_conf,
422 build_by_default: false,
425 exe_tinc = executable(
427 sources: 'tincctl.c',
428 dependencies: deps_tinc,
430 implicit_include_directories: false,
431 include_directories: inc_conf,
433 install_dir: dir_sbin,
436 exe_tincd = executable(
439 dependencies: deps_tincd,
440 link_with: lib_tincd,
441 c_args: cc_flags_tincd,
442 implicit_include_directories: false,
443 include_directories: inc_conf,
445 install_dir: dir_sbin,
448 exe_sptps_test = executable(
450 sources: [src_getopt, 'sptps_test.c'],
451 dependencies: deps_lib_common,
452 link_with: lib_common,
453 implicit_include_directories: false,
454 include_directories: inc_conf,
455 build_by_default: false,
458 exe_sptps_keypair = executable(
460 sources: [src_getopt, 'sptps_keypair.c'],
461 dependencies: deps_lib_common,
462 link_with: lib_common,
463 implicit_include_directories: false,
464 include_directories: inc_conf,
465 build_by_default: false,
468 if os_name == 'linux'
469 dep_rt = cc.find_library('rt')
471 exe_sptps_speed = executable(
473 sources: 'sptps_speed.c',
474 dependencies: [deps_lib_common, dep_rt],
475 link_with: lib_common,
476 implicit_include_directories: false,
477 include_directories: inc_conf,
478 build_by_default: false,
481 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)