Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libfreenect2: migrate to Conan v2, add CUDA support #18834

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions recipes/libfreenect2/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
add_subdirectory(src)
2 changes: 0 additions & 2 deletions recipes/libfreenect2/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
url: "https://github.com/OpenKinect/libfreenect2/archive/refs/tags/v0.2.1.tar.gz"
sha256: "c09e52c97b0e90335f4762ed5363293ad0fc1ea0064e578b879e7d15cc3559df"
patches:
"0.2.1":
- patch_file: "patches/0.2.1-fix-cmake.patch"

Check warning on line 7 in recipes/libfreenect2/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0.2.1-fi ... ^ (line: 7)
base_path: "source_subfolder"
- patch_file: "patches/0.2.1-generate-resources.patch"

Check warning on line 8 in recipes/libfreenect2/all/conandata.yml

View workflow job for this annotation

GitHub Actions / Lint changed files (YAML files)

conandata.yml schema warning

Schema outlined in https://github.com/conan-io/conan-center-index/blob/master/docs/adding_packages/conandata_yml_format.md#patches-fields is not followed. required key(s) 'patch_description', 'patch_type' not found in - patch_file: patches/0.2.1-ge ... ^ (line: 8)
base_path: "source_subfolder"
164 changes: 110 additions & 54 deletions recipes/libfreenect2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,110 +1,166 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, rmdir, replace_in_file
from conan.tools.gnu import PkgConfigDeps

required_conan_version = ">=1.53.0"


class Libfreenect2Conan(ConanFile):
name = "libfreenect2"
description = "Open source drivers for the Kinect for Windows v2 device."
license = ("Apache-2.0", "GPL-2.0")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/OpenKinect/libfreenect2"
description = "Open source drivers for the Kinect for Windows v2 device."
topics = ("usb", "camera", "kinect")
settings = "os", "compiler", "build_type", "arch"

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_opencl": [True, False],
"with_opengl": [True, False],
"with_vaapi": [True, False],
"with_cuda": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_opencl": True,
"with_opengl": True,
"with_vaapi": True,
"with_cuda": False,
}
generators = "cmake", "cmake_find_package"
exports_sources = ["CMakeLists.txt", "patches/*"]

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os != "Linux":
del self.options.with_vaapi
if self.settings.os not in ["Linux", "FreeBSD"]:
self.options.rm_safe("with_vaapi")

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("libusb/1.0.24")
self.requires("libjpeg-turbo/2.1.1")
self.requires("libusb/1.0.26")
self.requires("libjpeg-turbo/3.0.0")
if self.options.with_opencl:
self.requires("opencl-headers/2021.04.29")
self.requires("opencl-icd-loader/2021.04.29")
# 2023.02.06 is the latest compatible version
self.requires("opencl-headers/2023.02.06")
self.requires("opencl-icd-loader/2023.02.06")
if self.options.with_opengl:
self.requires("opengl/system")
self.requires("glfw/3.3.4")
self.requires("glfw/3.3.8")
if self.options.get_safe("with_vaapi"):
self.requires("vaapi/system")
if self.options.with_cuda:
self.requires("cuda-samples/12.2")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)
check_min_cppstd(self, 11)
if self.options.with_cuda:
self.output.warning("Conan package for CUDA is not available, will use system CUDA")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_FIND_ROOT_PATH_MODE_PACKAGE"] = "NONE"
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["BUILD_OPENNI2_DRIVER"] = False
tc.variables["ENABLE_CXX11"] = True
tc.variables["ENABLE_OPENCL"] = self.options.with_opencl
tc.variables["ENABLE_CUDA"] = self.options.with_cuda
tc.variables["ENABLE_OPENGL"] = self.options.with_opengl
tc.variables["ENABLE_VAAPI"] = self.options.get_safe("with_vaapi", False)
tc.variables["ENABLE_TEGRAJPEG"] = False # TODO: TegraJPEG
tc.variables["ENABLE_PROFILING"] = False
if self.options.with_cuda:
tc.variables["NVCUDASAMPLES_ROOT"] = os.path.join(self.dependencies["cuda-samples"].package_folder, "include")
# Required for deprecated FindCUDA support
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0146"] = "OLD"
tc.generate()

deps = CMakeDeps(self)
deps.set_property("libusb", "cmake_file_name", "LibUSB")
deps.set_property("glfw3", "cmake_file_name", "GLFW3")
deps.set_property("libjpeg-turbo", "cmake_file_name", "TurboJPEG")
deps.generate()

deps = PkgConfigDeps(self)
deps.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_EXAMPLES"] = False
self._cmake.definitions["BUILD_OPENNI2_DRIVER"] = False
self._cmake.definitions["ENABLE_CXX11"] = True
self._cmake.definitions["ENABLE_OPENCL"] = self.options.with_opencl
self._cmake.definitions["ENABLE_CUDA"] = False # TODO: CUDA
self._cmake.definitions["ENABLE_OPENGL"] = self.options.with_opengl
self._cmake.definitions["ENABLE_VAAPI"] = self.options.get_safe("with_vaapi", False)
self._cmake.definitions["ENABLE_TEGRAJPEG"] = False # TODO: TegraJPEG
self._cmake.definitions["ENABLE_PROFILING"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"FIND_PACKAGE(JPEG)", "FIND_PACKAGE(TurboJPEG REQUIRED CONFIG)")
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
" JPEG_FOUND", " TRUE")

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("APACHE20", src=self._source_subfolder, dst="licenses", keep_path=False)
self.copy("GPL2", src=self._source_subfolder, dst="licenses", keep_path=False)
cmake = self._configure_cmake()
copy(self, "APACHE20",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
keep_path=False)
copy(self, "GPL2",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
keep_path=False)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "freenect2"
self.cpp_info.names["cmake_find_package_multi"] = "freenect2"
self.cpp_info.names["pkg_config"] = "freenect2"
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.set_property("cmake_file_name", "freenect2")
self.cpp_info.set_property("cmake_target_name", "freenect2::freenect2")
self.cpp_info.set_property("pkg_config_name", "freenect2")
self.cpp_info.libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread", "dl"])
elif self.settings.os == "Macos":
elif is_apple_os(self):
self.cpp_info.frameworks.extend(["VideoToolbox", "CoreFoundation", "CoreMedia", "CoreVideo"])

self.cpp_info.requires += [
"libusb::libusb",
"libjpeg-turbo::jpeg",
"libjpeg-turbo::turbojpeg",
]
if self.options.with_opencl:
self.cpp_info.requires += [
"opencl-headers::opencl-headers",
"opencl-icd-loader::opencl-icd-loader",
]
if self.options.with_opengl:
self.cpp_info.requires += [
"opengl::opengl",
"glfw::glfw",
]
if self.options.get_safe("with_vaapi"):
self.cpp_info.requires += ["vaapi::vaapi"]
if self.options.with_cuda:
self.cpp_info.requires += ["cuda-samples::cuda-samples"]

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "freenect2"
self.cpp_info.names["cmake_find_package_multi"] = "freenect2"
Loading