Repository: mesonbuild/meson

Issue:
cpp_eh=none should set -fno-exceptions on non-MSVC compilers
see title :)


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -142,7 +142,11 @@ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None,
 
     def get_options(self):
         opts = CPPCompiler.get_options(self)
-        opts.update({'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
+        opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
+                                                        'C++ exception handling type.',
+                                                        ['none', 'default'],
+                                                        'default'),
+                     'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
                                                          ['none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a',
                                                           'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z', 'gnu++2a'],
                                                          'none')})
@@ -153,6 +157,8 @@ def get_option_compile_args(self, options):
         std = options['cpp_std']
         if std.value != 'none':
             args.append(self._find_best_cpp_std(std.value))
+        if options['cpp_eh'].value == 'none':
+            args.append('-fno-exceptions')
         return args
 
     def get_option_link_args(self, options):
@@ -174,7 +180,11 @@ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None,
 
     def get_options(self):
         opts = CPPCompiler.get_options(self)
-        opts.update({'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
+        opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
+                                                        'C++ exception handling type.',
+                                                        ['none', 'default'],
+                                                        'default'),
+                     'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
                                                          ['none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17',
                                                           'gnu++98', 'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17'],
                                                          'none')})
@@ -185,6 +195,8 @@ def get_option_compile_args(self, options):
         std = options['cpp_std']
         if std.value != 'none':
             args.append('-std=' + std.value)
+        if options['cpp_eh'].value == 'none':
+            args.append('-fno-exceptions')
         return args
 
     def get_option_link_args(self, options):
@@ -203,7 +215,11 @@ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap, defines,
 
     def get_options(self):
         opts = CPPCompiler.get_options(self)
-        opts.update({'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
+        opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
+                                                        'C++ exception handling type.',
+                                                        ['none', 'default'],
+                                                        'default'),
+                     'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
                                                          ['none', 'c++98', 'c++03', 'c++11', 'c++14', 'c++17', 'c++1z', 'c++2a',
                                                           'gnu++03', 'gnu++11', 'gnu++14', 'gnu++17', 'gnu++1z', 'gnu++2a'],
                                                          'none'),
@@ -221,6 +237,8 @@ def get_option_compile_args(self, options):
         std = options['cpp_std']
         if std.value != 'none':
             args.append(self._find_best_cpp_std(std.value))
+        if options['cpp_eh'].value == 'none':
+            args.append('-fno-exceptions')
         if options['cpp_debugstl'].value:
             args.append('-D_GLIBCXX_DEBUG=1')
         return args
@@ -251,7 +269,11 @@ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None,
     # It does not support c++/gnu++ 17 and 1z, but still does support 0x, 1y, and gnu++98.
     def get_options(self):
         opts = CPPCompiler.get_options(self)
-        opts.update({'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
+        opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
+                                                        'C++ exception handling type.',
+                                                        ['none', 'default'],
+                                                        'default'),
+                     'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
                                                          ['none', 'c++98', 'c++03', 'c++0x', 'c++11', 'c++14', 'c++1y',
                                                           'gnu++98', 'gnu++03', 'gnu++0x', 'gnu++11', 'gnu++14', 'gnu++1y'],
                                                          'none'),
@@ -297,7 +319,11 @@ def get_options(self):
             c_stds += ['c++17']
         if version_compare(self.version, '>=17.0.0'):
             g_stds += ['gnu++14']
-        opts.update({'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
+        opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
+                                                        'C++ exception handling type.',
+                                                        ['none', 'default'],
+                                                        'default'),
+                     'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
                                                          ['none'] + c_stds + g_stds,
                                                          'none'),
                      'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl',
@@ -314,6 +340,8 @@ def get_option_compile_args(self, options):
                 'gnu++03': 'gnu++98'
             }
             args.append('-std=' + remap_cpp03.get(std.value, std.value))
+        if options['cpp_eh'].value == 'none':
+            args.append('-fno-exceptions')
         if options['cpp_debugstl'].value:
             args.append('-D_GLIBCXX_DEBUG=1')
         return args
@@ -343,8 +371,8 @@ def get_options(self):
         opts = CPPCompiler.get_options(self)
         opts.update({'cpp_eh': coredata.UserComboOption('cpp_eh',
                                                         'C++ exception handling type.',
-                                                        ['none', 'a', 's', 'sc'],
-                                                        'sc'),
+                                                        ['none', 'a', 's', 'sc', 'default'],
+                                                        'default'),
                      'cpp_std': coredata.UserComboOption('cpp_std',
                                                          'C++ language standard to use',
                                                          cpp_stds,
@@ -358,7 +386,9 @@ def get_option_compile_args(self, options):
         args = []
 
         eh = options['cpp_eh']
-        if eh.value != 'none':
+        if eh.value == 'default':
+            args.append('/EHsc')
+        elif eh.value != 'none':
             args.append('/EH' + eh.value)
 
         vc_version_map = {


Test patch:
diff --git a/test cases/common/91 default options/meson.build b/test cases/common/91 default options/meson.build
--- a/test cases/common/91 default options/meson.build	
+++ b/test cases/common/91 default options/meson.build	
@@ -8,13 +8,10 @@ project('default options', 'cpp', 'c', default_options : [
 
 assert(get_option('buildtype') == 'debugoptimized', 'Build type default value wrong.')
 
-if meson.get_compiler('cpp').get_argument_syntax() == 'msvc'
-  cpp_eh = get_option('cpp_eh')
-  assert(cpp_eh == 'none', 'MSVC eh value is "' + cpp_eh + '" instead of "none"')
-else
-  cpp_std = get_option('cpp_std')
-  assert(cpp_std == 'c++11', 'C++ std value is "' + cpp_std + '" instead of c++11.')
-endif
+cpp_eh = get_option('cpp_eh')
+assert(cpp_eh == 'none', 'EH value is "' + cpp_eh + '" instead of "none"')
+cpp_std = get_option('cpp_std')
+assert(cpp_std == 'c++11', 'C++ std value is "' + cpp_std + '" instead of c++11.')
 
 w_level = get_option('warning_level')
 assert(w_level == '3', 'warning level "' + w_level + '" instead of "3"')