feat: update protos to 2020-02-25 version (#37)

Update the dependencies based on the new protos.
This commit is contained in:
Carlos O'Ryan 2020-02-25 13:20:33 -05:00 committed by GitHub
parent 3e4f8c025e
commit c1713cb00d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 306 additions and 365 deletions

View file

@ -19,12 +19,11 @@
# We use a function to define the property so it can be called multiple times
# without introducing the property over and over.
function (google_cloud_cpp_add_protos_property)
set_property(TARGET
PROPERTY PROTO_SOURCES
BRIEF_DOCS
"The list of .proto files for a target."
FULL_DOCS
"List of .proto files specified for a target.")
set_property(
TARGET
PROPERTY PROTO_SOURCES BRIEF_DOCS
"The list of .proto files for a target." FULL_DOCS
"List of .proto files specified for a target.")
endfunction ()
# Generate C++ for .proto files preserving the directory hierarchy
@ -54,11 +53,7 @@ endfunction ()
# `foo/bar/baz.proto` then the directory containing `foo` must be in the search
# path.
function (google_cloud_cpp_generate_proto SRCS)
cmake_parse_arguments(_opt
""
""
"PROTO_PATH_DIRECTORIES"
${ARGN})
cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN})
if (NOT _opt_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: google_cloud_cpp_generate_proto() called"
" without any proto files")
@ -71,7 +66,7 @@ function (google_cloud_cpp_generate_proto SRCS)
foreach (dir ${_opt_PROTO_PATH_DIRECTORIES})
get_filename_component(absolute_path ${dir} ABSOLUTE)
list(FIND protobuf_include_path "${absolute_path}"
already_in_search_path)
already_in_search_path)
if (${already_in_search_path} EQUAL -1)
list(APPEND protobuf_include_path "--proto_path" "${absolute_path}")
endif ()
@ -89,11 +84,7 @@ function (google_cloud_cpp_generate_proto SRCS)
set(D "${file_directory}")
if (DEFINED _opt_PROTO_PATH_DIRECTORIES)
foreach (P ${_opt_PROTO_PATH_DIRECTORIES})
string(REGEX
REPLACE "^${P}"
""
T
"${D}")
string(REGEX REPLACE "^${P}" "" T "${D}")
set(D ${T})
endforeach ()
endif ()
@ -102,22 +93,19 @@ function (google_cloud_cpp_generate_proto SRCS)
list(APPEND ${SRCS} "${pb_cc}" "${pb_h}")
add_custom_command(
OUTPUT "${pb_cc}" "${pb_h}"
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS
--cpp_out
"${CMAKE_CURRENT_BINARY_DIR}"
${protobuf_include_path}
"${filename}"
COMMAND
$<TARGET_FILE:protobuf::protoc> ARGS --cpp_out
"${CMAKE_CURRENT_BINARY_DIR}" ${protobuf_include_path}
"${filename}"
DEPENDS "${filename}" protobuf::protoc
COMMENT "Running C++ protocol buffer compiler on ${filename}"
VERBATIM)
endforeach ()
set_source_files_properties(${${SRCS}}
PROPERTIES
GENERATED
TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE)
set(${SRCS}
${${SRCS}}
PARENT_SCOPE)
endfunction ()
# Generate gRPC C++ files from .proto files preserving the directory hierarchy.
@ -147,11 +135,7 @@ endfunction ()
# `foo/bar/baz.proto` then the directory containing `foo` must be in the search
# path.
function (google_cloud_cpp_generate_grpcpp SRCS)
cmake_parse_arguments(_opt
""
""
"PROTO_PATH_DIRECTORIES"
${ARGN})
cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN})
if (NOT _opt_UNPARSED_ARGUMENTS)
message(
SEND_ERROR "Error: google_cloud_cpp_generate_grpc() called without"
@ -165,7 +149,7 @@ function (google_cloud_cpp_generate_grpcpp SRCS)
foreach (dir ${_opt_PROTO_PATH_DIRECTORIES})
get_filename_component(absolute_path ${dir} ABSOLUTE)
list(FIND protobuf_include_path "${absolute_path}"
already_in_search_path)
already_in_search_path)
if (${already_in_search_path} EQUAL -1)
list(APPEND protobuf_include_path "--proto_path" "${absolute_path}")
endif ()
@ -183,11 +167,7 @@ function (google_cloud_cpp_generate_grpcpp SRCS)
set(D "${file_directory}")
if (DEFINED _opt_PROTO_PATH_DIRECTORIES)
foreach (P ${_opt_PROTO_PATH_DIRECTORIES})
string(REGEX
REPLACE "^${P}"
""
T
"${D}")
string(REGEX REPLACE "^${P}" "" T "${D}")
set(D ${T})
endforeach ()
endif ()
@ -198,23 +178,20 @@ function (google_cloud_cpp_generate_grpcpp SRCS)
add_custom_command(
OUTPUT "${grpc_pb_cc}" "${grpc_pb_h}"
COMMAND
$<TARGET_FILE:protobuf::protoc>
ARGS
$<TARGET_FILE:protobuf::protoc> ARGS
--plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin>
"--grpc_out=${CMAKE_CURRENT_BINARY_DIR}"
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}"
${protobuf_include_path}
"--cpp_out=${CMAKE_CURRENT_BINARY_DIR}" ${protobuf_include_path}
"${filename}"
DEPENDS "${filename}" protobuf::protoc gRPC::grpc_cpp_plugin
COMMENT "Running gRPC C++ protocol buffer compiler on ${filename}"
VERBATIM)
endforeach ()
set_source_files_properties(${${SRCS}}
PROPERTIES
GENERATED
TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set_source_files_properties(${${SRCS}} PROPERTIES GENERATED TRUE)
set(${SRCS}
${${SRCS}}
PARENT_SCOPE)
endfunction ()
include(GNUInstallDirs)
@ -227,10 +204,7 @@ function (google_cloud_cpp_install_proto_library_headers target)
if (NOT "${header}" MATCHES "\\.h$")
continue()
endif ()
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/"
""
relative
"${header}")
string(REPLACE "${CMAKE_CURRENT_BINARY_DIR}/" "" relative "${header}")
get_filename_component(dir "${relative}" DIRECTORY)
install(FILES "${header}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${dir}")
@ -245,10 +219,7 @@ function (google_cloud_cpp_install_proto_library_protos target strip_prefix)
if (NOT "${proto}" MATCHES "\\.proto$")
continue()
endif ()
string(REPLACE "${strip_prefix}/"
""
relative
"${proto}")
string(REPLACE "${strip_prefix}/" "" relative "${proto}")
get_filename_component(dir "${relative}" DIRECTORY)
# This is modeled after the Protobuf library, it installs the basic
# protos (think google/protobuf/any.proto) in the include directory for
@ -259,27 +230,22 @@ function (google_cloud_cpp_install_proto_library_protos target strip_prefix)
endfunction ()
function (google_cloud_cpp_proto_library libname)
cmake_parse_arguments(_opt
""
""
"PROTO_PATH_DIRECTORIES"
${ARGN})
cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN})
if (NOT _opt_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called"
" without any proto files")
return()
endif ()
google_cloud_cpp_generate_proto(proto_sources
${_opt_UNPARSED_ARGUMENTS}
PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
google_cloud_cpp_generate_proto(
proto_sources ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
add_library(${libname} ${proto_sources})
set_property(TARGET ${libname}
PROPERTY PROTO_SOURCES ${_opt_UNPARSED_ARGUMENTS})
target_link_libraries(${libname}
PUBLIC gRPC::grpc++ gRPC::grpc protobuf::libprotobuf)
set_property(TARGET ${libname} PROPERTY PROTO_SOURCES
${_opt_UNPARSED_ARGUMENTS})
target_link_libraries(${libname} PUBLIC gRPC::grpc++ gRPC::grpc
protobuf::libprotobuf)
target_include_directories(
${libname}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
@ -288,24 +254,18 @@ function (google_cloud_cpp_proto_library libname)
endfunction ()
function (google_cloud_cpp_grpcpp_library libname)
cmake_parse_arguments(_opt
""
""
"PROTO_PATH_DIRECTORIES"
${ARGN})
cmake_parse_arguments(_opt "" "" "PROTO_PATH_DIRECTORIES" ${ARGN})
if (NOT _opt_UNPARSED_ARGUMENTS)
message(SEND_ERROR "Error: google_cloud_cpp_proto_library() called"
" without any proto files")
return()
endif ()
google_cloud_cpp_generate_grpcpp(grpcpp_sources
${_opt_UNPARSED_ARGUMENTS}
PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
google_cloud_cpp_proto_library(${libname}
${_opt_UNPARSED_ARGUMENTS}
PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
google_cloud_cpp_generate_grpcpp(
grpcpp_sources ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
google_cloud_cpp_proto_library(
${libname} ${_opt_UNPARSED_ARGUMENTS} PROTO_PATH_DIRECTORIES
${_opt_PROTO_PATH_DIRECTORIES})
target_sources(${libname} PRIVATE ${grpcpp_sources})
endfunction ()