xmake.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package("cpu-features")
  2. set_homepage("https://github.com/google/cpu_features")
  3. set_description("A cross platform C99 library to get cpu features at runtime.")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/google/cpu_features/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/google/cpu_features.git")
  7. add_versions("v0.10.1", "52639b380fced11d738f8b151dbfee63fb94957731d07f1966c812e5b90cbad4")
  8. add_versions("v0.10.0", "dc1be36d02b178e904aa91cce5c2701fe418d728f1c0a130a4196b66b087471a")
  9. add_versions("v0.6.0", "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932")
  10. add_versions("v0.7.0", "df80d9439abf741c7d2fdcdfd2d26528b136e6c52976be8bd0cd5e45a27262c0")
  11. add_versions("v0.9.0", "bdb3484de8297c49b59955c3b22dba834401bc2df984ef5cfc17acbe69c5018e")
  12. add_configs("tools", {description = "Build tools", default = true, type = "boolean"})
  13. if not is_host("windows") and is_plat("windows") then
  14. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  15. end
  16. if is_plat("macosx") then
  17. add_extsources("brew::cpu_features")
  18. end
  19. add_deps("cmake")
  20. on_check("windows|arm64", function (package)
  21. if not package:is_cross() then
  22. raise("package(cpu-features) unsupported windows arm64 native build")
  23. end
  24. end)
  25. on_load(function (package)
  26. if package:config("tools") then
  27. package:addenv("PATH", "bin")
  28. end
  29. end)
  30. on_install("!wasm", function (package)
  31. if package:is_cross() then
  32. local arch
  33. if package:is_arch("arm.*") then
  34. arch = (package:is_arch64() and "set(PROCESSOR_IS_AARCH64 TRUE)" or "set(PROCESSOR_IS_ARM TRUE)")
  35. io.replace("CMakeLists.txt", "set(PROCESSOR_IS_X86 TRUE)", arch, {plain = true})
  36. end
  37. end
  38. local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_INSTALL=ON"}
  39. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  40. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  41. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=" .. (package:config("pic") and "ON" or "OFF"))
  42. table.insert(configs, "-DBUILD_PIC=" .. (package:config("pic") and "ON" or "OFF"))
  43. if package:is_plat("cross", "iphoneos") then
  44. table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=" .. package:arch())
  45. end
  46. if package:config("shared") and package:is_plat("windows") then
  47. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  48. end
  49. table.insert(configs, "-DBUILD_EXECUTABLE=" .. (package:config("tools") and "ON" or "OFF"))
  50. import("package.tools.cmake").install(package, configs)
  51. end)
  52. on_test(function (package)
  53. if not package:is_cross() and package:config("tools") then
  54. os.vrun("list_cpu_features")
  55. end
  56. assert(package:check_csnippets({test = [[
  57. #include <cpu_features/cpu_features_macros.h>
  58. #if defined(CPU_FEATURES_ARCH_X86)
  59. #include <cpu_features/cpuinfo_x86.h>
  60. #elif defined(CPU_FEATURES_ARCH_ARM)
  61. #include <cpu_features/cpuinfo_arm.h>
  62. #elif defined(CPU_FEATURES_ARCH_AARCH64)
  63. #include <cpu_features/cpuinfo_aarch64.h>
  64. #elif defined(CPU_FEATURES_ARCH_MIPS)
  65. #include <cpu_features/cpuinfo_mips.h>
  66. #elif defined(CPU_FEATURES_ARCH_PPC)
  67. #include <cpu_features/ccpuinfo_ppc.h>
  68. #endif
  69. void test() {
  70. #if defined(CPU_FEATURES_ARCH_X86)
  71. X86Features features = GetX86Info().features;
  72. #elif defined(CPU_FEATURES_ARCH_ARM)
  73. ArmFeatures features = GetArmInfo().features;
  74. #elif defined(CPU_FEATURES_ARCH_AARCH64)
  75. Aarch64Features features = GetAarch64Info().features;
  76. #elif defined(CPU_FEATURES_ARCH_MIPS)
  77. MipsFeatures features = GetMipsInfo().features;
  78. #elif defined(CPU_FEATURES_ARCH_PPC)
  79. PPCFeatures features = GetPPCInfo().features;
  80. #endif
  81. }
  82. ]]}))
  83. end)