diff mbox series

build: add --enable/--disable-libudev

Message ID 20201015150638.1396659-1-pbonzini@redhat.com
State New
Headers show
Series build: add --enable/--disable-libudev | expand

Commit Message

Paolo Bonzini Oct. 15, 2020, 3:06 p.m. UTC
Initially, libudev detection was bundled with --enable-mpath because
qemu-pr-helper was the only user of libudev.  Recently however the USB
U2F emulation has also started using libudev, so add a separate
option.  This also allows 1) disabling libudev if desired for static
builds and 2) for non-static builds, requiring libudev even if
multipath support is undesirable.

The multipath test is adjusted, because it is now possible to enter it
with configurations that should fail, such as --static --enable-mpath
--disable-libudev.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure         |  8 +++++++-
 meson.build       | 29 ++++++++++++++++-------------
 meson_options.txt |  2 ++
 3 files changed, 25 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/configure b/configure
index b553288c5e..05b246cd24 100755
--- a/configure
+++ b/configure
@@ -302,6 +302,7 @@  netmap="no"
 sdl="auto"
 sdl_image="auto"
 virtfs=""
+libudev="auto"
 mpath="auto"
 vnc="enabled"
 sparse="auto"
@@ -1004,6 +1005,10 @@  for opt do
   ;;
   --enable-virtfs) virtfs="yes"
   ;;
+  --disable-libudev) libudev="disabled"
+  ;;
+  --enable-libudev) libudev="enabled"
+  ;;
   --disable-mpath) mpath="disabled"
   ;;
   --enable-mpath) mpath="enabled"
@@ -1761,6 +1766,7 @@  disabled with --disable-FEATURE, default is enabled if available:
   vnc-png         PNG compression for VNC server
   cocoa           Cocoa UI (Mac OS X only)
   virtfs          VirtFS
+  libudev         Use libudev to enumerate host devices
   mpath           Multipath persistent reservation passthrough
   xen             xen backend driver support
   xen-pci-passthrough    PCI passthrough support for Xen
@@ -7216,7 +7222,7 @@  NINJA=${ninja:-$PWD/ninjatool} $meson setup \
 	-Dxen=$xen -Dxen_pci_passthrough=$xen_pci_passthrough -Dtcg=$tcg \
 	-Dcocoa=$cocoa -Dmpath=$mpath -Dsdl=$sdl -Dsdl_image=$sdl_image \
 	-Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \
-	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f \
+	-Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f -Dlibudev=$libudev \
 	-Dcapstone=$capstone -Dslirp=$slirp -Dfdt=$fdt \
         $cross_arg \
         "$PWD" "$source_path"
diff --git a/meson.build b/meson.build
index 652c37cceb..5bcd21a9f4 100644
--- a/meson.build
+++ b/meson.build
@@ -358,10 +358,11 @@  endif
 libudev = not_found
 if targetos == 'linux' and (have_system or have_tools)
   libudev = dependency('libudev',
-                       required: get_option('mpath').enabled(),
+                       required: get_option('libudev'),
                        static: enable_static)
 endif
 
+mpathlibs = [libudev]
 mpathpersist = not_found
 mpathpersist_new_api = false
 if targetos == 'linux' and have_tools and not get_option('mpath').disabled()
@@ -392,7 +393,6 @@  if targetos == 'linux' and have_tools and not get_option('mpath').disabled()
           mpath_lib_init(udev);
           return 0;
       }'''
-  mpathlibs = [libudev]
   if enable_static
     mpathlibs += cc.find_library('devmapper',
                                    required: get_option('mpath'),
@@ -410,18 +410,21 @@  if targetos == 'linux' and have_tools and not get_option('mpath').disabled()
       break
     endif
   endforeach
-  if mpathlibs.length() > 0
-    if cc.links(mpath_test_source_new, dependencies: mpathlibs)
-      mpathpersist = declare_dependency(dependencies: mpathlibs)
-      mpathpersist_new_api = true
-    elif cc.links(mpath_test_source_old, dependencies: mpathlibs)
-      mpathpersist = declare_dependency(dependencies: mpathlibs)
+  if mpathlibs.length() == 0
+    msg = 'Dependencies missing for libmpathpersist'
+  elif cc.links(mpath_test_source_new, dependencies: mpathlibs)
+    mpathpersist = declare_dependency(dependencies: mpathlibs)
+    mpathpersist_new_api = true
+  elif cc.links(mpath_test_source_old, dependencies: mpathlibs)
+    mpathpersist = declare_dependency(dependencies: mpathlibs)
+  else
+    msg = 'Cannot detect libmpathpersist API'
+  endif
+  if not mpathpersist.found()
+    if get_option('mpath').enabled()
+      error(msg)
     else
-      if get_option('mpath').enabled()
-        error('Cannot detect libmpathpersist API')
-      else
-        warning('Cannot detect libmpathpersist API, disabling')
-      endif
+      warning(msg + ', disabling')
     endif
   endif
 endif
diff --git a/meson_options.txt b/meson_options.txt
index 1d3c94840a..5a302fe308 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -32,6 +32,8 @@  option('cocoa', type : 'feature', value : 'auto',
        description: 'Cocoa user interface (macOS only)')
 option('mpath', type : 'feature', value : 'auto',
        description: 'Multipath persistent reservation passthrough')
+option('libudev', type : 'feature', value : 'auto',
+       description: 'Use libudev to enumerate host devices')
 option('sdl', type : 'feature', value : 'auto',
        description: 'SDL user interface')
 option('sdl_image', type : 'feature', value : 'auto',