summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorfreezeboy <freezeboy@users.noreply.github.com>2020-07-12 22:55:11 +0200
committerJon <jonringer@users.noreply.github.com>2020-08-14 15:47:17 -0700
commitff8e1825ab87f010e37ecca4ce18b8f5c1bf0275 (patch)
tree42093e3318a7a6ef24a73cf9321dbc6a3a8e5516 /pkgs
parentd22cd376e501df3012f208488b9ff12384efffc6 (diff)
downloadnixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar.gz
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar.bz2
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar.lz
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar.xz
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.tar.zst
nixpkgs-ff8e1825ab87f010e37ecca4ce18b8f5c1bf0275.zip
librealsense,python3Packages.pyrealsense2: refactor to add cudaSupport and python bindings
Diffstat (limited to 'pkgs')
-rw-r--r--pkgs/development/libraries/librealsense/default.nix30
-rw-r--r--pkgs/development/libraries/librealsense/py_sitepackage_dir.patch15
-rw-r--r--pkgs/top-level/all-packages.nix8
-rw-r--r--pkgs/top-level/python-packages.nix15
4 files changed, 66 insertions, 2 deletions
diff --git a/pkgs/development/libraries/librealsense/default.nix b/pkgs/development/libraries/librealsense/default.nix
index 263aa613a9b..d092cc89f10 100644
--- a/pkgs/development/libraries/librealsense/default.nix
+++ b/pkgs/development/libraries/librealsense/default.nix
@@ -1,4 +1,9 @@
-{ stdenv, fetchFromGitHub, cmake, libusb1, ninja, pkgconfig }:
+{ stdenv, config, lib, fetchFromGitHub, cmake, libusb1, ninja, pkgconfig, gcc
+, cudaSupport ? config.cudaSupport or false, cudatoolkit
+, enablePython ? false, pythonPackages ? null }:
+
+assert cudaSupport -> cudatoolkit != null;
+assert enablePython -> pythonPackages != null;
 
 stdenv.mkDerivation rec {
   pname = "librealsense";
@@ -15,6 +20,12 @@ stdenv.mkDerivation rec {
 
   buildInputs = [
     libusb1
+    gcc.cc.lib
+  ] ++ lib.optional cudaSupport cudatoolkit
+    ++ lib.optional enablePython pythonPackages.python;
+
+  patches = lib.optionals enablePython [
+    ./py_sitepackage_dir.patch
   ];
 
   nativeBuildInputs = [
@@ -23,7 +34,22 @@ stdenv.mkDerivation rec {
     pkgconfig
   ];
 
-  cmakeFlags = [ "-DBUILD_EXAMPLES=false" ];
+  cmakeFlags = [
+    "-DBUILD_EXAMPLES=ON"
+    "-DBUILD_GRAPHICAL_EXAMPLES=OFF"
+    "-DBUILD_GLSL_EXTENSIONS=OFF"
+  ] ++ lib.optionals enablePython [
+    "-DBUILD_PYTHON_BINDINGS:bool=true"
+    "-DXXNIX_PYTHON_SITEPACKAGES=${placeholder "out"}/${pythonPackages.python.sitePackages}"
+  ] ++ lib.optional cudaSupport "-DBUILD_WITH_CUDA:bool=true";
+
+  # ensure python package contains its __init__.py. for some reason the install
+  # script does not do this, and it's questionable if intel knows it should be
+  # done
+  # ( https://github.com/IntelRealSense/meta-intel-realsense/issues/20 )
+  postInstall = lib.optionalString enablePython  ''
+    cp ../wrappers/python/pyrealsense2/__init__.py $out/${pythonPackages.python.sitePackages}/pyrealsense2
+  '';
 
   meta = with stdenv.lib; {
     description = "A cross-platform library for IntelĀ® RealSenseā„¢ depth cameras (D400 series and the SR300)";
diff --git a/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch b/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch
new file mode 100644
index 00000000000..99b567a429e
--- /dev/null
+++ b/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch
@@ -0,0 +1,15 @@
+--- a/wrappers/python/CMakeLists.txt
++++ b/wrappers/python/CMakeLists.txt
+@@ -10,11 +10,11 @@
+ if (CMAKE_VERSION VERSION_LESS 3.12)
+   find_package(PythonInterp REQUIRED)
+   find_package(PythonLibs REQUIRED)
+-  set(PYTHON_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
++  set(PYTHON_INSTALL_DIR "${XXNIX_PYTHON_SITEPACKAGES}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
+   set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2")
+ else()
+   find_package(Python REQUIRED COMPONENTS Interpreter Development)
+-  set(PYTHON_INSTALL_DIR "${Python_SITEARCH}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
++  set(PYTHON_INSTALL_DIR "${XXNIX_PYTHON_SITEPACKAGES}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
+   set(CMAKECONFIG_PY_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pyrealsense2")
+ endif()
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 4bb32179429..8061195f0e4 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -17710,6 +17710,14 @@ in
 
   librealsense = callPackage ../development/libraries/librealsense { };
 
+  librealsenseWithCuda = callPackage ../development/libraries/librealsense {
+    cudaSupport = true;
+  };
+
+  librealsenseWithoutCuda = callPackage ../development/libraries/librealsense {
+    cudaSupport = false;
+  };
+
   libsass = callPackage ../development/libraries/libsass { };
 
   libsepol = callPackage ../os-specific/linux/libsepol { };
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 4cc74d37bbc..598b55d7c92 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -2618,6 +2618,21 @@ in {
 
   pyhs100 = callPackage ../development/python-modules/pyhs100 { };
 
+  pyrealsense2 = toPythonModule (pkgs.librealsense.override {
+    enablePython = true;
+    pythonPackages = self;
+  });
+
+  pyrealsense2WithCuda = toPythonModule (pkgs.librealsenseWithCuda.override {
+    enablePython = true;
+    pythonPackages = self;
+  });
+
+  pyrealsense2WithoutCuda = toPythonModule (pkgs.librealsenseWithoutCuda.override {
+    enablePython = true;
+    pythonPackages = self;
+  });
+
   pytest = if isPy3k then self.pytest_5 else self.pytest_4;
 
   pytest_5 = callPackage ../development/python-modules/pytest {