pull/380/head
xq114 4 years ago
parent 2d970e8ecb
commit 28747955e4
  1. 59
      packages/t/tbb/fetch.lua
  2. 37
      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 if is_plat("windows") then
-- use precompiled binary -- 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("2020.3", "cda37eed5209746a79c88a658f8c1bf3782f58bd9f9f6ba0da3a16624a9bfaa1")
add_versions("2021.2.0", "9be37b1cb604a5905db0a15b2b893d85579fd0b2f1024859e1f75e96d7331a02")
else else
add_urls("https://github.com/oneapi-src/oneTBB/archive/v$(version).tar.gz") add_urls("https://github.com/oneapi-src/oneTBB/archive/v$(version).tar.gz")
add_versions("2020.3", "ebc4f6aa47972daed1f7bf71d100ae5bf6931c2e3144cf299c8cc7d041dca2f3") add_versions("2020.3", "ebc4f6aa47972daed1f7bf71d100ae5bf6931c2e3144cf299c8cc7d041dca2f3")
add_versions("2021.2.0", "cee20b0a71d977416f3e3b4ec643ee4f38cedeb2a9ff015303431dd9d8d79854")
if is_plat("macosx") then 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]"}}) add_configs("compiler", {description = "Compiler used to compile tbb." , default = "clang", type = "string", values = {"clang", "gcc", "icc", "cl", "icl", "[others]"}})
@ -18,7 +20,25 @@ package("tbb")
end end
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) on_install("macosx", "linux", "mingw@windows", "mingw@msys", function (package)
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
local configs = {"-j4", "tbb_build_prefix=build_dir"} local configs = {"-j4", "tbb_build_prefix=build_dir"}
local cfg = package:debug() and "debug" or "release" local cfg = package:debug() and "debug" or "release"
table.insert(configs, "cfg=" .. cfg) table.insert(configs, "cfg=" .. cfg)
@ -36,11 +56,14 @@ package("tbb")
if package:is_plat("mingw") then if package:is_plat("mingw") then
package:addenv("PATH", "lib") package:addenv("PATH", "lib")
end end
package:add("links", "tbb", "tbbmalloc") end
end) end)
on_install("windows", function (package) 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 = "" local prefix = ""
if package:is_arch("x64", "x86_64") then if package:is_arch("x64", "x86_64") then
prefix = "intel64/vc14" prefix = "intel64/vc14"
@ -48,11 +71,11 @@ package("tbb")
prefix = "ia32/vc14" prefix = "ia32/vc14"
end end
if package:config("debug") then if package:config("debug") then
os.cp("tbb/lib/" .. prefix .. "/*_debug.*", package:installdir("lib")) os.cp(libdir .. prefix .. "/*_debug.*", package:installdir("lib"))
os.cp("tbb/bin/" .. prefix .. "/*_debug.*", package:installdir("bin")) os.cp(bindir .. prefix .. "/*_debug.*", package:installdir("bin"))
else else
os.cp("tbb/lib/" .. prefix .. "/**|*_debug.*", package:installdir("lib")) os.cp(libdir .. prefix .. "/**|*_debug.*", package:installdir("lib"))
os.cp("tbb/bin/" .. prefix .. "/**|*_debug.*", package:installdir("bin")) os.cp(bindir .. prefix .. "/**|*_debug.*", package:installdir("bin"))
end end
package:addenv("PATH", "bin") package:addenv("PATH", "bin")
end) end)

Loading…
Cancel
Save