diff --git a/recipes/ydcpp-tcpcat/all/conandata.yml b/recipes/ydcpp-tcpcat/all/conandata.yml new file mode 100644 index 0000000000000..93679778e120e --- /dev/null +++ b/recipes/ydcpp-tcpcat/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0.4": + url: "https://github.com/ydcpp/tcpcat/archive/refs/tags/1.0.4.tar.gz" + sha256: "3413e74eab0a1bf7927b747e393b1931e8a516ee769642ce89c558a93e00e38b" diff --git a/recipes/ydcpp-tcpcat/all/conanfile.py b/recipes/ydcpp-tcpcat/all/conanfile.py new file mode 100644 index 0000000000000..ff79b54fa821b --- /dev/null +++ b/recipes/ydcpp-tcpcat/all/conanfile.py @@ -0,0 +1,95 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout +from conan.tools.microsoft import is_msvc +from conan.tools.files import copy, get +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +import os + + +class TcpcatConan(ConanFile): + name = "ydcpp-tcpcat" + + # Optional metadata + license = "MIT" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/ydcpp/tcpcat" + description = "Simple C++ TCP Server and Client library." + topics = ("network", "tcp", "tcp-server", "tcp-client") + + # Binary configuration + package_type = "library" + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + @property + def _min_cppstd(self): + return 17 + + @property + def _compilers_minimum_version(self): + return { + "gcc": "7", + "Visual Studio": "16", + "msvc": "192", + "clang": "7", + "apple-clang": "12" + } + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self, src_folder="src") + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + + # Upstream meant to support Windows Shared builds, but they don't currently export any symbols + # Disable for now until fixed. As this is an upstream issue they want fixed, we don't set + # package_type = "static-library" in the configure() method so that users have a clear message error for now + if is_msvc(self) and self.options.shared: + raise ConanInvalidConfiguration(f"{self.ref} does not currently support Windows shared builds due to an upstream issue") + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def requirements(self): + self.requires("asio/1.30.2", transitive_headers = True) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + copy(self, "*", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include")) + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["ydcpp-tcpcat"] + self.cpp_info.set_property("cmake_target_name", "ydcpp-tcpcat") + if self.settings.os in ("Linux", "FreeBSD"): + self.cpp_info.system_libs.append("m") diff --git a/recipes/ydcpp-tcpcat/all/test_package/CMakeLists.txt b/recipes/ydcpp-tcpcat/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..0be8339e35258 --- /dev/null +++ b/recipes/ydcpp-tcpcat/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +add_executable(test_package test_package.cpp) + +find_package(ydcpp-tcpcat CONFIG REQUIRED) +target_link_libraries(test_package ydcpp-tcpcat) +target_compile_features(test_package PRIVATE cxx_std_17) diff --git a/recipes/ydcpp-tcpcat/all/test_package/conanfile.py b/recipes/ydcpp-tcpcat/all/test_package/conanfile.py new file mode 100644 index 0000000000000..806fd5ae2a792 --- /dev/null +++ b/recipes/ydcpp-tcpcat/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import can_run + + +class tcpcatTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "CMakeToolchain" + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def layout(self): + cmake_layout(self) + + def test(self): + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "test_package") + self.run(cmd, env="conanrun") diff --git a/recipes/ydcpp-tcpcat/all/test_package/test_package.cpp b/recipes/ydcpp-tcpcat/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..aa337b33b0be6 --- /dev/null +++ b/recipes/ydcpp-tcpcat/all/test_package/test_package.cpp @@ -0,0 +1,11 @@ +#include + +#include +#include + +int main() +{ + tcpcat::TcpSession session(nullptr, nullptr, 0); + std::cout << "session id: " << session.GetId() << std::endl; + return 0; +} diff --git a/recipes/ydcpp-tcpcat/config.yml b/recipes/ydcpp-tcpcat/config.yml new file mode 100644 index 0000000000000..c20e44b006f1a --- /dev/null +++ b/recipes/ydcpp-tcpcat/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.4": + folder: all