xmake.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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.3", "5572eecd903fff0e66694310ca438531243b18782ce331a4262eeb6f6ad675bc")
  8. add_versions("2.1.1", "8740b03053162c1ace651364c4c5e31859eeb6c522859aa00cb4c31fa9cbbed2")
  9. add_deps("cmake")
  10. add_deps("glib")
  11. if is_plat("linux", "bsd") then
  12. add_syslinks("pthread", "m")
  13. end
  14. add_configs("logging", {description = "Enable logging", default = false, type = "boolean"})
  15. add_configs("tracer", {description = "Trace unicorn execution", default = false, type = "boolean"})
  16. add_configs("archs", {description = "Enabled unicorn architectures", default = {"x86", "aarch64"}, type = "table"})
  17. on_load(function (package)
  18. if package:is_plat("windows") and package:config("shared") then
  19. package:add("defines", "UNICORN_SHARED")
  20. end
  21. end)
  22. on_install("windows|!arm64", "macosx", "linux", "cross", function (package)
  23. io.replace("CMakeLists.txt", "if(UNICORN_INSTALL AND NOT MSVC)", "if(1)", {plain = true})
  24. local configs = {"-DUNICORN_BUILD_TESTS=OFF"}
  25. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  26. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  27. table.insert(configs, "-DUNICORN_LOGGING=" .. (package:config("logging") and "ON" or "OFF"))
  28. table.insert(configs, "-DUNICORN_TRACER=" .. (package:config("tracer") and "ON" or "OFF"))
  29. local archs = table.concat(package:config("archs"), ";")
  30. table.insert(configs, "-DUNICORN_ARCH=" .. archs)
  31. import("package.tools.cmake").install(package, configs)
  32. -- Do not install .o file into lib folder or it would fail to link against it
  33. os.rm(package:installdir("lib/*.o"))
  34. os.rm(package:installdir("lib/*.obj"))
  35. if package:config("shared") then
  36. os.tryrm(package:installdir("lib/unicorn.lib"))
  37. os.rm(package:installdir("lib/*.a"))
  38. end
  39. if package:is_plat("windows") and package:config("shared") then
  40. io.replace(package:installdir("include/unicorn/unicorn.h"), "__declspec(dllexport)", "__declspec(dllimport)", {plain = true})
  41. end
  42. end)
  43. on_test(function (package)
  44. assert(package:has_cfuncs("uc_open", {includes = "unicorn/unicorn.h"}))
  45. end)