meson: Do not force libc++ when using clang

Currently the meson scripts force the use of libc++ when using clang
as the compiler. This behaviour cannot be overridden by the user, and
it is suboptimal as it means that a clang build cannot reliably use
system qt, gtest, etc since those might use libstdc++.

To fix that, simply do not force the use of any particular standard
library, and detect the currently used one based on predefined macros.
This is exactly what meson does internally, although the result is
not readily available for meson scripts[0][1]; so the test needs
to be largely replicated.

[0]: 675b47b069
[1]: https://stackoverflow.com/a/31658120

Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/226
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Khem Raj
2026-01-05 09:30:10 +01:00
committed by Barnabás Pőcze
parent 65db93f8f4
commit ab9c943971

View File

@@ -118,7 +118,16 @@ cpp_arguments = [
'-Wnon-virtual-dtor',
]
cxx_stdlib = 'libstdc++'
# \todo Switch to `version` when moving to C++20 as `ciso646` has been removed in C++20.
if cxx.has_header_symbol('ciso646', '_LIBCPP_VERSION')
cxx_stdlib = 'libc++'
elif cxx.has_header_symbol('ciso646', '__GLIBCXX__')
cxx_stdlib = 'libstdc++'
else
error('C++ standard library cannot be detected')
endif
message('Detected C++ standard library: ' + cxx_stdlib)
if cc.get_id() == 'clang'
if cc.version().version_compare('<9')
@@ -139,15 +148,6 @@ if cc.get_id() == 'clang'
endif
endif
# Use libc++ by default if available instead of libstdc++ when compiling
# with clang.
if cc.find_library('c++', required : false).found()
cpp_arguments += [
'-stdlib=libc++',
]
cxx_stdlib = 'libc++'
endif
cpp_arguments += [
'-Wextra-semi',
'-Wthread-safety',