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

tcpcat library publish #24062

Merged
merged 17 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
4 changes: 4 additions & 0 deletions recipes/tcpcat/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.3":
url: "https://github.com/ydcpp/tcpcat/archive/refs/tags/1.0.3.tar.gz"
sha256: "29cafd7e71685fc51a16770a589a5a9a16a2361b214329e6c64ea482293a0742"
86 changes: 86 additions & 0 deletions recipes/tcpcat/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMakeToolchain, CMake, CMakeDeps, cmake_layout
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 = "tcpcat"
package_type = "library"

# 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")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

# Binary configuration
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"
}
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

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)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
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]", transitive_headers = True)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

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"))
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
cmake = CMake(self)
cmake.install()
ydcpp marked this conversation as resolved.
Show resolved Hide resolved

def package_info(self):
self.cpp_info.libs = ["tcpcat"]
self.cpp_info.set_property("cmake_target_name", "tcpcat")
7 changes: 7 additions & 0 deletions recipes/tcpcat/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

add_executable(test_package test_package.cpp)

find_package(tcpcat CONFIG REQUIRED)
target_link_libraries(test_package tcpcat)
26 changes: 26 additions & 0 deletions recipes/tcpcat/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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")
11 changes: 11 additions & 0 deletions recipes/tcpcat/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <tcpcat/tcpcat.h>

#include <iostream>
#include <string>

int main()
{
tcpcat::TcpSession session(nullptr, nullptr, 0);
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "session id: " << session.GetId() << std::endl;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/tcpcat/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.3":
folder: all
Loading