[Mesa-dev] [PATCH 13/48] meson: add windows compiler checks and libraries

Dylan Baker dylan at pnwbakers.com
Mon Jun 11 22:55:40 UTC 2018


---
 meson.build | 126 ++++++++++++++++++++++++++++++++++------------------
 1 file changed, 82 insertions(+), 44 deletions(-)

diff --git a/meson.build b/meson.build
index fb07c2dd0de..4247d195bc1 100644
--- a/meson.build
+++ b/meson.build
@@ -688,6 +688,8 @@ if has_mako.returncode() != 0
 endif
 
 cc = meson.get_compiler('c')
+cpp = meson.get_compiler('cpp')
+
 if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
   error('When using GCC, version 4.4.6 or later is required.')
 endif
@@ -750,63 +752,97 @@ endif
 # TODO: this is very incomplete
 if ['linux', 'cygwin'].contains(host_machine.system())
   pre_args += '-D_GNU_SOURCE'
+elif host_machine.system() == 'windows'
+  pre_args += [
+    '-DWIN32', '-D_WINDOWS', '-D_WIN32_WINNT=0x0601', '-D_WINVER=0x0601',
+    '-DPIPE_SUBSYSTEM_WINDOWS_USER',
+    '-D_USE_MATH_DEFINES',  # XXX: scons doesn't use this for mingw
+  ]
+  if cc.get_id() == 'msvc'
+    pre_args += [
+      '-DVC_EXTRALEAN',
+      '-D_CRT_SECURE_NO_WARNINGS',
+      '-D_CRT_SECURE_NO_DEPRECATE',
+      '-D_SCL_SECURE_NO_WARNINGS',
+      '-D_SCL_SECURE_NO_DEPRECATE',
+      '-D_ALLOW_KEYWORD_MACROS',
+      '-D_HAS_EXCEPTIONS=0', # Tell C++ STL to not use exceptions
+    ]
+  else
+    pre_args += ['-D__MSVCRT_VERSION__=0x0700']
+  endif
 endif
 
 # Check for generic C arguments
 c_args = []
-foreach a : ['-Wall', '-Werror=implicit-function-declaration',
-             '-Werror=missing-prototypes', '-fno-math-errno',
-             '-fno-trapping-math', '-Qunused-arguments']
-  if cc.has_argument(a)
-    c_args += a
-  endif
-endforeach
 c_vis_args = []
-if cc.has_argument('-fvisibility=hidden')
-  c_vis_args += '-fvisibility=hidden'
-endif
-
-# Check for generic C++ arguments
-cpp = meson.get_compiler('cpp')
+c_msvc_compat_args = []
+no_override_init_args = []
+cpp_msvc_compat_args = []
+cpp_vis_args = []
 cpp_args = []
-foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
-             '-Qunused-arguments']
-  if cpp.has_argument(a)
-    cpp_args += a
+if cc.get_id() == 'msvc'
+  foreach a : ['/wd4018', '/wd4056', '/wd4244', '/wd4246', '/wd4305',
+               '/wd4351', '/wd4756', '/wd4800', '/wd4996']
+    if cc.has_argument(a)
+      c_args += a
+    endif
+    if cpp.has_argument(a)
+      cpp_args += a
+    endif
+  endforeach
+  if cc.has_argument('-Wmicrosoft-enum-value')  # Clang
+    c_args += '-Wno-microsoft-enum-value'
+    cpp_args += '-Wno-microsoft-enum-value'
+  endif
+else
+  foreach a : ['-Wall', '-Werror=implicit-function-declaration',
+               '-Werror=missing-prototypes', '-fno-math-errno',
+               '-fno-trapping-math', '-Qunused-arguments']
+    if cc.has_argument(a)
+      c_args += a
+    endif
+  endforeach
+  if cc.has_argument('-fvisibility=hidden')
+    c_vis_args += '-fvisibility=hidden'
   endif
-endforeach
 
-# For some reason, the test for -Wno-foo always succeeds with gcc, even if the
-# option is not supported. Hence, check for -Wfoo instead.
-if cpp.has_argument('-Wnon-virtual-dtor')
-  cpp_args += '-Wno-non-virtual-dtor'
-endif
+  # Check for generic C++ arguments
+  foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math',
+               '-Qunused-arguments']
+    if cpp.has_argument(a)
+      cpp_args += a
+    endif
+  endforeach
 
-no_override_init_args = []
-foreach a : ['override-init', 'initializer-overrides']
-  if cc.has_argument('-W' + a)
-    no_override_init_args += '-Wno-' + a
+  # For some reason, the test for -Wno-foo always succeeds with gcc, even if
+  # the option is not supported. Hence, check for -Wfoo instead.
+  if cpp.has_argument('-Wnon-virtual-dtor')
+    cpp_args += '-Wno-non-virtual-dtor'
   endif
-endforeach
 
-cpp_vis_args = []
-if cpp.has_argument('-fvisibility=hidden')
-  cpp_vis_args += '-fvisibility=hidden'
-endif
+  foreach a : ['override-init', 'initializer-overrides']
+    if cc.has_argument('-W' + a)
+      no_override_init_args += '-Wno-' + a
+    endif
+  endforeach
 
-# Check for C and C++ arguments for MSVC2013 compatibility. These are only used
-# in parts of the mesa code base that need to compile with old versions of
-# MSVC, mainly common code
-c_msvc_compat_args = []
-cpp_msvc_compat_args = []
-foreach a : ['-Werror=pointer-arith', '-Werror=vla']
-  if cc.has_argument(a)
-    c_msvc_compat_args += a
-  endif
-  if cpp.has_argument(a)
-    cpp_msvc_compat_args += a
+  if cpp.has_argument('-fvisibility=hidden')
+    cpp_vis_args += '-fvisibility=hidden'
   endif
-endforeach
+
+  # Check for C and C++ arguments for MSVC2013 compatibility. These are only
+  # used in parts of the mesa code base that need to compile with old versions
+  # of MSVC, mainly common code
+  foreach a : ['-Werror=pointer-arith', '-Werror=vla']
+    if cc.has_argument(a)
+      c_msvc_compat_args += a
+    endif
+    if cpp.has_argument(a)
+      cpp_msvc_compat_args += a
+    endif
+  endforeach
+endif
 
 if host_machine.cpu_family().startswith('x86')
   pre_args += '-DUSE_SSE41'
@@ -856,6 +892,8 @@ if not cc.links('''#include <stdint.h>
   pre_args += '-DMISSING_64_BIT_ATOMICS'
 endif
 
+dep_ws2_32 = cc.find_library('ws2_32', required : with_platform_windows) 
+
 # TODO: endian
 # TODO: powr8
 # TODO: shared/static? Is this even worth doing?
-- 
2.17.1



More information about the mesa-dev mailing list