From 3612a16e3a4d148a41d209cb5c9a7249be97a73c Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 23 May 2022 16:52:41 +0800 Subject: Meson/MSVC: Compensate for the lack of msvc_recommended_pragmas.h Since cairomm does not hard-depend on GLib, it may be the case that msvc_recommended_pragmas.h is not available during the build. If it is not, disable warnings C4244 and C4101, which are part of the warnings that it disables. --- meson.build | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index b55921a..e7eb27d 100644 --- a/meson.build +++ b/meson.build @@ -234,7 +234,14 @@ msvc14x_toolset_ver = '' # MSVC: Ignore warnings that aren't really harmful, but make those # that should not be overlooked stand out. if is_msvc - foreach wd : ['/FImsvc_recommended_pragmas.h', '/wd4267', '/wd4800', '/utf-8'] + use_recommended_pragmas = cpp_compiler.get_supported_arguments('/FImsvc_recommended_pragmas.h') + if use_recommended_pragmas.length() > 0 + add_project_arguments(use_recommended_pragmas, language: 'cpp') + else + disabled_warning = cpp_compiler.get_supported_arguments(['/wd4244', '/wd4101']) + add_project_arguments(disabled_warning, language: 'cpp') + endif + foreach wd : ['/wd4267', '/wd4800', '/utf-8'] disabled_warning = cpp_compiler.get_supported_arguments(wd) add_project_arguments(disabled_warning, language: 'cpp') endforeach -- cgit v1.2.3 From 07223e7c19a79458084c872cba9b371155dde037 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 23 May 2022 17:04:29 +0800 Subject: Meson: Re-organize warnings-related compiler flags for MSVC Add a short description for the warning-related compiler flags for Visual Studio. Also, use the `/wd4267` compiler flag only when building a 64-bit build, since warning C4267 only applies for 64-bit builds. --- meson.build | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index e7eb27d..f84658a 100644 --- a/meson.build +++ b/meson.build @@ -234,17 +234,33 @@ msvc14x_toolset_ver = '' # MSVC: Ignore warnings that aren't really harmful, but make those # that should not be overlooked stand out. if is_msvc + disable_warnings_list = [ + '/EHsc', # avoid warnings caused by exception handling model used + '/utf-8', # Avoid C4819 unicode conversion warnings when building on CJK locales + '/wd4800', # Implicit conversion from 'type' to bool. Possible information loss + ] + + # Turn off harmless warnings but make potentially dangerous ones glaring, + # distributed with GLib, if available use_recommended_pragmas = cpp_compiler.get_supported_arguments('/FImsvc_recommended_pragmas.h') if use_recommended_pragmas.length() > 0 add_project_arguments(use_recommended_pragmas, language: 'cpp') else - disabled_warning = cpp_compiler.get_supported_arguments(['/wd4244', '/wd4101']) - add_project_arguments(disabled_warning, language: 'cpp') + disable_warnings_list += [ + '/wd4244', # 'conversion' conversion from 'type1' to 'type2', possible loss of data + '/wd4101', # unreferenced local variable + ] endif - foreach wd : ['/wd4267', '/wd4800', '/utf-8'] - disabled_warning = cpp_compiler.get_supported_arguments(wd) - add_project_arguments(disabled_warning, language: 'cpp') - endforeach + + if host_machine.cpu_family() == 'x86_64' or host_machine.cpu_family() == 'aarch64' + # 'var' : conversion from 'size_t' to 'type', possible loss of data (applies on 64-bit builds) + disable_warnings_list += '/wd4267' + endif + + add_project_arguments( + cpp_compiler.get_supported_arguments(disable_warnings_list), + language: 'cpp' + ) if use_msvc14x_toolset_ver if cpp_compiler.version().version_compare('>=19.30') msvc14x_toolset_ver = '-vc143' -- cgit v1.2.3