-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #936 from gocarlos/feat--add-paho-mqtt-cpp
feat: add paho mqtt cpp
- Loading branch information
Showing
10 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 2.8.11) | ||
project(cmake_wrapper) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_subdirectory("source_subfolder") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sources: | ||
"1.0.1": | ||
sha256: e97386d159b811e534b98d21e3f6881ab2b43678ec026da7525d5c21ebc292ff | ||
url: https://github.com/eclipse/paho.mqtt.cpp/archive/v1.0.1.tar.gz | ||
patches: | ||
"1.0.1": | ||
- patch_file: "patches/0001-fix-cmake-module-path.patch" | ||
base_path: "source_subfolder" | ||
- patch_file: "patches/0002-fix-cmake-find-paho-mqtt-c-static.patch" | ||
base_path: "source_subfolder" | ||
- patch_file: "patches/0003-fix-paho-mqtt-cpp-config-cmake.patch" | ||
base_path: "source_subfolder" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import os | ||
from conans import CMake, ConanFile, tools | ||
from conans.errors import ConanInvalidConfiguration | ||
|
||
|
||
class PahoMqttCppConan(ConanFile): | ||
name = "paho-mqtt-cpp" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/eclipse/paho.mqtt.cpp" | ||
topics = ("MQTT", "IoT", "eclipse", "SSL", "paho", "Cpp") | ||
license = "EPL-1.0" | ||
description = """The open-source client implementations of MQTT and MQTT-SN""" | ||
exports_sources = ["CMakeLists.txt", "patches/*"] | ||
generators = "cmake" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], | ||
"fPIC": [True, False], | ||
"ssl": [True, False], | ||
} | ||
default_options = {"shared": False, | ||
"fPIC": True, | ||
"ssl": False | ||
} | ||
|
||
_cmake = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
minimal_cpp_standard = "11" | ||
if self.settings.compiler.cppstd: | ||
tools.check_min_cppstd(self, minimal_cpp_standard) | ||
|
||
if self.settings.os == "Windows" and self.options.shared: | ||
raise ConanInvalidConfiguration( | ||
"Paho cpp can not be built as shared on Windows.") | ||
|
||
self.options["paho-mqtt-c"].shared = self.options.shared | ||
self.options["paho-mqtt-c"].ssl = self.options.ssl | ||
|
||
def requirements(self): | ||
self.requires("paho-mqtt-c/1.3.0") | ||
|
||
def source(self): | ||
tools.get(**self.conan_data["sources"][self.version]) | ||
extracted_dir = self.name.replace("-", ".") + "-" + self.version | ||
os.rename(extracted_dir, self._source_subfolder) | ||
|
||
def _configure_cmake(self): | ||
if self._cmake: | ||
return self._cmake | ||
self._cmake = CMake(self) | ||
self._cmake.definitions["PAHO_BUILD_DOCUMENTATION"] = False | ||
self._cmake.definitions["PAHO_BUILD_SAMPLES"] = False | ||
self._cmake.definitions["PAHO_BUILD_STATIC"] = not self.options.shared | ||
self._cmake.definitions["PAHO_BUILD_SHARED"] = self.options.shared | ||
self._cmake.definitions["PAHO_WITH_SSL"] = self.options.ssl | ||
self._cmake.configure() | ||
return self._cmake | ||
|
||
def build(self): | ||
for patch in self.conan_data["patches"][self.version]: | ||
tools.patch(**patch) | ||
cmake = self._configure_cmake() | ||
cmake.build() | ||
|
||
def package(self): | ||
self.copy("edl-v10", src=self._source_subfolder, dst="licenses") | ||
self.copy("epl-v10", src=self._source_subfolder, dst="licenses") | ||
self.copy("notice.html", src=self._source_subfolder, dst="licenses") | ||
cmake = self._configure_cmake() | ||
cmake.install() | ||
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) | ||
|
||
def package_info(self): | ||
self.cpp_info.libs = tools.collect_libs(self) | ||
self.cpp_info.names["cmake_find_package"] = "PahoMqttCpp" | ||
self.cpp_info.names["cmake_find_package_multi"] = "PahoMqttCpp" |
14 changes: 14 additions & 0 deletions
14
recipes/paho-mqtt-cpp/all/patches/0001-fix-cmake-module-path.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 1f6ab07..bb0b31f 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -69,7 +69,7 @@ endif() | ||
## --- Build directories --- | ||
|
||
# For the paho_mqtt_c module | ||
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) | ||
+list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) | ||
add_subdirectory(src) | ||
|
||
# --- Documentation --- | ||
|
16 changes: 16 additions & 0 deletions
16
recipes/paho-mqtt-cpp/all/patches/0002-fix-cmake-find-paho-mqtt-c-static.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
diff --git a/cmake/FindPahoMqttC.cmake b/cmake/FindPahoMqttC.cmake | ||
index 10c2bfa..a03b226 100644 | ||
--- a/cmake/FindPahoMqttC.cmake | ||
+++ b/cmake/FindPahoMqttC.cmake | ||
@@ -5,6 +5,10 @@ if(PAHO_WITH_SSL) | ||
else() | ||
set(_PAHO_MQTT_C_LIB_NAME paho-mqtt3a) | ||
endif() | ||
+# add suffix when using static Paho MQTT C library variant | ||
+if(PAHO_BUILD_STATIC) | ||
+ set(_PAHO_MQTT_C_LIB_NAME ${_PAHO_MQTT_C_LIB_NAME}-static) | ||
+endif() | ||
|
||
find_library(PAHO_MQTT_C_LIBRARIES NAMES ${_PAHO_MQTT_C_LIB_NAME}) | ||
unset(_PAHO_MQTT_C_LIB_NAME) | ||
|
17 changes: 17 additions & 0 deletions
17
recipes/paho-mqtt-cpp/all/patches/0003-fix-paho-mqtt-cpp-config-cmake.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
diff --git a/cmake/PahoMqttCppConfig.cmake.in b/cmake/PahoMqttCppConfig.cmake.in | ||
index e06dc68..f1137fc 100644 | ||
--- a/cmake/PahoMqttCppConfig.cmake.in | ||
+++ b/cmake/PahoMqttCppConfig.cmake.in | ||
@@ -1,6 +1,11 @@ | ||
+set(PAHO_BUILD_STATIC @PAHO_BUILD_STATIC@) | ||
+set(PAHO_BUILD_SHARED @PAHO_BUILD_SHARED@) | ||
+set(PAHO_WITH_SSL @PAHO_WITH_SSL@) | ||
+ | ||
include(CMakeFindDependencyMacro) | ||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) | ||
find_dependency(PahoMqttC REQUIRED) | ||
list(REMOVE_AT CMAKE_MODULE_PATH -1) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/@package_name@Targets.cmake") | ||
+ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cmake_minimum_required(VERSION 2.8.12) | ||
project(test_package) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE TRUE) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
add_executable(${PROJECT_NAME} test_package.cpp) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) | ||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from conans import ConanFile, CMake, tools | ||
import os | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <string> | ||
#include "mqtt/async_client.h" | ||
#include "mqtt/client.h" | ||
|
||
const std::string SERVER_ADDRESS { "tcp://localhost:1883" }; | ||
const std::string CLIENT_ID { "consume" }; | ||
|
||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
mqtt::connect_options connOpts; | ||
connOpts.set_keep_alive_interval(20); | ||
connOpts.set_clean_session(true); | ||
|
||
mqtt::async_client cli_async(SERVER_ADDRESS, CLIENT_ID); | ||
mqtt::client cli(SERVER_ADDRESS, CLIENT_ID); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
versions: | ||
"1.0.1": | ||
folder: "all" |