xmake.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package("openimagedenoise")
  2. set_homepage("https://www.openimagedenoise.org")
  3. set_description("Intel® Open Image Denoise library")
  4. set_license("Apache-2.0")
  5. set_urls("https://github.com/RenderKit/oidn/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/RenderKit/oidn.git", {submodules = false})
  7. add_versions("v2.3.3", "2b32bd506b819ec0bd0137858af15186d83b760d457b0ac12bd02e0a8544381a")
  8. add_configs("cpu", {description = "Enable CPU device.", default = false, type = "boolean"})
  9. add_configs("sycl", {description = "Enable SYCL device.", default = false, type = "boolean"})
  10. add_configs("cuda", {description = "Enable CUDA device.", default = false, type = "boolean"})
  11. add_configs("hip", {description = "Enable HIP device.", default = false, type = "boolean"})
  12. add_configs("filter_rt", {description = "Include trained weights of the RT filter.", default = false, type = "boolean"})
  13. add_configs("filter_rtlightmap", {description = "Include trained weights of the RTLightmap filter.", default = false, type = "boolean"})
  14. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  15. if is_plat("mingw") and is_subhost("msys") then
  16. add_extsources("pacman::openimagedenoise")
  17. elseif is_plat("linux") then
  18. add_extsources("pacman::openimagedenoise")
  19. elseif is_plat("macosx") then
  20. add_extsources("brew::open-image-denoise")
  21. end
  22. add_links(
  23. "OpenImageDenoise_device_cpu",
  24. "OpenImageDenoise_device_cuda",
  25. "OpenImageDenoise_device_hip",
  26. "OpenImageDenoise_device_sycl",
  27. "OpenImageDenoise", "OpenImageDenoise_core"
  28. )
  29. if is_plat("linux", "bsd") then
  30. add_syslinks("pthread")
  31. end
  32. add_deps("cmake", "python 3.x", {kind = "binary"})
  33. if on_check then
  34. on_check(function (package)
  35. if package:check_sizeof("void*") == "4" then
  36. raise("package(openimagedenoise) unsupported 32-bit")
  37. end
  38. end)
  39. end
  40. on_load(function (package)
  41. if package:config("cpu") then
  42. package:add("deps", "ispc", "tbb >=2017")
  43. end
  44. if package:config("cuda") then
  45. package:add("deps", "cuda")
  46. end
  47. if package:config("filter_rt") or package:config("filter_rtlightmap") then
  48. local ok = try { function()
  49. os.vrun("git lfs version")
  50. return true
  51. end }
  52. if not ok then
  53. raise("package(openimagedenoise) filter_rt or filter_rtlightmap config require git lfs to donwload weights")
  54. end
  55. package:add("resources", "*", "weights", "https://github.com/RenderKit/oidn-weights.git", "28883d1769d5930e13cf7f1676dd852bd81ed9e7")
  56. end
  57. if not package:config("shared") then
  58. package:add("defines", "OIDN_STATIC_LIB")
  59. end
  60. end)
  61. on_install("!android and !wasm", function (package)
  62. local configs = {}
  63. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  64. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  65. table.insert(configs, "-DOIDN_STATIC_LIB=" .. (package:config("shared") and "OFF" or "ON"))
  66. table.insert(configs, "-DOIDN_DEVICE_CPU=" .. (package:config("cpu") and "ON" or "OFF"))
  67. table.insert(configs, "-DOIDN_DEVICE_SYCL=" .. (package:config("sycl") and "ON" or "OFF"))
  68. table.insert(configs, "-DOIDN_DEVICE_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
  69. table.insert(configs, "-DOIDN_DEVICE_HIP=" .. (package:config("hip") and "ON" or "OFF"))
  70. table.insert(configs, "-DOIDN_FILTER_RT=" .. (package:config("filter_rt") and "ON" or "OFF"))
  71. table.insert(configs, "-DOIDN_FILTER_RTLIGHTMAP=" .. (package:config("filter_rtlightmap") and "ON" or "OFF"))
  72. table.insert(configs, "-DOIDN_APPS=" .. (package:config("tools") and "ON" or "OFF"))
  73. local cuda = package:dep("cuda")
  74. if not is_plat("windows") and package:config("cuda") and cuda then
  75. local fetch = cuda:fetch()
  76. if fetch and fetch.includedirs and #fetch.includedirs ~= 0 then
  77. -- /usr/local/cuda/include -> /usr/local/cuda/bin
  78. table.insert(configs, "-DCUDAToolkit_ROOT=" .. path.join(path.directory(fetch.includedirs[1]), "bin"))
  79. end
  80. end
  81. if package:config("filter_rt") or package:config("filter_rtlightmap") then
  82. local weights = package:resourcedir("weights")
  83. if os.isdir(weights) then
  84. os.vcp(weights, "weights")
  85. else
  86. os.vcp(path.join(path.directory(weights), "**.tza"), "weights/")
  87. end
  88. end
  89. import("package.tools.cmake").install(package, configs)
  90. end)
  91. on_test(function (package)
  92. assert(package:has_cfuncs("oidnGetNumPhysicalDevices", {includes = "OpenImageDenoise/oidn.h"}))
  93. end)