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 sha256 = "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 ++ lib.optional (
70 stdenv.hostPlatform.isx86_64 && (precision == "single" || precision == "double")
71 ) "--enable-sse2 --enable-avx --enable-avx2 --enable-avx512 --enable-avx128-fma"
72 ++ lib.optional enableMpi "--enable-mpi"
73 # doc generation causes Fortran wrapper generation which hard-codes gcc
74 ++ lib.optional (!withDoc) "--disable-doc";
75
76 # fftw builds with -mtune=native by default
77 postPatch = ''
78 substituteInPlace configure --replace "-mtune=native" "-mtune=generic"
79 '';
80
81 enableParallelBuilding = true;
82
83 nativeCheckInputs = [ perl ];
84
85 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
86
87 meta = with lib; {
88 description = "Fastest Fourier Transform in the West library";
89 homepage = "https://www.fftw.org/";
90 license = licenses.gpl2Plus;
91 maintainers = [ ];
92 pkgConfigModules = [
93 {
94 "single" = "fftw3f";
95 "double" = "fftw3";
96 "long-double" = "fftw3l";
97 "quad-precision" = "fftw3q";
98 }
99 .${precision}
100 ];
101 platforms = platforms.unix;
102 # quad-precision requires libquadmath from gfortran, but libquadmath is not supported on aarch64
103 badPlatforms = lib.optionals (precision == "quad-precision") platforms.aarch64;
104 };
105})