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.nix86
-rw-r--r--nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch39
-rw-r--r--nixpkgs/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch15
3 files changed, 140 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..135969210d36
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/librealsense/default.nix
@@ -0,0 +1,86 @@
+{ stdenv
+, config
+, lib
+, fetchFromGitHub
+, fetchpatch
+, cmake
+, libusb1
+, ninja
+, pkg-config
+, gcc
+, mesa
+, gtk3
+, glfw
+, libGLU
+, curl
+, cudaSupport ? config.cudaSupport or false, 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.45.0";
+
+  outputs = [ "out" "dev" ];
+
+  src = fetchFromGitHub {
+    owner = "IntelRealSense";
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "0aqf48zl7825v7x8c3x5w4d17m4qq377f1mn6xyqzf9b0dnk4i1j";
+  };
+
+  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 = [
+    # fix build on aarch64-darwin
+    # https://github.com/IntelRealSense/librealsense/pull/9253
+    (fetchpatch {
+      url = "https://github.com/IntelRealSense/librealsense/commit/beb4c44debc8336de991c983274cad841eb5c323.patch";
+      sha256 = "05mxsd2pz3xrvywdqyxkwdvxx8hjfxzcgl51897avz4v2j89pyq8";
+    })
+    ./py_sitepackage_dir.patch
+    ./py_pybind11_no_external_download.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 = 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/py_pybind11_no_external_download.patch b/nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch
new file mode 100644
index 000000000000..2b48edb62e37
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/librealsense/py_pybind11_no_external_download.patch
@@ -0,0 +1,39 @@
+From 01e51b9c90ba51b2d0ca797dde676812cf3db415 Mon Sep 17 00:00:00 2001
+From: "Robert T. McGibbon" <rmcgibbo@gmail.com>
+Date: Mon, 10 May 2021 17:26:04 -0400
+Subject: [PATCH 1/1] V1
+
+---
+ wrappers/python/CMakeLists.txt | 15 +--------------
+ 1 file changed, 1 insertion(+), 14 deletions(-)
+
+diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt
+index aa83e4c77..4ec92ccfa 100644
+--- a/wrappers/python/CMakeLists.txt
++++ b/wrappers/python/CMakeLists.txt
+@@ -8,21 +8,8 @@ if (NOT BUILD_PYTHON_BINDINGS)
+ endif()
+ 
+ set(DEPENDENCIES realsense2)
+-# In order for the external project clone to occur during cmake configure step(rather than during compilation, as would normally happen),
+-# we copy the external project declaration to the build folder and then execute it
+-configure_file(${CMAKE_SOURCE_DIR}/third-party/pybind11/CMakeLists.txt ${CMAKE_BINARY_DIR}/external-projects/pybind11/CMakeLists.txt)
+-execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
+-    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
+-)
+-execute_process(COMMAND "${CMAKE_COMMAND}" --build .
+-    WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/pybind11"
+-)
+ 
+-# Add pybind11 makefile
+-add_subdirectory("${CMAKE_BINARY_DIR}/third-party/pybind11"
+-                 "${CMAKE_BINARY_DIR}/third-party/pybind11"
+-                 EXCLUDE_FROM_ALL
+-)
++find_package(pybind11 REQUIRED)
+ 
+ set(PYBIND11_CPP_STANDARD -std=c++11)
+ # Force Pybind11 not to share pyrealsense2 resources with other pybind modules.
+-- 
+2.29.3
+
diff --git a/nixpkgs/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch b/nixpkgs/pkgs/development/libraries/librealsense/py_sitepackage_dir.patch
new file mode 100644
index 000000000000..99b567a429ed
--- /dev/null
+++ b/nixpkgs/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()