xmake.lua 4.9 KB

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