xmake.lua 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package("safetyhook")
  2. set_homepage("https://cursey.dev/safetyhook")
  3. set_description("C++23 procedure hooking library.")
  4. set_license("BSL-1.0")
  5. add_urls("https://github.com/cursey/safetyhook/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/cursey/safetyhook.git")
  7. add_versions("v0.6.6", "3189b59255d9824fd7e501bb0353f46f0f1e487116cff56090766ef1fd136bc9")
  8. add_versions("v0.6.5", "453e6c200fa9c5384ea3351f1e655759744909b3436d31bf00c003af8212352c")
  9. add_versions("v0.6.4", "57c2a7e23e9e0857eb0f5c6322d97d75147b579ae2b8831c821e6dbf6da04298")
  10. add_deps("cmake", "zydis 4.1.0")
  11. on_check(function (package)
  12. import("core.base.semver")
  13. if package:is_plat("windows") then
  14. local msvc = package:toolchain("msvc")
  15. if msvc then
  16. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  17. assert(vs_toolset and semver.new(vs_toolset):minor() >= 30, "package(safetyhook): need vs_toolset >= v143")
  18. end
  19. end
  20. if not package:is_arch("i386", "x86", "x64", "x86_64") then
  21. raise("package(safetyhook) only support x86 arch")
  22. end
  23. end)
  24. on_install("windows", "linux", "mingw", "msys", function (package)
  25. local configs = {"-DSAFETYHOOK_FETCH_ZYDIS=OFF", "-DSAFETYHOOK_BUILD_TEST=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. import("package.tools.cmake").install(package, configs, {packagedeps = {"zycore-c"}})
  29. end)
  30. on_test(function (package)
  31. assert(package:check_cxxsnippets({test = [[
  32. SAFETYHOOK_NOINLINE int add(int x, int y) {
  33. return x + y;
  34. }
  35. SafetyHookInline g_add_hook{};
  36. int hook_add(int x, int y) {
  37. return g_add_hook.call<int>(x * 2, y * 2);
  38. }
  39. void test() {
  40. g_add_hook = safetyhook::create_inline(reinterpret_cast<void*>(add), reinterpret_cast<void*>(hook_add));
  41. }
  42. ]]}, {configs = {languages = "c++23"}, includes = "safetyhook.hpp"}))
  43. end)