Commit 1f81efc8 authored by Emily's avatar Emily
Browse files

kissfft: build with CMake

Fix the library install names on macOS and replace a patch with a
smaller one.
parent 990e9653
Loading
Loading
Loading
Loading
+0 −48
Original line number Diff line number Diff line
From c0dc376be9154d143574a818417ceed23308b5f2 Mon Sep 17 00:00:00 2001
From: OPNA2608 <christoph.neidahl@gmail.com>
Date: Sun, 18 Apr 2021 01:45:20 +0200
Subject: [PATCH] pkgconfig darwin

---
 Makefile | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/Makefile b/Makefile
index 971c6d6..0f4be0c 100644
--- a/Makefile
+++ b/Makefile
@@ -153,7 +153,6 @@ endif
 # -DKISS_FFT_BUILD to TYPEFLAGS
 #
 
-ifneq ($(shell uname -s),Darwin)
 	PKGCONFIG_KISSFFT_VERSION = $(KFVER_MAJOR).$(KFVER_MINOR).$(KFVER_PATCH)
 	PKGCONFIG_KISSFFT_OUTPUT_NAME = $(KISSFFTLIB_SHORTNAME)
 	PKGCONFIG_PKG_KISSFFT_DEFS = $(TYPEFLAGS)
@@ -170,7 +169,6 @@ ifneq ($(shell uname -s),Darwin)
 	PKGCONFIG_KISSFFT_LIBDIR = $(ABS_LIBDIR)
   endif
 	PKGCONFIG_KISSFFT_PKGINCLUDEDIR = $${includedir}/kissfft
-endif
 
 export TYPEFLAGS
 
@@ -226,7 +224,6 @@ ifneq ($(KISSFFT_STATIC), 1)
 	ln -sf $(KISSFFTLIB_NAME) $(KISSFFTLIB_SODEVELNAME)
   endif
 endif
-ifneq ($(shell uname -s),Darwin)
 	mkdir "$(ABS_LIBDIR)/pkgconfig"
 	sed \
 		-e 's+@PKGCONFIG_KISSFFT_VERSION@+$(PKGCONFIG_KISSFFT_VERSION)+' \
@@ -238,7 +235,6 @@ ifneq ($(shell uname -s),Darwin)
 		-e 's+@PKGCONFIG_KISSFFT_LIBDIR@+$(PKGCONFIG_KISSFFT_LIBDIR)+' \
 		-e 's+@PKGCONFIG_KISSFFT_PKGINCLUDEDIR@+$(PKGCONFIG_KISSFFT_PKGINCLUDEDIR)+' \
 		kissfft.pc.in 1>"$(ABS_LIBDIR)/pkgconfig/$(KISSFFT_PKGCONFIG)"
-endif
 ifneq ($(KISSFFT_TOOLS), 0)
 	make -C tools install
 endif
-- 
2.29.3
+23 −0
Original line number Diff line number Diff line
From a73134e594d85abc32e27a34a78ce75c5f006f92 Mon Sep 17 00:00:00 2001
From: Emily <hello@emily.moe>
Date: Sat, 3 Aug 2024 17:49:57 +0100
Subject: [PATCH] Fix FFTW dependency check

`KISFFT_FLOAT` is not defined anywhere.
---
 test/CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 0a0e403..d7d8350 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -24,7 +24,7 @@ add_kissfft_test_executable(bm_kiss benchkiss.c pstats.c)
 # set_tests_properties(${NAME} PROPERTIES TIMEOUT 3600)
 
 include(FindPkgConfig)
-if(KISSFFT_FLOAT)
+if(KISSFFT_DATATYPE MATCHES "^float$")
     set(fftw3_pkg fftw3f)
 else()
     set(fftw3_pkg fftw3)
+48 −50
Original line number Diff line number Diff line
@@ -2,87 +2,85 @@
  lib,
  stdenv,
  fetchFromGitHub,
  cmake,
  ninja,
  pkg-config,
  fftw,
  fftwFloat,
  python3,
  datatype ? "double",
  withTools ? false,
  libpng,
  enableStatic ? stdenv.hostPlatform.isStatic,
  enableOpenmp ? false,
  llvmPackages,
}:
let
  py = python3.withPackages (ps: with ps; [ numpy ]);
  option = cond: if cond then "1" else "0";
in
stdenv.mkDerivation rec {

stdenv.mkDerivation (finalAttrs: {
  pname = "kissfft-${datatype}${lib.optionalString enableOpenmp "-openmp"}";
  version = "131.1.0";

  outputs = [
    "bin"
    "dev"
    "out"
  ];

  src = fetchFromGitHub {
    owner = "mborgerding";
    repo = "kissfft";
    rev = version;
    sha256 = "1yfws5bn4kh62yk6hdyp9h9775l6iz7wsfisbn58jap6b56s8j5s";
    rev = finalAttrs.version;
    hash = "sha256-ukikTVnmKomKXTo6zc+PhpZzEkzXN2imFwZOYlfR3Pk=";
  };

  patches = [ ./0001-pkgconfig-darwin.patch ];

  # https://bugs.llvm.org/show_bug.cgi?id=45034
  postPatch =
    lib.optionalString
      (stdenv.hostPlatform.isLinux && stdenv.cc.isClang && lib.versionOlder stdenv.cc.version "10")
      ''
        substituteInPlace test/Makefile \
          --replace "-ffast-math" ""
      ''
    + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
      substituteInPlace test/Makefile \
        --replace "LD_LIBRARY_PATH" "DYLD_LIBRARY_PATH"
      # Don't know how to make math.h's double long constants available
      substituteInPlace test/testcpp.cc \
        --replace "M_PIl" "M_PI"
    '';
  patches = [
    # Fix FFTW dependency check
    # https://github.com/mborgerding/kissfft/pull/95
    ./fix-fftw-dependency-check.patch
  ];

  makeFlags = [
    "PREFIX=${placeholder "out"}"
    "KISSFFT_DATATYPE=${datatype}"
    "KISSFFT_TOOLS=${option withTools}"
    "KISSFFT_STATIC=${option enableStatic}"
    "KISSFFT_OPENMP=${option enableOpenmp}"
  nativeBuildInputs = [
    cmake
    ninja
    pkg-config
  ];

  buildInputs =
    lib.optionals (withTools && datatype != "simd") [ libpng ]
    lib.optionals (datatype != "simd") [ libpng ]
    # TODO: This may mismatch the LLVM version in the stdenv, see #79818.
    ++ lib.optional (enableOpenmp && stdenv.cc.isClang) llvmPackages.openmp;

  doCheck = true;
  nativeCheckInputs = [ (python3.withPackages (ps: [ ps.numpy ])) ];

  checkInputs = [ (if datatype == "float" then fftwFloat else fftw) ];

  nativeCheckInputs = [
    py
    (if datatype == "float" then fftwFloat else fftw)
  cmakeFlags = [
    (lib.cmakeFeature "KISSFFT_DATATYPE" datatype)
    (lib.cmakeBool "KISSFFT_STATIC" enableStatic)
    # `test/testkiss.py` expects this…
    (lib.cmakeFeature "KISSFFT_OPENMP" (if enableOpenmp then "ON" else "OFF"))
  ];

  checkFlags = [ "testsingle" ];
  # Required for `test/testcpp.c`.
  env = {
    NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-D__MATH_LONG_DOUBLE_CONSTANTS=1";
  };

  postInstall = ''
    ln -s ${pname}.pc $out/lib/pkgconfig/kissfft.pc
  '';
  doCheck = true;

  # Tools can't find kissfft libs on Darwin
  postFixup = lib.optionalString (withTools && stdenv.hostPlatform.isDarwin) ''
    for bin in $out/bin/*; do
      install_name_tool -change lib${pname}.dylib $out/lib/lib${pname}.dylib $bin
    done
  # https://bugs.llvm.org/show_bug.cgi?id=45034
  postPatch =
    lib.optionalString
      (stdenv.hostPlatform.isLinux && stdenv.cc.isClang && lib.versionOlder stdenv.cc.version "10")
      ''
        substituteInPlace CMakeLists.txt \
          --replace "-ffast-math" ""
      '';

  meta = with lib; {
  meta = {
    description = "Mixed-radix Fast Fourier Transform based up on the KISS principle";
    homepage = "https://github.com/mborgerding/kissfft";
    license = licenses.bsd3;
    license = lib.licenses.bsd3;
    maintainers = [ ];
    platforms = platforms.all;
    platforms = lib.platforms.all;
  };
}
})