diff mbox series

[meta-multimedia,02/11] libcamera: Detect platform/toolchain defaults for C++ library

Message ID 20251025034017.2071643-2-raj.khem@gmail.com
State New
Headers show
Series [meta-oe,01/11] botan: Upgrade to 3.9.0 | expand

Commit Message

Khem Raj Oct. 25, 2025, 3:40 a.m. UTC
This ensures that meson does not detect it and automatically link to it
when using clang with gnu runtime

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 ...camera-Do-not-assume-libc-with-clang.patch | 68 +++++++++++++++++++
 .../libcamera/libcamera_0.5.2.bb              |  1 +
 2 files changed, 69 insertions(+)
 create mode 100644 meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-libcamera-Do-not-assume-libc-with-clang.patch
diff mbox series

Patch

diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-libcamera-Do-not-assume-libc-with-clang.patch b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-libcamera-Do-not-assume-libc-with-clang.patch
new file mode 100644
index 0000000000..7495205041
--- /dev/null
+++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera/0001-libcamera-Do-not-assume-libc-with-clang.patch
@@ -0,0 +1,68 @@ 
+From 82e9d391d312d65e7a62252e9e153b93c06ad37b Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Fri, 24 Oct 2025 11:10:59 -0700
+Subject: [PATCH] libcamera: Do not assume libc++ with clang
+
+Clang on linux can be defaulting to use libstdc++, it
+should be using default platform C++ runtime library which the
+toolchain should be configured to do the right thing
+
+Add logic in meson file to detect C++ runtime used by toolchain
+and defile -stdlib= parameter accordingly
+
+Upstream-Status: Submitted [https://lists.libcamera.org/pipermail/libcamera-devel/2025-October/054151.html]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ meson.build | 32 +++++++++++++++++++++-----------
+ 1 file changed, 21 insertions(+), 11 deletions(-)
+
+diff --git a/meson.build b/meson.build
+index fd508fd7..5707f850 100644
+--- a/meson.build
++++ b/meson.build
+@@ -118,7 +118,24 @@ cpp_arguments = [
+     '-Wnon-virtual-dtor',
+ ]
+
+-cxx_stdlib = 'libstdc++'
++# Try to detect libc++
++libcxx_ver = cxx.get_define('_LIBCPP_VERSION',
++  prefix: '#include <vector>\n')
++
++# Try to detect libstdc++
++glibcxx_ver = cxx.get_define('__GLIBCXX__',
++  prefix: '#include <vector>\n')
++
++stdlib_msg = 'unknown'
++
++if libcxx_ver != ''
++  cxx_stdlib = 'libc++'
++elif glibcxx_ver != ''
++  # __GLIBCXX__ is usually a yyyymmdd date code
++  cxx_stdlib = 'libstdc++'
++endif
++
++message('Detected C++ standard library: ' + cxx_stdlib)
+
+ if cc.get_id() == 'clang'
+     if cc.version().version_compare('<9')
+@@ -138,16 +155,9 @@ 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 += [
++        '-stdlib=' + cxx_stdlib,
++    ]
+     cpp_arguments += [
+         '-Wextra-semi',
+         '-Wthread-safety',
diff --git a/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.5.2.bb b/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.5.2.bb
index 88fe9cf39c..8b8d6815c5 100644
--- a/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.5.2.bb
+++ b/meta-multimedia/recipes-multimedia/libcamera/libcamera_0.5.2.bb
@@ -10,6 +10,7 @@  LIC_FILES_CHKSUM = "\

 SRC_URI = " \
         git://git.libcamera.org/libcamera/libcamera.git;protocol=https;branch=master;tag=v${PV} \
+        file://0001-libcamera-Do-not-assume-libc-with-clang.patch \
 "

 SRCREV = "096c50ca881f72d858aca19757a5e73b4775a7cc"