xmake.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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("4.3.0", "006f5784a9bcee43e5a7e943dc4f02de1ba2ee7a7af1ee5f190d383f3b6c9ebe")
  7. add_versions("4.2.0", "8a4d051df2ab2218998a16f7712e843ee9e96d8b09ffbfcc18533da127e0da02")
  8. add_versions("3.3.2", "5d25d16e77c844c297ece2044df57651139bc3c8ad8c4108916374267ac68b64")
  9. add_versions("3.2.1", "bd98e3b501b4c24dc127f4ad93e467f42923fe3eefa99e143b5b93158f024395")
  10. add_configs("gpu", {description = "Enable GPU-accelerated training.", default = false, type = "boolean"})
  11. add_deps("cmake")
  12. on_load("windows|x64", "linux", function (package)
  13. if package:config("gpu") then
  14. package:add("deps", "opencl")
  15. package:add("deps", "boost", {configs = {filesystem = true, system = true}})
  16. end
  17. if package:is_plat("linux") and package:has_tool("cc", "clang", "clangxx") then
  18. package:add("deps", "libomp")
  19. end
  20. end)
  21. on_install("windows|x64", "linux", function (package)
  22. if package:version():lt("4.2.0") then
  23. os.cd("compile")
  24. end
  25. local configs = {"-DBoost_USE_STATIC_LIBS=ON", "-DBUILD_CLI=OFF"}
  26. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  27. table.insert(configs, "-DBUILD_STATIC_LIB=" .. (package:config("shared") and "OFF" or "ON"))
  28. if package:is_plat("windows") then
  29. table.insert(configs, "-DBoost_USE_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  30. end
  31. if package:is_plat("linux") and package:has_tool("cc", "clang", "clangxx") then
  32. local libomp = package:dep("libomp"):fetch()
  33. if libomp then
  34. local includedirs = table.wrap(libomp.includedirs or libomp.sysincludedirs)
  35. local libfiles = table.wrap(libomp.libfiles)
  36. if #includedirs > 0 and #libfiles > 0 then
  37. table.insert(configs, "-DOpenMP_C_LIB_NAMES=libomp")
  38. table.insert(configs, "-DOpenMP_C_FLAGS=-I" .. includedirs[1])
  39. table.insert(configs, "-DOpenMP_CXX_LIB_NAMES=libomp")
  40. table.insert(configs, "-DOpenMP_CXX_FLAGS=-I" .. includedirs[1])
  41. table.insert(configs, "-DOpenMP_libomp_LIBRARY=" .. table.concat(libfiles, " "))
  42. end
  43. end
  44. end
  45. import("package.tools.cmake").install(package, configs)
  46. package:addenv("PATH", "bin")
  47. end)
  48. on_test(function (package)
  49. assert(package:has_cxxtypes("LightGBM::ChunkedArray<int>", {includes = "LightGBM/utils/chunked_array.hpp"}))
  50. end)