[libcamera-devel] [PATCH] meson: Use library() in order to let user chose the library type

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Nov 29 00:23:21 CET 2022


Hi Christian,

On Tue, Nov 29, 2022 at 12:00:26AM +0100, Christian Rauch wrote:
> Am 28.11.22 um 06:29 schrieb Laurent Pinchart:
> > On Mon, Nov 28, 2022 at 12:01:10AM +0100, Christian Rauch via libcamera-devel wrote:
> >> Defining libraries via shared_library() prevents compiling libcamera as
> >> static library. The meson project recommends using library() instead of
> >> shared_library(), static_library() or both_libraries():
> >> https://mesonbuild.com/Reference-manual_functions.html#library
> >
> > I'm curious, do you personally have use cases for libcamera as a static
> > library ?
> 
> Yes. I want/have to distribute my application with a statically linked
> libcamera in order to avoid dynamic linking issues with the libcamera
> package distributed by Ubuntu.

Note that IPA modules are always loaded dynamically.

> >> Signed-off-by: Christian Rauch <Rauch.Christian at gmx.de>
> >> ---
> >>   src/android/meson.build        | 16 ++++++++--------
> >>   src/gstreamer/meson.build      |  2 +-
> >>   src/libcamera/base/meson.build | 18 +++++++++---------
> >>   src/libcamera/meson.build      | 18 +++++++++---------
> >>   src/v4l2/meson.build           | 12 ++++++------
> >>   5 files changed, 33 insertions(+), 33 deletions(-)
> >>
> >> diff --git a/src/android/meson.build b/src/android/meson.build
> >> index 1bba54de..51b365e3 100644
> >> --- a/src/android/meson.build
> >> +++ b/src/android/meson.build
> >> @@ -67,11 +67,11 @@ android_camera_metadata = static_library('camera_metadata',
> >>                                            c_args : '-Wno-shadow',
> >>                                            include_directories : android_includes)
> >>
> >> -libcamera_hal = shared_library('libcamera-hal',
> >> -                               android_hal_sources,
> >> -                               name_prefix : '',
> >> -                               link_with : android_camera_metadata,
> >> -                               install : true,
> >> -                               cpp_args : android_cpp_args,
> >> -                               include_directories : android_includes,
> >> -                               dependencies : android_deps)
> >> +libcamera_hal = library('libcamera-hal',
> >> +                        android_hal_sources,
> >> +                        name_prefix : '',
> >> +                        link_with : android_camera_metadata,
> >> +                        install : true,
> >> +                        cpp_args : android_cpp_args,
> >> +                        include_directories : android_includes,
> >> +                        dependencies : android_deps)
> >
> > I'm curious, how do you envision the HAL to be loaded by the Android
> > camera service if it's a static library ? :-)
> 
> Isn't it possible to link the libraries statically on Android too?

The Android camera HAL is a shared object loaded dynamically by the
camera service.

> >> diff --git a/src/gstreamer/meson.build b/src/gstreamer/meson.build
> >> index eda246d7..b364837d 100644
> >> --- a/src/gstreamer/meson.build
> >> +++ b/src/gstreamer/meson.build
> >> @@ -39,7 +39,7 @@ if cc.get_id() == 'clang' and glib_dep.version().version_compare('<2.63.0')
> >>       libcamera_gst_cpp_args += ['-Wno-unused-function']
> >>   endif
> >>
> >> -libcamera_gst = shared_library('gstlibcamera',
> >> +libcamera_gst = library('gstlibcamera',
> >
> > Same here, and for the V4L2 compat library.
> 
> I might have overdone this. How is this library supposed to be used? Do
> you preload it in order to emulate V4L2 APIs?

Yes, it's LD_PRELOADed and overrides several libc symbols.

> Could this also be done with a 'shared_module'?

Possibly, but
https://mesonbuild.com/Reference-manual_functions.html#shared_module
notes that

  Linking to a shared module on platforms other than Android is
  deprecated, and will be an error in the future. It was previously
  allowed because it was the only way to have a shared-library-like
  target that contained references to undefined symbols. However, since
  0.40.0, the override_options: build_target() keyword argument can be
  used to create such a shared_library() by passing override_options:
  'b_lundef=false'. Shared modules have other characteristics that make
  them incompatible with linking, such as a lack of SONAME. On macOS and
  iOS, linking to shared modules is disallowed by the linker, so we
  disallow it at configure time. On Android, if a shared module foo uses
  symbols from another shared module bar, foo must also be linked to
  bar. Hence, linking one shared module to another will always be
  allowed when building for Android.

But in any case, I think you can keep using shared_library() here (and
in src/android/meson.build) while switching libcamera and libcamera-base
to library().

> >>       libcamera_gst_sources,
> >>       cpp_args : libcamera_gst_cpp_args,
> >>       dependencies : [libcamera_private, gstvideo_dep, gstallocator_dep],
> >> diff --git a/src/libcamera/base/meson.build b/src/libcamera/base/meson.build
> >> index 7a7fd7e4..91dc1e71 100644
> >> --- a/src/libcamera/base/meson.build
> >> +++ b/src/libcamera/base/meson.build
> >> @@ -48,15 +48,15 @@ libcamera_base_deps = [
> >>   # the use of headers which must not be exposed to the libcamera public api.
> >>   libcamera_base_args = [ '-DLIBCAMERA_BASE_PRIVATE' ]
> >>
> >> -libcamera_base_lib = shared_library('libcamera-base',
> >> -                                    [libcamera_base_sources, libcamera_base_headers],
> >> -                                    version : libcamera_version,
> >> -                                    soversion : libcamera_soversion,
> >> -                                    name_prefix : '',
> >> -                                    install : true,
> >> -                                    cpp_args : libcamera_base_args,
> >> -                                    include_directories : libcamera_includes,
> >> -                                    dependencies : libcamera_base_deps)
> >> +libcamera_base_lib = library('libcamera-base',
> >> +                             [libcamera_base_sources, libcamera_base_headers],
> >> +                             version : libcamera_version,
> >> +                             soversion : libcamera_soversion,
> >> +                             name_prefix : '',
> >> +                             install : true,
> >> +                             cpp_args : libcamera_base_args,
> >> +                             include_directories : libcamera_includes,
> >> +                             dependencies : libcamera_base_deps)
> >>
> >>   libcamera_base = declare_dependency(sources : [
> >>                                           libcamera_base_headers,
> >> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> >> index 0494e808..cd1bf4ed 100644
> >> --- a/src/libcamera/meson.build
> >> +++ b/src/libcamera/meson.build
> >> @@ -163,15 +163,15 @@ libcamera_deps = [
> >>   # runtime if the library is running from an installed location by checking
> >>   # for the presence or abscence of the dynamic tag.
> >>
> >> -libcamera = shared_library('libcamera',
> >> -                           libcamera_sources,
> >> -                           version : libcamera_version,
> >> -                           soversion : libcamera_soversion,
> >> -                           name_prefix : '',
> >> -                           install : true,
> >> -                           include_directories : includes,
> >> -                           build_rpath : '/',
> >> -                           dependencies : libcamera_deps)
> >> +libcamera = library('libcamera',
> >> +                    libcamera_sources,
> >> +                    version : libcamera_version,
> >> +                    soversion : libcamera_soversion,
> >> +                    name_prefix : '',
> >> +                    install : true,
> >> +                    include_directories : includes,
> >> +                    build_rpath : '/',
> >> +                    dependencies : libcamera_deps)
> >
> > Do libcameraBuildPath() and libcameraSourcePath() still work as expected
> > when compiling libcamera as a static library ?
> 
> I haven't tested this yet. I only tested that I can build and link
> libcamera statically. I added this option in order to test this and get
> some feedback. The default behaviour will still build a shared library.

The default behaviour is fine, but I'd like to know if
libcameraBuildPath() and libcameraSourcePath() work as expected with
static libraries or if we should fix them. It could possibly be done on
top.

> >>
> >>   libcamera_public = declare_dependency(sources : [
> >>                                             libcamera_ipa_headers,
> >> diff --git a/src/v4l2/meson.build b/src/v4l2/meson.build
> >> index f132103c..46dab168 100644
> >> --- a/src/v4l2/meson.build
> >> +++ b/src/v4l2/meson.build
> >> @@ -27,12 +27,12 @@ v4l2_compat_cpp_args = [
> >>       '-fvisibility=hidden',
> >>   ]
> >>
> >> -v4l2_compat = shared_library('v4l2-compat',
> >> -                             v4l2_compat_sources,
> >> -                             name_prefix : '',
> >> -                             install : true,
> >> -                             dependencies : [libcamera_private, libdl],
> >> -                             cpp_args : v4l2_compat_cpp_args)
> >> +v4l2_compat = library('v4l2-compat',
> >> +                      v4l2_compat_sources,
> >> +                      name_prefix : '',
> >> +                      install : true,
> >> +                      dependencies : [libcamera_private, libdl],
> >> +                      cpp_args : v4l2_compat_cpp_args)
> >>
> >>   # Provide a wrapper script to support easily loading applications with the V4L2
> >>   # adaptation layer.

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list