mirror of https://github.com/eclipse/paho.mqtt.c
adds conanfile and test_package
This commit is contained in:
parent
99fb071d6d
commit
6432878fee
|
|
@ -0,0 +1,92 @@
|
||||||
|
from conans import ConanFile, CMake, tools
|
||||||
|
|
||||||
|
|
||||||
|
class PahocConan(ConanFile):
|
||||||
|
name = "paho.mqtt.c"
|
||||||
|
version = "1.2.0"
|
||||||
|
license = "Eclipse Public License - v 1.0"
|
||||||
|
url = "https://github.com/eclipse/paho.mqtt.c"
|
||||||
|
description = """The Eclipse Paho project provides open-source client implementations of MQTT
|
||||||
|
and MQTT-SN messaging protocols aimed at new, existing, and emerging applications for the Internet
|
||||||
|
of Things (IoT)"""
|
||||||
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
|
options = {"shared": [True, False], "SSL": [True, False], "asynchronous": [True, False]}
|
||||||
|
default_options = "shared=False", "SSL=False", "asynchronous=False"
|
||||||
|
generators = "cmake"
|
||||||
|
exports_sources = "*"
|
||||||
|
|
||||||
|
def requirements(self):
|
||||||
|
if self.options.SSL:
|
||||||
|
self.requires("OpenSSL/1.0.2n@conan/stable")
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
tools.replace_in_file("CMakeLists.txt", "PROJECT(\"paho\" C)", '''PROJECT("paho" C)
|
||||||
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
|
conan_basic_setup()''')
|
||||||
|
tools.replace_in_file("CMakeLists.txt", "ADD_SUBDIRECTORY(test)", "") # Disable tests
|
||||||
|
tools.replace_in_file("CMakeLists.txt",
|
||||||
|
"ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN -MD)",
|
||||||
|
"ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -DWIN32_LEAN_AND_MEAN)") # Allow other runtimes
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.definitions["PAHO_BUILD_DOCUMENTATION"] = False
|
||||||
|
cmake.definitions["PAHO_BUILD_SAMPLES"] = False
|
||||||
|
cmake.definitions["PAHO_BUILD_DEB_PACKAGE"] = False
|
||||||
|
cmake.definitions["PAHO_BUILD_STATIC"] = not self.options.shared
|
||||||
|
cmake.definitions["PAHO_WITH_SSL"] = self.options.SSL
|
||||||
|
cmake.configure()
|
||||||
|
cmake.build()
|
||||||
|
|
||||||
|
def package(self):
|
||||||
|
self.copy("*e*l-v10", dst="licenses")
|
||||||
|
self.copy("*.h", dst="include", src="src")
|
||||||
|
self.copy("*paho*.dll", dst="bin", keep_path=False)
|
||||||
|
self.copy("*paho*.dylib", dst="lib", keep_path=False)
|
||||||
|
self.copy("*paho*.so*", dst="lib", keep_path=False)
|
||||||
|
self.copy("*paho*.a", dst="lib", keep_path=False)
|
||||||
|
self.copy("*paho*.lib", dst="lib", keep_path=False)
|
||||||
|
|
||||||
|
def package_info(self):
|
||||||
|
self.cpp_info.libs = []
|
||||||
|
|
||||||
|
if self.options.shared and self:
|
||||||
|
if self.options.asynchronous:
|
||||||
|
if self.options.SSL:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3as")
|
||||||
|
else:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3a")
|
||||||
|
else:
|
||||||
|
if self.options.SSL:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3cs")
|
||||||
|
else:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3c")
|
||||||
|
else:
|
||||||
|
if self.options.asynchronous:
|
||||||
|
if self.options.SSL:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3as-static")
|
||||||
|
else:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3a-static")
|
||||||
|
else:
|
||||||
|
if self.options.SSL:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3cs-static")
|
||||||
|
else:
|
||||||
|
self.cpp_info.libs.append("paho-mqtt3c-static")
|
||||||
|
|
||||||
|
if self.settings.os == "Windows":
|
||||||
|
if not self.options.shared:
|
||||||
|
self.cpp_info.libs.append("ws2_32")
|
||||||
|
if self.settings.compiler == "gcc":
|
||||||
|
self.cpp_info.libs.append("wsock32") # (MinGW) needed?
|
||||||
|
else:
|
||||||
|
if self.settings.os == "Linux":
|
||||||
|
self.cpp_info.libs.append("c")
|
||||||
|
self.cpp_info.libs.append("dl")
|
||||||
|
self.cpp_info.libs.append("pthread")
|
||||||
|
elif self.settings.os == "FreeBSD":
|
||||||
|
self.cpp_info.libs.append("compat")
|
||||||
|
self.cpp_info.libs.append("pthread")
|
||||||
|
else:
|
||||||
|
self.cpp_info.libs.append("c")
|
||||||
|
self.cpp_info.libs.append("pthread")
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
|
del self.settings.compiler.libcxx
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
project(test_package C)
|
||||||
|
cmake_minimum_required(VERSION 2.8.11)
|
||||||
|
|
||||||
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
|
conan_basic_setup()
|
||||||
|
|
||||||
|
file(GLOB SOURCE_FILES *.c)
|
||||||
|
|
||||||
|
message("LIBS: ${CONAN_LIBS}")
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
from conans import ConanFile, CMake, tools, RunEnvironment
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class TestPackageConan(ConanFile):
|
||||||
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
|
generators = "cmake"
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.configure()
|
||||||
|
cmake.build()
|
||||||
|
|
||||||
|
def imports(self):
|
||||||
|
self.copy("*paho*.dll", dst="bin", src="bin")
|
||||||
|
self.copy("*paho*.dylib*", dst="bin", src="lib")
|
||||||
|
|
||||||
|
def test(self):
|
||||||
|
with tools.environment_append(RunEnvironment(self).vars):
|
||||||
|
bin_path = os.path.join("bin", "test_package")
|
||||||
|
if self.settings.os == "Windows":
|
||||||
|
self.run(bin_path)
|
||||||
|
elif self.settings.os == "Macos":
|
||||||
|
self.run("DYLD_LIBRARY_PATH=%s %s" % (os.environ.get('DYLD_LIBRARY_PATH', ''), bin_path))
|
||||||
|
else:
|
||||||
|
self.run("LD_LIBRARY_PATH=%s %s" % (os.environ.get('LD_LIBRARY_PATH', ''), bin_path))
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "MQTTClient.h"
|
||||||
|
|
||||||
|
#define ADDRESS "tcp://localhost:1883"
|
||||||
|
#define CLIENTID "ExampleClientSub"
|
||||||
|
#define TOPIC "MQTT Examples"
|
||||||
|
#define PAYLOAD "Hello World!"
|
||||||
|
#define QOS 1
|
||||||
|
#define TIMEOUT 10000L
|
||||||
|
|
||||||
|
volatile MQTTClient_deliveryToken deliveredtoken;
|
||||||
|
|
||||||
|
void delivered(void *context, MQTTClient_deliveryToken dt)
|
||||||
|
{
|
||||||
|
printf("Message with token value %d delivery confirmed\n", dt);
|
||||||
|
deliveredtoken = dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *payloadptr;
|
||||||
|
printf("Message arrived\n");
|
||||||
|
printf(" topic: %s\n", topicName);
|
||||||
|
printf(" message: ");
|
||||||
|
payloadptr = message->payload;
|
||||||
|
for (i = 0; i < message->payloadlen; i++)
|
||||||
|
{
|
||||||
|
putchar(*payloadptr++);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
MQTTClient_freeMessage(&message);
|
||||||
|
MQTTClient_free(topicName);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void connlost(void *context, char *cause)
|
||||||
|
{
|
||||||
|
printf("\nConnection lost\n");
|
||||||
|
printf(" cause: %s\n", cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
printf("\nCreating MQTTClient\n");
|
||||||
|
MQTTClient client;
|
||||||
|
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
|
||||||
|
MQTTClient_create(&client, ADDRESS, CLIENTID,
|
||||||
|
MQTTCLIENT_PERSISTENCE_NONE, NULL);
|
||||||
|
conn_opts.keepAliveInterval = 20;
|
||||||
|
conn_opts.cleansession = 1;
|
||||||
|
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
|
||||||
|
MQTTClient_destroy(&client);
|
||||||
|
printf("\nExiting\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue