From b3fe4a0a18edbd85c3a9e119912c968960f99574 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 30 Oct 2019 22:49:17 +0200 Subject: [PATCH] Add option for controlling RTTI. --- docs/markdown/Builtin-options.md | 1 + docs/markdown/FAQ.md | 11 +++++++++++ docs/markdown/snippets/nortti.md | 3 +++ mesonbuild/compilers/cpp.py | 15 +++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 docs/markdown/snippets/nortti.md diff --git a/docs/markdown/Builtin-options.md b/docs/markdown/Builtin-options.md index 3219af85f..4172f1a97 100644 --- a/docs/markdown/Builtin-options.md +++ b/docs/markdown/Builtin-options.md @@ -144,6 +144,7 @@ compiler being used: | cpp_std | none | none, c++98, c++03, c++11, c++14, c++17,
c++1z, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z,
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 diff --git a/docs/markdown/FAQ.md b/docs/markdown/FAQ.md index 06379aec7..7625361cf 100644 --- a/docs/markdown/FAQ.md +++ b/docs/markdown/FAQ.md @@ -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 +``` + +The RTTI option is only available since Meson version 0.53.0. diff --git a/docs/markdown/snippets/nortti.md b/docs/markdown/snippets/nortti.md new file mode 100644 index 000000000..63d85c5ac --- /dev/null +++ b/docs/markdown/snippets/nortti.md @@ -0,0 +1,3 @@ +## Added global option to disable C++ RTTI + +The new boolean option is called `cpp_rtti`. diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 6161b7af9..973ffbb6b 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -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: