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 16 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/ydcpp-tcpcat/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.4":
url: "https://github.com/ydcpp/tcpcat/archive/refs/tags/1.0.4.tar.gz"
sha256: "3413e74eab0a1bf7927b747e393b1931e8a516ee769642ce89c558a93e00e38b"
97 changes: 97 additions & 0 deletions recipes/ydcpp-tcpcat/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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)
if not self.settings.get_safe("compiler.cppstd"):
tc.variables["CMAKE_CXX_STANDARD"] = self._min_cppstd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing something, because the project already does it: https://github.com/ydcpp/tcpcat/blob/1.0.4/CMakeLists.txt#L16

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I actually didn't catch that - let's just try with your test package changes, see if that fixes everything :)

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")
8 changes: 8 additions & 0 deletions recipes/ydcpp-tcpcat/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
target_compile_features(test_package PRIVATE cxx_std_17)
26 changes: 26 additions & 0 deletions recipes/ydcpp-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/ydcpp-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);
std::cout << "session id: " << session.GetId() << std::endl;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/ydcpp-tcpcat/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.4":
folder: all
Loading