v4: - Fix typo in warning code (4246 -> 4267) - Copy comments from scons for what MSVC warnings codes do - Merge linker argument changes into this commit --- meson.build | 155 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 106 insertions(+), 49 deletions(-)
diff --git a/meson.build b/meson.build index 32a731e2024..6cdb6888d1e 100644 --- a/meson.build +++ b/meson.build @@ -781,69 +781,124 @@ 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 += [ + '-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 -if cc.has_argument('-Wmissing-field-initializers') - c_args += '-Wno-missing-field-initializers' -endif - c_vis_args = [] -if cc.has_argument('-fvisibility=hidden') - c_vis_args += '-fvisibility=hidden' -endif - -# Check for generic C++ arguments +c_msvc_compat_args = [] +no_override_init_args = [] cpp_args = [] -foreach a : ['-Wall', '-fno-math-errno', '-fno-trapping-math', - '-Qunused-arguments'] - if cpp.has_argument(a) - cpp_args += a +cpp_vis_args = [] +cpp_msvc_compat_args = [] +if cc.get_id() == 'msvc' + foreach a : ['/wd4018', # signed/unsigned mismatch + '/wd4056', # overflow in floating-point constant arithmetic + '/wd4244', # conversion from 'type1' to 'type2', possible loss of data + '/wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data + '/wd4305', # trancation from 'type1' to 'type2' + '/wd4351', # new behavior: elements of array 'array' will be default initialized + '/wd4756', # overflow in constant arithmetic + '/wd4800', # forcing value to bool 'true' or 'false' (performance warning) + '/wd4996'] # disabled deprecated POSIX name warnings + 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 -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. - -foreach a : ['non-virtual-dtor', 'missing-field-initializers'] - if cpp.has_argument('-W' + a) - cpp_args += '-Wno-' + a +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('-Wmissing-field-initializers') + c_args += '-Wno-missing-field-initializers' endif -endforeach -no_override_init_args = [] -foreach a : ['override-init', 'initializer-overrides'] - if cc.has_argument('-W' + a) - no_override_init_args += '-Wno-' + a + c_vis_args = [] + if cc.has_argument('-fvisibility=hidden') + c_vis_args += '-fvisibility=hidden' endif -endforeach -cpp_vis_args = [] -if cpp.has_argument('-fvisibility=hidden') - cpp_vis_args += '-fvisibility=hidden' -endif + # For some reason, the test for -Wno-foo always succeeds with gcc, even if + # the option is not supported. Hence, check for -Wfoo instead. + foreach a : ['non-virtual-dtor', 'missing-field-initializers'] + if cpp.has_argument('-W' + a) + cpp_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 + foreach a : ['override-init', 'initializer-overrides'] + if cc.has_argument('-W' + a) + no_override_init_args += '-Wno-' + a + endif + endforeach + + if cpp.has_argument('-fvisibility=hidden') + cpp_vis_args += '-fvisibility=hidden' endif - if cpp.has_argument(a) - cpp_msvc_compat_args += a + + # 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 + +# set linker arguments +if host_machine.system() == 'windows' + if cc.get_id() == 'msvc' + add_project_link_arguments( + '/fixed:no', + '/incremental:no', + '/dynamicbase', + '/nxcompat', + language : ['c', 'cpp'], + ) + else + add_project_link_arguments( + '-Wl,--nxcompat', + '-Wl,--dynamicbase', + '-static-libgcc', + '-static-libstdc++', + language : ['c', 'cpp'], + ) endif -endforeach +endif if host_machine.cpu_family().startswith('x86') pre_args += '-DUSE_SSE41' @@ -902,6 +957,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: shared/static? Is this even worth doing? # When cross compiling we generally need to turn off the use of assembly, -- 2.18.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev