Repository: conan-io/conan-center-index

Issue:
feat: add COSE-C
- [x] I've read the [guidelines](https://github.com/conan-io/conan-center-index/wiki#how-to-submit-a-pull-request) for contributing.
- [x] I've followed the [PEP8](https://www.python.org/dev/peps/pep-0008/) style guides for Python code in the recipes.
- [x] I've used the [latest](https://github.com/conan-io/conan/releases/latest) Conan client version.
- [x] I've tried at least one configuration locally with the
      [conan-center hook](https://github.com/conan-io/hooks.git) activated.




Discussion:

Resolving patch:
diff --git a/recipes/cose-c/all/conanfile.py b/recipes/cose-c/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/cose-c/all/conanfile.py
@@ -0,0 +1,94 @@
+from conans import CMake, ConanFile, tools
+import glob
+import os
+
+
+class CoseCConan(ConanFile):
+    name = "cose-c"
+    license = "BSD-3-Clause"
+    homepage = "https://github.com/cose-wg/COSE-C"
+    url = "https://github.com/conan-io/conan-center-index"
+    description = """Implementation of COSE in C using cn-cbor and openssl"""
+    topics = ("cbor")
+    exports_sources =  ["CMakeLists.txt", "patches/**"]
+    settings = "os", "compiler", "build_type", "arch"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_ssl": ["openssl", "mbedtls"]
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_ssl": "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 config_options(self):
+        if self.settings.os == "Windows":
+            del self.options.fPIC
+
+    def configure(self):
+        if self.options.shared:
+            del self.options.fPIC
+        del self.settings.compiler.libcxx
+        del self.settings.compiler.cppstd
+
+    def requirements(self):
+        self.requires("cn-cbor/1.0.0")
+
+        if self.options.with_ssl == "mbedtls":
+            self.requires("mbedtls/2.23.0")
+        else:
+            self.requires("openssl/1.1.1h")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        os.rename(glob.glob("COSE-C-*")[0], self._source_subfolder)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+        self._cmake.definitions["COSE_C_COVERALLS"] = False
+        self._cmake.definitions["COSE_C_BUILD_TESTS"] = False
+        self._cmake.definitions["COSE_C_BUILD_DOCS"] = False
+        self._cmake.definitions["COSE_C_BUILD_DUMPER"] = False
+        self._cmake.definitions["COSE_C_USE_MBEDTLS"] = self.options.with_ssl == "mbedtls"
+        self._cmake.definitions["COSE_C_USE_FIND_PACKAGE"] = True
+        self._cmake.definitions["COSE_C_EXPORT_TARGETS"] = True
+        self._cmake.configure(build_folder=self._build_subfolder)
+        return self._cmake
+
+    def build(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            tools.patch(**patch)
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+        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)
+        if self.settings.os == "Windows":
+            self.cpp_info.system_libs.extend(["ws2_32", "secur32", "crypt32", "bcrypt"])
+        if self.settings.os == "Macos":
+            self.cpp_info.frameworks.extend(["CoreFoundation", "Security"])
+        if self.options.with_ssl == "mbedtls":
+            self.cpp_info.defines.append("COSE_C_USE_MBEDTLS")
+        else:
+            self.cpp_info.defines.append("COSE_C_USE_OPENSSL")


Test patch:
diff --git a/recipes/cose-c/all/test_package/CMakeLists.txt b/recipes/cose-c/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/cose-c/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(cose-c REQUIRED)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} cose-c::cose-c)
+set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
diff --git a/recipes/cose-c/all/test_package/conanfile.py b/recipes/cose-c/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/cose-c/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"
+
+    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/cose-c/all/test_package/test_package.cpp b/recipes/cose-c/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/cose-c/all/test_package/test_package.cpp
@@ -0,0 +1,20 @@
+#include <cose/cose.h>
+#include <stdio.h>
+
+#if defined(COSE_C_USE_OPENSSL)
+#include <openssl/opensslv.h>
+#endif
+
+#if defined(COSE_C_USE_MBEDTLS)
+#include <mbedtls/config.h>
+#endif
+
+int main(int argc, char *argv[])
+{
+  const int aCoseInitFlags = COSE_INIT_FLAGS_NONE;
+
+  const auto mSign =
+      COSE_Sign0_Init(static_cast<COSE_INIT_FLAGS>(aCoseInitFlags), nullptr);
+
+  return 0;
+}