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