Repository: conan-io/conan-center-index

Issue:
[request] seasocks/1.4.3
### Package Details
  * Package Name/Version: **seasocks/1.4.3**
  * Website: **https://github.com/mattgodbolt/seasocks**
  * Source code: **https://github.com/mattgodbolt/seasocks**


### Description Of The Library / Tool

Simple, small, C++ embeddable webserver with WebSockets support.


Discussion:
Seems like @danimtb has a prototype https://github.com/danimtb/conan-seasocks
Yes, we tried while preparing a demo but didn't have the chance to continue and make it all the way to the index. Anyone, feel free to copy the recipe and create a PR with it!

Resolving patch:
diff --git a/recipes/seasocks/all/conanfile.py b/recipes/seasocks/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/seasocks/all/conanfile.py
@@ -0,0 +1,80 @@
+from conans import CMake, ConanFile, tools
+from conans.errors import ConanInvalidConfiguration
+import os
+
+
+class SeasocksConan(ConanFile):
+    name = "seasocks"
+    description = "A tiny embeddable C++ HTTP and WebSocket server for Linux"
+    topics = ("seasocks", "embeddable", "webserver", "websockets")
+    homepage = "https://github.com/mattgodbolt/seasocks"
+    url = "https://github.com/conan-io/conan-center-index"
+    license = "BSD-2-Clause"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+        "with_zlib": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+        "with_zlib": True,
+    }
+    generators = "cmake", "cmake_find_package"
+    exports_sources = "CMakeLists.txt"
+
+    _cmake = None
+
+    @property
+    def _source_subfolder(self):
+        return "source_subfolder"
+
+    def configure(self):
+        if self.settings.os != "Linux":
+            raise ConanInvalidConfiguration("Seasocks doesn't support this os")
+        if self.options.shared:
+            del self.options.fPIC
+
+    def requirements(self):
+        if self.options.with_zlib:
+            self.requires("zlib/1.2.11")
+
+    def source(self):
+        tools.get(**self.conan_data["sources"][self.version])
+        os.rename("seasocks-{}".format(self.version), self._source_subfolder)
+
+    def _configure_cmake(self):
+        if self._cmake:
+            return self._cmake
+        self._cmake = CMake(self)
+        self._cmake.definitions["DEFLATE_SUPPORT"] = self.options.with_zlib
+        self._cmake.definitions["SEASOCKS_SHARED"] = self.options.shared
+        self._cmake.definitions["SEASOCKS_EXAMPLE_APP"] = False
+        self._cmake.definitions["UNITTESTS"] = False
+        self._cmake.configure()
+        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"))
+        tools.rmdir(os.path.join(self.package_folder, "share"))
+
+    def package_info(self):
+        # Set the name of the generated `FindSeasocks.cmake` and
+        # `SeasocksConfig.cmake` cmake scripts
+        self.cpp_info.names["cmake_find_package"] = "Seasocks"
+        self.cpp_info.names["cmake_find_package_multi"] = "Seasocks"
+        self.cpp_info.components["libseasocks"].libs = ["seasocks"]
+        self.cpp_info.components["libseasocks"].system_libs = ["pthread"]
+        # Set the name of the generated seasocks target: `Seasocks::seasocks`
+        self.cpp_info.components["libseasocks"].names["cmake_find_package"] = "seasocks"
+        self.cpp_info.components["libseasocks"].names["cmake_find_package_multi"] = "seasocks"
+        if self.options.with_zlib:
+            self.cpp_info.components["libseasocks"].requires = ["zlib::zlib"]


Test patch:
diff --git a/recipes/seasocks/all/test_package/CMakeLists.txt b/recipes/seasocks/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/seasocks/all/test_package/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.3)
+project(PackageTest CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+find_package(Seasocks REQUIRED)
+find_package(Threads REQUIRED)
+
+add_executable(seasocks_test seasocks_test.cpp)
+target_link_libraries(seasocks_test PRIVATE Seasocks::seasocks Threads::Threads)
+set_property(TARGET seasocks_test PROPERTY CXX_STANDARD 11)
diff --git a/recipes/seasocks/all/test_package/conanfile.py b/recipes/seasocks/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/seasocks/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"
+
+    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", "seasocks_test")
+            self.run(bin_path, run_environment=True)
diff --git a/recipes/seasocks/all/test_package/seasocks_test.cpp b/recipes/seasocks/all/test_package/seasocks_test.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/seasocks/all/test_package/seasocks_test.cpp
@@ -0,0 +1,24 @@
+#include "seasocks/Server.h"
+#include "seasocks/Connection.h"
+#include "seasocks/PrintfLogger.h"
+
+#include <thread>
+#include <unistd.h>
+
+using namespace seasocks;
+
+// This is a conan test program to ensure the packaging works.
+// It's not meant as an example of how best to use Seasocks.
+int main(int argc, const char* argv[]) {
+    auto logger = std::make_shared<PrintfLogger>();
+    Server server(logger);
+    server.startListening(0);
+    std::thread seasocksThread([&] {
+        server.loop();
+    });
+
+    sleep(1);
+
+    server.terminate();
+    seasocksThread.join();
+}