[glib/clang-cl-improvements: 1/2] msvc_recommended_pragmas.h: Refine for clang-cl




commit c710d550ca71f777110c80f4edda382e0602548c
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Sat Mar 20 10:15:02 2021 +0800

    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                | 27 ++++++++++++++++-----------
 msvc_recommended_pragmas.h |  4 +++-
 2 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/meson.build b/meson.build
index 2cf1c7b4f..3314d9be7 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
-  # 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')
-  # 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')
+  # (also for clang-cl)
+  add_project_arguments('/FImsvc_recommended_pragmas.h',language : 'c')
+
+  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',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']
+  endif
 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]