1{ fetchurl
2, fetchpatch
3, stdenv
4, lib
5, gfortran
6, perl
7, llvmPackages
8, precision ? "double"
9, enableMpi ? false
10, mpi
11, withDoc ? stdenv.cc.isGNU
12, testers
13}:
14
15assert lib.elem precision [ "single" "double" "long-double" "quad-precision" ];
16
17stdenv.mkDerivation (finalAttrs: {
18 pname = "fftw-${precision}";
19 version = "3.3.10";
20
21 src = fetchurl {
22 urls = [
23 "https://fftw.org/fftw-${finalAttrs.version}.tar.gz"
24 "ftp://ftp.fftw.org/pub/fftw/fftw-${finalAttrs.version}.tar.gz"
25 ];
26 sha256 = "sha256-VskyVJhSzdz6/as4ILAgDHdCZ1vpIXnlnmIVs0DiZGc=";
27 };
28
29 patches = [
30 (fetchpatch {
31 name = "remove_missing_FFTW3LibraryDepends.patch";
32 url = "https://github.com/FFTW/fftw3/pull/338/commits/f69fef7aa546d4477a2a3fd7f13fa8b2f6c54af7.patch";
33 hash = "sha256-lzX9kAHDMY4A3Td8necXwYLcN6j8Wcegi3A7OIECKeU=";
34 })
35 ];
36
37 outputs = [ "out" "dev" "man" ]
38 ++ lib.optional withDoc "info"; # it's dev-doc only
39 outputBin = "dev"; # fftw-wisdom
40
41 nativeBuildInputs = [ gfortran ];
42
43 buildInputs = lib.optionals stdenv.cc.isClang [
44 # TODO: This may mismatch the LLVM version sin the stdenv, see #79818.
45 llvmPackages.openmp
46 ] ++ lib.optional enableMpi mpi;
47
48 configureFlags = [
49 "--enable-shared"
50 "--enable-threads"
51 "--enable-openmp"
52 ]
53
54 ++ lib.optional (precision != "double") "--enable-${precision}"
55 # https://www.fftw.org/fftw3_doc/SIMD-alignment-and-fftw_005fmalloc.html
56 # FFTW will try to detect at runtime whether the CPU supports these extensions
57 ++ lib.optional (stdenv.isx86_64 && (precision == "single" || precision == "double"))
58 "--enable-sse2 --enable-avx --enable-avx2 --enable-avx512 --enable-avx128-fma"
59 ++ lib.optional enableMpi "--enable-mpi"
60 # doc generation causes Fortran wrapper generation which hard-codes gcc
61 ++ lib.optional (!withDoc) "--disable-doc";
62
63 # fftw builds with -mtune=native by default
64 postPatch = ''
65 substituteInPlace configure --replace "-mtune=native" "-mtune=generic"
66 '';
67
68 enableParallelBuilding = true;
69
70 nativeCheckInputs = [ perl ];
71
72 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
73
74 meta = with lib; {
75 description = "Fastest Fourier Transform in the West library";
76 homepage = "https://www.fftw.org/";
77 license = licenses.gpl2Plus;
78 maintainers = [ ];
79 pkgConfigModules = [
80 {
81 "single" = "fftw3f";
82 "double" = "fftw3";
83 "long-double" = "fftw3l";
84 "quad-precision" = "fftw3q";
85 }.${precision}
86 ];
87 platforms = platforms.unix;
88 };
89})