xmake.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package("hwinfo")
  2. set_homepage("https://github.com/lfreist/hwinfo")
  3. set_description("Cross platform C++ library for hardware information (CPU, RAM, GPU, ...)")
  4. set_license("MIT")
  5. add_urls("https://github.com/lfreist/hwinfo.git")
  6. add_versions("2025.05.09", "64bc6ea98518d2964443bb1104cde90e9e031820")
  7. local comps = {"os", "mainboard", "cpu", "disk", "ram", "gpu", "battery", "network"}
  8. for _, c in ipairs(comps) do
  9. add_configs(c, {description = "Enable " .. c .. " information", default = true, type = "boolean"})
  10. end
  11. add_configs("gpu_opencl", {description = "Enable OpenCL support", default = false, type = "boolean"})
  12. if is_plat("linux") then
  13. add_syslinks("pthread", "dl")
  14. end
  15. add_deps("cmake")
  16. on_install("windows", "linux", "macosx", function (package)
  17. local configs = {"-DBUILD_TESTING=OFF", "-DBUILD_EXAMPLES=OFF"}
  18. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  19. table.insert(configs, "-DHWINFO_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  20. table.insert(configs, "-DHWINFO_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  21. table.insert(configs, "-DHWINFO_GPU_OPENCL=" .. (package:config("gpu_opencl") and "ON" or "OFF"))
  22. local comps = {"OS","MAINBOARD","CPU","DISK","RAM","GPU","BATTERY","NETWORK"}
  23. for _, c in ipairs(comps) do
  24. table.insert(configs, "-DHWINFO_" .. c .. "=" .. (package:config(c:lower()) and "ON" or "OFF"))
  25. end
  26. import("package.tools.cmake").install(package, configs)
  27. os.cp("include", package:installdir())
  28. end)
  29. on_test(function (package)
  30. assert(package:check_cxxsnippets({test = [[
  31. #include <iostream>
  32. void test(){
  33. const auto cpus = hwinfo::getAllCPUs();
  34. for(const auto& cpu : cpus){
  35. std::cout << cpu.vendor();
  36. }
  37. }
  38. ]]}, {configs = {languages = "cxx20"}, includes = "hwinfo/hwinfo.h"}))
  39. end)