nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 fetchurl,
3 fetchpatch,
4 stdenv,
5 lib,
6 gfortran,
7 perl,
8 llvmPackages,
9 precision ? "double",
10 enableMpi ? false,
11 mpi,
12 withDoc ? stdenv.cc.isGNU,
13 testers,
14}:
15
16assert lib.elem precision [
17 "single"
18 "double"
19 "long-double"
20 "quad-precision"
21];
22
23stdenv.mkDerivation (finalAttrs: {
24 pname = "fftw-${precision}";
25 version = "3.3.10";
26
27 src = fetchurl {
28 urls = [
29 "https://fftw.org/fftw-${finalAttrs.version}.tar.gz"
30 "ftp://ftp.fftw.org/pub/fftw/fftw-${finalAttrs.version}.tar.gz"
31 ];
32 hash = "sha256-VskyVJhSzdz6/as4ILAgDHdCZ1vpIXnlnmIVs0DiZGc=";
33 };
34
35 patches = [
36 (fetchpatch {
37 name = "remove_missing_FFTW3LibraryDepends.patch";
38 url = "https://github.com/FFTW/fftw3/pull/338/commits/f69fef7aa546d4477a2a3fd7f13fa8b2f6c54af7.patch";
39 hash = "sha256-lzX9kAHDMY4A3Td8necXwYLcN6j8Wcegi3A7OIECKeU=";
40 })
41 ];
42
43 outputs = [
44 "out"
45 "dev"
46 "man"
47 ]
48 ++ lib.optional withDoc "info"; # it's dev-doc only
49 outputBin = "dev"; # fftw-wisdom
50
51 nativeBuildInputs = [ gfortran ];
52
53 buildInputs =
54 lib.optionals stdenv.cc.isClang [
55 # TODO: This may mismatch the LLVM version sin the stdenv, see #79818.
56 llvmPackages.openmp
57 ]
58 ++ lib.optional enableMpi mpi;
59
60 configureFlags = [
61 "--enable-shared"
62 "--enable-threads"
63 "--enable-openmp"
64 ]
65
66 ++ lib.optional (precision != "double") "--enable-${precision}"
67 # https://www.fftw.org/fftw3_doc/SIMD-alignment-and-fftw_005fmalloc.html
68 # FFTW will try to detect at runtime whether the CPU supports these extensions
69 ++
70 lib.optionals (stdenv.hostPlatform.isx86_64 && (precision == "single" || precision == "double"))
71 [
72 "--enable-sse2"
73 "--enable-avx"
74 "--enable-avx2"
75 "--enable-avx512"
76 "--enable-avx128-fma"
77 ]
78 ++ lib.optionals enableMpi [
79 "--enable-mpi"
80 # link libfftw3_mpi explicitly with -lmpi
81 # linker on darwin requires all symbols to be resolvable at link time
82 # see
83 # https://github.com/FFTW/fftw3/issues/274
84 # https://github.com/spack/spack/pull/29279
85 "MPILIBS=-lmpi"
86 ]
87 # doc generation causes Fortran wrapper generation which hard-codes gcc
88 ++ lib.optional (!withDoc) "--disable-doc";
89
90 # fftw builds with -mtune=native by default
91 postPatch = ''
92 substituteInPlace configure --replace-fail "-mtune=native" "-mtune=generic"
93 '';
94
95 strictDeps = true;
96 enableParallelBuilding = true;
97
98 nativeCheckInputs = [ perl ];
99
100 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
101
102 __structuredAttrs = true;
103
104 meta = {
105 description = "Fastest Fourier Transform in the West library";
106 homepage = "https://www.fftw.org/";
107 license = lib.licenses.gpl2Plus;
108 maintainers = [ ];
109 pkgConfigModules = [
110 {
111 "single" = "fftw3f";
112 "double" = "fftw3";
113 "long-double" = "fftw3l";
114 "quad-precision" = "fftw3q";
115 }
116 .${precision}
117 ];
118 platforms = lib.platforms.unix;
119 # quad-precision requires libquadmath from gfortran, but libquadmath is not supported on aarch64
120 badPlatforms = lib.optionals (precision == "quad-precision") lib.platforms.aarch64;
121 };
122})