xmake.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package("lightgbm")
  2. set_homepage("https://github.com/microsoft/LightGBM")
  3. set_description("LightGBM is a gradient boosting framework that uses tree based learning algorithms.")
  4. set_license("MIT")
  5. add_urls("https://github.com/microsoft/LightGBM/releases/download/v$(version)/lightgbm-$(version).tar.gz")
  6. add_versions("3.3.2", "5d25d16e77c844c297ece2044df57651139bc3c8ad8c4108916374267ac68b64")
  7. add_versions("3.2.1", "bd98e3b501b4c24dc127f4ad93e467f42923fe3eefa99e143b5b93158f024395")
  8. add_configs("gpu", {description = "Enable GPU-accelerated training.", default = false, type = "boolean"})
  9. add_deps("cmake")
  10. on_load("windows|x64", "linux", function (package)
  11. if package:config("gpu") then
  12. package:add("deps", "opencl")
  13. package:add("deps", "boost", {configs = {filesystem = true, system = true}})
  14. end
  15. if package:is_plat("linux") and package:has_tool("cc", "clang", "clangxx") then
  16. package:add("deps", "libomp")
  17. end
  18. end)
  19. on_install("windows|x64", "linux", function (package)
  20. os.cd("compile")
  21. local configs = {"-DBoost_USE_STATIC_LIBS=ON"}
  22. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  23. table.insert(configs, "-DBUILD_STATIC_LIB=" .. (package:config("shared") and "OFF" or "ON"))
  24. if package:is_plat("windows") then
  25. table.insert(configs, "-DBoost_USE_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  26. end
  27. if package:is_plat("linux") and package:has_tool("cc", "clang", "clangxx") then
  28. local libomp = package:dep("libomp"):fetch()
  29. if libomp then
  30. local includedirs = table.wrap(libomp.includedirs or libomp.sysincludedirs)
  31. local libfiles = table.wrap(libomp.libfiles)
  32. if #includedirs > 0 and #libfiles > 0 then
  33. table.insert(configs, "-DOpenMP_C_LIB_NAMES=libomp")
  34. table.insert(configs, "-DOpenMP_C_FLAGS=-I" .. includedirs[1])
  35. table.insert(configs, "-DOpenMP_CXX_LIB_NAMES=libomp")
  36. table.insert(configs, "-DOpenMP_CXX_FLAGS=-I" .. includedirs[1])
  37. table.insert(configs, "-DOpenMP_libomp_LIBRARY=" .. table.concat(libfiles, " "))
  38. end
  39. end
  40. end
  41. import("package.tools.cmake").install(package, configs)
  42. package:addenv("PATH", "bin")
  43. end)
  44. on_test(function (package)
  45. assert(package:has_cxxtypes("LightGBM::ChunkedArray<int>", {includes = "LightGBM/utils/chunked_array.hpp"}))
  46. end)