Add option for controlling RTTI.

pull/4973/head
Jussi Pakkanen 5 years ago
parent 760b8633bc
commit b3fe4a0a18
  1. 1
      docs/markdown/Builtin-options.md
  2. 11
      docs/markdown/FAQ.md
  3. 3
      docs/markdown/snippets/nortti.md
  4. 15
      mesonbuild/compilers/cpp.py

@ -144,6 +144,7 @@ compiler being used:
| cpp_std | none | none, c++98, c++03, c++11, c++14, c++17, <br/>c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z, <br/> vc++14, vc++17, vc++latest | C++ language standard to use |
| cpp_debugstl | false | true, false | C++ STL debug mode |
| cpp_eh | default | none, default, a, s, sc | C++ exception handling type |
| cpp_rtti | true | true, false | Whether to enable RTTI (runtime type identification) |
| cpp_winlibs | see below | free-form comma-separated list | Standard Windows libs to link against |
The default values of `c_winlibs` and `cpp_winlibs` are in compiler-specific

@ -489,3 +489,14 @@ libbar = library('bar', sources: libbar_sources, dependencies: libfoo_dep)
A good example of a generator that outputs both sources and headers is
[`gnome.mkenums()`](https://mesonbuild.com/Gnome-module.html#gnomemkenums).
## How do I disable exceptions and RTTI in my C++ project?
With the `cpp_eh` and `cpp_rtti` options. A typical invocation would
look like this:
```
meson -Dcpp_eh=none -Dcpp_rtti=false <other options>
```
The RTTI option is only available since Meson version 0.53.0.

@ -0,0 +1,3 @@
## Added global option to disable C++ RTTI
The new boolean option is called `cpp_rtti`.

@ -167,6 +167,7 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
opts.update({'cpp_eh': coredata.UserComboOption('C++ exception handling type.',
['none', 'default', 'a', 's', 'sc'],
'default'),
'cpp_rtti': coredata.UserBooleanOption('Enable RTTI', True),
'cpp_std': coredata.UserComboOption('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'],
@ -181,6 +182,9 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
non_msvc_eh_options(options['cpp_eh'].value, args)
if not options['cpp_rtti'].value:
args.append('-fno-rtti')
return args
def get_option_link_args(self, options):
@ -265,6 +269,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
opts.update({'cpp_eh': coredata.UserComboOption('C++ exception handling type.',
['none', 'default', 'a', 's', 'sc'],
'default'),
'cpp_rtti': coredata.UserBooleanOption('Enable RTTI', True),
'cpp_std': coredata.UserComboOption('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'],
@ -285,6 +290,9 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
non_msvc_eh_options(options['cpp_eh'].value, args)
if not options['cpp_rtti'].value:
args.append('-fno-rtti')
if options['cpp_debugstl'].value:
args.append('-D_GLIBCXX_DEBUG=1')
return args
@ -373,6 +381,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
opts.update({'cpp_eh': coredata.UserComboOption('C++ exception handling type.',
['none', 'default', 'a', 's', 'sc'],
'default'),
'cpp_rtti': coredata.UserBooleanOption('Enable RTTI', True),
'cpp_std': coredata.UserComboOption('C++ language standard to use',
['none'] + c_stds + g_stds,
'none'),
@ -391,6 +400,8 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
args.append('-std=' + remap_cpp03.get(std.value, std.value))
if options['cpp_eh'].value == 'none':
args.append('-fno-exceptions')
if not options['cpp_rtti'].value:
args.append('-fno-rtti')
if options['cpp_debugstl'].value:
args.append('-D_GLIBCXX_DEBUG=1')
return args
@ -422,6 +433,7 @@ class VisualStudioLikeCPPCompilerMixin:
opts.update({'cpp_eh': coredata.UserComboOption('C++ exception handling type.',
['none', 'default', 'a', 's', 'sc'],
'default'),
'cpp_rtti': coredata.UserBooleanOption('Enable RTTI', True),
'cpp_std': coredata.UserComboOption('C++ language standard to use',
cpp_stds,
'none'),
@ -440,6 +452,9 @@ class VisualStudioLikeCPPCompilerMixin:
else:
args.append('/EH' + eh.value)
if not options['cpp_rtti'].value:
args.append('/GR-')
permissive, ver = self.VC_VERSION_MAP[options['cpp_std'].value]
if ver is not None:

Loading…
Cancel
Save