xmake.lua 2.7 KB

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