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>
pull/13014/head
Sam James 8 months ago committed by Eli Schwartz
parent 5bd28febf7
commit 3e1e37f563
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 13
      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}']

Loading…
Cancel
Save