From b0592de58fb9f7a285fcc6f4f7de29fc4607b31b Mon Sep 17 00:00:00 2001 From: star9029 Date: Tue, 25 Jun 2024 07:41:13 +0800 Subject: [PATCH] pahomqttc: fix syslinks (#4454) * pahomqttc: fix syslinks * add openssl config * improve defines * improve xmake.lua * improve license * fix mingw syslinks * improve links * improve test * fix links on non-windows --- packages/p/pahomqttc/xmake.lua | 66 ++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 10 deletions(-) diff --git a/packages/p/pahomqttc/xmake.lua b/packages/p/pahomqttc/xmake.lua index d5e740fbd..cc60b2d7b 100644 --- a/packages/p/pahomqttc/xmake.lua +++ b/packages/p/pahomqttc/xmake.lua @@ -1,25 +1,71 @@ package("pahomqttc") set_homepage("https://github.com/eclipse/paho.mqtt.c") set_description("Eclipse Paho MQTT C Client Library") - set_license("MIT") + set_license("EPL-2.0") add_urls("https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/$(version).zip", "https://github.com/eclipse/paho.mqtt.c.git") add_versions("v1.3.13", "5ba7c7ab7ebb1499938fa2e358e6c1f9a926b270f2bf082acf89d59b4771a132") + add_configs("uuid", {description = "Flag that defines whether libuuid or a custom uuid implementation should be used", default = false, type = "boolean"}) + add_configs("openssl", {description = "Flag that defines whether to build ssl-enabled binaries too.", default = false, type = "boolean"}) + add_configs("high_performance", {description = "Enable tracing and heap tracking", default = false, type = "boolean"}) + add_configs("asynchronous", {description = "Use asynchronous", default = false, type = "boolean"}) + + if is_plat("windows", "mingw") then + add_syslinks("ws2_32", "advapi32", "rpcrt4", "crypt32") + elseif is_plat("linux") then + add_syslinks("dl", "pthread", "rt") + elseif is_plat("android") then + add_syslinks("dl") + elseif is_plat("bsd") then + add_syslinks("compat", "pthread") + end + add_deps("cmake") - on_install("windows", "linux", "macosx", function (package) - local configs = {"-DPAHO_BUILD_SAMPLES=FALSE", - "-DPAHO_WITH_SSL=FALSE", - "-DPAHO_BUILD_DOCUMENTATION=FALSE"} - table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) - table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF")) + on_load(function (package) + if package:config("uuid") then + package:add("deps", "uuid") + end + if package:config("openssl") then + package:add("deps", "openssl") + end + + if package:config("shared") and package:is_plat("windows") then + package:add("defines", "PAHO_MQTT_IMPORTS") + end + -- paho-mqtt3[a|c][-static] + local links = "paho-mqtt3" .. (package:config("asynchronous") and "a" or "c") + if package:is_plat("windows", "mingw") and (not package:config("shared")) then + links = links .. "-static" + end + package:add("links", links) + end) + + on_install("!wasm", function (package) + local configs = { + "-DPAHO_BUILD_SAMPLES=FALSE", + "-DPAHO_ENABLE_TESTING=OFF", + "-DPAHO_ENABLE_CPACK=OFF", + "-DPAHO_BUILD_DOCUMENTATION=FALSE", + } + local shared = package:config("shared") + table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release")) + table.insert(configs, "-DPAHO_BUILD_SHARED=" .. (shared and "TRUE" or "FALSE")) + table.insert(configs, "-DPAHO_BUILD_STATIC=" .. (shared and "FALSE" or "TRUE")) + + table.insert(configs, "-DPAHO_WITH_SSL=" .. (package:config("openssl") and "TRUE" or "FALSE")) + table.insert(configs, "-DPAHO_WITH_LIBUUID=" .. (package:config("uuid") and "TRUE" or "FALSE")) + table.insert(configs, "-DPAHO_HIGH_PERFORMANCE=" .. (package:config("high_performance") and "TRUE" or "FALSE")) import("package.tools.cmake").install(package, configs) end) on_test(function (package) - assert(package:has_cfuncs("MQTTClient_connect", {includes = "MQTTClient.h"})) - end) -package_end() \ No newline at end of file + if package:config("asynchronous") then + assert(package:has_cfuncs("MQTTAsync_connect", {includes = "MQTTAsync.h"})) + else + assert(package:has_cfuncs("MQTTClient_connect", {includes = "MQTTClient.h"})) + end + end)