1{
2 lib,
3 stdenv,
4 cmake,
5 fetchurl,
6 python3,
7 blas,
8 lapack,
9 gfortran,
10 suitesparse,
11 lapackSupport ? true,
12 kluSupport ? true,
13}:
14
15stdenv.mkDerivation rec {
16 pname = "sundials";
17 version = "7.3.0";
18
19 outputs = [
20 "out"
21 "examples"
22 ];
23
24 src = fetchurl {
25 url = "https://github.com/LLNL/sundials/releases/download/v${version}/sundials-${version}.tar.gz";
26 hash = "sha256-/ZcKkCP46je4HFBlwGe/Fyb2VrOfWQe0gWmm+Y0wa6c=";
27 };
28
29 nativeBuildInputs = [
30 cmake
31 gfortran
32 ];
33
34 buildInputs =
35 [
36 python3
37 ]
38 ++
39 lib.optionals (lapackSupport)
40 # Check that the same index size is used for both libraries
41 (
42 assert (blas.isILP64 == lapack.isILP64);
43 [
44 blas
45 lapack
46 ]
47 )
48 # KLU support is based on Suitesparse. It is tested upstream according to the
49 # section 1.1.4.2 of INSTALL_GUIDE.pdf found in the source tarball.
50 ++ lib.optionals (kluSupport) [
51 suitesparse
52 ];
53
54 cmakeFlags =
55 [
56 "-DEXAMPLES_INSTALL_PATH=${placeholder "examples"}/share/examples"
57 ]
58 ++ lib.optionals (lapackSupport) [
59 "-DENABLE_LAPACK=ON"
60 "-DLAPACK_LIBRARIES=${lapack}/lib/liblapack${stdenv.hostPlatform.extensions.sharedLibrary}"
61 ]
62 ++ lib.optionals (kluSupport) [
63 "-DENABLE_KLU=ON"
64 "-DKLU_INCLUDE_DIR=${suitesparse.dev}/include"
65 "-DKLU_LIBRARY_DIR=${suitesparse}/lib"
66 ]
67 ++ [
68 (
69 # Use the correct index type according to lapack and blas used. They are
70 # already supposed to be compatible but we check both for extra safety. 64
71 # should be the default but we prefer to be explicit, for extra safety.
72 if blas.isILP64 then "-DSUNDIALS_INDEX_SIZE=64" else "-DSUNDIALS_INDEX_SIZE=32"
73 )
74 ];
75
76 doCheck = true;
77 checkTarget = "test";
78
79 meta = with lib; {
80 description = "Suite of nonlinear differential/algebraic equation solvers";
81 homepage = "https://computing.llnl.gov/projects/sundials";
82 platforms = platforms.all;
83 maintainers = with maintainers; [ idontgetoutmuch ];
84 license = licenses.bsd3;
85 };
86}