1{ lib
2, cmake
3, fetchFromGitHub
4, fetchpatch
5, lz4
6, pkg-config
7, python3
8, stdenv
9, unzip
10, enablePython ? false
11}:
12
13stdenv.mkDerivation rec {
14 pname = "flann";
15 version = "1.9.1";
16
17 src = fetchFromGitHub {
18 owner = "flann-lib";
19 repo = "flann";
20 rev = version;
21 sha256 = "13lg9nazj5s9a41j61vbijy04v6839i67lqd925xmxsbybf36gjc";
22 };
23
24 patches = [
25 # Patch HDF5_INCLUDE_DIR -> HDF_INCLUDE_DIRS.
26 (fetchpatch {
27 url = "https://salsa.debian.org/science-team/flann/-/raw/debian/1.9.1+dfsg-9/debian/patches/0001-Updated-fix-cmake-hdf5.patch";
28 sha256 = "yM1ONU4mu6lctttM5YcSTg8F344TNUJXwjxXLqzr5Pk=";
29 })
30 # Patch no-source library workaround that breaks on CMake > 3.11.
31 (fetchpatch {
32 url = "https://salsa.debian.org/science-team/flann/-/raw/debian/1.9.1+dfsg-9/debian/patches/0001-src-cpp-fix-cmake-3.11-build.patch";
33 sha256 = "REsBnbe6vlrZ+iCcw43kR5wy2o6q10RM73xjW5kBsr4=";
34 })
35 ] ++ lib.optionals (!stdenv.cc.isClang) [
36 # Avoid the bundled version of LZ4 and instead use the system one.
37 (fetchpatch {
38 url = "https://salsa.debian.org/science-team/flann/-/raw/debian/1.9.1+dfsg-9/debian/patches/0003-Use-system-version-of-liblz4.patch";
39 sha256 = "xi+GyFn9PEjLgbJeAIEmsbp7ut9G9KIBkVulyT3nfsg=";
40 })
41 # Fix LZ4 string separator issue, see: https://github.com/flann-lib/flann/pull/480
42 (fetchpatch {
43 url = "https://github.com/flann-lib/flann/commit/25eb56ec78472bd419a121c6905095a793cf8992.patch";
44 sha256 = "qt8h576Gn8uR7+T9u9bEBIRz6e6AoTKpa1JfdZVvW9s=";
45 })
46 ] ++ lib.optionals stdenv.cc.isClang [
47 # Fix build with Clang 16.
48 (fetchpatch {
49 url = "https://github.com/flann-lib/flann/commit/be80cefa69b314a3d9e1ab971715e84145863ebb.patch";
50 hash = "sha256-4SUKzQCm0Sx8N43Z6ShuMbgbbe7q8b2Ibk3WgkB0qa4=";
51 })
52 ];
53
54 cmakeFlags = [
55 "-DBUILD_EXAMPLES:BOOL=OFF"
56 "-DBUILD_TESTS:BOOL=OFF"
57 "-DBUILD_MATLAB_BINDINGS:BOOL=OFF"
58 "-DBUILD_PYTHON_BINDINGS:BOOL=${if enablePython then "ON" else "OFF"}"
59 ];
60
61 nativeBuildInputs = [
62 cmake
63 pkg-config
64 unzip
65 ];
66
67 # lz4 unbundling broken for llvm, use internal version
68 propagatedBuildInputs = lib.optional (!stdenv.cc.isClang) lz4;
69
70 buildInputs = lib.optionals enablePython [ python3 ];
71
72 meta = {
73 homepage = "https://github.com/flann-lib/flann";
74 license = lib.licenses.bsd3;
75 description = "Fast approximate nearest neighbor searches in high dimensional spaces";
76 maintainers = with lib.maintainers; [viric];
77 platforms = with lib.platforms; linux ++ darwin;
78 };
79}