fetch.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import("lib.detect.find_path")
  2. import("lib.detect.find_library")
  3. function _find_package(package, opt)
  4. local rdir = (package:is_arch("x64", "x86_64") and "intel64" or "ia32")
  5. local paths = {
  6. "$(env TBB_ROOT)",
  7. "$(env ONEAPI_ROOT)/tbb/latest"
  8. }
  9. -- find includes and links
  10. local result = {links = {}, linkdirs = {}, includedirs = {}}
  11. for _, lib in ipairs({"tbb", "tbbmalloc", "tbbmalloc_proxy"}) do
  12. local linkinfo = find_library(lib, paths, {suffixes = {"lib", path.join("lib", rdir, "vc14")}})
  13. if linkinfo then
  14. table.insert(result.linkdirs, linkinfo.linkdir)
  15. table.insert(result.links, lib)
  16. end
  17. end
  18. result.linkdirs = table.unique(result.linkdirs)
  19. local incpath = find_path(path.join("tbb", "tbb.h"), paths, {suffixes = "include"})
  20. if incpath then
  21. table.insert(result.includedirs, incpath)
  22. end
  23. if #result.includedirs > 0 and #result.linkdirs > 0 then
  24. local version_file = path.join(incpath, "oneapi", "tbb", "version.h")
  25. if not os.isfile(version_file) then
  26. version_file = path.join(incpath, "tbb", "tbb_stddef.h")
  27. end
  28. if os.isfile(version_file) then
  29. local content = io.readfile(version_file)
  30. local major = content:match("TBB_VERSION_MAJOR (%d+)\n")
  31. local minor = content:match("TBB_VERSION_MINOR (%d+)\n")
  32. local patch = content:match("TBB_VERSION_PATCH (%d+)\n")
  33. if patch then
  34. result.version = format("%s.%s.%s", major, minor, patch)
  35. else
  36. result.version = format("%s.%s", major, minor)
  37. end
  38. end
  39. return result
  40. end
  41. end
  42. function main(package, opt)
  43. if opt.system and package.find_package then
  44. local result
  45. result = _find_package(package, opt)
  46. if not result then
  47. result = package:find_package("tbb", opt)
  48. end
  49. return result or false
  50. end
  51. end