From 4f5742959f87d0fc3f65ea6e88ffa5d8f23d50c9 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 21 Feb 2020 13:23:19 +0100 Subject: [PATCH 1/5] feat: add paho mqtt cpp --- recipes/paho-mqtt-cpp/all/CMakeLists.txt | 7 ++ recipes/paho-mqtt-cpp/all/conandata.yml | 12 +++ recipes/paho-mqtt-cpp/all/conanfile.py | 78 +++++++++++++++++++ .../patches/0001-fix-cmake-module-path.patch | 14 ++++ ...02-fix-cmake-find-paho-mqtt-c-static.patch | 16 ++++ .../0003-fix-paho-mqtt-cpp-config-cmake.patch | 17 ++++ .../all/test_package/CMakeLists.txt | 10 +++ .../all/test_package/conanfile.py | 16 ++++ .../all/test_package/test_package.cpp | 19 +++++ recipes/paho-mqtt-cpp/config.yml | 4 + 10 files changed, 193 insertions(+) create mode 100644 recipes/paho-mqtt-cpp/all/CMakeLists.txt create mode 100644 recipes/paho-mqtt-cpp/all/conandata.yml create mode 100644 recipes/paho-mqtt-cpp/all/conanfile.py create mode 100644 recipes/paho-mqtt-cpp/all/patches/0001-fix-cmake-module-path.patch create mode 100644 recipes/paho-mqtt-cpp/all/patches/0002-fix-cmake-find-paho-mqtt-c-static.patch create mode 100644 recipes/paho-mqtt-cpp/all/patches/0003-fix-paho-mqtt-cpp-config-cmake.patch create mode 100644 recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt create mode 100644 recipes/paho-mqtt-cpp/all/test_package/conanfile.py create mode 100644 recipes/paho-mqtt-cpp/all/test_package/test_package.cpp create mode 100644 recipes/paho-mqtt-cpp/config.yml diff --git a/recipes/paho-mqtt-cpp/all/CMakeLists.txt b/recipes/paho-mqtt-cpp/all/CMakeLists.txt new file mode 100644 index 0000000000000..d17aaff199b4a --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/CMakeLists.txt @@ -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") diff --git a/recipes/paho-mqtt-cpp/all/conandata.yml b/recipes/paho-mqtt-cpp/all/conandata.yml new file mode 100644 index 0000000000000..7cb8254fce955 --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/conandata.yml @@ -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" \ No newline at end of file diff --git a/recipes/paho-mqtt-cpp/all/conanfile.py b/recipes/paho-mqtt-cpp/all/conanfile.py new file mode 100644 index 0000000000000..b6f34cae9bbe3 --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/conanfile.py @@ -0,0 +1,78 @@ +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): + 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) + diff --git a/recipes/paho-mqtt-cpp/all/patches/0001-fix-cmake-module-path.patch b/recipes/paho-mqtt-cpp/all/patches/0001-fix-cmake-module-path.patch new file mode 100644 index 0000000000000..1eae81cadb7a3 --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/patches/0001-fix-cmake-module-path.patch @@ -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 --- + diff --git a/recipes/paho-mqtt-cpp/all/patches/0002-fix-cmake-find-paho-mqtt-c-static.patch b/recipes/paho-mqtt-cpp/all/patches/0002-fix-cmake-find-paho-mqtt-c-static.patch new file mode 100644 index 0000000000000..5846fe7e82581 --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/patches/0002-fix-cmake-find-paho-mqtt-c-static.patch @@ -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) + diff --git a/recipes/paho-mqtt-cpp/all/patches/0003-fix-paho-mqtt-cpp-config-cmake.patch b/recipes/paho-mqtt-cpp/all/patches/0003-fix-paho-mqtt-cpp-config-cmake.patch new file mode 100644 index 0000000000000..c84f74f66c0de --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/patches/0003-fix-paho-mqtt-cpp-config-cmake.patch @@ -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") ++ + diff --git a/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt b/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..56a1bba89a19d --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +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}) diff --git a/recipes/paho-mqtt-cpp/all/test_package/conanfile.py b/recipes/paho-mqtt-cpp/all/test_package/conanfile.py new file mode 100644 index 0000000000000..12acc7a675c1d --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/test_package/conanfile.py @@ -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) \ No newline at end of file diff --git a/recipes/paho-mqtt-cpp/all/test_package/test_package.cpp b/recipes/paho-mqtt-cpp/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..15e2f657fd57b --- /dev/null +++ b/recipes/paho-mqtt-cpp/all/test_package/test_package.cpp @@ -0,0 +1,19 @@ +#include +#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; +} \ No newline at end of file diff --git a/recipes/paho-mqtt-cpp/config.yml b/recipes/paho-mqtt-cpp/config.yml new file mode 100644 index 0000000000000..89d9a24069fed --- /dev/null +++ b/recipes/paho-mqtt-cpp/config.yml @@ -0,0 +1,4 @@ +--- +versions: + "1.0.1": + folder: "all" From 72d960aeb16e87556e37dae86bfa964be84bed87 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 24 Feb 2020 20:03:55 +0100 Subject: [PATCH 2/5] chore: make sure we use cpp11 --- recipes/paho-mqtt-cpp/all/conanfile.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/recipes/paho-mqtt-cpp/all/conanfile.py b/recipes/paho-mqtt-cpp/all/conanfile.py index b6f34cae9bbe3..67bc24ac867da 100644 --- a/recipes/paho-mqtt-cpp/all/conanfile.py +++ b/recipes/paho-mqtt-cpp/all/conanfile.py @@ -47,6 +47,11 @@ def source(self): extracted_dir = self.name.replace("-", ".") + "-" + self.version os.rename(extracted_dir, self._source_subfolder) + def configure(self): + minimal_cpp_standard = "11" + if self.settings.compiler.cppstd: + tools.check_min_cppstd(self, minimal_cpp_standard) + def _configure_cmake(self): if self._cmake: return self._cmake From 8b71a2e98fde40af62d1d18f2a6856eaab47ad72 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 24 Feb 2020 21:29:46 +0100 Subject: [PATCH 3/5] Update recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt Co-Authored-By: Uilian Ries --- recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt b/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt index 56a1bba89a19d..b36f7e7878dde 100644 --- a/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt +++ b/recipes/paho-mqtt-cpp/all/test_package/CMakeLists.txt @@ -8,3 +8,4 @@ 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) From 953338a94bae6927f141accb2e86c41f32b610ca Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Mon, 24 Feb 2020 23:00:16 +0100 Subject: [PATCH 4/5] fix: only have one configure --- recipes/paho-mqtt-cpp/all/conanfile.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/recipes/paho-mqtt-cpp/all/conanfile.py b/recipes/paho-mqtt-cpp/all/conanfile.py index 67bc24ac867da..70aed826fb25f 100644 --- a/recipes/paho-mqtt-cpp/all/conanfile.py +++ b/recipes/paho-mqtt-cpp/all/conanfile.py @@ -33,12 +33,16 @@ def config_options(self): 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") @@ -47,11 +51,6 @@ def source(self): extracted_dir = self.name.replace("-", ".") + "-" + self.version os.rename(extracted_dir, self._source_subfolder) - def configure(self): - minimal_cpp_standard = "11" - if self.settings.compiler.cppstd: - tools.check_min_cppstd(self, minimal_cpp_standard) - def _configure_cmake(self): if self._cmake: return self._cmake From e1ac4d74c49b905a1b19b14d7d2b9d313092fe5f Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Fri, 28 Feb 2020 15:20:02 +0100 Subject: [PATCH 5/5] chore: add cmake find package name --- recipes/paho-mqtt-cpp/all/conanfile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/recipes/paho-mqtt-cpp/all/conanfile.py b/recipes/paho-mqtt-cpp/all/conanfile.py index 70aed826fb25f..a7a57a9b6df40 100644 --- a/recipes/paho-mqtt-cpp/all/conanfile.py +++ b/recipes/paho-mqtt-cpp/all/conanfile.py @@ -38,7 +38,8 @@ def configure(self): 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.") + 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 @@ -79,4 +80,5 @@ def package(self): 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"