nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 (finalAttrs: {
15 pname = "flann";
16 version = "1.9.1";
17
18 src = fetchFromGitHub {
19 owner = "flann-lib";
20 repo = "flann";
21 rev = finalAttrs.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 # The LZ4 patch updates cmake_minimum_required to 3.12, but only for non-clang builds.
58 # For clang builds (like Darwin), we need to manually update it.
59 # ref. https://github.com/flann-lib/flann/pull/526 not merged yet
60 postPatch = lib.optionalString stdenv.cc.isClang ''
61 substituteInPlace CMakeLists.txt \
62 --replace-fail "cmake_minimum_required(VERSION 2.6)" "cmake_minimum_required(VERSION 3.5)"
63 '';
64
65 cmakeFlags = [
66 "-DBUILD_EXAMPLES:BOOL=OFF"
67 "-DBUILD_TESTS:BOOL=OFF"
68 "-DBUILD_MATLAB_BINDINGS:BOOL=OFF"
69 "-DBUILD_PYTHON_BINDINGS:BOOL=${if enablePython then "ON" else "OFF"}"
70 ];
71
72 nativeBuildInputs = [
73 cmake
74 pkg-config
75 unzip
76 ];
77
78 # lz4 unbundling broken for llvm, use internal version
79 propagatedBuildInputs = lib.optional (!stdenv.cc.isClang) lz4;
80
81 buildInputs = lib.optionals enablePython [ python3 ];
82
83 meta = {
84 homepage = "https://github.com/flann-lib/flann";
85 license = lib.licenses.bsd3;
86 description = "Fast approximate nearest neighbor searches in high dimensional spaces";
87 maintainers = [ ];
88 platforms = with lib.platforms; linux ++ darwin;
89 };
90})