librealsense,python3Packages.pyrealsense2: refactor to add cudaSupport and python bindings

authored by freezeboy and committed by Jon ff8e1825 d22cd376

+66 -2
+28 -2
pkgs/development/libraries/librealsense/default.nix
··· 1 - { stdenv, fetchFromGitHub, cmake, libusb1, ninja, pkgconfig }: 2 3 stdenv.mkDerivation rec { 4 pname = "librealsense"; ··· 15 16 buildInputs = [ 17 libusb1 18 ]; 19 20 nativeBuildInputs = [ ··· 23 pkgconfig 24 ]; 25 26 - cmakeFlags = [ "-DBUILD_EXAMPLES=false" ]; 27 28 meta = with stdenv.lib; { 29 description = "A cross-platform library for Intel® RealSense™ depth cameras (D400 series and the SR300)";
··· 1 + { stdenv, config, lib, fetchFromGitHub, cmake, libusb1, ninja, pkgconfig, gcc 2 + , cudaSupport ? config.cudaSupport or false, cudatoolkit 3 + , enablePython ? false, pythonPackages ? null }: 4 + 5 + assert cudaSupport -> cudatoolkit != null; 6 + assert enablePython -> pythonPackages != null; 7 8 stdenv.mkDerivation rec { 9 pname = "librealsense"; ··· 20 21 buildInputs = [ 22 libusb1 23 + gcc.cc.lib 24 + ] ++ lib.optional cudaSupport cudatoolkit 25 + ++ lib.optional enablePython pythonPackages.python; 26 + 27 + patches = lib.optionals enablePython [ 28 + ./py_sitepackage_dir.patch 29 ]; 30 31 nativeBuildInputs = [ ··· 34 pkgconfig 35 ]; 36 37 + cmakeFlags = [ 38 + "-DBUILD_EXAMPLES=ON" 39 + "-DBUILD_GRAPHICAL_EXAMPLES=OFF" 40 + "-DBUILD_GLSL_EXTENSIONS=OFF" 41 + ] ++ lib.optionals enablePython [ 42 + "-DBUILD_PYTHON_BINDINGS:bool=true" 43 + "-DXXNIX_PYTHON_SITEPACKAGES=${placeholder "out"}/${pythonPackages.python.sitePackages}" 44 + ] ++ lib.optional cudaSupport "-DBUILD_WITH_CUDA:bool=true"; 45 + 46 + # ensure python package contains its __init__.py. for some reason the install 47 + # script does not do this, and it's questionable if intel knows it should be 48 + # done 49 + # ( https://github.com/IntelRealSense/meta-intel-realsense/issues/20 ) 50 + postInstall = lib.optionalString enablePython '' 51 + cp ../wrappers/python/pyrealsense2/__init__.py $out/${pythonPackages.python.sitePackages}/pyrealsense2 52 + ''; 53 54 meta = with stdenv.lib; { 55 description = "A cross-platform library for Intel® RealSense™ depth cameras (D400 series and the SR300)";
+15
pkgs/development/libraries/librealsense/py_sitepackage_dir.patch
···
··· 1 + --- a/wrappers/python/CMakeLists.txt 2 + +++ b/wrappers/python/CMakeLists.txt 3 + @@ -10,11 +10,11 @@ 4 + if (CMAKE_VERSION VERSION_LESS 3.12) 5 + find_package(PythonInterp REQUIRED) 6 + find_package(PythonLibs REQUIRED) 7 + - set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/pyrealsense2" CACHE PATH "Installation directory for Python bindings") 8 + + set(PYTHON_INSTALL_DIR "${XXNIX_PYTHON_SITEPACKAGES}/pyrealsense2" CACHE PATH "Installation directory for Python bindings") 9 + set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2") 10 + else() 11 + find_package(Python REQUIRED COMPONENTS Interpreter Development) 12 + - set(PYTHON_INSTALL_DIR "${Python_SITEARCH}/pyrealsense2" CACHE PATH "Installation directory for Python bindings") 13 + + set(PYTHON_INSTALL_DIR "${XXNIX_PYTHON_SITEPACKAGES}/pyrealsense2" CACHE PATH "Installation directory for Python bindings") 14 + set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2") 15 + endif()
+8
pkgs/top-level/all-packages.nix
··· 17710 17711 librealsense = callPackage ../development/libraries/librealsense { }; 17712 17713 libsass = callPackage ../development/libraries/libsass { }; 17714 17715 libsepol = callPackage ../os-specific/linux/libsepol { };
··· 17710 17711 librealsense = callPackage ../development/libraries/librealsense { }; 17712 17713 + librealsenseWithCuda = callPackage ../development/libraries/librealsense { 17714 + cudaSupport = true; 17715 + }; 17716 + 17717 + librealsenseWithoutCuda = callPackage ../development/libraries/librealsense { 17718 + cudaSupport = false; 17719 + }; 17720 + 17721 libsass = callPackage ../development/libraries/libsass { }; 17722 17723 libsepol = callPackage ../os-specific/linux/libsepol { };
+15
pkgs/top-level/python-packages.nix
··· 2618 2619 pyhs100 = callPackage ../development/python-modules/pyhs100 { }; 2620 2621 pytest = if isPy3k then self.pytest_5 else self.pytest_4; 2622 2623 pytest_5 = callPackage ../development/python-modules/pytest {
··· 2618 2619 pyhs100 = callPackage ../development/python-modules/pyhs100 { }; 2620 2621 + pyrealsense2 = toPythonModule (pkgs.librealsense.override { 2622 + enablePython = true; 2623 + pythonPackages = self; 2624 + }); 2625 + 2626 + pyrealsense2WithCuda = toPythonModule (pkgs.librealsenseWithCuda.override { 2627 + enablePython = true; 2628 + pythonPackages = self; 2629 + }); 2630 + 2631 + pyrealsense2WithoutCuda = toPythonModule (pkgs.librealsenseWithoutCuda.override { 2632 + enablePython = true; 2633 + pythonPackages = self; 2634 + }); 2635 + 2636 pytest = if isPy3k then self.pytest_5 else self.pytest_4; 2637 2638 pytest_5 = callPackage ../development/python-modules/pytest {