diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cb2d1c..5a735cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,7 +122,6 @@ else() include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGRPC.cmake) set(GRPC_LIBRARIES ${GPR_LIBRARY} ${GRPC_LIBRARY} ${GRPC_GRPC++_LIBRARY}) endif() -message("-- Found GRPC: ${GRPC_LIBRARIES} (found version: \"${gRPC_VERSION}\")") # avoid use the apt-get installed libgrpc-dev (version v1.13) on Ubuntu 18.04 if(gRPC_FOUND AND gRPC_VERSION VERSION_LESS "1.14") message(FATAL_ERROR "gRPC '${gRPC_VERSION}' is not supported, please install a newer gRPC library " @@ -153,6 +152,20 @@ check_cxx_compiler_flag(-Wno-c++17-extensions W_NO_CPP17_EXTENSIONS) if(W_NO_CPP17_EXTENSIONS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions") endif() + +set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11") +set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES} ${GRPC_INCLUDE_DIR}") +set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${GRPC_LIBRARIES}") +set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") +check_cxx_source_compiles(" +#include +namespace grpc { class Channel; } +int main() {} +" GRPC_CHANNEL_CLASS_FOUND) +if(GRPC_CHANNEL_CLASS_FOUND) + add_definitions(-DWITH_GRPC_CHANNEL_CLASS) +endif() + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) add_subdirectory(src) diff --git a/etcd/Client.hpp b/etcd/Client.hpp index 3ab3261..43e84d3 100644 --- a/etcd/Client.hpp +++ b/etcd/Client.hpp @@ -55,7 +55,12 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ Client(std::string const & etcd_url, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -75,7 +80,12 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ static Client *WithUrl(std::string const & etcd_url, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -108,7 +118,12 @@ namespace etcd std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -141,7 +156,12 @@ namespace etcd std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -175,7 +195,12 @@ namespace etcd std::string const & cert, std::string const & privkey, std::string const & target_name_override, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -211,11 +236,15 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ static Client *WithSSL(std::string const & etcd_url, - grpc::ChannelArguments const & arguments, - std::string const & ca, - std::string const & cert = "", - std::string const & privkey = "", - std::string const & target_name_override = ""); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments, +#else + grpc_impl::ChannelArguments const & arguments, +#endif + std::string const & ca, + std::string const & cert = "", + std::string const & privkey = "", + std::string const & target_name_override = ""); ~Client(); @@ -654,7 +683,11 @@ namespace etcd /** * Obtain the underlying gRPC channel. */ +#if defined(WITH_GRPC_CHANNEL_CLASS) std::shared_ptr grpc_channel() const; +#else + std::shared_ptr grpc_channel() const; +#endif /** * Set a timeout value for grpc operations. diff --git a/etcd/SyncClient.hpp b/etcd/SyncClient.hpp index a832e6d..121c2be 100644 --- a/etcd/SyncClient.hpp +++ b/etcd/SyncClient.hpp @@ -13,7 +13,7 @@ namespace etcdv3 { struct ActionParameters; - + class AsyncCompareAndDeleteAction; class AsyncCompareAndSwapAction; class AsyncDeleteAction; @@ -45,10 +45,17 @@ namespace etcdv3 { } } +#if defined(WITH_GRPC_CHANNEL_CLASS) namespace grpc { class Channel; class ChannelArguments; } +#else +namespace grpc_impl { + class Channel; + class ChannelArguments; +} +#endif namespace etcd { @@ -101,7 +108,12 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ SyncClient(std::string const & etcd_url, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -121,7 +133,12 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ static SyncClient *WithUrl(std::string const & etcd_url, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** * Constructs an etcd client object. @@ -154,7 +171,12 @@ namespace etcd std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** @@ -188,7 +210,12 @@ namespace etcd std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** @@ -223,7 +250,12 @@ namespace etcd std::string const & cert, std::string const & privkey, std::string const & target_name_override, - grpc::ChannelArguments const & arguments); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ); /** @@ -260,11 +292,15 @@ namespace etcd * @param arguments user provided grpc channel arguments. */ static SyncClient *WithSSL(std::string const & etcd_url, - grpc::ChannelArguments const & arguments, - std::string const & ca, - std::string const & cert = "", - std::string const & privkey = "", - std::string const & target_name_override = ""); +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments, +#else + grpc_impl::ChannelArguments const & arguments, +#endif + std::string const & ca, + std::string const & cert = "", + std::string const & privkey = "", + std::string const & target_name_override = ""); ~SyncClient(); @@ -722,7 +758,11 @@ namespace etcd /** * Obtain the underlying gRPC channel. */ +#if defined(WITH_GRPC_CHANNEL_CLASS) std::shared_ptr grpc_channel() const; +#else + std::shared_ptr grpc_channel() const; +#endif /** * Set a timeout value for grpc operations. @@ -740,7 +780,11 @@ namespace etcd } private: +#if defined(WITH_GRPC_CHANNEL_CLASS) std::shared_ptr channel; +#else + std::shared_ptr channel; +#endif mutable std::unique_ptr token_authenticator; mutable std::chrono::microseconds grpc_timeout = std::chrono::microseconds::zero(); diff --git a/src/Client.cpp b/src/Client.cpp index 3894ad6..028ad72 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -82,7 +82,13 @@ etcd::Client::Client(std::string const & address, } etcd::Client::Client(std::string const & address, - grpc::ChannelArguments const & arguments) +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { this->own_client = true; this->client = new SyncClient(address, arguments); @@ -94,7 +100,13 @@ etcd::Client *etcd::Client::WithUrl(std::string const & etcd_url, } etcd::Client *etcd::Client::WithUrl(std::string const & etcd_url, - grpc::ChannelArguments const & arguments) { +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { return new etcd::Client(etcd_url, arguments); } @@ -112,7 +124,13 @@ etcd::Client::Client(std::string const & address, std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments) +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { this->own_client = true; this->client = new SyncClient(address, username, password, auth_token_ttl, arguments); @@ -130,7 +148,13 @@ etcd::Client *etcd::Client::WithUser(std::string const & etcd_url, std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments) { +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { return new etcd::Client(etcd_url, username, password, auth_token_ttl, arguments); } @@ -151,7 +175,13 @@ etcd::Client::Client(std::string const & address, std::string const & cert, std::string const & privkey, std::string const & target_name_override, - grpc::ChannelArguments const & arguments) +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { this->own_client = true; this->client = new SyncClient(address, ca, cert, privkey, target_name_override, arguments); @@ -167,7 +197,11 @@ etcd::Client *etcd::Client::WithSSL(std::string const & etcd_url, } etcd::Client *etcd::Client::WithSSL(std::string const & etcd_url, - grpc::ChannelArguments const & arguments, +#if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments, +#else + grpc_impl::ChannelArguments const & arguments, +#endif std::string const & ca, std::string const & cert, std::string const & privkey, diff --git a/src/SyncClient.cpp b/src/SyncClient.cpp index 8a3d68c..7114f1a 100644 --- a/src/SyncClient.cpp +++ b/src/SyncClient.cpp @@ -271,7 +271,12 @@ etcd::SyncClient::SyncClient(std::string const & address, } etcd::SyncClient::SyncClient(std::string const & address, - grpc::ChannelArguments const & arguments) + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ) { // create channels std::string const addresses = etcd::detail::strip_and_resolve_addresses(address); @@ -297,7 +302,12 @@ etcd::SyncClient *etcd::SyncClient::WithUrl(std::string const & etcd_url, } etcd::SyncClient *etcd::SyncClient::WithUrl(std::string const & etcd_url, - grpc::ChannelArguments const & arguments) { + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ) { return new etcd::SyncClient(etcd_url, arguments); } @@ -332,7 +342,13 @@ etcd::SyncClient::SyncClient(std::string const & address, std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments) + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { // create channels std::string const addresses = etcd::detail::strip_and_resolve_addresses(address); @@ -366,7 +382,12 @@ etcd::SyncClient *etcd::SyncClient::WithUser(std::string const & etcd_url, std::string const & username, std::string const & password, int const auth_token_ttl, - grpc::ChannelArguments const & arguments) { + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + ) { return new etcd::SyncClient(etcd_url, username, password, auth_token_ttl, arguments); } @@ -406,7 +427,13 @@ etcd::SyncClient::SyncClient(std::string const & address, std::string const & cert, std::string const & privkey, std::string const & target_name_override, - grpc::ChannelArguments const & arguments) + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments +#else + grpc_impl::ChannelArguments const & arguments +#endif + + ) { // create channels std::string const addresses = etcd::detail::strip_and_resolve_addresses(address); @@ -440,7 +467,11 @@ etcd::SyncClient *etcd::SyncClient::WithSSL(std::string const & etcd_url, } etcd::SyncClient *etcd::SyncClient::WithSSL(std::string const & etcd_url, - grpc::ChannelArguments const & arguments, + #if defined(WITH_GRPC_CHANNEL_CLASS) + grpc::ChannelArguments const & arguments, +#else + grpc_impl::ChannelArguments const & arguments, +#endif std::string const & ca, std::string const & cert, std::string const & privkey,