xmake.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package("opencl")
  2. set_homepage("https://opencl.org/")
  3. set_description("OpenCL is an open, royalty-free industry standard that makes much faster computations possible through parallel computing.")
  4. add_configs("vendor", {description = "Set OpenCL Vendor.", default = nil, type = "string", values = {"nvidia", "intel", "amd"}})
  5. on_fetch(function (package, opt)
  6. if opt.system then
  7. import("lib.detect.find_path")
  8. import("lib.detect.find_library")
  9. import("detect.sdks.find_cuda")
  10. local result = {includedirs = {}, linkdirs = {}, links = {"OpenCL"}}
  11. local vendor = package:config("vendor")
  12. local archsuffixes = {"lib"}
  13. if package:is_arch("x64") then
  14. table.insert(archsuffixes, "lib64")
  15. table.insert(archsuffixes, path.join("lib", "x64"))
  16. elseif package:is_arch("x86", "i386") then
  17. table.insert(archsuffixes, path.join("lib", "x86"))
  18. elseif package:is_arch("x86_64") then
  19. table.insert(archsuffixes, "lib64")
  20. table.insert(archsuffixes, path.join("lib", "x86_64"))
  21. end
  22. if not vendor or vendor == "nvidia" then
  23. local cuda = find_cuda()
  24. if cuda then
  25. result.includedirs = cuda.includedirs
  26. result.linkdirs = cuda.linkdirs
  27. return result
  28. elseif vendor == "nvidia" then
  29. return nil
  30. end
  31. elseif not vendor or vendor == "intel" then
  32. local intelsdkpaths = {"$(env INTELOCLSDKROOT)"}
  33. local linkinfo = find_library("OpenCL", intelsdkpaths, {suffixes = archsuffixes})
  34. if linkinfo then
  35. table.insert(result.linkdirs, linkinfo.linkdir)
  36. local incpath = find_path(path.join("CL", "cl.h"), intelsdkpaths, {suffixes = {"include"}})
  37. if incpath then
  38. table.insert(result.includedirs, incpath)
  39. return result
  40. end
  41. end
  42. if vendor == "intel" then
  43. return nil
  44. end
  45. elseif not vendor or vendor == "amd" then
  46. local amdsdkpaths = {"$(env AMDAPPSDKROOT)"}
  47. local linkinfo = find_library("OpenCL", amdsdkpaths, {suffixes = archsuffixes})
  48. if linkinfo then
  49. table.insert(result.linkdirs, linkinfo.linkdir)
  50. local incpath = find_path(path.join("CL", "cl.h"), amdsdkpaths, {suffixes = {"include"}})
  51. if incpath then
  52. table.insert(result.includedirs, incpath)
  53. return result
  54. end
  55. end
  56. if vendor == "amd" then
  57. return nil
  58. end
  59. end
  60. end
  61. end)