From 470b6070718461d17b55db1a902742ca76168b57 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 20 Jul 2023 23:16:20 +0300 Subject: [PATCH 1/5] libfreenect2: migrate to Conan v2, add CUDA support --- recipes/libfreenect2/all/CMakeLists.txt | 7 +- recipes/libfreenect2/all/conandata.yml | 2 - recipes/libfreenect2/all/conanfile.py | 142 ++++++++------ .../all/patches/0.2.1-fix-cmake.patch | 183 ++++++------------ .../all/test_package/CMakeLists.txt | 5 +- .../all/test_package/conanfile.py | 21 +- .../all/test_v1_package/CMakeLists.txt | 8 + .../all/test_v1_package/conanfile.py | 17 ++ 8 files changed, 192 insertions(+), 193 deletions(-) create mode 100644 recipes/libfreenect2/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libfreenect2/all/test_v1_package/conanfile.py diff --git a/recipes/libfreenect2/all/CMakeLists.txt b/recipes/libfreenect2/all/CMakeLists.txt index c986d294c7547..39e8fdc50bacf 100644 --- a/recipes/libfreenect2/all/CMakeLists.txt +++ b/recipes/libfreenect2/all/CMakeLists.txt @@ -1,7 +1,6 @@ -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) diff --git a/recipes/libfreenect2/all/conandata.yml b/recipes/libfreenect2/all/conandata.yml index 7fab4fd83db66..95824e496a47a 100644 --- a/recipes/libfreenect2/all/conandata.yml +++ b/recipes/libfreenect2/all/conandata.yml @@ -5,6 +5,4 @@ sources: 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" diff --git a/recipes/libfreenect2/all/conanfile.py b/recipes/libfreenect2/all/conanfile.py index dbb951cc733d9..a0285f3595ed6 100644 --- a/recipes/libfreenect2/all/conanfile.py +++ b/recipes/libfreenect2/all/conanfile.py @@ -1,21 +1,32 @@ -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 +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, @@ -23,88 +34,105 @@ class Libfreenect2Conan(ConanFile): "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") 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) - - 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 + 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: + # Required for deprecated FindCUDA support + tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0146"] = "OLD" + # TODO: create a Conan package for https://github.com/NVIDIA/cuda-samples Common headers + # The user will have to set NVCUDASAMPLES_ROOT either as a CMake or environment variable for now + 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", "JPEG") + deps.generate() + + deps = PkgConfigDeps(self) + deps.generate() def build(self): - self._patch_sources() - cmake = self._configure_cmake() + apply_conandata_patches(self) + 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"]) + + # 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" diff --git a/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch b/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch index 93324460a3d71..1aad0499dd636 100644 --- a/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch +++ b/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch @@ -1,27 +1,6 @@ -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 +@@ -157,7 +157,7 @@ ) SET(LIBRARIES @@ -30,174 +9,138 @@ index d8ef047..a81aa8e 100644 ${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 +@@ -210,7 +210,7 @@ ) LIST(APPEND LIBRARIES -- ${VAAPI_LIBRARIES} + ${VAAPI_LIBRARIES} - ${JPEG_LIBRARY} -+ vaapi::vaapi -+ libjpeg-turbo::libjpeg-turbo ++ ${JPEG_LIBRARIES} ) -- ENDIF() -+ # ENDIF() + ENDIF() ENDIF(ENABLE_VAAPI) - - SET(HAVE_TegraJPEG disabled) -@@ -237,38 +237,38 @@ IF(ENABLE_TEGRAJPEG) +@@ -236,32 +236,28 @@ + ENDIF() ENDIF() - IF(LIBFREENECT2_WITH_VT_SUPPORT) +-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. +-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) +-ENDIF() +- +-SET(HAVE_TurboJPEG no) -IF(TurboJPEG_FOUND) -+IF(libjpeg-turbo_FOUND) ++FIND_PACKAGE(JPEG REQUIRED CONFIG) SET(LIBFREENECT2_WITH_TURBOJPEG_SUPPORT 1) SET(HAVE_TurboJPEG yes) - INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS}) -+ #INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS}) ++ INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIRS}) LIST(APPEND SOURCES src/turbo_jpeg_rgb_packet_processor.cpp ) ++ if(TARGET libjpeg-turbo::jpeg) ++ LIST(APPEND LIBRARIES libjpeg-turbo::jpeg) ++ else() ++ LIST(APPEND LIBRARIES libjpeg-turbo::jpeg-static) ++ endif() LIST(APPEND LIBRARIES - ${TurboJPEG_LIBRARIES} -+ libjpeg-turbo::libjpeg-turbo ++ ${libjpeg-turbo_LIBRARIES} ) LIST(APPEND LIBFREENECT2_DLLS -- ${TurboJPEG_DLL} -+ #${TurboJPEG_DLL} + ${TurboJPEG_DLL} ) - ENDIF() +-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) +@@ -276,8 +272,8 @@ LIST(APPEND LIBFREENECT2_DLLS ${GLFW3_DLL}) LIST(APPEND LIBRARIES - ${GLFW3_LIBRARIES} - ${OPENGL_gl_LIBRARY} -+ glfw::glfw -+ opengl::opengl ++ ${GLFW3_LIBRARIES} glfw ++ ${OPENGL_gl_LIBRARY} 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) +@@ -297,10 +293,10 @@ SET(HAVE_OpenCL disabled) IF(ENABLE_OPENCL) - FIND_PACKAGE(OpenCL) -+ find_package(opencl-icd-loader REQUIRED) ++ find_package(OpenCLICDLoader REQUIRED) ++ find_package(OpenCLHeaders 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) +@@ -312,7 +308,7 @@ 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}) ++ INCLUDE_DIRECTORIES(${OpenCLHeaders_INCLUDE_DIRS}) LIST(APPEND SOURCES src/opencl_depth_packet_processor.cpp -@@ -320,7 +320,7 @@ IF(ENABLE_OPENCL) +@@ -320,7 +316,7 @@ ) LIST(APPEND LIBRARIES - ${OpenCL_LIBRARIES} -+ opencl-icd-loader::opencl-icd-loader ++ OpenCL::Headers OpenCL::OpenCL ) LIST(APPEND RESOURCES -@@ -334,7 +334,7 @@ IF(ENABLE_OPENCL) +@@ -334,12 +330,11 @@ 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() + IF(ENABLE_CUDA) +- FIND_PACKAGE(CUDA) ++ FIND_PACKAGE(CUDA REQUIRED) + SET(HAVE_CUDA no) + IF(CUDA_FOUND AND MSVC14 AND CUDA_VERSION VERSION_LESS 8.0) + SET(HAVE_CUDA "no (VS2015 not supported)") +@@ -347,12 +342,15 @@ + SET(LIBFREENECT2_WITH_CUDA_SUPPORT 1) + SET(HAVE_CUDA yes) + +- STRING(REPLACE "\\" "/" NVCUDASAMPLES_ROOT "$ENV{NVCUDASAMPLES_ROOT}") ++ IF(NOT DEFINED NVCUDASAMPLES_ROOT) ++ STRING(REPLACE "\\" "/" NVCUDASAMPLES_ROOT "$ENV{NVCUDASAMPLES_ROOT}") ++ ENDIF() + STRING(REPLACE "\\" "/" NVCUDASAMPLES8_0_ROOT "$ENV{NVCUDASAMPLES8_0_ROOT}") + CUDA_INCLUDE_DIRECTORIES( + "${MY_DIR}/include/" + "${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc" + "${NVCUDASAMPLES_ROOT}/common/inc" ++ "${NVCUDASAMPLES_ROOT}/Common" + "${NVCUDASAMPLES8_0_ROOT}/common/inc" + ) + SET(CUDA_FLAGS -use_fast_math) +@@ -403,11 +401,6 @@ # 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") +- 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() +- SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} CACHE STRING "Set RPATH for a private libusb") +-ENDIF() IF(DEFINED CMAKE_INSTALL_RPATH) + MESSAGE(STATUS "RPATH set to ${CMAKE_INSTALL_RPATH}") + ENDIF() diff --git a/recipes/libfreenect2/all/test_package/CMakeLists.txt b/recipes/libfreenect2/all/test_package/CMakeLists.txt index 5742a7e29c0d5..1ef3ef562dbc8 100644 --- a/recipes/libfreenect2/all/test_package/CMakeLists.txt +++ b/recipes/libfreenect2/all/test_package/CMakeLists.txt @@ -1,9 +1,6 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.15) 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) diff --git a/recipes/libfreenect2/all/test_package/conanfile.py b/recipes/libfreenect2/all/test_package/conanfile.py index 3da371b660e0a..ef5d7042163ec 100644 --- a/recipes/libfreenect2/all/test_package/conanfile.py +++ b/recipes/libfreenect2/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libfreenect2/all/test_v1_package/CMakeLists.txt b/recipes/libfreenect2/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..91630d79f4abb --- /dev/null +++ b/recipes/libfreenect2/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libfreenect2/all/test_v1_package/conanfile.py b/recipes/libfreenect2/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..49a3a66ea5bad --- /dev/null +++ b/recipes/libfreenect2/all/test_v1_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", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) From 8dff2a44f3740cf6819e7ff2844a8e8d77890d70 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Tue, 22 Aug 2023 14:45:03 +0300 Subject: [PATCH 2/5] libfreenect2: use cuda-samples package for with_cuda --- recipes/libfreenect2/all/conanfile.py | 5 +++-- recipes/libfreenect2/all/test_package/CMakeLists.txt | 6 ++++++ recipes/libfreenect2/all/test_package/conanfile.py | 9 +++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/recipes/libfreenect2/all/conanfile.py b/recipes/libfreenect2/all/conanfile.py index a0285f3595ed6..639f9bde34d23 100644 --- a/recipes/libfreenect2/all/conanfile.py +++ b/recipes/libfreenect2/all/conanfile.py @@ -65,6 +65,8 @@ def requirements(self): 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"): @@ -88,10 +90,9 @@ def generate(self): 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" - # TODO: create a Conan package for https://github.com/NVIDIA/cuda-samples Common headers - # The user will have to set NVCUDASAMPLES_ROOT either as a CMake or environment variable for now tc.generate() deps = CMakeDeps(self) diff --git a/recipes/libfreenect2/all/test_package/CMakeLists.txt b/recipes/libfreenect2/all/test_package/CMakeLists.txt index 1ef3ef562dbc8..198570f2fcede 100644 --- a/recipes/libfreenect2/all/test_package/CMakeLists.txt +++ b/recipes/libfreenect2/all/test_package/CMakeLists.txt @@ -7,3 +7,9 @@ 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) + +if (WITH_CUDA) + cmake_minimum_required(VERSION 3.17) + find_package(CUDAToolkit REQUIRED) + target_link_libraries(${PROJECT_NAME} PRIVATE CUDA::cudart) +endif() diff --git a/recipes/libfreenect2/all/test_package/conanfile.py b/recipes/libfreenect2/all/test_package/conanfile.py index ef5d7042163ec..66cde37e06dd2 100644 --- a/recipes/libfreenect2/all/test_package/conanfile.py +++ b/recipes/libfreenect2/all/test_package/conanfile.py @@ -1,12 +1,12 @@ from conan import ConanFile from conan.tools.build import can_run -from conan.tools.cmake import cmake_layout, CMake +from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain import os class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + generators = "CMakeDeps", "VirtualRunEnv" test_type = "explicit" def requirements(self): @@ -15,6 +15,11 @@ def requirements(self): def layout(self): cmake_layout(self) + def generate(self): + tc = CMakeToolchain(self) + tc.variables["WITH_CUDA"] = self.dependencies[self.tested_reference_str].options.with_cuda + tc.generate() + def build(self): cmake = CMake(self) cmake.configure() From 151c1da08d514b904ce3f89cf4fb3bb898094ad4 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 21 Sep 2023 22:13:46 +0300 Subject: [PATCH 3/5] libfreenect2: explicitly list requires --- recipes/libfreenect2/all/conanfile.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/recipes/libfreenect2/all/conanfile.py b/recipes/libfreenect2/all/conanfile.py index 639f9bde34d23..3c85872e203f2 100644 --- a/recipes/libfreenect2/all/conanfile.py +++ b/recipes/libfreenect2/all/conanfile.py @@ -134,6 +134,26 @@ def package_info(self): 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" From 0bae085c57405a8561c1f2830ea1517794b8fb24 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 1 Nov 2023 18:42:41 +0200 Subject: [PATCH 4/5] libfreenect2: link against freenect2::freenect2 --- recipes/libfreenect2/all/test_package/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/recipes/libfreenect2/all/test_package/CMakeLists.txt b/recipes/libfreenect2/all/test_package/CMakeLists.txt index 198570f2fcede..9acae9b976620 100644 --- a/recipes/libfreenect2/all/test_package/CMakeLists.txt +++ b/recipes/libfreenect2/all/test_package/CMakeLists.txt @@ -4,8 +4,7 @@ project(test_package LANGUAGES CXX) 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}) +target_link_libraries(${PROJECT_NAME} PRIVATE freenect2::freenect2) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) if (WITH_CUDA) From 8614cf817be7ee84011bdfcb8b1b3883ed3c418f Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Thu, 16 Nov 2023 20:36:41 +0200 Subject: [PATCH 5/5] libfreenect2: fix libjpeg-turbo linking --- recipes/libfreenect2/all/CMakeLists.txt | 2 - recipes/libfreenect2/all/conanfile.py | 13 +++-- .../all/patches/0.2.1-fix-cmake.patch | 50 ------------------- 3 files changed, 10 insertions(+), 55 deletions(-) diff --git a/recipes/libfreenect2/all/CMakeLists.txt b/recipes/libfreenect2/all/CMakeLists.txt index 39e8fdc50bacf..ff20e4a7a17dd 100644 --- a/recipes/libfreenect2/all/CMakeLists.txt +++ b/recipes/libfreenect2/all/CMakeLists.txt @@ -1,6 +1,4 @@ cmake_minimum_required(VERSION 3.15) project(cmake_wrapper) - - add_subdirectory(src) diff --git a/recipes/libfreenect2/all/conanfile.py b/recipes/libfreenect2/all/conanfile.py index 3c85872e203f2..b9a827fb5ffdb 100644 --- a/recipes/libfreenect2/all/conanfile.py +++ b/recipes/libfreenect2/all/conanfile.py @@ -4,7 +4,7 @@ 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 +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" @@ -98,14 +98,21 @@ def generate(self): 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", "JPEG") + deps.set_property("libjpeg-turbo", "cmake_file_name", "TurboJPEG") deps.generate() deps = PkgConfigDeps(self) deps.generate() - def build(self): + def _patch_sources(self): 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 = CMake(self) cmake.configure() cmake.build() diff --git a/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch b/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch index 1aad0499dd636..fcc8f8dfa20e8 100644 --- a/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch +++ b/recipes/libfreenect2/all/patches/0.2.1-fix-cmake.patch @@ -9,56 +9,6 @@ ${LIBFREENECT2_THREADING_LIBRARIES} ) -@@ -210,7 +210,7 @@ - ) - LIST(APPEND LIBRARIES - ${VAAPI_LIBRARIES} -- ${JPEG_LIBRARY} -+ ${JPEG_LIBRARIES} - ) - ENDIF() - ENDIF(ENABLE_VAAPI) -@@ -236,32 +236,28 @@ - ENDIF() - ENDIF() - --IF(LIBFREENECT2_WITH_VT_SUPPORT) -- FIND_PACKAGE(TurboJPEG) --ELSE() -- # VAAPI can fail to start at runtime. It must have a fallback. -- FIND_PACKAGE(TurboJPEG REQUIRED) --ENDIF() -- --SET(HAVE_TurboJPEG no) --IF(TurboJPEG_FOUND) -+FIND_PACKAGE(JPEG REQUIRED CONFIG) - SET(LIBFREENECT2_WITH_TURBOJPEG_SUPPORT 1) - SET(HAVE_TurboJPEG yes) - -- INCLUDE_DIRECTORIES(${TurboJPEG_INCLUDE_DIRS}) -+ INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIRS}) - - LIST(APPEND SOURCES - src/turbo_jpeg_rgb_packet_processor.cpp - ) - -+ if(TARGET libjpeg-turbo::jpeg) -+ LIST(APPEND LIBRARIES libjpeg-turbo::jpeg) -+ else() -+ LIST(APPEND LIBRARIES libjpeg-turbo::jpeg-static) -+ endif() - LIST(APPEND LIBRARIES -- ${TurboJPEG_LIBRARIES} -+ ${libjpeg-turbo_LIBRARIES} - ) - - LIST(APPEND LIBFREENECT2_DLLS - ${TurboJPEG_DLL} - ) --ENDIF() - - SET(HAVE_OpenGL disabled) - IF(ENABLE_OPENGL) @@ -276,8 +272,8 @@ LIST(APPEND LIBFREENECT2_DLLS ${GLFW3_DLL})