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 src_event_select = files('event_select.c')
179 if os_name != 'windows'
180 src_tincd += 'signal.c'
183 cc_flags_tinc = cc_flags
184 cc_flags_tincd = cc_flags
188 deps_tincd = [cc.find_library('m', required: false)]
190 if os_name != 'windows'
191 src_lib_common += 'random.c'
194 if os_name in ['linux', 'android']
196 elif os_name.endswith('bsd') or os_name in ['dragonfly', 'darwin']
198 elif os_name == 'sunos'
200 elif os_name == 'windows'
204 foreach h : check_headers
206 cdata.set('HAVE_' + h.to_upper().underscorify(),
208 description: '#include <' + h + '>')
212 if cdata.has('HAVE_SYS_UN_H')
213 src_tincd += 'fd_device.c'
216 confdata = configuration_data()
217 confdata.merge_from(cdata)
218 configure_file(output: 'meson_config.h', configuration: confdata)
221 #include "@0@/src/meson_config.h"
222 #include "@1@/have.h"
223 '''.format(build_root, meson.current_source_dir())
225 foreach f : check_functions
226 if cc.has_function(f, prefix: have_prefix, args: cc_defs)
227 cdata.set('HAVE_' + f.to_upper(),
229 description: 'function ' + f)
233 if cc.has_function('res_init', prefix: '''
234 #include <netinet/in.h>
237 cdata.set('HAVE_DECL_RES_INIT', 1)
240 foreach type : check_types
241 if cc.has_type(type, prefix: have_prefix, args: cc_defs)
242 name = 'HAVE_' + type.to_upper().underscorify()
243 cdata.set(name, 1, description: type)
248 if not cdata.has('HAVE_GETOPT_H') or not cc.has_function('getopt_long', prefix: have_prefix, args: cc_defs)
249 src_getopt = ['getopt.c', 'getopt1.c']
250 src_lib_common += src_getopt
253 if not opt_miniupnpc.disabled()
254 dep_miniupnpc = dependency('miniupnpc', required: false, static: static)
255 if not dep_miniupnpc.found()
256 # No pkg-config files on MinGW
257 dep_miniupnpc = cc.find_library('miniupnpc', required: opt_miniupnpc, static: static)
259 if dep_miniupnpc.found()
260 src_tincd += 'upnp.c'
262 dependency('threads', static: static),
266 cc_flags_tincd += '-DMINIUPNP_STATICLIB'
268 cdata.set('HAVE_MINIUPNPC', 1)
272 if not opt_curses.disabled()
273 # The meta-dependency covers more alternatives, but is only available in 0.54+
274 curses_name = meson_version.version_compare('>=0.54') ? 'curses' : 'ncurses'
275 dep_curses = dependency(curses_name, required: opt_curses, static: static)
276 if dep_curses.found()
277 cdata.set('HAVE_CURSES', 1)
278 deps_tinc += dep_curses
280 cc_flags_tinc += '-DNCURSES_STATIC'
285 # Some distributions do not supply pkg-config files for readline
286 if opt_readline.auto() and os_name == 'windows'
287 message('readline not available on Windows')
289 dep_readline = dependency('readline', required: opt_readline, static: static)
290 if not dep_readline.found()
291 dep_readline = cc.find_library('readline', required: opt_readline, static: static)
293 if not dep_readline.found()
294 dep_readline = cc.find_library('libedit', required: opt_readline, static: static)
296 if dep_readline.found() and \
297 cc.has_header('readline/readline.h', dependencies: dep_readline) and \
298 cc.has_header('readline/history.h', dependencies: dep_readline)
299 cdata.set('HAVE_READLINE', 1)
300 deps_tinc += dep_readline
304 dep_zlib = dependency('zlib',
307 fallback: ['zlib', 'zlib_dep'])
309 cdata.set('HAVE_ZLIB', 1)
310 deps_tincd += dep_zlib
313 if not opt_lzo.disabled()
314 dep_lzo = dependency('lzo2', required: false, static: static)
315 if not dep_lzo.found()
316 dep_lzo = cc.find_library('lzo2', required: opt_lzo, static: static)
318 if not dep_lzo.found()
319 dep_lzo = dependency('lzo2',
322 fallback: ['lzo2', 'lzo2_dep'])
325 if dep_lzo.type_name() == 'internal' or cc.has_header('lzo/lzo1x.h', dependencies: dep_lzo)
326 cdata.set('LZO1X_H', '<lzo/lzo1x.h>')
327 elif cc.has_header('lzo1x.h', dependencies: dep_lzo)
328 cdata.set('LZO1X_H', '<lzo1x.h>')
330 msg = 'lzo1x.h not found'
337 if cdata.has('LZO1X_H')
338 cdata.set('HAVE_LZO', 1)
339 deps_tincd += dep_lzo
344 dep_lz4 = dependency('liblz4',
347 fallback: ['lz4', 'liblz4_dep'])
349 deps_tincd += dep_lz4
350 cdata.set('HAVE_LZ4', 1)
353 dep_vde = dependency('vdeplug', required: opt_vde, static: static)
354 dep_dl = cc.find_library('dl', required: opt_vde)
355 if dep_vde.found() and dep_dl.found()
356 cdata.set('ENABLE_VDE', 1)
357 src_tincd += 'vde_device.c'
358 deps_tincd += [dep_dl, dep_vde]
362 cdata.set('ENABLE_JUMBOGRAMS', 1)
367 if opt_crypto != 'nolegacy'
368 src_lib_crypto += ['cipher.c', 'digest.c']
373 have_sandbox = cdata.has('HAVE_SANDBOX')
375 src_lib_common += 'sandbox.c'
378 lib_crypto = static_library(
380 sources: src_lib_crypto,
381 dependencies: dep_crypto,
382 implicit_include_directories: false,
383 include_directories: inc_conf,
384 build_by_default: false,
387 deps_lib_common = [deps_common, dep_crypto]
388 deps_tinc += deps_lib_common
389 deps_tincd += deps_lib_common
391 lib_common = static_library(
393 sources: src_lib_common,
394 dependencies: deps_lib_common,
395 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
396 implicit_include_directories: false,
397 include_directories: inc_conf,
398 build_by_default: false,
401 lib_tinc = static_library(
404 dependencies: deps_tinc,
405 link_with: lib_common,
406 c_args: cc_flags_tinc,
407 implicit_include_directories: false,
408 include_directories: inc_conf,
409 build_by_default: false,
412 lib_tincd = static_library(
415 dependencies: deps_tincd,
416 link_with: lib_common,
417 c_args: cc_flags_tincd,
418 implicit_include_directories: false,
419 include_directories: inc_conf,
420 build_by_default: false,
423 exe_tinc = executable(
425 sources: 'tincctl.c',
426 dependencies: deps_tinc,
428 implicit_include_directories: false,
429 include_directories: inc_conf,
431 install_dir: dir_sbin,
434 exe_tincd = executable(
437 dependencies: deps_tincd,
438 link_with: lib_tincd,
439 c_args: cc_flags_tincd,
440 implicit_include_directories: false,
441 include_directories: inc_conf,
443 install_dir: dir_sbin,
446 exe_sptps_test = executable(
448 sources: [src_getopt, 'sptps_test.c'],
449 dependencies: deps_lib_common,
450 link_with: lib_common,
451 implicit_include_directories: false,
452 include_directories: inc_conf,
453 build_by_default: false,
456 exe_sptps_keypair = executable(
458 sources: [src_getopt, 'sptps_keypair.c'],
459 dependencies: deps_lib_common,
460 link_with: lib_common,
461 implicit_include_directories: false,
462 include_directories: inc_conf,
463 build_by_default: false,
466 if os_name == 'linux'
467 dep_rt = cc.find_library('rt')
469 exe_sptps_speed = executable(
471 sources: 'sptps_speed.c',
472 dependencies: [deps_lib_common, dep_rt],
473 link_with: lib_common,
474 implicit_include_directories: false,
475 include_directories: inc_conf,
476 build_by_default: false,
479 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)