summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorSam James <sam@gentoo.org>2024-03-13 01:14:30 +0000
committerEli Schwartz <eschwartz93@gmail.com>2024-03-28 00:52:25 -0400
commit3e1e37f563916221d2b090df41f684ab37e843bb (patch)
treeddd13a24f436e892b8f1913e45445f34f3a6cc94 /mesonbuild/compilers/cpp.py
parent5bd28febf7887eebc8e55aa6e39962ae7da51281 (diff)
downloadmeson-3e1e37f563916221d2b090df41f684ab37e843bb.tar.gz
compilers: cpp: factor out C++ stdlib detection
We're going to use it in some more places in a minute (for controlling assertions). 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.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index c26def9fc..449a6888b 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -183,6 +183,13 @@ class _StdCPPLibMixin(CompilerMixinBase):
"""Detect whether to use libc++ or libstdc++."""
+ def language_stdlib_provider(self, env: Environment) -> str:
+ # https://stackoverflow.com/a/31658120
+ header = 'version' if self.has_header('<version>', '', env) else 'ciso646'
+ is_libcxx = self.has_header_symbol(header, '_LIBCPP_VERSION', '', env)[0]
+ lib = 'c++' if is_libcxx else 'stdc++'
+ return lib
+
@functools.lru_cache(None)
def language_stdlib_only_link_flags(self, env: Environment) -> T.List[str]:
"""Detect the C++ stdlib and default search dirs
@@ -202,11 +209,7 @@ class _StdCPPLibMixin(CompilerMixinBase):
machine = env.machines[self.for_machine]
assert machine is not None, 'for mypy'
- # https://stackoverflow.com/a/31658120
- header = 'version' if self.has_header('<version>', '', env) else 'ciso646'
- is_libcxx = self.has_header_symbol(header, '_LIBCPP_VERSION', '', env)[0]
- lib = 'c++' if is_libcxx else 'stdc++'
-
+ lib = self.language_stdlib_provider(env)
if self.find_library(lib, env, []) is not None:
return search_dirs + [f'-l{lib}']