Repository: conan-io/conan-center-index

Issue:
[request] libusrsctp/0.9.3.0
### Package Details
  * Package Name/Version: **libusrsctp/0.9.3.0**
  * Website: **https://github.com/sctplab/usrsctp**
  * Source code: **https://github.com/sctplab/usrsctp**


### Description Of The Library / Tool
SCTP is a message oriented, reliable transport protocol with direct support for multihoming that runs on top of IP or UDP, and supports both v4 and v6 versions.

Like TCP, SCTP provides reliable, connection oriented data delivery with congestion control. Unlike TCP, SCTP also provides message boundary preservation, ordered and unordered message delivery, multi-streaming and multi-homing. Detection of data corruption, loss of data and duplication of data is achieved by using checksums and sequence numbers. A selective retransmission mechanism is applied to correct loss or corruption of data.




Discussion:

Resolving patch:
diff --git a/recipes/usrsctp/all/conanfile.py b/recipes/usrsctp/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/usrsctp/all/conanfile.py
@@ -0,0 +1,74 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class UsrsctpConan(ConanFile):
+    name = "usrsctp"
+    license = "BSD-3-Clause"
+    homepage = "https://github.com/sctplab/usrsctp"
+    url = "https://github.com/conan-io/conan-center-index"
+    topics = ("conan", "network", "sctp")
+    description = " A portable SCTP userland stack"
+    settings = "os", "compiler", "arch", "build_type"
+    options = {"shared": [True, False],
+               "fPIC": [True, False]}
+    default_options = {"shared": False,
+                       "fPIC": True}
+    exports_sources = ["CMakeLists.txt", "patches/*"]
+    generators = "cmake"
+
+    _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.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 = "usrsctp-{}".format(self.version)
+        os.rename(extracted_dir, self._source_subfolder)
+
+    def _patch_sources(self):
+        for patch in self.conan_data.get("patches", {}).get(self.version, []):
+            tools.patch(**patch)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+        self._cmake.definitions["sctp_debug"] = False
+        self._cmake.definitions["sctp_werror"] = False
+        self._cmake.definitions["sctp_build_shared_lib"] = self.options.shared
+        self._cmake.definitions["sctp_build_programs"] = False
+        self._cmake.configure()
+        return self._cmake
+
+    def build(self):
+        self._patch_sources()
+        cmake = self._configure_cmake()
+        cmake.build()
+
+    def package(self):
+        self.copy("LICENSE.md", src=self._source_subfolder, dst="licenses")
+        cmake = self._configure_cmake()
+        cmake.install()
+        tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
+
+    def package_info(self):
+        self.cpp_info.names["pkg_config"] = "usrsctp"
+        if self.settings.os == "Windows":
+            self.cpp_info.system_libs.extend(['ws2_32', 'iphlpapi'])
+        elif self.settings.os == "Linux":
+            self.cpp_info.system_libs.extend(['pthread'])
+        suffix = "_import" if self.settings.os == "Windows" and self.options.shared else ""
+        self.cpp_info.libs = ["usrsctp" + suffix]


Test patch:
diff --git a/recipes/usrsctp/all/test_package/CMakeLists.txt b/recipes/usrsctp/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/usrsctp/all/test_package/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.1)
+project(test_package C)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(usrsctp REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.c)
+target_link_libraries(${PROJECT_NAME} usrsctp::usrsctp)
diff --git a/recipes/usrsctp/all/test_package/conanfile.py b/recipes/usrsctp/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/usrsctp/all/test_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(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")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/usrsctp/all/test_package/test_package.c b/recipes/usrsctp/all/test_package/test_package.c
new file mode 100644
--- /dev/null
+++ b/recipes/usrsctp/all/test_package/test_package.c
@@ -0,0 +1,7 @@
+#include <usrsctp.h>
+
+int main(int argc, char **argv)
+{
+  usrsctp_finish();
+  return 0;
+}