Add check for __Static_assert() and asserts on struct sizes
[tinc] / src / meson.build
index c9f5d59..b1796af 100644 (file)
@@ -15,7 +15,16 @@ foreach attr : ['malloc', 'nonnull', 'warn_unused_result']
   cc.has_function_attribute(attr)
 endforeach
 
+if cc.compiles('''
+    _Static_assert(1, "ok");
+    int main(void) { return 0; }
+''')
+  cdata.set('HAVE_STATIC_ASSERT', 1,
+            description: 'C11 _Static_assert()')
+endif
+
 check_headers = [
+  'alloca.h',
   'arpa/inet.h',
   'arpa/nameser.h',
   'dirent.h',
@@ -46,17 +55,22 @@ check_headers = [
   'sys/stat.h',
   'sys/time.h',
   'sys/types.h',
-  'sys/un.h',
   'sys/wait.h',
   'syslog.h',
+  'string.h',
   'termios.h',
+  'unistd.h',
 ]
 
+# 'struct msghdr' misses some required fields
+if os_name != 'sunos'
+  check_headers += 'sys/un.h'
+endif
+
 check_functions = [
   'asprintf',
   'daemon',
   'fchmod',
-  'fork',
   'gettimeofday',
   'mlockall',
   'putenv',
@@ -64,6 +78,11 @@ check_functions = [
   'unsetenv',
 ]
 
+# Broken definition, fails to link
+if os_name != 'windows'
+  check_functions += 'fork'
+endif
+
 check_types = [
   'struct arphdr',
   'struct ether_arp',
@@ -79,7 +98,7 @@ check_types = [
 subdir('ed25519')
 subdir('chacha-poly1305')
 
-src_lib_tinc = [
+src_lib_common = [
   'conf.c',
   'dropin.c',
   'keys.c',
@@ -101,7 +120,6 @@ src_tinc = [
   'ifconfig.c',
   'info.c',
   'invitation.c',
-  'tincctl.c',
   'top.c',
 ]
 
@@ -116,7 +134,6 @@ src_tincd = [
   'dummy_device.c',
   'edge.c',
   'event.c',
-  'fd_device.c',
   'graph.c',
   'meta.c',
   'multicast_device.c',
@@ -135,7 +152,6 @@ src_tincd = [
   'raw_socket_device.c',
   'route.c',
   'subnet.c',
-  'tincd.c',
 ]
 
 cc_flags_tincd = cc_flags
@@ -151,7 +167,7 @@ elif os_name.endswith('bsd') or os_name in ['dragonfly', 'darwin']
 elif os_name == 'sunos'
   subdir('solaris')
 elif os_name == 'windows'
-  subdir('mingw')
+  subdir('windows')
 endif
 
 foreach h : check_headers
@@ -162,6 +178,10 @@ foreach h : check_headers
   endif
 endforeach
 
+if cdata.has('HAVE_SYS_UN_H')
+  src_tincd += 'fd_device.c'
+endif
+
 confdata = configuration_data()
 confdata.merge_from(cdata)
 configure_file(output: 'meson_config.h', configuration: confdata)
@@ -172,14 +192,10 @@ have_prefix = '''
 '''.format(build_root, meson.current_source_dir())
 
 foreach f : check_functions
-  if f == 'fork' and os_name == 'windows'
-    message('MinGW does not have correct definition for fork()')
-  else
-    if cc.has_function(f, prefix: have_prefix, args: cc_defs)
-      cdata.set('HAVE_' + f.to_upper(),
-                1,
-                description: 'function ' + f)
-    endif
+  if cc.has_function(f, prefix: have_prefix, args: cc_defs)
+    cdata.set('HAVE_' + f.to_upper(),
+              1,
+              description: 'function ' + f)
   endif
 endforeach
 
@@ -198,7 +214,7 @@ foreach type : check_types
 endforeach
 
 if not cdata.has('HAVE_GETOPT_H') or not cc.has_function('getopt_long', prefix: have_prefix, args: cc_defs)
-  src_lib_tinc += ['getopt.c', 'getopt1.c']
+  src_lib_common += ['getopt.c', 'getopt1.c']
 endif
 
 if not opt_miniupnpc.disabled()
@@ -220,9 +236,7 @@ if not opt_miniupnpc.disabled()
   endif
 endif
 
-if opt_curses.auto() and os_name == 'windows'
-  message('curses does not link under MinGW')
-else
+if not opt_curses.disabled()
   # The meta-dependency covers more alternatives, but is only available in 0.54+
   curses_name = meson_version.version_compare('>=0.54') ? 'curses' : 'ncurses'
   dep_curses = dependency(curses_name, required: opt_curses, static: static)
@@ -234,7 +248,7 @@ endif
 
 # Some distributions do not supply pkg-config files for readline
 if opt_readline.auto() and os_name == 'windows'
-  message('readline does not link under MinGW')
+  message('readline not available on Windows')
 else
   dep_readline = dependency('readline', required: opt_readline, static: static)
   if not dep_readline.found()
@@ -326,13 +340,36 @@ lib_crypto = static_library(
   build_by_default: false,
 )
 
-deps_lib_tinc = [deps_common, dep_crypto]
+deps_lib_common = [deps_common, dep_crypto]
+deps_tinc += deps_lib_common
+deps_tincd += deps_lib_common
+
+lib_common = static_library(
+  'common',
+  sources: src_lib_common,
+  dependencies: deps_lib_common,
+  link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
+  implicit_include_directories: false,
+  include_directories: inc_conf,
+  build_by_default: false,
+)
 
 lib_tinc = static_library(
   'tinc',
-  sources: src_lib_tinc,
-  dependencies: deps_lib_tinc,
-  link_with: [lib_ed25519, lib_chacha_poly, lib_crypto],
+  sources: src_tinc,
+  dependencies: deps_tinc,
+  link_with: lib_common,
+  implicit_include_directories: false,
+  include_directories: inc_conf,
+  build_by_default: false,
+)
+
+lib_tincd = static_library(
+  'tincd',
+  sources: src_tincd,
+  dependencies: deps_tincd,
+  link_with: lib_common,
+  c_args: cc_flags_tincd,
   implicit_include_directories: false,
   include_directories: inc_conf,
   build_by_default: false,
@@ -340,8 +377,8 @@ lib_tinc = static_library(
 
 exe_tinc = executable(
   'tinc',
-  sources: src_tinc,
-  dependencies: [deps_lib_tinc, deps_tinc],
+  sources: 'tincctl.c',
+  dependencies: deps_tinc,
   link_with: lib_tinc,
   implicit_include_directories: false,
   include_directories: inc_conf,
@@ -351,9 +388,9 @@ exe_tinc = executable(
 
 exe_tincd = executable(
   'tincd',
-  sources: src_tincd,
-  dependencies: [deps_lib_tinc, deps_tincd],
-  link_with: lib_tinc,
+  sources: 'tincd.c',
+  dependencies: deps_tincd,
+  link_with: lib_tincd,
   c_args: cc_flags_tincd,
   implicit_include_directories: false,
   include_directories: inc_conf,
@@ -364,8 +401,8 @@ exe_tincd = executable(
 exe_sptps_test = executable(
   'sptps_test',
   sources: 'sptps_test.c',
-  dependencies: deps_lib_tinc,
-  link_with: lib_tinc,
+  dependencies: deps_lib_common,
+  link_with: lib_common,
   implicit_include_directories: false,
   include_directories: inc_conf,
   build_by_default: false,
@@ -374,8 +411,8 @@ exe_sptps_test = executable(
 exe_sptps_keypair = executable(
   'sptps_keypair',
   sources: 'sptps_keypair.c',
-  dependencies: deps_lib_tinc,
-  link_with: lib_tinc,
+  dependencies: deps_lib_common,
+  link_with: lib_common,
   implicit_include_directories: false,
   include_directories: inc_conf,
   build_by_default: false,
@@ -387,8 +424,8 @@ if os_name == 'linux'
   exe_sptps_speed = executable(
     'sptps_speed',
     sources: 'sptps_speed.c',
-    dependencies: [deps_lib_tinc, dep_rt],
-    link_with: lib_tinc,
+    dependencies: [deps_lib_common, dep_rt],
+    link_with: lib_common,
     implicit_include_directories: false,
     include_directories: inc_conf,
     build_by_default: false,