compilers: cpp: reduce macro pollution for stdlib macros

Now that we have access to Environment in get_assert_args, we can check what
the actual C++ stdlib provider is and only set relevant macros rather than
all possibly-relevant ones based on the compiler.

Also, while we're here, now that's sorted, wire up the GCC experimental
libc++ support in the macro emission given it doesn't uglify anything for
libstdc++ users now.

Bug: https://github.com/mesonbuild/meson/issues/12962
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
pull/13014/head
Sam James 8 months ago committed by Eli Schwartz
parent 3e1e37f563
commit a63739d394
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 35
      mesonbuild/compilers/cpp.py

@ -311,7 +311,6 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
return []
def get_assert_args(self, disable: bool, env: 'Environment') -> T.List[str]:
args: T.List[str] = []
if disable:
return ['-DNDEBUG']
@ -320,15 +319,15 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
if self.defines.get(macro) is not None:
return []
# Clang supports both libstdc++ and libc++
# TODO: Pipe through the C++ stdlib impl information to here so we can avoid pollution
args.append('-D_GLIBCXX_ASSERTIONS=1')
if version_compare(self.version, '>=18'):
args.append('-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST')
elif version_compare(self.version, '>=15'):
args.append('-D_LIBCPP_ENABLE_ASSERTIONS=1')
if self.language_stdlib_provider(env) == 'stdc++':
return ['-D_GLIBCXX_ASSERTIONS=1']
else:
if version_compare(self.version, '>=18'):
return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
elif version_compare(self.version, '>=15'):
return ['-D_LIBCPP_ENABLE_ASSERTIONS=1']
return args
return []
class ArmLtdClangCPPCompiler(ClangCPPCompiler):
@ -510,13 +509,19 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
return ['-DNDEBUG']
# Don't inject the macro if the compiler already has it pre-defined.
if self.defines.get('_GLIBCXX_ASSERTIONS') is not None:
return []
for macro in ['_GLIBCXX_ASSERTIONS', '_LIBCPP_HARDENING_MODE', '_LIBCPP_ENABLE_ASSERTIONS']:
if self.defines.get(macro) is not None:
return []
if self.language_stdlib_provider(env) == 'stdc++':
return ['-D_GLIBCXX_ASSERTIONS=1']
else:
if version_compare(self.version, '>=18'):
return ['-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST']
elif version_compare(self.version, '>=15'):
return ['-D_LIBCPP_ENABLE_ASSERTIONS=1']
# XXX: This needs updating if/when GCC starts to support libc++.
# It currently only does so via an experimental configure arg.
# TODO: Pipe through the C++ stdlib impl information to here so we can avoid pollution
return ['-D_GLIBCXX_ASSERTIONS=1']
return []
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
return ['-fpch-preprocess', '-include', os.path.basename(header)]

Loading…
Cancel
Save