Reliable macro condition to adapt to different version of gRPC. (#187)
This commit is contained in:
parent
fe80439c5b
commit
fb41073a90
|
|
@ -122,6 +122,7 @@ else()
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGRPC.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGRPC.cmake)
|
||||||
set(GRPC_LIBRARIES ${GPR_LIBRARY} ${GRPC_LIBRARY} ${GRPC_GRPC++_LIBRARY})
|
set(GRPC_LIBRARIES ${GPR_LIBRARY} ${GRPC_LIBRARY} ${GRPC_GRPC++_LIBRARY})
|
||||||
endif()
|
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
|
# 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")
|
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 "
|
message(FATAL_ERROR "gRPC '${gRPC_VERSION}' is not supported, please install a newer gRPC library "
|
||||||
|
|
@ -131,6 +132,10 @@ if(gRPC_FOUND AND gRPC_VERSION VERSION_LESS "1.14")
|
||||||
endif()
|
endif()
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateProtobufGRPC.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateProtobufGRPC.cmake)
|
||||||
|
|
||||||
|
if(gRPC_VERSION VERSION_LESS "1.21" OR gRPC_VERSION VERSION_GREATER "1.31")
|
||||||
|
add_definitions(-DWITH_GRPC_CHANNEL_CLASS)
|
||||||
|
endif()
|
||||||
|
|
||||||
# will set `PROTOBUF_GENERATES`, indicates all generated .cc files, and a target `protobuf_generates`.
|
# will set `PROTOBUF_GENERATES`, indicates all generated .cc files, and a target `protobuf_generates`.
|
||||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateProtobuf.cmake)
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateProtobuf.cmake)
|
||||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/proto)
|
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/proto)
|
||||||
|
|
@ -153,19 +158,6 @@ if(W_NO_CPP17_EXTENSIONS)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")
|
||||||
endif()
|
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 <grpc++/grpc++.h>
|
|
||||||
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)
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
|
||||||
|
|
@ -82,13 +82,7 @@ etcd::Client::Client(std::string const & address,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::Client::Client(std::string const & address,
|
etcd::Client::Client(std::string const & address,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->own_client = true;
|
this->own_client = true;
|
||||||
this->client = new SyncClient(address, arguments);
|
this->client = new SyncClient(address, arguments);
|
||||||
|
|
@ -100,13 +94,7 @@ etcd::Client *etcd::Client::WithUrl(std::string const & etcd_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::Client *etcd::Client::WithUrl(std::string const & etcd_url,
|
etcd::Client *etcd::Client::WithUrl(std::string const & etcd_url,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments) {
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
) {
|
|
||||||
return new etcd::Client(etcd_url, arguments);
|
return new etcd::Client(etcd_url, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,13 +112,7 @@ etcd::Client::Client(std::string const & address,
|
||||||
std::string const & username,
|
std::string const & username,
|
||||||
std::string const & password,
|
std::string const & password,
|
||||||
int const auth_token_ttl,
|
int const auth_token_ttl,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->own_client = true;
|
this->own_client = true;
|
||||||
this->client = new SyncClient(address, username, password, auth_token_ttl, arguments);
|
this->client = new SyncClient(address, username, password, auth_token_ttl, arguments);
|
||||||
|
|
@ -148,13 +130,7 @@ etcd::Client *etcd::Client::WithUser(std::string const & etcd_url,
|
||||||
std::string const & username,
|
std::string const & username,
|
||||||
std::string const & password,
|
std::string const & password,
|
||||||
int const auth_token_ttl,
|
int const auth_token_ttl,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments) {
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
) {
|
|
||||||
return new etcd::Client(etcd_url, username, password, auth_token_ttl, arguments);
|
return new etcd::Client(etcd_url, username, password, auth_token_ttl, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,13 +151,7 @@ etcd::Client::Client(std::string const & address,
|
||||||
std::string const & cert,
|
std::string const & cert,
|
||||||
std::string const & privkey,
|
std::string const & privkey,
|
||||||
std::string const & target_name_override,
|
std::string const & target_name_override,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this->own_client = true;
|
this->own_client = true;
|
||||||
this->client = new SyncClient(address, ca, cert, privkey, target_name_override, arguments);
|
this->client = new SyncClient(address, ca, cert, privkey, target_name_override, arguments);
|
||||||
|
|
@ -197,11 +167,7 @@ etcd::Client *etcd::Client::WithSSL(std::string const & etcd_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::Client *etcd::Client::WithSSL(std::string const & etcd_url,
|
etcd::Client *etcd::Client::WithSSL(std::string const & etcd_url,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
|
||||||
grpc::ChannelArguments const & arguments,
|
grpc::ChannelArguments const & arguments,
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments,
|
|
||||||
#endif
|
|
||||||
std::string const & ca,
|
std::string const & ca,
|
||||||
std::string const & cert,
|
std::string const & cert,
|
||||||
std::string const & privkey,
|
std::string const & privkey,
|
||||||
|
|
|
||||||
|
|
@ -271,12 +271,7 @@ etcd::SyncClient::SyncClient(std::string const & address,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::SyncClient::SyncClient(std::string const & address,
|
etcd::SyncClient::SyncClient(std::string const & address,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// create channels
|
// create channels
|
||||||
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
||||||
|
|
@ -302,12 +297,7 @@ etcd::SyncClient *etcd::SyncClient::WithUrl(std::string const & etcd_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::SyncClient *etcd::SyncClient::WithUrl(std::string const & etcd_url,
|
etcd::SyncClient *etcd::SyncClient::WithUrl(std::string const & etcd_url,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments) {
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
return new etcd::SyncClient(etcd_url, arguments);
|
return new etcd::SyncClient(etcd_url, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,13 +332,7 @@ etcd::SyncClient::SyncClient(std::string const & address,
|
||||||
std::string const & username,
|
std::string const & username,
|
||||||
std::string const & password,
|
std::string const & password,
|
||||||
int const auth_token_ttl,
|
int const auth_token_ttl,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// create channels
|
// create channels
|
||||||
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
||||||
|
|
@ -382,12 +366,7 @@ etcd::SyncClient *etcd::SyncClient::WithUser(std::string const & etcd_url,
|
||||||
std::string const & username,
|
std::string const & username,
|
||||||
std::string const & password,
|
std::string const & password,
|
||||||
int const auth_token_ttl,
|
int const auth_token_ttl,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments) {
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
return new etcd::SyncClient(etcd_url, username, password, auth_token_ttl, arguments);
|
return new etcd::SyncClient(etcd_url, username, password, auth_token_ttl, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,13 +406,7 @@ etcd::SyncClient::SyncClient(std::string const & address,
|
||||||
std::string const & cert,
|
std::string const & cert,
|
||||||
std::string const & privkey,
|
std::string const & privkey,
|
||||||
std::string const & target_name_override,
|
std::string const & target_name_override,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
grpc::ChannelArguments const & arguments)
|
||||||
grpc::ChannelArguments const & arguments
|
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments
|
|
||||||
#endif
|
|
||||||
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// create channels
|
// create channels
|
||||||
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
std::string const addresses = etcd::detail::strip_and_resolve_addresses(address);
|
||||||
|
|
@ -467,11 +440,7 @@ etcd::SyncClient *etcd::SyncClient::WithSSL(std::string const & etcd_url,
|
||||||
}
|
}
|
||||||
|
|
||||||
etcd::SyncClient *etcd::SyncClient::WithSSL(std::string const & etcd_url,
|
etcd::SyncClient *etcd::SyncClient::WithSSL(std::string const & etcd_url,
|
||||||
#if defined(WITH_GRPC_CHANNEL_CLASS)
|
|
||||||
grpc::ChannelArguments const & arguments,
|
grpc::ChannelArguments const & arguments,
|
||||||
#else
|
|
||||||
grpc_impl::ChannelArguments const & arguments,
|
|
||||||
#endif
|
|
||||||
std::string const & ca,
|
std::string const & ca,
|
||||||
std::string const & cert,
|
std::string const & cert,
|
||||||
std::string const & privkey,
|
std::string const & privkey,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue