Skip to content

Commit

Permalink
fftw: support more platform
Browse files Browse the repository at this point in the history
  • Loading branch information
star-hengxing committed Nov 13, 2024
1 parent ea9a699 commit f79bc78
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions packages/f/fftw/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package("fftw")

set_homepage("http://fftw.org/")
set_description("A C subroutine library for computing the discrete Fourier transform (DFT) in one or more dimensions.")
set_license("GPL-2.0")

add_urls("http://fftw.org/fftw-$(version).tar.gz")

add_versions("3.3.8", "6113262f6e92c5bd474f2875fa1b01054c4ad5040f6b0da7c03c98821d9ae303")
add_versions("3.3.9", "bf2c7ce40b04ae811af714deb512510cc2c17b9ab9d6ddcf49fe4487eea7af3d")
add_versions("3.3.10", "56c932549852cddcfafdab3820b0200c7742675be92179e59e6215b340e26467")
Expand All @@ -14,18 +14,29 @@ package("fftw")
add_configs("enable_mpi", {description = "Enable MPI support.", default = false, type = "boolean"})
add_configs("simd", {description = "SIMD instruction sets used.", default = "avx2", type = "string", values = {"none", "sse", "sse2", "avx", "avx2", "avx512", "avx-128-fma", "kcvi", "altivec", "vsx", "neon", "generic-simd128", "generic-simd256"}})

if is_plat("windows") then
if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

if not is_plat("linux", "macosx") then
add_deps("cmake")
end

on_install("windows", function (package)
local configs = {"-DBUILD_TESTS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
if package:config("shared") then
on_load(function (package)
if package:config("thread") == "openmp" then
package:add("deps", "openmp")
end

if package:is_plat("windows") and package:config("shared") then
package:add("defines", "FFTW_DLL")
table.insert(configs, "-DWITH_COMBINED_THREADS=ON")
end
end)

on_install(function (package)
local configs = {"-DBUILD_TESTS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DWITH_COMBINED_THREADS=" .. (package:config("shared") and "ON" or "OFF"))
if package:config("precision") == "float" then
table.insert(configs, "-DENABLE_FLOAT=ON")
elseif package:config("precision") == "quad" then
Expand All @@ -38,12 +49,23 @@ package("fftw")
elseif package:config("thread") == "openmp" then
table.insert(configs, "-DENABLE_OPENMP=ON")
end

local simds = import("core.base.hashset").of("sse", "sse2", "avx", "avx2")
local simd = package:config("simd")
if simd ~= "none" and simds:has(simd) then
table.insert(configs, "-DENABLE_" .. string.upper(simd) .. "=ON")
end
import("package.tools.cmake").install(package, configs)

local opt = {}
if package:is_plat("mingw") then
opt.cxflags = "-DWITH_OUR_MALLOC"
end
import("package.tools.cmake").install(package, configs, opt)

if package:is_plat("windows") and package:is_debug() then
local dir = package:installdir(package:config("shared") and "bin" or "lib")
os.trycp(path.join(package:buildir(), "fftw3.pdb"), dir)
end
end)

on_install("linux", "macosx", function (package)
Expand Down Expand Up @@ -80,5 +102,13 @@ package("fftw")
end)

on_test(function (package)
assert(package:has_cfuncs("fftw_execute", {includes = "fftw3.h"}))
local precision_map = {
float = "f",
long = "l",
quad = "q",
}

local name = precision_map[package:config("precision")] or ""
local fn = "fftw" .. name .. "_execute"
assert(package:has_cfuncs(fn, {includes = "fftw3.h"}))
end)

0 comments on commit f79bc78

Please sign in to comment.