Skip to content

Commit

Permalink
feat: add initial libcoap (#929)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update recipes/libcoap/all/conanfile.py

Co-Authored-By: Uilian Ries <[email protected]>

* Update recipes/libcoap/all/conanfile.py

Co-authored-by: Uilian Ries <[email protected]>

* fix: pkgconfig

* style: fix new hooks

* style: fix new hooks

* Update recipes/libcoap/all/conanfile.py

Co-authored-by: Michael "Croydon" Keck <[email protected]>

* 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 <[email protected]>

* Update recipes/libcoap/all/conanfile.py

Co-authored-by: Uilian Ries <[email protected]>

* Update recipes/libcoap/all/conanfile.py

Co-authored-by: Uilian Ries <[email protected]>

* Update recipes/libcoap/all/conanfile.py

Co-authored-by: Anonymous Maarten <[email protected]>

* Apply suggestions from code review

Co-authored-by: SpaceIm <[email protected]>

* Apply suggestions from code review

Co-authored-by: Chris Mc <[email protected]>
Co-authored-by: SpaceIm <[email protected]>

Co-authored-by: Uilian Ries <[email protected]>
Co-authored-by: Michael "Croydon" Keck <[email protected]>
Co-authored-by: Anonymous Maarten <[email protected]>
Co-authored-by: SpaceIm <[email protected]>
Co-authored-by: Chris Mc <[email protected]>
  • Loading branch information
6 people authored Sep 30, 2020
1 parent a53039f commit a2911ef
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libcoap/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder)
4 changes: 4 additions & 0 deletions recipes/libcoap/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20200424":
sha256: 8402bf2dd9979d6d5f823a050cd3533619fe9b21e76be8c69a9b7d8b8ea175ab
url: https://github.com/obgm/libcoap/archive/17957e1e687c2218b7752a8a959eac36dbf5cb62.zip
100 changes: 100 additions & 0 deletions recipes/libcoap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"]
11 changes: 11 additions & 0 deletions recipes/libcoap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions recipes/libcoap/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions recipes/libcoap/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "coap2/coap.h"
#include <iostream>

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;
}
4 changes: 4 additions & 0 deletions recipes/libcoap/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
versions:
"cci.20200424":
folder: "all"

0 comments on commit a2911ef

Please sign in to comment.