pull/380/head
xq114 4 years ago
parent 2d970e8ecb
commit 28747955e4
  1. 59
      packages/t/tbb/fetch.lua
  2. 67
      packages/t/tbb/xmake.lua

@ -0,0 +1,59 @@
import("lib.detect.find_path")
import("lib.detect.find_library")
function _find_package_on_windows(package, opt)
local rdir = (package:is_arch("x64") and "intel64" or "ia32")
local paths = {
"$(env TBB_ROOT)",
"$(env ONEAPI_ROOT)\\tbb\\latest"
}
-- find library
local result = {links = {}, linkdirs = {}, includedirs = {}}
for _, lib in ipairs({"tbb", "tbbmalloc", "tbbmalloc_proxy"}) do
local linkinfo = find_library(lib, paths, {suffixes = path.join("lib", rdir, "vc14")})
if linkinfo then
table.insert(result.linkdirs, linkinfo.linkdir)
table.insert(result.links, lib)
end
end
result.linkdirs = table.unique(result.linkdirs)
-- find include
table.insert(result.includedirs, find_path(path.join("tbb", "tbb.h"), paths, {suffixes = "include"}))
if #result.includedirs > 0 and #result.linkdirs > 0 then
-- find version
local root = result.includedirs[1]
local version_file = path.join(root, "oneapi", "tbb", "version.h")
if not os.isfile(version_file) then
version_file = path.join(root, "tbb", "tbb_stddef.h")
end
if os.isfile(version_file) then
local content = io.readfile(version_file)
local major = content:match("TBB_VERSION_MAJOR (%d+)\n")
local minor = content:match("TBB_VERSION_MINOR (%d+)\n")
local patch = content:match("TBB_VERSION_PATCH (%d+)\n")
if patch then
result.version = format("%s.%s.%s", major, minor, patch)
else
result.version = format("%s.%s", major, minor)
end
end
return result
end
end
function main(package, opt)
if opt.system and package.find_package then
local result
if package:is_plat("windows") then
result = _find_package_on_windows(package, opt)
else
result = package:find_package("tbb", opt)
end
return result or false
end
end

@ -5,11 +5,13 @@ package("tbb")
if is_plat("windows") then
-- use precompiled binary
add_urls("https://github.com/oneapi-src/oneTBB/releases/download/v$(version)/tbb-$(version)-win.zip")
add_urls("https://github.com/oneapi-src/oneTBB/releases/download/v$(version)-win.zip", {version = function (version) return version .. (version:ge("2021.0") and "/oneapi-tbb-" or "/tbb-") .. version end})
add_versions("2020.3", "cda37eed5209746a79c88a658f8c1bf3782f58bd9f9f6ba0da3a16624a9bfaa1")
add_versions("2021.2.0", "9be37b1cb604a5905db0a15b2b893d85579fd0b2f1024859e1f75e96d7331a02")
else
add_urls("https://github.com/oneapi-src/oneTBB/archive/v$(version).tar.gz")
add_versions("2020.3", "ebc4f6aa47972daed1f7bf71d100ae5bf6931c2e3144cf299c8cc7d041dca2f3")
add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
if is_plat("macosx") then
add_configs("compiler", {description = "Compiler used to compile tbb." , default = "clang", type = "string", values = {"clang", "gcc", "icc", "cl", "icl", "[others]"}})
@ -18,29 +20,50 @@ package("tbb")
end
end
on_fetch("fetch")
add_links("tbb", "tbbmalloc", "tbbmalloc_proxy")
on_load("macosx", "linux", "mingw@windows", "mingw@msys", function (package)
if package:version():ge("2021.0") then
package:add("deps", "cmake")
end
end)
on_install("macosx", "linux", "mingw@windows", "mingw@msys", function (package)
local configs = {"-j4", "tbb_build_prefix=build_dir"}
local cfg = package:debug() and "debug" or "release"
table.insert(configs, "cfg=" .. cfg)
table.insert(configs, "arch=" .. (package:is_arch("x86_64") and "intel64" or "ia32"))
table.insert(configs, "compiler=" .. (package:config("compiler")))
if package:is_plat("mingw") then
os.vrunv("mingw32-make", configs)
if package:version():ge("2021.0") then
if package:is_plat("mingw") then
raise("mingw build is not supported in this version")
end
local configs = {"-DTBB_TEST=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
import("package.tools.cmake").install(package, configs)
else
os.vrunv("make", configs)
end
os.cp("include", package:installdir())
os.rm("build/build_dir_" .. cfg .. "/*.d")
os.rm("build/build_dir_" .. cfg .. "/*.o")
os.cp("build/build_dir_" .. cfg .. "/**", package:installdir("lib"))
if package:is_plat("mingw") then
package:addenv("PATH", "lib")
local configs = {"-j4", "tbb_build_prefix=build_dir"}
local cfg = package:debug() and "debug" or "release"
table.insert(configs, "cfg=" .. cfg)
table.insert(configs, "arch=" .. (package:is_arch("x86_64") and "intel64" or "ia32"))
table.insert(configs, "compiler=" .. (package:config("compiler")))
if package:is_plat("mingw") then
os.vrunv("mingw32-make", configs)
else
os.vrunv("make", configs)
end
os.cp("include", package:installdir())
os.rm("build/build_dir_" .. cfg .. "/*.d")
os.rm("build/build_dir_" .. cfg .. "/*.o")
os.cp("build/build_dir_" .. cfg .. "/**", package:installdir("lib"))
if package:is_plat("mingw") then
package:addenv("PATH", "lib")
end
end
package:add("links", "tbb", "tbbmalloc")
end)
on_install("windows", function (package)
os.cp("tbb/include", package:installdir())
local incdir = (package:version():ge("2021.0") and "include" or "tbb/include")
local libdir = (package:version():ge("2021.0") and "lib/" or "tbb/lib/")
local bindir = (package:version():ge("2021.0") and "redist/" or "tbb/bin/")
os.cp(incdir, package:installdir())
local prefix = ""
if package:is_arch("x64", "x86_64") then
prefix = "intel64/vc14"
@ -48,11 +71,11 @@ package("tbb")
prefix = "ia32/vc14"
end
if package:config("debug") then
os.cp("tbb/lib/" .. prefix .. "/*_debug.*", package:installdir("lib"))
os.cp("tbb/bin/" .. prefix .. "/*_debug.*", package:installdir("bin"))
os.cp(libdir .. prefix .. "/*_debug.*", package:installdir("lib"))
os.cp(bindir .. prefix .. "/*_debug.*", package:installdir("bin"))
else
os.cp("tbb/lib/" .. prefix .. "/**|*_debug.*", package:installdir("lib"))
os.cp("tbb/bin/" .. prefix .. "/**|*_debug.*", package:installdir("bin"))
os.cp(libdir .. prefix .. "/**|*_debug.*", package:installdir("lib"))
os.cp(bindir .. prefix .. "/**|*_debug.*", package:installdir("bin"))
end
package:addenv("PATH", "bin")
end)

Loading…
Cancel
Save