summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2024-03-13 01:15:07 +0000
committerEli Schwartz <eschwartz93@gmail.com>2024-03-28 00:52:25 -0400
commita63739d394dd77314270f5a46f79171a8c544e77 (patch)
treea1eb75db65fba129c1fbc6fe9daeecef153ad0f7 /mesonbuild/compilers/cpp.py
parent3e1e37f563916221d2b090df41f684ab37e843bb (diff)
downloadmeson-a63739d394dd77314270f5a46f79171a8c544e77.tar.gz
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>
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
-rw-r--r--mesonbuild/compilers/cpp.py35
1 files changed, 20 insertions, 15 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 449a6888b..525c9fcdf 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/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)]