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