xmake.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package("lief")
  2. set_homepage("https://lief.quarkslab.com")
  3. set_description("Library to Instrument Executable Formats.")
  4. set_license("Apache-2.0")
  5. set_urls("https://github.com/lief-project/LIEF/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/lief-project/LIEF.git")
  7. add_versions("0.15.1", "28653b59afc8b8b255251f21a0f3cbfbdec05dd988fb3f473e22dde28f427ad8")
  8. add_versions("0.10.1", "6f30c98a559f137e08b25bcbb376c0259914b33c307b8b901e01ca952241d00a")
  9. add_versions("0.11.5", "6d6d57304a56850958e4ce54f3da2ea2b9eb856ccbab61c6cde9cba15d7c9da5")
  10. add_versions("0.14.0", "400804e38cb5ce8d15fb52a4db6345f02da7b2e5cb773665712283001482b808")
  11. add_versions("0.14.1", "92916dcb3178353d863aef4f409186889983c56e025b774741d5316a72ec3a7d")
  12. add_patches("<=0.15.1", "patches/0.15.1/algorithm.patch", "3e110539c3db037b2b24cd32f97ad8cc6241b1f69d4a65dab9fd6c84e482bbd9")
  13. add_configs("elf", {description = "Enable ELF module.", default = true, type = "boolean"})
  14. add_configs("pe", {description = "Enable PE module.", default = true, type = "boolean"})
  15. add_configs("macho", {description = "Enable MachO module.", default = true, type = "boolean"})
  16. add_configs("dex", {description = "Enable Dex module.", default = false, type = "boolean"})
  17. add_configs("vdex", {description = "Enable Vdex module.", default = false, type = "boolean"})
  18. add_configs("oat", {description = "Enable Oat module.", default = false, type = "boolean"})
  19. add_configs("art", {description = "Enable Art module.", default = false, type = "boolean"})
  20. add_configs("exceptions", {description = "Build with exception support.", default = true, type = "boolean"})
  21. if is_plat("windows") then
  22. add_syslinks("advapi32")
  23. end
  24. add_deps("cmake")
  25. add_deps("spdlog", {configs = {header_only = false, noexcept = true}})
  26. add_deps("nlohmann_json", {configs = {cmake = true}})
  27. add_deps("tl_expected", "utfcpp", "mbedtls <3.6.0", "tcb-span", "frozen")
  28. if on_check then
  29. on_check(function (package)
  30. if package:is_plat("windows") then
  31. local vs_toolset = package:toolchain("msvc"):config("vs_toolset")
  32. if vs_toolset then
  33. local vs_toolset_ver = import("core.base.semver").new(vs_toolset)
  34. local minor = vs_toolset_ver:minor()
  35. assert(minor and minor >= 30, "package(lief) require vs_toolset >= 14.3")
  36. end
  37. end
  38. if package:is_arch("arm.*") then
  39. raise("package(lief) dep(mbedtls <3.6.0) unsupported arm arch")
  40. end
  41. end)
  42. end
  43. on_install(function (package)
  44. if package:config("shared") then
  45. package:add("defines", "LIEF_IMPORT")
  46. end
  47. io.replace("CMakeLists.txt", "target_link_libraries(LIB_LIEF PRIVATE utf8cpp)", "target_link_libraries(LIB_LIEF PRIVATE utf8cpp::utf8cpp)", {plain = true})
  48. local configs = {
  49. "-DLIEF_C_API=ON",
  50. "-DLIEF_PYTHON_API=OFF",
  51. "-DLIEF_DOC=OFF",
  52. "-DLIEF_TESTS=OFF",
  53. "-DLIEF_EXAMPLES=OFF",
  54. "-DLIEF_INSTALL_PYTHON=OFF",
  55. "-DLIEF_EXTERNAL_SPDLOG=ON",
  56. "-DLIEF_OPT_EXTERNAL_EXPECTED=ON",
  57. "-DLIEF_OPT_UTFCPP_EXTERNAL=ON",
  58. "-DLIEF_OPT_MBEDTLS_EXTERNAL=ON",
  59. "-DLIEF_OPT_EXTERNAL_SPAN=ON",
  60. "-DLIEF_ENABLE_JSON=ON",
  61. "-DLIEF_OPT_NLOHMANN_JSON_EXTERNAL=ON",
  62. "-DLIEF_OPT_FROZEN_EXTERNAL=ON",
  63. "-DLIEF_DISABLE_FROZEN=OFF",
  64. }
  65. table.insert(configs, "-DLIEF_EXTERNAL_SPAN_DIR=" .. package:dep("tcb-span"):installdir("include"))
  66. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  67. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  68. table.insert(configs, "-DLIEF_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
  69. table.insert(configs, "-DLIEF_DISABLE_EXCEPTIONS=" .. (package:config("exceptions") and "OFF" or "ON"))
  70. for name, enabled in pairs(package:configs()) do
  71. if not package:extraconf("configs", name, "builtin") then
  72. table.insert(configs, "-DLIEF_" .. name:upper() .. "=" .. (enabled and "ON" or "OFF"))
  73. end
  74. end
  75. import("package.tools.cmake").install(package, configs)
  76. end)
  77. on_test(function (package)
  78. local parse_entry
  79. if package:config("elf") then
  80. parse_entry = "elf_parse"
  81. elseif package:config("pe") then
  82. parse_entry = "pe_parse"
  83. elseif package:config("macho") then
  84. parse_entry = "macho_parse"
  85. end
  86. if parse_entry then
  87. assert(package:has_cfuncs(parse_entry, {includes = "LIEF/LIEF.h"}))
  88. end
  89. end)