xmake.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_deps("cmake", "python 3.x", {kind = "binary"})
  9. if is_plat("windows", "mingw") then
  10. add_syslinks("shell32", "ole32", "uuid")
  11. end
  12. on_load(function (package)
  13. if package:is_cross() or package:is_plat("mingw") or (package:is_plat("windows") and package:config("shared")) then
  14. package:data_set("build_libs_only", true)
  15. end
  16. if not package:data("build_libs_only") then
  17. package:addenv("PATH", "bin")
  18. end
  19. end)
  20. on_install(function (package)
  21. io.replace("CMakeLists.txt", "add_subdirectory(suite/fuzz)", "", {plain = true})
  22. io.replace("llvm/keystone/CMakeLists.txt",
  23. "install(TARGETS keystone DESTINATION lib${LLVM_LIBDIR_SUFFIX})", [[
  24. install(TARGETS keystone
  25. RUNTIME DESTINATION bin
  26. LIBRARY DESTINATION lib
  27. ARCHIVE DESTINATION lib
  28. )
  29. install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include)
  30. ]], {plain = true})
  31. local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  34. table.insert(configs, "-DBUILD_LIBS_ONLY=" .. (package:data("build_libs_only") and "ON" or "OFF"))
  35. if package:is_plat("windows") then
  36. table.insert(configs, "-DKEYSTONE_BUILD_STATIC_RUNTIME=" .. (package:has_runtime("MT", "MTd") and "ON" or "OFF"))
  37. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  38. end
  39. import("package.tools.cmake").install(package, configs)
  40. if package:is_plat("windows") and package:is_debug() then
  41. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  42. os.vcp(path.join(package:buildir(), "llvm/**.pdb"), dir)
  43. os.trycp(path.join(package:buildir(), "kstool/kstool.pdb"), package:installdir("bin"))
  44. end
  45. end)
  46. on_test(function (package)
  47. if not package:data("build_libs_only") then
  48. os.vrun('kstool -b x64 "mov rax, 1; ret"')
  49. end
  50. assert(package:has_cfuncs("ks_version", {includes = "keystone/keystone.h"}))
  51. end)