fetch.lua 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import("lib.detect.find_path")
  2. import("lib.detect.find_library")
  3. function _find_package(package, opt)
  4. local paths = {
  5. "$(env DPL_ROOT)",
  6. "$(env ONEAPI_ROOT)/dpl/latest"
  7. }
  8. -- find library
  9. local result = {links = {}, linkdirs = {}, includedirs = {}}
  10. -- find include
  11. local includepath = find_path(path.join("oneapi", "dpl", "algorithm"), paths, {suffixes = "include"})
  12. if includepath then
  13. table.insert(result.includedirs, includepath)
  14. end
  15. if #result.includedirs > 0 then
  16. local version_file = path.join(includepath, "oneapi", "dpl", "pstl", "onedpl_config.h")
  17. if os.isfile(version_file) then
  18. local content = io.readfile(version_file)
  19. local major = content:match("ONEDPL_VERSION_MAJOR +(%d+)\n")
  20. local minor = content:match("ONEDPL_VERSION_MINOR +(%d+)\n")
  21. local patch = content:match("ONEDPL_VERSION_PATCH +(%d+)\n")
  22. if patch then
  23. result.version = format("%s.%s.%s", major, minor, patch)
  24. else
  25. result.version = format("%s.%s", major, minor)
  26. end
  27. end
  28. return result
  29. end
  30. end
  31. function main(package, opt)
  32. if opt.system and package.find_package then
  33. local result = _find_package(package, opt)
  34. if not result then
  35. result = package:find_package("onedpl", opt)
  36. end
  37. return result or false
  38. end
  39. end