diff --git a/cmake/configs/default.cmake b/cmake/configs/default.cmake index 93bf0b5e50..db946e8e04 100644 --- a/cmake/configs/default.cmake +++ b/cmake/configs/default.cmake @@ -197,6 +197,7 @@ hunter_default_version(angles VERSION 1.9.11-p0) hunter_default_version(apg VERSION 0.0.0-b322f7a-p0) hunter_default_version(arabica VERSION 0.0.0-a202766-p0) hunter_default_version(asio VERSION 1.17.0-p0) +hunter_default_version(asio-grpc VERSION 1.6.0) hunter_default_version(astc-encoder VERSION 3.0-7257cbd-p0) hunter_default_version(autobahn-cpp VERSION 0.2.0) hunter_default_version(autoutils VERSION 0.3.0) diff --git a/cmake/projects/asio-grpc/hunter.cmake b/cmake/projects/asio-grpc/hunter.cmake new file mode 100644 index 0000000000..a8951f0a56 --- /dev/null +++ b/cmake/projects/asio-grpc/hunter.cmake @@ -0,0 +1,24 @@ +# Copyright (c) 2022, Tradias +# All rights reserved. + +# !!! DO NOT PLACE HEADER GUARDS HERE !!! + +include(hunter_add_version) +include(hunter_cacheable) +include(hunter_download) +include(hunter_pick_scheme) + +hunter_add_version( + PACKAGE_NAME + asio-grpc + VERSION + 1.6.0 + URL + "https://github.com/Tradias/asio-grpc/archive/refs/tags/v1.6.0.tar.gz" + SHA1 + a5ab9797a34b390236fdd52986ee792a6894221f +) + +hunter_pick_scheme(DEFAULT url_sha1_cmake) +hunter_cacheable(asio-grpc) +hunter_download(PACKAGE_NAME asio-grpc) diff --git a/docs/packages/pkg/asio-grpc.rst b/docs/packages/pkg/asio-grpc.rst new file mode 100644 index 0000000000..4323170403 --- /dev/null +++ b/docs/packages/pkg/asio-grpc.rst @@ -0,0 +1,54 @@ +.. spelling:: + + asio-grpc + +.. index:: + single: concurrency ; asio-grpc + single: networking ; asio-grpc + +.. _pkg.asio-grpc: + +asio-grpc +========= + +- `Official `__ +- `Example `__ +- Added by `Tradias `__ (`pr-554 `__) + +.. literalinclude:: /../examples/asio-grpc/CMakeLists.txt + :language: cmake + :start-after: # DOCUMENTATION_START { + :end-before: # DOCUMENTATION_END } + +CMake options +------------- + +The ``CMAKE_ARGS`` feature (see +`customization `__) +can be used to customize asio-grpc: + +- To use standalone Asio instead of Boost.Asio: + + .. code-block:: cmake + + hunter_config( + asio-grpc + VERSION ${HUNTER_asio-grpc_VERSION} + CMAKE_ARGS + ASIO_GRPC_HUNTER_BACKEND_BOOST_ASIO=OFF + ASIO_GRPC_HUNTER_BACKEND_STANDALONE_ASIO=ON + ) + +- To use Boost.Container instead of ````: + + .. code-block:: cmake + + hunter_config( + asio-grpc + VERSION ${HUNTER_asio-grpc_VERSION} + CMAKE_ARGS + ASIO_GRPC_USE_BOOST_CONTAINER=ON + ) + +For more options see `asio-grpc repository `__. + diff --git a/examples/asio-grpc/CMakeLists.txt b/examples/asio-grpc/CMakeLists.txt new file mode 100644 index 0000000000..8b16240ced --- /dev/null +++ b/examples/asio-grpc/CMakeLists.txt @@ -0,0 +1,35 @@ +# Copyright (c) 2016-2020, Rahul Sheth, Ruslan Baratov +# All rights reserved. + +cmake_minimum_required(VERSION 3.2) + +# Emulate HunterGate: +# * https://github.com/hunter-packages/gate +include("../common.cmake") + +project(download-asio-grpc) + +# DOCUMENTATION_START { +hunter_add_package(asio-grpc) +find_package(asio-grpc CONFIG REQUIRED) + +add_executable(boo boo.cpp) +target_link_libraries(boo PUBLIC asio-grpc::asio-grpc) +# DOCUMENTATION_END } + +# Test double library creation +find_package(asio-grpc CONFIG REQUIRED) + +# Check license +string(COMPARE EQUAL "${asio-grpc_LICENSES}" "" is_empty) +if(is_empty) + message(FATAL_ERROR "Licenses not found") +endif() + +message("asio-grpc licenses:") +foreach(x ${asio-grpc_LICENSES}) + message("* ${x}") + if(NOT EXISTS "${x}") + message(FATAL_ERROR "File not found") + endif() +endforeach() diff --git a/examples/asio-grpc/boo.cpp b/examples/asio-grpc/boo.cpp new file mode 100644 index 0000000000..1279d2c819 --- /dev/null +++ b/examples/asio-grpc/boo.cpp @@ -0,0 +1,14 @@ +#include + +#include + +int main() { + agrpc::GrpcContext grpc_context{std::make_unique()}; + grpc::Alarm alarm; + agrpc::wait(alarm, + std::chrono::system_clock::now() + std::chrono::milliseconds(10), + boost::asio::bind_executor(grpc_context, [](bool ok) { + std::cout << "Waited for grpc::Alarm: " << ok << std::endl; + })); + grpc_context.run(); +}