Add support for building tinc with MSVC
[tinc] / meson.build
index 38062a9..f0c2fa1 100644 (file)
@@ -1,5 +1,5 @@
 project('tinc', 'c',
-  version: run_command('./src/git_tag.sh', check: true).stdout().strip(),
+  version: '1.18pre',
   license: 'GPL-2.0-or-later',
   meson_version: '>=0.51',
   default_options: [
@@ -12,6 +12,7 @@ project('tinc', 'c',
 dir_run_state = get_option('runstatedir')
 opt_crypto = get_option('crypto')
 opt_curses = get_option('curses')
+opt_debug = get_option('debug')
 opt_docs = get_option('docs')
 opt_harden = get_option('hardening')
 opt_jumbograms = get_option('jumbograms')
@@ -31,6 +32,7 @@ meson_version = meson.version()
 
 cc = meson.get_compiler('c')
 os_name = host_machine.system()
+cpu_family = host_machine.cpu_family()
 cc_name = cc.get_id()
 
 cc_defs = ['-D_GNU_SOURCE']
@@ -47,33 +49,45 @@ else
   static = opt_static.enabled()
 endif
 
-if static
+if static and cc_name != 'msvc'
   ld_flags += '-static'
 endif
 
 if opt_harden
-  cc_flags += [
-    '-D_FORTIFY_SOURCE=2',
-    '-fwrapv',
-    '-fno-strict-overflow',
-    '-Wreturn-type',
-    '-Wold-style-definition',
-    '-Wmissing-declarations',
-    '-Wmissing-prototypes',
-    '-Wstrict-prototypes',
-    '-Wredundant-decls',
-    '-Wbad-function-cast',
-    '-Wwrite-strings',
-    '-fdiagnostics-show-option',
-    '-fstrict-aliasing',
-    '-Wmissing-noreturn',
-  ]
-  if cc_name == 'clang'
-    cc_flags += '-Qunused-arguments'
-  endif
-  ld_flags += ['-Wl,-z,relro', '-Wl,-z,now']
-  if os_name == 'windows'
-    ld_flags += ['-Wl,--dynamicbase', '-Wl,--nxcompat']
+  if cc_name == 'msvc'
+    # Most of these flags are already ON by default in the latest version of MSVC.
+    # Add anyway in case someone is building using an old toolchain.
+    cc_flags += ['/guard:cf', '/GS']
+    ld_flags += [
+      '/guard:cf',
+      '/NXCOMPAT',
+      '/DYNAMICBASE',
+      cpu_family.endswith('64') ? '/HIGHENTROPYVA' : '/SAFESEH',
+    ]
+  else
+    cc_flags += [
+      '-D_FORTIFY_SOURCE=2',
+      '-fwrapv',
+      '-fno-strict-overflow',
+      '-Wreturn-type',
+      '-Wold-style-definition',
+      '-Wmissing-declarations',
+      '-Wmissing-prototypes',
+      '-Wstrict-prototypes',
+      '-Wredundant-decls',
+      '-Wbad-function-cast',
+      '-Wwrite-strings',
+      '-fdiagnostics-show-option',
+      '-fstrict-aliasing',
+      '-Wmissing-noreturn',
+    ]
+    if cc_name == 'clang'
+      cc_flags += '-Qunused-arguments'
+    endif
+    ld_flags += ['-Wl,-z,relro', '-Wl,-z,now']
+    if os_name == 'windows'
+      ld_flags += ['-Wl,--dynamicbase', '-Wl,--nxcompat']
+    endif
   endif
 endif