Repository: conan-io/conan-center-index

Issue:
[request] libuvc/0.0.6
### Package Details
  * Package Name/Version: **libuvc/0.0.6**
  * Website: **https://ken.tossell.net/libuvc/doc/**
  * Source code: **https://github.com/libuvc/libuvc**


### Description Of The Library / Tool

> `libuvc` is a cross-platform library for USB video devices, built atop `libusb`. It enables fine-grained control over USB video devices exporting the standard USB Video Class (UVC) interface, enabling developers to write drivers for previously unsupported devices, or just access UVC devices in a generic fashion.

More about the UVC standard:

- https://en.wikipedia.org/wiki/USB_video_device_class
- https://en.wikipedia.org/wiki/List_of_USB_video_class_devices



Discussion:
https://github.com/bincrafters/conan-libuvc can be migrated
Out of curiosity, when is a conan recipe merged into conan-center-index?

It looks like bincrafters has a recipe for libuvc. Is there something more that needs to be completed?

Thanks
@akshit-sharma It requires that someone ports it to Conan Center Index, it can be anyone, including you :)

There is a nice guide line to start a recipe on CCI if you are interested: https://github.com/conan-io/conan-center-index/wiki#adding-packages-to-conancenter

Resolving patch:
diff --git a/recipes/libuvc/all/conanfile.py b/recipes/libuvc/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libuvc/all/conanfile.py
@@ -0,0 +1,76 @@
+import os
+from conans import ConanFile, CMake, tools
+from conans.errors import ConanInvalidConfiguration
+
+
+class LibuvcConan(ConanFile):
+    name = "libuvc"
+    description = "A cross-platform library for USB video devices"
+    topics = ("conan", "libuvc", "libusb", "usb", "video")
+    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", "cmake_find_package"
+    requires = "libusb/1.0.23"
+    exports_sources = ["CMakeLists.txt", "patches/*"]
+    _cmake = None
+
+    @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
+        del self.settings.compiler.cppstd
+        if self.settings.compiler == "Visual Studio":
+            # Upstream issues, e.g.:
+            # https://github.com/libuvc/libuvc/issues/100
+            # https://github.com/libuvc/libuvc/issues/105
+            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 _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
+
+    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.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)


Test patch:
diff --git a/recipes/libuvc/all/test_package/CMakeLists.txt b/recipes/libuvc/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/libuvc/all/test_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
diff --git a/recipes/libuvc/all/test_package/conanfile.py b/recipes/libuvc/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/libuvc/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/libuvc/all/test_package/test_package.c b/recipes/libuvc/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/libuvc/all/test_package/test_package.c
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <libuvc/libuvc.h>
+
+int main()
+{
+	uvc_context_t *ctx;
+	uvc_error_t res;
+	uvc_device_t *dev;
+	uvc_device_handle_t *devh;
+
+	res = uvc_init(&ctx, NULL);
+
+	if (res < 0) {
+		uvc_perror(res, "uvc_init");
+		return res;
+	}
+
+	puts("UVC initialized");
+
+	res = uvc_find_device(
+		ctx, &dev,
+		0, 0, NULL);
+
+	if (res < 0) {
+		uvc_perror(res, "uvc_find_device");
+	} else {
+		puts("Device found");
+
+		res = uvc_open(dev, &devh);
+
+		if (res < 0) {
+			uvc_perror(res, "uvc_open");
+		} else {
+			puts("Device opened");
+			uvc_print_diag(devh, stderr);
+			uvc_close(devh);
+			puts("Device closed");
+		}
+		uvc_unref_device(dev);
+	}
+
+	uvc_exit(ctx);
+	puts("UVC exited");
+
+	return 0;
+}