From 97959cd7eb76b7ff52b3c40002d974e3d4c03f77 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Sat, 20 Mar 2021 10:15:02 +0800 Subject: [PATCH] msvc_recommended_pragmas.h: Refine for clang-cl Make msvc_recommended_pragmas.h work better with clang-cl so that we can use that to eliminate some warnings that are emitted as it also consumes Microsoft compiler and SDK headers. Also, for GLib builds, force-include msvc_recommended_pragmas.h for clang-cl builds as well, as it becomes usable and useful there. Fixes issue #2357. --- meson.build | 13 +++++++++---- msvc_recommended_pragmas.h | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 2cf1c7b4f..65304b3c1 100644 --- a/meson.build +++ b/meson.build @@ -14,18 +14,23 @@ cxx = meson.get_compiler('cpp') cc_can_run = not meson.is_cross_build() or meson.has_exe_wrapper() -if cc.get_id() == 'msvc' +if cc.get_argument_syntax() == 'msvc' # Ignore several spurious warnings for things glib does very commonly + # (also for clang-cl) + add_project_arguments('/FImsvc_recommended_pragmas.h',language : 'c') +endif + +if cc.get_id() == 'msvc' # If a warning is completely useless and spammy, use '/wdXXXX' to suppress it # If a warning is harmless but hard to fix, use '/woXXXX' so it's shown once # NOTE: Only add warnings here if you are sure they're spurious add_project_arguments('/wd4035', '/wd4715', '/wd4116', - '/wd4046', '/wd4068', '/wo4090', '/FImsvc_recommended_pragmas.h',language : 'c') + '/wd4046', '/wd4068', '/wo4090',language : 'c') + # Set the input and exec encoding to utf-8, like is the default with GCC + add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c') # Disable SAFESEH with MSVC for plugins and libs that use external deps that # are built with MinGW noseh_link_args = ['/SAFESEH:NO'] - # Set the input and exec encoding to utf-8, like is the default with GCC - add_project_arguments(cc.get_supported_arguments(['/utf-8']), language: 'c') else noseh_link_args = [] # -mms-bitfields vs -fnative-struct ? diff --git a/msvc_recommended_pragmas.h b/msvc_recommended_pragmas.h index e70698712..051a02ae4 100644 --- a/msvc_recommended_pragmas.h +++ b/msvc_recommended_pragmas.h @@ -1,10 +1,11 @@ #ifndef _MSC_VER -#pragma error "This header is for Microsoft VC only." +#pragma error "This header is for Microsoft VC or clang-cl only." #endif /* _MSC_VER */ /* Make MSVC more pedantic, this is a recommended pragma list * from _Win32_Programming_ by Rector and Newcomer. */ +#ifndef __clang__ #pragma warning(error:4002) /* too many actual parameters for macro */ #pragma warning(error:4003) /* not enough actual parameters for macro */ #pragma warning(1:4010) /* single-line comment contains line-continuation character */ @@ -33,6 +34,7 @@ #pragma warning(disable:4305) /* No truncation from int to char warnings */ #pragma warning(error:4819) /* The file contains a character that cannot be represented in the current code page */ +#endif /* __clang__ */ /* work around Microsoft's premature attempt to deprecate the C-Library */ #define _CRT_SECURE_NO_WARNINGS