xmake.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package("pcapplusplus")
  2. set_homepage("https://github.com/seladb/PcapPlusPlus")
  3. set_description("PcapPlusPlus is a multiplatform C++ library for capturing, parsing and crafting of network packets.")
  4. set_license("Unlicense")
  5. set_urls("https://github.com/seladb/PcapPlusPlus/archive/refs/tags/$(version).zip",
  6. "https://github.com/seladb/PcapPlusPlus.git")
  7. add_versions("v24.09", "0a9d80d09a906c08a1df5f5a937134355c7cb3fc8a599bf1a0f10002cf0285be")
  8. add_versions("v23.09", "f2b92d817df6138363be0d144a61716f8ecc43216f0008135da2e0e15727d35a")
  9. add_patches("v24.09", "patches/v24.09/vla.patch", "8c380468c78118b6d85f6b3856cd49c4d890fd326dde3400b8c47c01c885cef4")
  10. add_patches("v24.09", "patches/v24.09/explicit-override.patch", "d4ff15e920ea4996f6d3105e898e42d75cfab47b7e930467442ae356a361cf25")
  11. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  12. add_configs("zstd", {description = "Support compile with zstd", default = false, type = "boolean"})
  13. add_configs("winpcap", {description = "Support compile with winpcap", default = false, type = "boolean"})
  14. add_links("Pcap++", "Packet++", "Common++")
  15. if is_plat("windows", "mingw") then
  16. add_syslinks("ws2_32", "iphlpapi")
  17. elseif is_plat("macosx") then
  18. add_frameworks("CoreFoundation", "SystemConfiguration")
  19. elseif is_plat("linux", "bsd") then
  20. add_syslinks("pthread")
  21. end
  22. add_deps("cmake")
  23. on_load(function (package)
  24. if package:config("zstd") then
  25. package:add("deps", "zstd")
  26. end
  27. if package:is_plat("windows") and not package:is_arch("arm.*") then
  28. if package:config("winpcap") then
  29. package:add("deps", "winpcap")
  30. else
  31. package:add("deps", "npcap_sdk")
  32. end
  33. elseif package:is_plat("linux", "macosx", "android", "bsd") then
  34. package:add("deps", "libpcap")
  35. else
  36. package:add("deps", "npcap_sdk")
  37. end
  38. end)
  39. on_install("windows", "mingw", "linux", "macosx", "android", "bsd", function (package)
  40. local configs = {
  41. "-DPCAPPP_BUILD_EXAMPLES=OFF",
  42. "-DPCAPPP_BUILD_TESTS=OFF"
  43. }
  44. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  45. table.insert(configs, "-DLIGHT_PCAPNG_ZSTD=" .. (package:config("zstd") and "ON" or "OFF"))
  46. for _, cmakefile in ipairs(os.files("**/CMakeLists.txt")) do
  47. io.replace(cmakefile, "COMPILE_WARNING_AS_ERROR ON", "COMPILE_WARNING_AS_ERROR OFF")
  48. end
  49. import("package.tools.cmake").install(package, configs)
  50. end)
  51. on_test(function (package)
  52. assert(package:check_cxxsnippets({test = [[
  53. #include <vector>
  54. #include "pcapplusplus/IPv4Layer.h"
  55. #include "pcapplusplus/Packet.h"
  56. #include "pcapplusplus/PcapFileDevice.h"
  57. #include "pcapplusplus/PcapLiveDeviceList.h"
  58. void testPcapFileReaderDevice() {
  59. pcpp::PcapFileReaderDevice reader("1_packet.pcap");
  60. }
  61. void testPcapLiveDeviceList() {
  62. std::vector<pcpp::PcapLiveDevice *> devList =
  63. pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList();
  64. }
  65. ]]}, {configs = {languages = "c++17"}}))
  66. end)