Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add initial libcoap #929

Merged
merged 30 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ad96cd7
feat: add initial libcoap
gocarlos Feb 20, 2020
7bd0fa5
chore: add some code to libcoap test package
gocarlos Feb 20, 2020
69ab89a
chore: add support for tls lib
gocarlos Feb 20, 2020
2ddc51c
chore: simplify recipe
gocarlos Feb 27, 2020
e9b988f
chore: patch openssl stuff
gocarlos Mar 23, 2020
0c517eb
fix: test package
gocarlos Mar 23, 2020
ad5f4bb
fix: path to license
gocarlos Mar 23, 2020
47f678f
chore: bump version
gocarlos Apr 24, 2020
0015c81
chore: use dtls_backend
gocarlos Apr 24, 2020
a027ad3
chore: rename to dtls_backend
gocarlos Apr 24, 2020
d1931ef
fix: conan exceptions
gocarlos Apr 26, 2020
822dab5
remove support for windows and mac
gocarlos Apr 26, 2020
ed57604
Update recipes/libcoap/all/conanfile.py
gocarlos Apr 27, 2020
ca1f675
Update recipes/libcoap/all/conanfile.py
gocarlos Apr 28, 2020
efac372
Update recipes/libcoap/all/conanfile.py
gocarlos May 1, 2020
5305607
fix: pkgconfig
gocarlos Jun 13, 2020
f76707c
style: fix new hooks
gocarlos Jun 13, 2020
582cfbd
style: fix new hooks
gocarlos Jun 13, 2020
ac6e219
Update recipes/libcoap/all/conanfile.py
gocarlos Jul 7, 2020
5f55700
Update conandata.yml
gocarlos Aug 23, 2020
0db20ff
Update config.yml
gocarlos Aug 23, 2020
f1ae576
Update CMakeLists.txt
gocarlos Aug 23, 2020
940d478
Update CMakeLists.txt
gocarlos Aug 23, 2020
c785fda
Update conanfile.py
gocarlos Aug 24, 2020
c3ea065
Update recipes/libcoap/all/conanfile.py
gocarlos Aug 26, 2020
8809346
Update recipes/libcoap/all/conanfile.py
gocarlos Aug 26, 2020
a917a60
Update recipes/libcoap/all/conanfile.py
gocarlos Aug 26, 2020
62074c0
Update recipes/libcoap/all/conanfile.py
gocarlos Aug 27, 2020
13d1458
Apply suggestions from code review
gocarlos Sep 23, 2020
7feb798
Apply suggestions from code review
gocarlos Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if its supported but there 2.23 in CCI now

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"]
gocarlos marked this conversation as resolved.
Show resolved Hide resolved
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"