(#23974) asyncpp: add new library to conan

* add asyncpp recipe

* Clean recipe up, improve cmake handling

* Fix newline at EOF

* update minimum required compiler versions for tested compilers

* remove unnecessary file operations

* use asyncpp::asyncpp as conan target name

* Fix shared libraries in test package

* Fix shared windows libs, add missing pthread

* use library version updated to shared library mode

---------

Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
This commit is contained in:
Péter Kardos
2024-06-07 10:51:40 +02:00
committed by GitHub
parent a8ab0ecbea
commit 8d8beb850d
6 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
sources:
"0.2.4":
url: "https://github.com/petiaccja/asyncpp/archive/refs/tags/v0.2.4.tar.gz"
sha256: "58138FF5801D3A547EAAD9ADC2C30FE7A0D506C0E41DC56071CEAAD5747210B5"

View File

@@ -0,0 +1,102 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, rm, rmdir
from conan.tools.scm import Version
import os
required_conan_version = ">=1.53.0"
class AsyncppRecipe(ConanFile):
name = "asyncpp"
description = "A C++20 coroutine library for asynchronous and parallel programming."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/project/package"
topics = ("coroutine", "c++20", "async", "parallel", "concurrency")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
@property
def _min_cppstd(self):
return 20
@property
def _compilers_minimum_version(self):
return {
"gcc": "13",
"clang": "17",
"msvc": "193",
"Visual Studio": "17",
}
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
# src_folder must use the same source folder name the project
cmake_layout(self, src_folder="src")
def validate(self):
# validate the minimum cpp standard supported. For C++ projects only
if self.settings.compiler.cppstd:
check_min_cppstd(self, self._min_cppstd)
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."
)
if self.settings.compiler == "apple-clang":
# As per https://en.cppreference.com/w/cpp/compiler_support, apple-clang 14.0.0 partially supports C++20 but not jthread
raise ConanInvalidConfiguration(f"{self.ref} does not support apple-clang compiler, as it lacks jthread support.")
def build_requirements(self):
self.tool_requires("cmake/[>=3.25 <4]")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["ASYNCPP_BUILD_TESTS"] = "OFF"
tc.variables["ASYNCPP_BUILD_BENCHMARKS"] = "OFF"
tc.generate()
venv = VirtualBuildEnv(self)
venv.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(self, "LICENSE.md", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
def package_info(self):
self.cpp_info.libs = ["asyncpp"]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.bindirs = ["libs"]
if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs = ["pthread"]

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(TestPackage CXX)
add_executable(test_package test_package.cpp)
find_package(asyncpp CONFIG REQUIRED)
target_link_libraries(test_package asyncpp::asyncpp)
target_compile_features(test_package PUBLIC cxx_std_20)

View File

@@ -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 AsyncppTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
def requirements(self):
self.requires(self.tested_reference_str)
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,18 @@
#include <asyncpp/task.hpp>
#include <asyncpp/join.hpp>
#include <iostream>
#include <string>
using namespace asyncpp;
task<std::string> message() {
co_return std::string("async++ installation works.");
}
int main() {
std::cout << join(message()) << std::endl;
return 0;
}

View File

@@ -0,0 +1,3 @@
versions:
"0.2.4":
folder: all