Skip to content

Commit

Permalink
(#7628) libfreenect2: Add new libfreenect2 package.
Browse files Browse the repository at this point in the history
* libfreenect2: Add new libfreenect2 package.

* libfreenect2: Add missing system libraries and Macos frameworks.

* libfreenect2: Add more missing Macos frameworks.

* libfreenect2: Add resource generation patch.

* libfreenect2: Find library name automatically.

* libfreenect2: Removed get_safe usage as recommended.

* libfreenect2: Test package update.
  • Loading branch information
sh0 authored Oct 20, 2021
1 parent 3eb2afb commit 332e8fe
Show file tree
Hide file tree
Showing 9 changed files with 410 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libfreenect2/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")
10 changes: 10 additions & 0 deletions recipes/libfreenect2/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"0.2.1":
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"
base_path: "source_subfolder"
- patch_file: "patches/0.2.1-generate-resources.patch"
base_path: "source_subfolder"
110 changes: 110 additions & 0 deletions recipes/libfreenect2/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from conans import ConanFile, CMake, tools
import os


class Libfreenect2Conan(ConanFile):
name = "libfreenect2"
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"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_opencl": [True, False],
"with_opengl": [True, False],
"with_vaapi": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_opencl": True,
"with_opengl": True,
"with_vaapi": True,
}
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 config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
if self.settings.os != "Linux":
del self.options.with_vaapi

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

def requirements(self):
self.requires("libusb/1.0.24")
self.requires("libjpeg-turbo/2.1.1")
if self.options.with_opencl:
self.requires("opencl-headers/2021.04.29")
self.requires("opencl-icd-loader/2021.04.29")
if self.options.with_opengl:
self.requires("opengl/system")
self.requires("glfw/3.3.4")
if self.options.get_safe("with_vaapi"):
self.requires("vaapi/system")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)

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

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

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
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()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(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.system_libs.extend(["m", "pthread", "dl"])
elif self.settings.os == "Macos":
self.cpp_info.frameworks.extend(["VideoToolbox", "CoreFoundation", "CoreMedia", "CoreVideo"])
203 changes: 203 additions & 0 deletions recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d8ef047..a81aa8e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -90,8 +90,7 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

# dependencies
-FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
-FIND_PACKAGE(LibUSB REQUIRED)
+find_package(libusb REQUIRED)

# Add includes
INCLUDE_DIRECTORIES(
@@ -99,7 +98,7 @@ INCLUDE_DIRECTORIES(
"${MY_DIR}/include/internal"
${PROJECT_BINARY_DIR} # for generated headers
${LIBFREENECT2_THREADING_INCLUDE_DIR}
- ${LibUSB_INCLUDE_DIRS}
+ # ${LibUSB_INCLUDE_DIRS}
)

SET(RESOURCES_INC_FILE "${PROJECT_BINARY_DIR}/resources.inc.h")
@@ -157,12 +156,12 @@ SET(SOURCES
)

SET(LIBRARIES
- ${LibUSB_LIBRARIES}
+ libusb::libusb
${LIBFREENECT2_THREADING_LIBRARIES}
)

SET(LIBFREENECT2_DLLS
- ${LibUSB_DLL}
+ #${LibUSB_DLL}
)

SET(HAVE_VideoToolbox "no (Apple only)")
@@ -193,13 +192,14 @@ ENDIF(APPLE)

SET(HAVE_VAAPI disabled)
IF(ENABLE_VAAPI)
- IF(PKG_CONFIG_FOUND)
- PKG_CHECK_MODULES(VAAPI libva libva-drm)
- ENDIF()
- FIND_PACKAGE(JPEG)
+ # IF(PKG_CONFIG_FOUND)
+ # PKG_CHECK_MODULES(VAAPI libva libva-drm)
+ # ENDIF()
+ find_package(vaapi REQUIRED)
+ find_package(libjpeg-turbo REQUIRED)

SET(HAVE_VAAPI no)
- IF(VAAPI_FOUND AND JPEG_FOUND)
+ # IF(VAAPI_FOUND AND JPEG_FOUND)
SET(LIBFREENECT2_WITH_VAAPI_SUPPORT 1)
SET(HAVE_VAAPI yes)

@@ -209,10 +209,10 @@ IF(ENABLE_VAAPI)
src/vaapi_rgb_packet_processor.cpp
)
LIST(APPEND LIBRARIES
- ${VAAPI_LIBRARIES}
- ${JPEG_LIBRARY}
+ vaapi::vaapi
+ libjpeg-turbo::libjpeg-turbo
)
- ENDIF()
+ # ENDIF()
ENDIF(ENABLE_VAAPI)

SET(HAVE_TegraJPEG disabled)
@@ -237,38 +237,38 @@ IF(ENABLE_TEGRAJPEG)
ENDIF()

IF(LIBFREENECT2_WITH_VT_SUPPORT)
- FIND_PACKAGE(TurboJPEG)
+ find_package(libjpeg-turbo REQUIRED)
ELSE()
# VAAPI can fail to start at runtime. It must have a fallback.
- FIND_PACKAGE(TurboJPEG REQUIRED)
+ find_package(libjpeg-turbo REQUIRED)
ENDIF()

SET(HAVE_TurboJPEG no)
-IF(TurboJPEG_FOUND)
+IF(libjpeg-turbo_FOUND)
SET(LIBFREENECT2_WITH_TURBOJPEG_SUPPORT 1)
SET(HAVE_TurboJPEG yes)

- INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS})
+ #INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS})

LIST(APPEND SOURCES
src/turbo_jpeg_rgb_packet_processor.cpp
)

LIST(APPEND LIBRARIES
- ${TurboJPEG_LIBRARIES}
+ libjpeg-turbo::libjpeg-turbo
)

LIST(APPEND LIBFREENECT2_DLLS
- ${TurboJPEG_DLL}
+ #${TurboJPEG_DLL}
)
ENDIF()

SET(HAVE_OpenGL disabled)
IF(ENABLE_OPENGL)
- FIND_PACKAGE(GLFW3)
- FIND_PACKAGE(OpenGL)
+ find_package(glfw3 REQUIRED)
+ find_package(opengl_system REQUIRED)
SET(HAVE_OpenGL no)
- IF(GLFW3_FOUND AND OPENGL_FOUND)
+ # IF(GLFW3_FOUND AND OPENGL_FOUND)
SET(LIBFREENECT2_WITH_OPENGL_SUPPORT 1)
SET(HAVE_OpenGL yes)

@@ -276,8 +276,8 @@ IF(ENABLE_OPENGL)

LIST(APPEND LIBFREENECT2_DLLS ${GLFW3_DLL})
LIST(APPEND LIBRARIES
- ${GLFW3_LIBRARIES}
- ${OPENGL_gl_LIBRARY}
+ glfw::glfw
+ opengl::opengl
)
LIST(APPEND SOURCES
src/flextGL.cpp
@@ -292,19 +292,19 @@ IF(ENABLE_OPENGL)
src/shader/stage1.fs
src/shader/stage2.fs
)
- ENDIF()
+ # ENDIF()
ENDIF(ENABLE_OPENGL)

SET(HAVE_OpenCL disabled)
IF(ENABLE_OPENCL)
- FIND_PACKAGE(OpenCL)
+ find_package(opencl-icd-loader REQUIRED)

SET(HAVE_OpenCL no)
- IF(OpenCL_FOUND)
+ #IF(OpenCL_FOUND)
SET(LIBFREENECT2_WITH_OPENCL_SUPPORT 1)
SET(HAVE_OpenCL yes)

- IF(UNIX AND NOT APPLE)
+ IF(0)
INCLUDE(CheckOpenCLICDLoader)
IF(OpenCL_C_WORKS AND NOT OpenCL_CXX_WORKS)
SET(LIBFREENECT2_OPENCL_ICD_LOADER_IS_OLD 1)
@@ -312,7 +312,7 @@ IF(ENABLE_OPENCL)
MESSAGE(WARNING "Your libOpenCL.so is incompatible with CL/cl.h. Install ocl-icd-opencl-dev to update libOpenCL.so?")
ENDIF()
ENDIF()
- INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIRS})
+ #INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIRS})

LIST(APPEND SOURCES
src/opencl_depth_packet_processor.cpp
@@ -320,7 +320,7 @@ IF(ENABLE_OPENCL)
)

LIST(APPEND LIBRARIES
- ${OpenCL_LIBRARIES}
+ opencl-icd-loader::opencl-icd-loader
)

LIST(APPEND RESOURCES
@@ -334,7 +334,7 @@ IF(ENABLE_OPENCL)
IF(UNIX AND NOT APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
ENDIF()
- ENDIF(OpenCL_FOUND)
+ #ENDIF(OpenCL_FOUND)
ENDIF(ENABLE_OPENCL)

SET(HAVE_CUDA disabled)
@@ -385,7 +385,7 @@ IF(ENABLE_CUDA)
ENDIF(ENABLE_CUDA)

# RPATH handling for CUDA 8.0 libOpenCL.so conflict. See #804.
-IF(HAVE_OpenCL STREQUAL yes AND UNIX AND NOT APPLE)
+IF(0)
FILE(GLOB CUDA_ld_so_conf /etc/ld.so.conf.d/cuda*.conf)
IF(CUDA_ld_so_conf)
MESSAGE(WARNING "Your CUDA installation overrides OpenCL system library path.")
@@ -403,9 +403,9 @@ ENDIF()
# Both command line -DCMAKE_INSTALL_RPATH=... and CMake GUI settings are accepted.
#
# Anyway if wrong versions of libusb is used, errors will be reported explicitly.
-IF(NOT DEFINED CMAKE_INSTALL_RPATH AND NOT ${LibUSB_LIBDIR} MATCHES "^/usr/lib")
+IF(0 AND NOT DEFINED CMAKE_INSTALL_RPATH AND NOT ${LibUSB_LIBDIR} MATCHES "^/usr/lib")
SET(CMAKE_INSTALL_RPATH ${LibUSB_LIBDIR} CACHE STRING "Set RPATH for a private libusb")
-ELSEIF(DEFINED CMAKE_INSTALL_RPATH)
+ELSEIF(0 AND DEFINED CMAKE_INSTALL_RPATH)
SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} CACHE STRING "Set RPATH for a private libusb")
ENDIF()
IF(DEFINED CMAKE_INSTALL_RPATH)
41 changes: 41 additions & 0 deletions recipes/libfreenect2/all/patches/0.2.1-generate-resources.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
This patch avoids compiling 'generate_resources_tool' to generate C sources of binary resources
and instead uses CMake functionality to generate the files. This patch is necessary to enable
cross-compiling without setting up host compiling environment. @sh0

diff --git a/cmake_modules/GenerateResources.cmake b/cmake_modules/GenerateResources.cmake
index 8616e38..6deea9a 100644
--- a/cmake_modules/GenerateResources.cmake
+++ b/cmake_modules/GenerateResources.cmake
@@ -1,14 +1,23 @@
FUNCTION(GENERATE_RESOURCES OUTPUT BASE_FOLDER)

-ADD_EXECUTABLE(generate_resources_tool
- tools/generate_resources.cpp
-)
-
-ADD_CUSTOM_COMMAND(
- OUTPUT ${OUTPUT}
- COMMAND generate_resources_tool ${BASE_FOLDER} ${ARGN} > ${OUTPUT}
- WORKING_DIRECTORY ${BASE_FOLDER}
- DEPENDS generate_resources_tool ${ARGN}
+set(RES_INDEX "0")
+foreach (SRC_ENTRY ${ARGN})
+ set(SRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_ENTRY}")
+ get_filename_component(SRC_NAME "${SRC_ENTRY}" NAME)
+ file(SIZE "${SRC_PATH}" DATA_SIZE)
+ file(READ "${SRC_PATH}" DATA_BIN HEX)
+ string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," DATA_HEX ${DATA_BIN})
+ string(APPEND RES_CONTENT "static unsigned char resource${RES_INDEX}[] = {\n ${DATA_HEX}\n};\n")
+ string(APPEND RES_DESCRIPTOR " { \"${SRC_NAME}\", resource${RES_INDEX}, sizeof(resource${RES_INDEX}) },\n")
+ math(EXPR RES_INDEX "${RES_INDEX} + 1")
+endforeach ()
+file(WRITE "${OUTPUT}"
+ "${RES_CONTENT}"
+ "static ResourceDescriptor resource_descriptors[] = {\n"
+ "${RES_DESCRIPTOR}"
+ " {NULL, NULL, 0},\n"
+ "};\n"
+ "static int resource_descriptors_length = ${RES_INDEX};\n"
)

ENDFUNCTION(GENERATE_RESOURCES)
12 changes: 12 additions & 0 deletions recipes/libfreenect2/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(freenect2 REQUIRED)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE ${freenect2_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${freenect2_INCLUDE_DIRS})
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
Loading

0 comments on commit 332e8fe

Please sign in to comment.