From a2911effcfe2f0ca1723833bd28eb94a290e65e8 Mon Sep 17 00:00:00 2001 From: Carlos Gomes Martinho Date: Wed, 30 Sep 2020 21:13:20 +0200 Subject: [PATCH] feat: add initial libcoap (#929) * feat: add initial libcoap * chore: add some code to libcoap test package * chore: add support for tls lib * chore: simplify recipe * chore: patch openssl stuff * fix: test package * fix: path to license * chore: bump version * chore: use dtls_backend * chore: rename to dtls_backend * fix: conan exceptions * remove support for windows and mac * Update recipes/libcoap/all/conanfile.py Co-Authored-By: Uilian Ries * Update recipes/libcoap/all/conanfile.py Co-Authored-By: Uilian Ries * Update recipes/libcoap/all/conanfile.py Co-authored-by: Uilian Ries * fix: pkgconfig * style: fix new hooks * style: fix new hooks * Update recipes/libcoap/all/conanfile.py Co-authored-by: Michael "Croydon" Keck * Update conandata.yml * Update config.yml * Update CMakeLists.txt * Update CMakeLists.txt * Update conanfile.py * Update recipes/libcoap/all/conanfile.py Co-authored-by: Uilian Ries * Update recipes/libcoap/all/conanfile.py Co-authored-by: Uilian Ries * Update recipes/libcoap/all/conanfile.py Co-authored-by: Uilian Ries * Update recipes/libcoap/all/conanfile.py Co-authored-by: Anonymous Maarten * Apply suggestions from code review Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Chris Mc Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Co-authored-by: Uilian Ries Co-authored-by: Michael "Croydon" Keck Co-authored-by: Anonymous Maarten Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Co-authored-by: Chris Mc --- recipes/libcoap/all/CMakeLists.txt | 7 ++ recipes/libcoap/all/conandata.yml | 4 + recipes/libcoap/all/conanfile.py | 100 ++++++++++++++++++ .../libcoap/all/test_package/CMakeLists.txt | 11 ++ recipes/libcoap/all/test_package/conanfile.py | 17 +++ .../libcoap/all/test_package/test_package.cpp | 15 +++ recipes/libcoap/config.yml | 4 + 7 files changed, 158 insertions(+) create mode 100644 recipes/libcoap/all/CMakeLists.txt create mode 100644 recipes/libcoap/all/conandata.yml create mode 100644 recipes/libcoap/all/conanfile.py create mode 100644 recipes/libcoap/all/test_package/CMakeLists.txt create mode 100644 recipes/libcoap/all/test_package/conanfile.py create mode 100644 recipes/libcoap/all/test_package/test_package.cpp create mode 100644 recipes/libcoap/config.yml diff --git a/recipes/libcoap/all/CMakeLists.txt b/recipes/libcoap/all/CMakeLists.txt new file mode 100644 index 0000000000000..bd3083b512cb9 --- /dev/null +++ b/recipes/libcoap/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/libcoap/all/conandata.yml b/recipes/libcoap/all/conandata.yml new file mode 100644 index 0000000000000..17daed23722ed --- /dev/null +++ b/recipes/libcoap/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "cci.20200424": + sha256: 8402bf2dd9979d6d5f823a050cd3533619fe9b21e76be8c69a9b7d8b8ea175ab + url: https://github.com/obgm/libcoap/archive/17957e1e687c2218b7752a8a959eac36dbf5cb62.zip diff --git a/recipes/libcoap/all/conanfile.py b/recipes/libcoap/all/conanfile.py new file mode 100644 index 0000000000000..88c964d612e68 --- /dev/null +++ b/recipes/libcoap/all/conanfile.py @@ -0,0 +1,100 @@ +import os +from conans import CMake, ConanFile, tools +from conans.errors import ConanInvalidConfiguration + + +class LibCoapConan(ConanFile): + name = "libcoap" + license = "BSD-2-Clause" + homepage = "https://github.com/obgm/libcoap" + url = "https://github.com/conan-io/conan-center-index" + description = """A CoAP (RFC 7252) implementation in C""" + topics = ("coap") + exports_sources = "CMakeLists.txt" + settings = "os", "compiler", "build_type", "arch" + options = { + "shared": [True, False], + "fPIC": [True, False], + "with_epoll": [True, False], + "dtls_backend": [None, "openssl", "gnutls", "tinydtls", "mbedtls"], + } + default_options = { + "shared": False, + "fPIC": True, + "with_epoll": False, + "dtls_backend": "openssl", + } + generators = "cmake", "cmake_find_package" + + _cmake = None + + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def requirements(self): + if self.options.dtls_backend == "openssl": + self.requires("openssl/1.1.1h") + elif self.options.dtls_backend == "mbedtls": + self.requires("mbedtls/2.16.3-apache") + elif self.options.dtls_backend == "gnutls": + raise ConanInvalidConfiguration("gnu tls not available yet") + elif self.options.dtls_backend == "tinydtls": + raise ConanInvalidConfiguration("tinydtls not available yet") + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.settings.os in ("Windows", "Macos"): + raise ConanInvalidConfiguration("Platform is currently not supported") + if self.options.shared: + del self.options.fPIC + del self.settings.compiler.libcxx + del self.settings.compiler.cppstd + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + extracted_dir = self.name + "-" + \ + os.path.basename( + self.conan_data["sources"][self.version]["url"]).split(".")[0] + os.rename(extracted_dir, self._source_subfolder) + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["WITH_EPOLL"] = self.options.with_epoll + self._cmake.definitions["ENABLE_DTLS"] = self.options.dtls_backend != None + self._cmake.definitions["DTLS_BACKEND"] = self.options.dtls_backend + self._cmake.configure(build_folder=self._build_subfolder) + return self._cmake + + def build(self): + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy("LICENSE", 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): + pkgconfig_filename = "libcoap-2{}".format("-{}".format(self.options.dtls_backend) if self.options.dtls_backend else "") + self.cpp_info.names["pkg_config"] = pkgconfig_filename + self.cpp_info.components["coap"].names["cmake_find_package"] = "coap" + self.cpp_info.components["coap"].names["cmake_find_package_multi"] = "coap" + self.cpp_info.components["coap"].names["pkg_config"] = pkgconfig_filename + self.cpp_info.components["coap"].libs = ["coap"] + if self.settings.os == "Linux": + self.cpp_info.components["coap"].system_libs = ["pthread"] + if self.options.dtls_backend == "openssl": + self.cpp_info.components["coap"].requires = ["openssl::openssl"] + elif self.options.dtls_backend == "mbedtls": + self.cpp_info.components["coap"].requires = ["mbedtls::mbedtls"] diff --git a/recipes/libcoap/all/test_package/CMakeLists.txt b/recipes/libcoap/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..a8acc4f57e48d --- /dev/null +++ b/recipes/libcoap/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +find_package(libcoap REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} libcoap::coap) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/libcoap/all/test_package/conanfile.py b/recipes/libcoap/all/test_package/conanfile.py new file mode 100644 index 0000000000000..6dffe66394a26 --- /dev/null +++ b/recipes/libcoap/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +import os +from conans import ConanFile, CMake, tools + + +class TestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package_multi" + + 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") + bin_path = self.run(bin_path, run_environment=True) diff --git a/recipes/libcoap/all/test_package/test_package.cpp b/recipes/libcoap/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..8e75bb8972a71 --- /dev/null +++ b/recipes/libcoap/all/test_package/test_package.cpp @@ -0,0 +1,15 @@ +#include "coap2/coap.h" +#include + +int main() { + std::cout << "starting" << std::endl; + coap_startup(); + + // create CoAP context and a client session + coap_context_t *ctx = coap_new_context(nullptr); + + coap_free_context(ctx); + coap_cleanup(); + std::cout << "stopping" << std::endl; + return 0; +} diff --git a/recipes/libcoap/config.yml b/recipes/libcoap/config.yml new file mode 100644 index 0000000000000..1293823b59323 --- /dev/null +++ b/recipes/libcoap/config.yml @@ -0,0 +1,4 @@ +--- +versions: + "cci.20200424": + folder: "all"