xmake.lua 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package("mosquitto")
  2. set_homepage("https://mosquitto.org")
  3. set_description("Eclipse Mosquitto - An open source MQTT broker")
  4. set_license("EPL-2.0")
  5. add_urls("https://github.com/eclipse/mosquitto/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/eclipse/mosquitto.git")
  7. add_versions("v2.0.15", "547f98acd2e4668c8f3b86ef61e71c755366d180565b6e7537813876467d04d9")
  8. add_versions("v2.0.18", "25499231664bc5338f9f05eb1815f4d5878f0c6c97e03afb3463a7b139a7e775")
  9. if is_plat("windows") then
  10. add_patches("v2.0.15", path.join(os.scriptdir(), "patches", "cmake.patch"),"b241fb965f3d00bad1fddf060fe9b99cba83df32c373a4eaee2289e05abd26b6")
  11. end
  12. add_configs("tls", {description = "Include SSL/TLS support", default = true, type = "boolean"})
  13. add_configs("cjson", {description = "Build with cJSON support (required for dynamic security plugin and useful for mosquitto_sub)", default = true, type = "boolean"})
  14. add_configs("bundled_deps", {description = "Build with bundled dependencies", default = true, type = "boolean"})
  15. add_configs("websockets", {description = "Include websockets support", default = false, type = "boolean"})
  16. add_configs("tls_psk", {description = "Include TLS-PSK support (requires WITH_TLS)", default = true, type = "boolean"})
  17. add_configs("ec", {description = "Include Elliptic Curve support (requires WITH_TLS)", default = true, type = "boolean"})
  18. add_configs("unix_sockets", {description = "Include Unix Domain Socket support", default = true, type = "boolean"})
  19. add_configs("socks", {description = "Include SOCKS5 support", default = true, type = "boolean"})
  20. add_configs("threading", {description = "Include client library threading support", default = true, type = "boolean"})
  21. if is_plat("linux") then
  22. add_configs("srv", {description = "Include SRV lookup support", default = true, type = "boolean"})
  23. end
  24. add_configs("dlt", {description = "Include DLT support", default = false, type = "boolean"})
  25. add_configs("lib_cpp", {description = "Build C++ library", default = true, type = "boolean"})
  26. add_configs("broker", {description = "Build broker", default = false, type = "boolean"})
  27. add_deps("cmake")
  28. if is_plat("macosx") then
  29. add_extsources("brew::mosquitto")
  30. end
  31. local deps_map =
  32. {
  33. tls = "openssl",
  34. cjson = "cjson",
  35. bundled_deps = "uthash",
  36. srv = "c-ares",
  37. websockets = "libwebsockets",
  38. }
  39. if is_plat("linux") then
  40. add_syslinks("pthread", "m")
  41. add_links("mosquittopp", "mosquitto")
  42. elseif is_plat("windows") then
  43. add_syslinks("ws2_32")
  44. deps_map["threading"] = "pthreads4w"
  45. end
  46. on_load("windows", "linux", "macosx", function (package)
  47. for key, value in pairs(deps_map) do
  48. if package:config(key) then
  49. package:add("deps", value)
  50. end
  51. end
  52. if package:version():eq("2.0.18") and package:is_plat("windows") and package:is_arch("arm.*") then
  53. raise("mosquitto 2.0.18 not support windows arm")
  54. end
  55. end)
  56. on_install("windows", "linux", "macosx", function (package)
  57. if package:version():eq("2.0.18") and package:is_plat("windows") then
  58. io.replace("CMakeLists.txt", 'add_definitions("-D_CRT_SECURE_NO_WARNINGS")', 'add_definitions("-D_CRT_SECURE_NO_WARNINGS")\nadd_definitions("-DWIN32")', {plain = true})
  59. end
  60. local configs ={"-DDOCUMENTATION=OFF", "-DWITH_CLIENTS=OFF", "-DWITH_APPS=OFF", "-DWITH_PLUGINS=OFF"}
  61. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  62. table.insert(configs, "-DWITH_STATIC_LIBRARIES=" .. (package:config("shared") and "OFF" or "ON"))
  63. for name, value in pairs(package:configs()) do
  64. if not package:extraconf("configs", name, "builtin") then
  65. table.insert(configs, "-DWITH_" .. name:upper() .. "=" .. (value and "ON" or "OFF"))
  66. end
  67. end
  68. local packagedeps = {}
  69. for key, value in pairs(deps_map) do
  70. if package:config(key) then
  71. table.insert(packagedeps, value)
  72. end
  73. end
  74. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  75. end)
  76. on_test(function (package)
  77. assert(package:check_csnippets({test = [[
  78. #include <mosquitto.h>
  79. void test() {
  80. mosquitto_lib_init();
  81. }
  82. ]]}))
  83. end)