xmake.lua 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package("pahomqttc")
  2. set_homepage("https://github.com/eclipse/paho.mqtt.c")
  3. set_description("Eclipse Paho MQTT C Client Library")
  4. set_license("EPL-2.0")
  5. add_urls("https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/$(version).zip",
  6. "https://github.com/eclipse/paho.mqtt.c.git")
  7. add_versions("v1.3.14", "ad67f3920b4dc618867c573626f6dbddc213d3f759abbdb9d785f7f85d086e41")
  8. add_versions("v1.3.13", "5ba7c7ab7ebb1499938fa2e358e6c1f9a926b270f2bf082acf89d59b4771a132")
  9. add_configs("uuid", {description = "Flag that defines whether libuuid or a custom uuid implementation should be used", default = false, type = "boolean"})
  10. add_configs("openssl", {description = "Flag that defines whether to build ssl-enabled binaries too.", default = false, type = "boolean"})
  11. add_configs("high_performance", {description = "Enable tracing and heap tracking", default = false, type = "boolean"})
  12. add_configs("asynchronous", {description = "Use asynchronous", default = false, type = "boolean"})
  13. if is_plat("windows", "mingw") then
  14. add_syslinks("ws2_32", "advapi32", "rpcrt4", "crypt32")
  15. elseif is_plat("linux") then
  16. add_syslinks("dl", "pthread", "rt")
  17. elseif is_plat("android") then
  18. add_syslinks("dl")
  19. elseif is_plat("bsd") then
  20. add_syslinks("compat", "pthread")
  21. end
  22. add_deps("cmake")
  23. on_load(function (package)
  24. if package:config("uuid") then
  25. package:add("deps", "uuid")
  26. end
  27. if package:config("shared") and package:is_plat("windows") then
  28. package:add("defines", "PAHO_MQTT_IMPORTS")
  29. end
  30. -- paho-mqtt3[a|c][s][-static]
  31. local links = "paho-mqtt3" .. (package:config("asynchronous") and "a" or "c")
  32. if package:config("openssl") then
  33. links = links .. "s"
  34. package:add("deps", "openssl")
  35. end
  36. if package:is_plat("windows", "mingw") and (not package:config("shared")) then
  37. links = links .. "-static"
  38. end
  39. package:add("links", links)
  40. end)
  41. on_install("!wasm", function (package)
  42. local configs = {
  43. "-DPAHO_BUILD_SAMPLES=FALSE",
  44. "-DPAHO_ENABLE_TESTING=OFF",
  45. "-DPAHO_ENABLE_CPACK=OFF",
  46. "-DPAHO_BUILD_DOCUMENTATION=FALSE",
  47. }
  48. local shared = package:config("shared")
  49. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  50. table.insert(configs, "-DPAHO_BUILD_SHARED=" .. (shared and "TRUE" or "FALSE"))
  51. table.insert(configs, "-DPAHO_BUILD_STATIC=" .. (shared and "FALSE" or "TRUE"))
  52. table.insert(configs, "-DPAHO_WITH_SSL=" .. (package:config("openssl") and "TRUE" or "FALSE"))
  53. table.insert(configs, "-DPAHO_WITH_LIBUUID=" .. (package:config("uuid") and "TRUE" or "FALSE"))
  54. table.insert(configs, "-DPAHO_HIGH_PERFORMANCE=" .. (package:config("high_performance") and "TRUE" or "FALSE"))
  55. import("package.tools.cmake").install(package, configs)
  56. end)
  57. on_test(function (package)
  58. if package:config("asynchronous") then
  59. assert(package:has_cfuncs("MQTTAsync_connect", {includes = "MQTTAsync.h"}))
  60. else
  61. assert(package:has_cfuncs("MQTTClient_connect", {includes = "MQTTClient.h"}))
  62. end
  63. end)