| Message ID | 20260105093119.1176922-1-barnabas.pocze@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
On Mon, Jan 05, 2026 at 10:31:19AM +0100, Barnabás Pőcze wrote: > From: Khem Raj <raj.khem@gmail.com> > > 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 <raj.khem@gmail.com> > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > changes in v2: > * use `has_header_symbol()` > * do not set `-stdlib=` when using clang > * reword commit message > > v1: https://patchwork.libcamera.org/patch/24811/ > --- > meson.build | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/meson.build b/meson.build > index fa6487f65..4aa7ecc96 100644 > --- a/meson.build > +++ b/meson.build > @@ -118,7 +118,16 @@ cpp_arguments = [ > '-Wnon-virtual-dtor', > ] > > -cxx_stdlib = 'libstdc++' > +cxx_stdlib = '' > + > +# \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(...) would be a nice addition. With that, > +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++' cxx_stdlib is used in test/py/meson.build only. Should the above be moved there ? > - endif > - > cpp_arguments += [ > '-Wextra-semi', > '-Wthread-safety',
2026. 01. 05. 11:21 keltezéssel, Laurent Pinchart írta: > On Mon, Jan 05, 2026 at 10:31:19AM +0100, Barnabás Pőcze wrote: >> From: Khem Raj <raj.khem@gmail.com> >> >> 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 <raj.khem@gmail.com> >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> >> --- >> changes in v2: >> * use `has_header_symbol()` >> * do not set `-stdlib=` when using clang >> * reword commit message >> >> v1: https://patchwork.libcamera.org/patch/24811/ >> --- >> meson.build | 20 ++++++++++---------- >> 1 file changed, 10 insertions(+), 10 deletions(-) >> >> diff --git a/meson.build b/meson.build >> index fa6487f65..4aa7ecc96 100644 >> --- a/meson.build >> +++ b/meson.build >> @@ -118,7 +118,16 @@ cpp_arguments = [ >> '-Wnon-virtual-dtor', >> ] >> >> -cxx_stdlib = 'libstdc++' >> +cxx_stdlib = '' >> + >> +# \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(...) Okay. > > would be a nice addition. With that, > I have to assume something is missing here? >> +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++' > > cxx_stdlib is used in test/py/meson.build only. Should the above be > moved there ? I would keep it here. > >> - endif >> - >> cpp_arguments += [ >> '-Wextra-semi', >> '-Wthread-safety', >
On Mon, Jan 05, 2026 at 11:28:30AM +0100, Barnabás Pőcze wrote: > 2026. 01. 05. 11:21 keltezéssel, Laurent Pinchart írta: > > On Mon, Jan 05, 2026 at 10:31:19AM +0100, Barnabás Pőcze wrote: > >> From: Khem Raj <raj.khem@gmail.com> > >> > >> 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 <raj.khem@gmail.com> > >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > >> --- > >> changes in v2: > >> * use `has_header_symbol()` > >> * do not set `-stdlib=` when using clang > >> * reword commit message > >> > >> v1: https://patchwork.libcamera.org/patch/24811/ > >> --- > >> meson.build | 20 ++++++++++---------- > >> 1 file changed, 10 insertions(+), 10 deletions(-) > >> > >> diff --git a/meson.build b/meson.build > >> index fa6487f65..4aa7ecc96 100644 > >> --- a/meson.build > >> +++ b/meson.build > >> @@ -118,7 +118,16 @@ cpp_arguments = [ > >> '-Wnon-virtual-dtor', > >> ] > >> > >> -cxx_stdlib = 'libstdc++' > >> +cxx_stdlib = '' > >> + > >> +# \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(...) > > Okay. > > > would be a nice addition. With that, > > I have to assume something is missing here? Ignore the "With that," :-) > >> +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++' > > > > cxx_stdlib is used in test/py/meson.build only. Should the above be > > moved there ? > > I would keep it here. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > >> - endif > >> - > >> cpp_arguments += [ > >> '-Wextra-semi', > >> '-Wthread-safety',
Quoting Laurent Pinchart (2026-01-05 18:04:40) > On Mon, Jan 05, 2026 at 11:28:30AM +0100, Barnabás Pőcze wrote: > > 2026. 01. 05. 11:21 keltezéssel, Laurent Pinchart írta: > > > On Mon, Jan 05, 2026 at 10:31:19AM +0100, Barnabás Pőcze wrote: > > >> From: Khem Raj <raj.khem@gmail.com> > > >> > > >> 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 <raj.khem@gmail.com> > > >> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > > >> --- > > >> changes in v2: > > >> * use `has_header_symbol()` > > >> * do not set `-stdlib=` when using clang > > >> * reword commit message > > >> > > >> v1: https://patchwork.libcamera.org/patch/24811/ > > >> --- > > >> meson.build | 20 ++++++++++---------- > > >> 1 file changed, 10 insertions(+), 10 deletions(-) > > >> > > >> diff --git a/meson.build b/meson.build > > >> index fa6487f65..4aa7ecc96 100644 > > >> --- a/meson.build > > >> +++ b/meson.build > > >> @@ -118,7 +118,16 @@ cpp_arguments = [ > > >> '-Wnon-virtual-dtor', > > >> ] > > >> > > >> -cxx_stdlib = 'libstdc++' > > >> +cxx_stdlib = '' > > >> + > > >> +# \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(...) > > > > Okay. > > > > > would be a nice addition. With that, > > > > I have to assume something is missing here? > > Ignore the "With that," :-) > > > >> +endif > > >> + > > >> +message('Detected C++ standard library: ' + cxx_stdlib) Any value in adding this to the summary? But a message is probably fine enough on it's own too. Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > >> > > >> 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++' > > > > > > cxx_stdlib is used in test/py/meson.build only. Should the above be > > > moved there ? > > > > I would keep it here. > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > >> - endif > > >> - > > >> cpp_arguments += [ > > >> '-Wextra-semi', > > >> '-Wthread-safety', > > -- > Regards, > > Laurent Pinchart
diff --git a/meson.build b/meson.build index fa6487f65..4aa7ecc96 100644 --- a/meson.build +++ b/meson.build @@ -118,7 +118,16 @@ cpp_arguments = [ '-Wnon-virtual-dtor', ] -cxx_stdlib = 'libstdc++' +cxx_stdlib = '' + +# \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++' +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',