cec: make libudev optional. if libudev is not available on linux, adapter autodetecti...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 8 Dec 2011 18:25:06 +0000 (19:25 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 8 Dec 2011 18:25:06 +0000 (19:25 +0100)
configure.ac
src/lib/AdapterDetection.cpp

index e961c1b2e6e1837a92d929d74749a8d04b91dd2b..22b634309a0d7245de0567270525cef79f49436d 100644 (file)
@@ -4,16 +4,23 @@ AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 AC_PROG_CXX
 AC_PROG_LIBTOOL
 
+has_libudev="yes"
 case "${host}" in
   *-*-linux*)
-    AC_SEARCH_LIBS([udev_new], [udev],, AC_MSG_ERROR("required library 'udev' is missing"))
-    REQUIRES="udev"
+    PKG_CHECK_MODULES([UDEV],[libudev],,[has_libudev="no";AC_MSG_WARN("library 'udev' is missing - adapter detection will not be available")])
     ;;
   *-apple-darwin*)
+    has_libudev="no";
     LIBS+="-framework CoreVideo -framework IOKit"
     ;;
 esac
 
+if test "x$has_libudev" != "xno"; then
+  INCLUDES="$INCLUDES $UDEV_CFLAGS";LIBS="$LIBS $UDEV_LIBS"
+  AC_DEFINE([HAVE_LIBUDEV],[1],["Define to 1 if libudev is installed"])
+  REQUIRES="udev"
+fi
+
 AC_SEARCH_LIBS([pthread_create],[pthread],, AC_MSG_ERROR("required library 'pthread' is missing"))
 
 libs_pre_dl=$LIBS
index 98c3a0e60a09a083daf38fc9e8cbc80d03b2a500..b304e43561d2eb5c0961a425b140b35bda88cd6a 100644 (file)
 #include <IOKit/usb/IOUSBLib.h>
 #include <IOKit/serial/IOSerialKeys.h>
 #include <CoreFoundation/CoreFoundation.h>
-
-#elif !defined(__WINDOWS__)
-#include <dirent.h>
-#include <libudev.h>
-#include <poll.h>
-#else
+#elif defined(__WINDOWS__)
 #include <setupapi.h>
 
 // the virtual COM port only shows up when requesting devices with the raw device guid!
 static GUID USB_RAW_GUID =  { 0xA5DCBF10, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };
+#elif defined(HAVE_LIBUDEV)
+#include <dirent.h>
+#include <libudev.h>
+#include <poll.h>
 #endif
 
 #define CEC_VID 0x2548
@@ -61,7 +60,7 @@ static GUID USB_RAW_GUID =  { 0xA5DCBF10, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0x
 using namespace CEC;
 using namespace std;
 
-#if !defined(__WINDOWS__)
+#if defined(HAVE_LIBUDEV)
 bool TranslateComPort(CStdString &strString)
 {
   CStdString strTmp(strString);
@@ -180,8 +179,7 @@ uint8_t CAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t iBufSiz
     }
     IOObjectRelease(serialPortIterator);
   }
-
-#elif !defined(__WINDOWS__)
+#elif defined(HAVE_LIBUDEV)
   struct udev *udev;
   if (!(udev = udev_new()))
     return -1;
@@ -229,7 +227,7 @@ uint8_t CAdapterDetection::FindAdapters(cec_adapter *deviceList, uint8_t iBufSiz
 
   udev_enumerate_unref(enumerate);
   udev_unref(udev);
-#else
+#elif defined(__WINDOWS__)
   HDEVINFO hDevHandle;
   DWORD    required = 0, iMemberIndex = 0;
   int      nBufferSize = 0;