xmake.lua 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package("libevent")
  2. set_homepage("https://libevent.org/")
  3. set_description("libevent – an event notification library")
  4. set_license("BSD-3-Clause")
  5. add_urls("https://github.com/libevent/libevent/releases/download/release-$(version)-stable/libevent-$(version)-stable.tar.gz")
  6. add_urls("https://github.com/libevent/libevent.git")
  7. add_versions("2.1.12", "92e6de1be9ec176428fd2367677e61ceffc2ee1cb119035037a27d346b0403bb")
  8. add_configs("openssl", {description = "Build with OpenSSL library.", default = false, type = "boolean"})
  9. add_configs("mbedtls", {description = "Build with mbedtls library.", default = false, type = "boolean"})
  10. add_deps("cmake")
  11. if is_plat("windows") then
  12. add_syslinks("ws2_32", "advapi32", "iphlpapi")
  13. end
  14. on_load(function (package)
  15. if package:config("openssl") then
  16. package:add("deps", "openssl3")
  17. end
  18. if package:config("mbedtls") then
  19. package:add("deps", "mbedtls")
  20. end
  21. end)
  22. on_install("windows", "linux", "macosx", function (package)
  23. io.replace("CMakeLists.txt", "advapi32", "advapi32 crypt32", {plain = true})
  24. if package:version():eq("2.1.12") then
  25. io.replace("cmake/LibeventConfig.cmake.in",
  26. 'get_filename_component(_INSTALL_PREFIX "${LIBEVENT_CMAKE_DIR}/../../.." ABSOLUTE)',
  27. 'get_filename_component(_INSTALL_PREFIX "${LIBEVENT_CMAKE_DIR}/../.." ABSOLUTE)',
  28. {plain = true})
  29. io.replace("cmake/LibeventConfig.cmake.in", "NO_DEFAULT_PATH)", ")", {plain = true})
  30. end
  31. local configs = {"-DEVENT__DISABLE_TESTS=ON", "-DEVENT__DISABLE_REGRESS=ON", "-DEVENT__DISABLE_SAMPLES=ON"}
  32. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  33. table.insert(configs, "-DEVENT__LIBRARY_TYPE=" .. (package:config("shared") and "SHARED" or "STATIC"))
  34. table.insert(configs, "-DEVENT__DISABLE_OPENSSL=" .. (package:config("openssl") and "OFF" or "ON"))
  35. table.insert(configs, "-DEVENT__DISABLE_MBEDTLS=" .. (package:config("mbedtls") and "OFF" or "ON"))
  36. if package:is_plat("windows") then
  37. table.insert(configs, "-DEVENT__MSVC_STATIC_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  38. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  39. end
  40. import("package.tools.cmake").install(package, configs)
  41. end)
  42. on_test(function (package)
  43. assert(package:has_cfuncs("event_base_new", {includes = "event2/event.h"}))
  44. end)