xmake.lua 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.6.0", "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932")
  8. add_versions("v0.7.0", "df80d9439abf741c7d2fdcdfd2d26528b136e6c52976be8bd0cd5e45a27262c0")
  9. add_versions("v0.9.0", "bdb3484de8297c49b59955c3b22dba834401bc2df984ef5cfc17acbe69c5018e")
  10. if is_plat("macosx") then
  11. add_extsources("brew::cpu_features")
  12. end
  13. add_deps("cmake")
  14. on_install("!wasm", function (package)
  15. if package:is_cross() then
  16. local arch
  17. if package:is_arch("arm.*") then
  18. arch = (package:is_arch64() and "set(PROCESSOR_IS_AARCH64 TRUE)" or "set(PROCESSOR_IS_ARM TRUE)")
  19. io.replace("CMakeLists.txt", "set(PROCESSOR_IS_X86 TRUE)", arch, {plain = true})
  20. end
  21. end
  22. local configs = {"-DBUILD_TESTING=OFF", "-DENABLE_INSTALL=ON", "-DBUILD_EXECUTABLE=ON"}
  23. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  24. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  25. table.insert(configs, "-DCMAKE_POSITION_INDEPENDENT_CODE=" .. (package:config("pic") and "ON" or "OFF"))
  26. table.insert(configs, "-DBUILD_PIC=" .. (package:config("pic") and "ON" or "OFF"))
  27. if package:is_plat("cross", "iphoneos") then
  28. table.insert(configs, "-DCMAKE_SYSTEM_PROCESSOR=" .. package:arch())
  29. end
  30. if package:config("shared") and package:is_plat("windows") then
  31. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  32. end
  33. import("package.tools.cmake").install(package, configs)
  34. package:addenv("PATH", "bin")
  35. if package:is_plat("windows") and package:is_debug() then
  36. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  37. os.vcp(path.join(package:buildir(), "*.pdb"), dir)
  38. end
  39. end)
  40. on_test(function (package)
  41. if not package:is_cross() then
  42. os.vrun("list_cpu_features")
  43. end
  44. assert(package:check_csnippets({test = [[
  45. #include <cpu_features/cpu_features_macros.h>
  46. #if defined(CPU_FEATURES_ARCH_X86)
  47. #include <cpu_features/cpuinfo_x86.h>
  48. #elif defined(CPU_FEATURES_ARCH_ARM)
  49. #include <cpu_features/cpuinfo_arm.h>
  50. #elif defined(CPU_FEATURES_ARCH_AARCH64)
  51. #include <cpu_features/cpuinfo_aarch64.h>
  52. #elif defined(CPU_FEATURES_ARCH_MIPS)
  53. #include <cpu_features/cpuinfo_mips.h>
  54. #elif defined(CPU_FEATURES_ARCH_PPC)
  55. #include <cpu_features/ccpuinfo_ppc.h>
  56. #endif
  57. void test() {
  58. #if defined(CPU_FEATURES_ARCH_X86)
  59. X86Features features = GetX86Info().features;
  60. #elif defined(CPU_FEATURES_ARCH_ARM)
  61. ArmFeatures features = GetArmInfo().features;
  62. #elif defined(CPU_FEATURES_ARCH_AARCH64)
  63. Aarch64Features features = GetAarch64Info().features;
  64. #elif defined(CPU_FEATURES_ARCH_MIPS)
  65. MipsFeatures features = GetMipsInfo().features;
  66. #elif defined(CPU_FEATURES_ARCH_PPC)
  67. PPCFeatures features = GetPPCInfo().features;
  68. #endif
  69. }
  70. ]]}))
  71. end)