xmake.lua 3.6 KB

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