about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/librealsense
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/librealsense')
-rw-r--r--nixpkgs/pkgs/development/libraries/librealsense/default.nix83
-rw-r--r--nixpkgs/pkgs/development/libraries/librealsense/install-presets.patch13
-rw-r--r--nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch15
3 files changed, 111 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/librealsense/default.nix b/nixpkgs/pkgs/development/libraries/librealsense/default.nix
new file mode 100644
index 000000000000..9a127fcd92ad
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/librealsense/default.nix
@@ -0,0 +1,83 @@
+{ stdenv
+, config
+, lib
+, fetchFromGitHub
+, fetchpatch
+, cmake
+, libusb1
+, ninja
+, pkg-config
+, gcc
+, mesa
+, gtk3
+, glfw
+, libGLU
+, curl
+, cudaSupport ? config.cudaSupport, cudaPackages ? { }
+, enablePython ? false, pythonPackages ? null
+, enableGUI ? false,
+}:
+
+assert cudaSupport -> (cudaPackages?cudatoolkit && cudaPackages.cudatoolkit != null);
+assert enablePython -> pythonPackages != null;
+
+stdenv.mkDerivation rec {
+  pname = "librealsense";
+  version = "2.54.2";
+
+  outputs = [ "out" "dev" ];
+
+  src = fetchFromGitHub {
+    owner = "IntelRealSense";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "sha256-EbnIHnsUgsqN/SVv4m9H7K8gfwni+u82+M55QBstAGI=";
+  };
+
+  buildInputs = [
+    libusb1
+    gcc.cc.lib
+  ] ++ lib.optional cudaSupport cudaPackages.cudatoolkit
+    ++ lib.optionals enablePython (with pythonPackages; [ python pybind11 ])
+    ++ lib.optionals enableGUI [ mesa gtk3 glfw libGLU curl ];
+
+  patches = [
+    ./py_pybind11_no_external_download.patch
+    ./install-presets.patch
+  ];
+
+  nativeBuildInputs = [
+    cmake
+    ninja
+    pkg-config
+  ];
+
+  cmakeFlags = [
+    "-DBUILD_EXAMPLES=ON"
+    "-DBUILD_GRAPHICAL_EXAMPLES=${lib.boolToString enableGUI}"
+    "-DBUILD_GLSL_EXTENSIONS=${lib.boolToString enableGUI}"
+    "-DCHECK_FOR_UPDATES=OFF" # activated by BUILD_GRAPHICAL_EXAMPLES, will make it download and compile libcurl
+  ] ++ 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 = ''
+    substituteInPlace $out/lib/cmake/realsense2/realsense2Targets.cmake \
+    --replace "\''${_IMPORT_PREFIX}/include" "$dev/include"
+  '' + lib.optionalString enablePython  ''
+    cp ../wrappers/python/pyrealsense2/__init__.py $out/${pythonPackages.python.sitePackages}/pyrealsense2
+  '';
+
+  meta = with lib; {
+    description = "A cross-platform library for IntelĀ® RealSenseā„¢ depth cameras (D400 series and the SR300)";
+    homepage = "https://github.com/IntelRealSense/librealsense";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ brian-dawn pbsds ];
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/librealsense/install-presets.patch b/nixpkgs/pkgs/development/libraries/librealsense/install-presets.patch
new file mode 100644
index 000000000000..347aa4345323
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/librealsense/install-presets.patch
@@ -0,0 +1,13 @@
+diff --git a/tools/realsense-viewer/CMakeLists.txt b/tools/realsense-viewer/CMakeLists.txt
+index 44be6278f..1a4531dff 100644
+--- a/tools/realsense-viewer/CMakeLists.txt
++++ b/tools/realsense-viewer/CMakeLists.txt
+@@ -253,7 +253,7 @@ install(
+ )
+ #https://cmake.org/cmake/help/latest/command/install.html
+ install(DIRECTORY presets/
+-    DESTINATION $ENV{HOME}/Documents/librealsense2/presets
++    DESTINATION $ENV{out}/share/librealsense2/presets
+     FILES_MATCHING PATTERN "*.preset"
+ )
+ endif()
diff --git a/nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch b/nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch
new file mode 100644
index 000000000000..c91945fa1523
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch
@@ -0,0 +1,15 @@
+diff --git a/CMake/global_config.cmake b/CMake/global_config.cmake
+index 350f7a268..2cf125c67 100644
+--- a/CMake/global_config.cmake
++++ b/CMake/global_config.cmake
+@@ -69,7 +69,8 @@ macro(global_set_flags)
+ 
+     if(BUILD_PYTHON_BINDINGS)
+         include(libusb_config)
+-        include(CMake/external_pybind11.cmake)
++        find_package(pybind11 REQUIRED)
++        set(PYTHON_INSTALL_DIR "${XXNIX_PYTHON_SITEPACKAGES}/pyrealsense2" CACHE PATH "Installation directory for Python bindings")
+     endif()
+ 
+     if(CHECK_FOR_UPDATES)
+