From b00e019c6e2191e5b61c82921815e7911d8b97c5 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 13 Jul 2020 16:39:18 -0300 Subject: [PATCH 1/2] Improve libuvc Signed-off-by: Uilian Ries --- recipes/libuvc/all/CMakeLists.txt | 7 +++ recipes/libuvc/all/LICENSE.md | 19 ------- .../all/patches/0001-adjust-libusb.patch | 51 +++++++++++++++++++ 3 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 recipes/libuvc/all/CMakeLists.txt delete mode 100644 recipes/libuvc/all/LICENSE.md create mode 100644 recipes/libuvc/all/patches/0001-adjust-libusb.patch diff --git a/recipes/libuvc/all/CMakeLists.txt b/recipes/libuvc/all/CMakeLists.txt new file mode 100644 index 0000000000000..c986d294c7547 --- /dev/null +++ b/recipes/libuvc/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("source_subfolder") diff --git a/recipes/libuvc/all/LICENSE.md b/recipes/libuvc/all/LICENSE.md deleted file mode 100644 index 058746c27dcf4..0000000000000 --- a/recipes/libuvc/all/LICENSE.md +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2019 Bincrafters - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/recipes/libuvc/all/patches/0001-adjust-libusb.patch b/recipes/libuvc/all/patches/0001-adjust-libusb.patch new file mode 100644 index 0000000000000..24c0fe99c85a7 --- /dev/null +++ b/recipes/libuvc/all/patches/0001-adjust-libusb.patch @@ -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 From 092478f08bd46e4424058360e1e973af2d060622 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 13 Jul 2020 16:41:28 -0300 Subject: [PATCH 2/2] Improve libuvc Signed-off-by: Uilian Ries --- recipes/libuvc/all/conandata.yml | 4 +++ recipes/libuvc/all/conanfile.py | 57 ++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/recipes/libuvc/all/conandata.yml b/recipes/libuvc/all/conandata.yml index 9c77e875691c4..f62deb82b3756 100644 --- a/recipes/libuvc/all/conandata.yml +++ b/recipes/libuvc/all/conandata.yml @@ -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" diff --git a/recipes/libuvc/all/conanfile.py b/recipes/libuvc/all/conanfile.py index fe379cabc977c..9bdf3f843cfd2 100644 --- a/recipes/libuvc/all/conanfile.py +++ b/recipes/libuvc/all/conanfile.py @@ -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 @@ -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)