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 lib_crypto = static_library(
373 sources: src_lib_crypto,
374 dependencies: dep_crypto,
375 implicit_include_directories: false,
376 include_directories: inc_conf,
377 build_by_default: false,
380 deps_lib_common = [deps_common, dep_crypto]
381 deps_tinc += deps_lib_common
382 deps_tincd += deps_lib_common
384 lib_common = static_library(
386 sources: src_lib_common,
387 dependencies: deps_lib_common,
388 link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
389 implicit_include_directories: false,
390 include_directories: inc_conf,
391 build_by_default: false,
394 lib_tinc = static_library(
397 dependencies: deps_tinc,
398 link_with: lib_common,
399 c_args: cc_flags_tinc,
400 implicit_include_directories: false,
401 include_directories: inc_conf,
402 build_by_default: false,
405 lib_tincd = static_library(
408 dependencies: deps_tincd,
409 link_with: lib_common,
410 c_args: cc_flags_tincd,
411 implicit_include_directories: false,
412 include_directories: inc_conf,
413 build_by_default: false,
416 exe_tinc = executable(
418 sources: 'tincctl.c',
419 dependencies: deps_tinc,
421 implicit_include_directories: false,
422 include_directories: inc_conf,
424 install_dir: dir_sbin,
427 exe_tincd = executable(
430 dependencies: deps_tincd,
431 link_with: lib_tincd,
432 c_args: cc_flags_tincd,
433 implicit_include_directories: false,
434 include_directories: inc_conf,
436 install_dir: dir_sbin,
439 exe_sptps_test = executable(
441 sources: [src_getopt, 'sptps_test.c'],
442 dependencies: deps_lib_common,
443 link_with: lib_common,
444 implicit_include_directories: false,
445 include_directories: inc_conf,
446 build_by_default: false,
449 exe_sptps_keypair = executable(
451 sources: [src_getopt, 'sptps_keypair.c'],
452 dependencies: deps_lib_common,
453 link_with: lib_common,
454 implicit_include_directories: false,
455 include_directories: inc_conf,
456 build_by_default: false,
459 if os_name == 'linux'
460 dep_rt = cc.find_library('rt')
462 exe_sptps_speed = executable(
464 sources: 'sptps_speed.c',
465 dependencies: [deps_lib_common, dep_rt],
466 link_with: lib_common,
467 implicit_include_directories: false,
468 include_directories: inc_conf,
469 build_by_default: false,
472 benchmark('sptps_speed', exe_sptps_speed, timeout: 90)