compilers/cpp: check libc++ vs libstdc++ harder

Instead of hardcoding any values, hardcode what we think the most likely
implementation is, and check that first. It was pointed out that while
for example, Apple only provides libc++ and supports that for xcode, a
user could install a custom environment (such as homebrew) which uses
it's own copy of libstdc++, and we need to account for that. This means
that a library search will be done, but only once and the result will be
cached, on all systems.
pull/11949/head
Dylan Baker 1 year ago committed by Eli Schwartz
parent de44455b4b
commit 9cc67b7fd1
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 25
      mesonbuild/compilers/cpp.py

@ -206,22 +206,19 @@ class _StdCPPLibMixin(CompilerMixinBase):
machine = env.machines[self.for_machine] machine = env.machines[self.for_machine]
assert machine is not None, 'for mypy' assert machine is not None, 'for mypy'
# We need to determine whether to us libc++ or libstdc++ In some cases # We need to determine whether to use libc++ or libstdc++. We can't
# we know the answer, so we'll hardcode those cases. There are other # really know the answer in most cases, only the most likely answer,
# cases where we can't know the answer just by looking at the OS, namely # because a user can install things themselves or build custom images.
# on Linux. In that case we have to fallback to manually checking search_order: T.List[str] = []
stdlib: str
if machine.system in {'android', 'darwin', 'dragonfly', 'freebsd', 'netbsd', 'openbsd'}: if machine.system in {'android', 'darwin', 'dragonfly', 'freebsd', 'netbsd', 'openbsd'}:
stdlib = 'c++' search_order = ['c++', 'stdc++']
elif self.find_library('c++', env, []) is not None:
stdlib = 'c++'
elif self.find_library('stdc++', env, []) is not None:
stdlib = 'stdc++'
else: else:
# TODO: maybe a bug exception? search_order = ['stdc++', 'c++']
raise MesonException('Could not detect either libc++ or libstdc++ as your C++ stdlib implementation.') for lib in search_order:
if self.find_library(lib, env, []) is not None:
return search_dirs + [f'-l{stdlib}'] return search_dirs + [f'-l{lib}']
# TODO: maybe a bug exception?
raise MesonException('Could not detect either libc++ or libstdc++ as your C++ stdlib implementation.')
class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler): class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):

Loading…
Cancel
Save