Skip to content

Commit

Permalink
Merge pull request #1 from uilianries/libuvc
Browse files Browse the repository at this point in the history
Improve libuvc
  • Loading branch information
akshit-sharma authored Aug 18, 2020
2 parents 5563ead + 092478f commit 97aa046
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 43 deletions.
7 changes: 7 additions & 0 deletions recipes/libuvc/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
19 changes: 0 additions & 19 deletions recipes/libuvc/all/LICENSE.md

This file was deleted.

4 changes: 4 additions & 0 deletions recipes/libuvc/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sources:
"0.0.6":
url: "https://github.com/libuvc/libuvc/archive/v0.0.6.tar.gz"
sha256: "42175a53c1c704365fdc782b44233925e40c9344fbb7f942181c1090f06e2873"
patches:
"0.0.6":
- patch_file: "patches/0001-adjust-libusb.patch"
base_path: "source_subfolder"
57 changes: 33 additions & 24 deletions recipes/libuvc/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ class LibuvcConan(ConanFile):
name = "libuvc"
description = "A cross-platform library for USB video devices"
topics = ("conan", "libuvc", "libusb", "usb", "video")
license = "MIT"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/libuvc/libuvc"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False], "jpeg_turbo": [True, False]}
default_options = {"shared": False, "fPIC": True, "jpeg_turbo": False}
generators = "cmake_find_package"
generators = "cmake", "cmake_find_package"
requires = "libusb/1.0.23"
exports_sources = ["CMakeLists.txt"]
exports_sources = ["CMakeLists.txt", "patches/*"]
_cmake = None

_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
del self.settings.compiler.libcxx
Expand All @@ -27,41 +37,40 @@ def configure(self):
# Upstream issues, e.g.:
# https://github.com/libuvc/libuvc/issues/100
# https://github.com/libuvc/libuvc/issues/105
raise ConanInvalidConfiguration("This library is not compatible with Windows")
raise ConanInvalidConfiguration("'{}' is not compatible with Windows.".format(self.name))
if self.options.shared:
del self.options.fPIC

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)


def requirements(self):
if self.options.jpeg_turbo:
self.requires("libjpeg-turbo/2.0.4")
else:
self.requires("libjpeg/9d")

def build(self):
_cmakelists = os.path.join(self._source_subfolder, "CMakeLists.txt")
tools.replace_in_file(_cmakelists, "pkg_check_modules(LIBUSB libusb-1.0)", "find_package(libusb REQUIRED)")
tools.replace_in_file(_cmakelists, "${LIBUSB_INCLUDE_DIRS}", "${libusb_INCLUDE_DIRS}")
def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["CMAKE_BUILD_TARGET"] = "Shared" if self.options.shared else "Static"
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

cmake = CMake(self)
if self.options.shared:
_cmake_defs = {"CMAKE_BUILD_TARGET" : "Shared" }
else:
_cmake_defs = {"CMAKE_BUILD_TARGET" : "Static" }
cmake.configure(defs = _cmake_defs, source_folder=self._source_subfolder, build_folder=self._build_subfolder)
def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

def package(self):
self.copy(pattern="LICENSE*", dst="licenses", src=self._source_subfolder)
self.copy("*.h", dst="include", src=os.path.join(self._source_subfolder, "include"))
self.copy("*.h", dst="include", src=os.path.join(self._build_subfolder, "include"))
if self.options.shared:
self.copy("libuvc.so", dst="lib", src=self._build_subfolder, keep_path=False)
else:
self.copy("libuvc.a", dst="lib", src=self._build_subfolder, keep_path=False)
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
51 changes: 51 additions & 0 deletions recipes/libuvc/all/patches/0001-adjust-libusb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a19209d..581a308 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,26 +19,9 @@ set(libuvc_VERSION ${libuvc_VERSION_MAJOR}.${libuvc_VERSION_MINOR}.${libuvc_VERS
set(libuvc_DESCRIPTION "A cross-platform library for USB video devices")
set(libuvc_URL "https://github.com/ktossell/libuvc")

-find_package(PkgConfig)
-pkg_check_modules(LIBUSB libusb-1.0)
-
# Try to find JPEG using a module or pkg-config. If that doesn't work, search for the header.
-find_package(jpeg QUIET)
-if(JPEG_FOUND)
- set(JPEG_LINK_FLAGS ${JPEG_LIBRARIES})
-else()
- pkg_check_modules(JPEG QUIET libjpeg)
- if(JPEG_FOUND)
- set(JPEG_INCLUDE_DIR ${JPEG_INCLUDE_DIRS})
- set(JPEG_LINK_FLAGS ${JPEG_LDFLAGS})
- else()
- find_path(JPEG_INCLUDE_DIR jpeglib.h)
- if(JPEG_INCLUDE_DIR)
- set(JPEG_FOUND ON)
- set(JPEG_LINK_FLAGS -ljpeg)
- endif()
- endif()
-endif()
+find_package(JPEG QUIET)
+set(JPEG_LINK_FLAGS ${JPEG_LIBRARIES})

include(GNUInstallDirs)

@@ -54,7 +37,7 @@ SET(SOURCES src/ctrl.c src/ctrl-gen.c src/device.c src/diag.c
include_directories(
${libuvc_SOURCE_DIR}/include
${libuvc_BINARY_DIR}/include
- ${LIBUSB_INCLUDE_DIRS}
+ ${CONAN_INCLUDE_DIRS_LIBUSB}
)

if(JPEG_FOUND)
@@ -101,7 +84,7 @@ if(BUILD_UVC_SHARED)
target_link_libraries (uvc ${JPEG_LINK_FLAGS})
endif(JPEG_FOUND)

- target_link_libraries(uvc ${LIBUSB_LIBRARIES})
+ target_link_libraries(uvc ${CONAN_LIBS_LIBUSB})

#add_executable(test src/test.c)
#target_link_libraries(test uvc ${LIBUSB_LIBRARIES} opencv_highgui

0 comments on commit 97aa046

Please sign in to comment.