xmake.lua 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package("keystone")
  2. set_homepage("http://www.keystone-engine.org")
  3. set_description("Keystone assembler framework: Core (Arm, Arm64, Hexagon, Mips, PowerPC, Sparc, SystemZ & X86) + bindings")
  4. set_license("GPL-2.0")
  5. add_urls("https://github.com/keystone-engine/keystone/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/keystone-engine/keystone.git")
  7. add_versions("0.9.2", "c9b3a343ed3e05ee168d29daf89820aff9effb2c74c6803c2d9e21d55b5b7c24")
  8. add_patches("0.9.2", "patches/0.9.2/fix-gcc15.diff", "6b2140fdb0e446d746feb44e71d6f6cf1afcc733282de364be37f527ab7d039f")
  9. add_deps("cmake", "python 3.x", {kind = "binary"})
  10. if is_subhost("windows") then
  11. add_deps("pkgconf")
  12. else
  13. add_deps("pkg-config")
  14. end
  15. if is_plat("windows", "mingw") then
  16. add_syslinks("shell32", "ole32", "uuid")
  17. end
  18. on_load(function (package)
  19. if package:is_cross() or package:is_plat("mingw") or
  20. (package:is_plat("windows") and package:config("shared")) or
  21. (package:is_plat("windows") and package:has_tool("cc", "clang", "clang_cl")) then
  22. package:data_set("build_libs_only", true)
  23. end
  24. if not package:data("build_libs_only") then
  25. package:addenv("PATH", "bin")
  26. end
  27. end)
  28. on_install(function (package)
  29. io.replace("CMakeLists.txt", "add_subdirectory(suite/fuzz)", "", {plain = true})
  30. io.replace("llvm/keystone/CMakeLists.txt",
  31. "install(TARGETS keystone DESTINATION lib${LLVM_LIBDIR_SUFFIX})", [[
  32. install(TARGETS keystone
  33. RUNTIME DESTINATION bin
  34. LIBRARY DESTINATION lib
  35. ARCHIVE DESTINATION lib
  36. )
  37. install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include)
  38. ]], {plain = true})
  39. local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
  40. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  41. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  42. table.insert(configs, "-DBUILD_LIBS_ONLY=" .. (package:data("build_libs_only") and "ON" or "OFF"))
  43. if package:is_plat("windows") then
  44. table.insert(configs, "-DKEYSTONE_BUILD_STATIC_RUNTIME=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
  45. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  46. end
  47. import("package.tools.cmake").install(package, configs)
  48. if package:is_plat("windows") and package:is_debug() then
  49. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  50. os.vcp(path.join(package:buildir(), "llvm/**.pdb"), dir)
  51. os.trycp(path.join(package:buildir(), "kstool/kstool.pdb"), package:installdir("bin"))
  52. end
  53. end)
  54. on_test(function (package)
  55. if not package:data("build_libs_only") then
  56. os.vrun('kstool -b x64 "mov rax, 1; ret"')
  57. end
  58. assert(package:has_cfuncs("ks_version", {includes = "keystone/keystone.h"}))
  59. end)