xmake.lua 3.4 KB

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