xmake.repo/packages/m/mimalloc-cmake/xmake.lua
2024-11-14 21:50:13 +08:00

33 lines
1.6 KiB
Lua

package("mimalloc-cmake")
set_homepage("https://github.com/microsoft/mimalloc")
set_description("A general purpose allocator with high performance and small memory footprint")
add_versions("2.1.7", "...")
add_configs("secure", {description = "Use a secured version of mimalloc", default = false, type = "boolean"})
add_configs("installdir", {description = "malloc source install dir", default = nil})
-- 定义安装 mimalloc 的过程
set_sourcedir(path.join(os.scriptdir(), "latest"))
on_install(function (package, target)
local installdir = package:config("installdir")
print(installdir, package:installdir())
local configs = {"-DMI_OVERRIDE=OFF"}
table.insert(configs, "-DMI_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
table.insert(configs, "-DMI_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DMI_SECURE=" .. (package:config("secure") and "ON" or "OFF"))
table.insert(configs, "-DMI_BUILD_TESTS=OFF")
table.insert(configs, "-DMI_BUILD_OBJECT=OFF")
-- 使用 CMake 从源码构建 mimalloc
import("package.tools.cmake").build(package, configs,{buildir = "build"})
local function get_dir(path)
if not os.isdir(path) then
os.mkdir(path)
end
return path
end
local lib = get_dir(path.join(installdir, "lib"))
if package:is_plat("windows") then
os.trycp("build/**.dll", lib)
os.trycp("build/**.lib", lib)
end
os.cp("include", installdir)
os.cp("src", installdir)
end)