xmake.lua 3.2 KB

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