aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/cpp.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-07-06 09:40:27 -0700
committerEli Schwartz <eschwartz@archlinux.org>2023-07-11 15:47:45 -0400
commit9cc67b7fd185f92fb6c21ea7ecdb3d798ef3c2ae (patch)
tree64a424e4902c0419337f6e17193eb5976e90e6b4 /mesonbuild/compilers/cpp.py
parentde44455b4b9fa771ba0b01b86a7734cc4748c19f (diff)
downloadmeson-9cc67b7fd185f92fb6c21ea7ecdb3d798ef3c2ae.zip
meson-9cc67b7fd185f92fb6c21ea7ecdb3d798ef3c2ae.tar.gz
meson-9cc67b7fd185f92fb6c21ea7ecdb3d798ef3c2ae.tar.bz2
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.
Diffstat (limited to 'mesonbuild/compilers/cpp.py')
-rw-r--r--mesonbuild/compilers/cpp.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 2605670..0c68923 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -206,22 +206,19 @@ class _StdCPPLibMixin(CompilerMixinBase):
machine = env.machines[self.for_machine]
assert machine is not None, 'for mypy'
- # We need to determine whether to us libc++ or libstdc++ In some cases
- # we know the answer, so we'll hardcode those cases. There are other
- # cases where we can't know the answer just by looking at the OS, namely
- # on Linux. In that case we have to fallback to manually checking
- stdlib: str
+ # We need to determine whether to use libc++ or libstdc++. We can't
+ # really know the answer in most cases, only the most likely answer,
+ # because a user can install things themselves or build custom images.
+ search_order: T.List[str] = []
if machine.system in {'android', 'darwin', 'dragonfly', 'freebsd', 'netbsd', 'openbsd'}:
- stdlib = 'c++'
- elif self.find_library('c++', env, []) is not None:
- stdlib = 'c++'
- elif self.find_library('stdc++', env, []) is not None:
- stdlib = 'stdc++'
+ search_order = ['c++', 'stdc++']
else:
- # TODO: maybe a bug exception?
- raise MesonException('Could not detect either libc++ or libstdc++ as your C++ stdlib implementation.')
-
- return search_dirs + [f'-l{stdlib}']
+ search_order = ['stdc++', 'c++']
+ for lib in search_order:
+ if self.find_library(lib, env, []) is not None:
+ 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):