xmake.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package("unicorn")
  2. set_homepage("http://www.unicorn-engine.org")
  3. set_description("Unicorn CPU emulator framework (ARM, AArch64, M68K, Mips, Sparc, PowerPC, RiscV, S390x, TriCore, X86)")
  4. set_license("GPL-2.0")
  5. add_urls("https://github.com/unicorn-engine/unicorn/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/unicorn-engine/unicorn.git")
  7. add_versions("2.1.1", "8740b03053162c1ace651364c4c5e31859eeb6c522859aa00cb4c31fa9cbbed2")
  8. add_deps("cmake")
  9. add_deps("glib")
  10. if is_plat("linux", "bsd") then
  11. add_syslinks("pthread", "m")
  12. end
  13. add_configs("logging", {description = "Enable logging", default = false, type = "boolean"})
  14. add_configs("tracer", {description = "Trace unicorn execution", default = false, type = "boolean"})
  15. add_configs("archs", {description = "Enabled unicorn architectures", default = {"x86", "aarch64"}, type = "table"})
  16. on_load(function (package)
  17. if package:is_plat("windows") and package:config("shared") then
  18. package:add("defines", "UNICORN_SHARED")
  19. end
  20. end)
  21. on_install("windows|!arm64", "macosx", "linux", "cross", function (package)
  22. io.replace("CMakeLists.txt", "if(UNICORN_INSTALL AND NOT MSVC)", "if(1)", {plain = true})
  23. local configs = {"-DUNICORN_BUILD_TESTS=OFF"}
  24. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  25. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  26. table.insert(configs, "-DUNICORN_LOGGING=" .. (package:config("logging") and "ON" or "OFF"))
  27. table.insert(configs, "-DUNICORN_TRACER=" .. (package:config("tracer") and "ON" or "OFF"))
  28. local archs = table.concat(package:config("archs"), ";")
  29. table.insert(configs, "-DUNICORN_ARCH=" .. archs)
  30. import("package.tools.cmake").install(package, configs)
  31. if package:config("shared") then
  32. os.tryrm(package:installdir("lib/unicorn.lib"))
  33. os.rm(package:installdir("lib/*.a"))
  34. end
  35. if package:is_plat("windows") then
  36. if package:config("shared") then
  37. io.replace(package:installdir("include/unicorn/unicorn.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true})
  38. end
  39. if package:is_debug() then
  40. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  41. os.trycp(path.join(package:buildir(), "unicorn.pdb"), dir)
  42. end
  43. end
  44. end)
  45. on_test(function (package)
  46. assert(package:has_cfuncs("uc_open", {includes = "unicorn/unicorn.h"}))
  47. end)