From ab9c943971c2ca16d73ea32d3b037e4793880f8d Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Mon, 5 Jan 2026 09:30:10 +0100 Subject: [PATCH] meson: Do not force libc++ when using clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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]: https://github.com/mesonbuild/meson/commit/675b47b0692131fae974298829ba807d730ab098 [1]: https://stackoverflow.com/a/31658120 Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/226 Signed-off-by: Khem Raj Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- meson.build | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/meson.build b/meson.build index fa6487f6..180ba16b 100644 --- a/meson.build +++ b/meson.build @@ -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',