[CMake] Fix FindGRPC cmake module to allow different layering

Take the library target out of `generate_protos` function so the caller
can decide where to layer the library using the source generated from
the function.

Fixes: https://github.com/llvm/llvm-project/issues/58075

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D135712
This commit is contained in:
Steven Wu 2022-10-12 15:25:43 -07:00
parent e669e2bd97
commit 4ba360d499
4 changed files with 17 additions and 8 deletions

View File

@ -194,7 +194,7 @@ if ( CLANGD_BUILD_XPC )
endif ()
if (CLANGD_ENABLE_REMOTE)
include(FindGRPC)
include(AddGRPC)
endif()
if(CLANG_INCLUDE_TESTS)

View File

@ -1,8 +1,8 @@
if (CLANGD_ENABLE_REMOTE)
generate_protos(clangdRemoteIndexProto "Index.proto")
generate_protos(clangdMonitoringServiceProto "MonitoringService.proto"
generate_clang_protos_library(clangdRemoteIndexProto "Index.proto")
generate_clang_protos_library(clangdMonitoringServiceProto "MonitoringService.proto"
GRPC)
generate_protos(clangdRemoteIndexServiceProto "Service.proto"
generate_clang_protos_library(clangdRemoteIndexServiceProto "Service.proto"
DEPENDS "Index.proto"
GRPC)
# FIXME: Move this into generate_protos. Currently we only mention proto

View File

@ -0,0 +1,11 @@
include(FindGRPC)
function(generate_clang_protos_library LibraryName ProtoFile)
# Take the first two args and forward the remaining to generate_proto_sources.
cmake_parse_arguments(PARSE_ARGV 2 PROTO "" "" "")
generate_proto_sources(ProtoSource ${ProtoFile} ${PROTO_UNPARSED_ARGUMENTS})
add_clang_library(${LibraryName} ${ProtoSource}
PARTIAL_SOURCES_INTENDED
LINK_LIBS PUBLIC grpc++ protobuf)
endfunction()

View File

@ -108,7 +108,7 @@ endif()
# If the "GRPC" argument is given, services are also generated.
# The DEPENDS list should name *.proto source files that are imported.
# They may be relative to the source dir or absolute (for generated protos).
function(generate_protos LibraryName ProtoFile)
function(generate_proto_sources GeneratedSource ProtoFile)
cmake_parse_arguments(PARSE_ARGV 2 PROTO "GRPC" "" "DEPENDS")
get_filename_component(ProtoSourceAbsolutePath "${CMAKE_CURRENT_SOURCE_DIR}/${ProtoFile}" ABSOLUTE)
get_filename_component(ProtoSourcePath ${ProtoSourceAbsolutePath} PATH)
@ -132,9 +132,7 @@ function(generate_protos LibraryName ProtoFile)
ARGS ${Flags} "${ProtoSourceAbsolutePath}"
DEPENDS "${ProtoSourceAbsolutePath}")
add_llvm_library(${LibraryName} ${GeneratedProtoSource}
PARTIAL_SOURCES_INTENDED
LINK_LIBS PUBLIC grpc++ protobuf)
set(${GeneratedSource} ${GeneratedProtoSource} PARENT_SCOPE)
# Ensure dependency headers are generated before dependent protos are built.
# DEPENDS arg is a list of "Foo.proto". While they're logically relative to