fetch.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 suffix = (package:config("interface") == 32 and "lp64" or "ilp64")
  6. local paths = {
  7. "$(env MKL_ROOT)",
  8. "$(env ONEAPI_ROOT)/mkl/latest"
  9. }
  10. -- find library
  11. local result = {links = {}, linkdirs = {}, includedirs = {}}
  12. if package:config("interface") == 64 then
  13. result.defines = {"MKL_ILP64"}
  14. end
  15. local linkinfo = find_library("mkl_core", paths, {suffixes = {"lib", path.join("lib", rdir), path.join("lib", rdir, "gcc*")}})
  16. if not linkinfo then
  17. return
  18. end
  19. table.insert(result.linkdirs, linkinfo.linkdir)
  20. if rdir == "intel64" then
  21. table.insert(result.links, "mkl_blas95_" .. suffix)
  22. table.insert(result.links, "mkl_lapack95_" .. suffix)
  23. else
  24. table.insert(result.links, "mkl_blas95")
  25. table.insert(result.links, "mkl_lapack95")
  26. end
  27. local group = {}
  28. if rdir == "intel64" then
  29. table.insert(group, "mkl_intel_" .. suffix)
  30. elseif package:is_plat("windows") then
  31. table.insert(group, "mkl_intel_c")
  32. else
  33. table.insert(group, "mkl_intel")
  34. end
  35. local threading = package:config("threading")
  36. if threading == "tbb" then
  37. table.join2(group, {"mkl_tbb_thread", "mkl_core"})
  38. elseif threading == "seq" then
  39. table.join2(group, {"mkl_sequential", "mkl_core"})
  40. elseif threading == "openmp" then
  41. table.join2(group, {"mkl_intel_thread", "mkl_core"})
  42. end
  43. if package:has_tool("cc", "gcc", "gxx") then
  44. result.ldflags = "-Wl,--start-group "
  45. for _, lib in ipairs(group) do
  46. result.ldflags = result.ldflags .. "-l" .. lib .. " "
  47. end
  48. result.ldflags = result.ldflags .. "-Wl,--end-group"
  49. else
  50. table.join2(result.links, group)
  51. end
  52. -- find include
  53. local includepath = find_path(path.join("mkl.h"), paths, {suffixes = "include"})
  54. if includepath then
  55. table.insert(result.includedirs, includepath)
  56. end
  57. if #result.includedirs > 0 and #result.linkdirs > 0 then
  58. local version_file = path.join(includepath, "mkl_version.h")
  59. if os.isfile(version_file) then
  60. local content = io.readfile(version_file)
  61. local major = content:match("__INTEL_MKL__ +(%d+)\n")
  62. local minor = content:match("__INTEL_MKL_MINOR__ +(%d+)\n")
  63. local patch = content:match("__INTEL_MKL_UPDATE__ +(%d+)\n")
  64. if patch then
  65. result.version = format("%s.%s.%s", major, minor, patch)
  66. else
  67. result.version = format("%s.%s", major, minor)
  68. end
  69. end
  70. return result
  71. end
  72. end
  73. function main(package, opt)
  74. if opt.system and package.find_package then
  75. local result = _find_package(package, opt)
  76. if not result then
  77. result = package:find_package("mkl", opt)
  78. end
  79. return result or false
  80. end
  81. end