steven_wu created this revision. steven_wu added reviewers: sammccall, akyrtzi, rymiel. Herald added subscribers: ributzka, kadircet, arphaman. Herald added a project: All. steven_wu requested review of this revision. Herald added projects: LLVM, clang-tools-extra. Herald added a subscriber: cfe-commits.
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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D135712 Files: clang-tools-extra/clangd/index/remote/CMakeLists.txt llvm/cmake/modules/FindGRPC.cmake Index: llvm/cmake/modules/FindGRPC.cmake =================================================================== --- llvm/cmake/modules/FindGRPC.cmake +++ llvm/cmake/modules/FindGRPC.cmake @@ -108,7 +108,7 @@ # 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_protos 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 @@ 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 Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/index/remote/CMakeLists.txt +++ clang-tools-extra/clangd/index/remote/CMakeLists.txt @@ -1,17 +1,32 @@ if (CLANGD_ENABLE_REMOTE) - generate_protos(clangdRemoteIndexProto "Index.proto") - generate_protos(clangdMonitoringServiceProto "MonitoringService.proto" + generate_protos(clangdRemoteIndexProtoSource "Index.proto") + generate_protos(clangdMonitoringServiceProtoSource "MonitoringService.proto" GRPC) - generate_protos(clangdRemoteIndexServiceProto "Service.proto" + generate_protos(clangdRemoteIndexServiceProtoSource "Service.proto" DEPENDS "Index.proto" GRPC) - # FIXME: Move this into generate_protos. Currently we only mention proto - # filename as a dependency, but linking requires target name. - target_link_libraries(clangdRemoteIndexServiceProto + + add_clang_library(clangdRemoteIndexProto ${clangdRemoteIndexProtoSource} + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC grpc++ protobuf) + add_clang_library(clangdMonitoringServiceProto ${clangdMonitoringServiceProtoSource} + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC grpc++ protobuf) + + add_clang_library(clangdRemoteIndexServiceProto + ${clangdRemoteIndexServiceProtoSource} + PARTIAL_SOURCES_INTENDED + + LINK_LIBS + PUBLIC + grpc++ + protobuf + PRIVATE clangdRemoteIndexProto clangdMonitoringServiceProto ) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) # FIXME(kirillbobyrev): target_compile_definitions is not working with
Index: llvm/cmake/modules/FindGRPC.cmake =================================================================== --- llvm/cmake/modules/FindGRPC.cmake +++ llvm/cmake/modules/FindGRPC.cmake @@ -108,7 +108,7 @@ # 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_protos 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 @@ 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 Index: clang-tools-extra/clangd/index/remote/CMakeLists.txt =================================================================== --- clang-tools-extra/clangd/index/remote/CMakeLists.txt +++ clang-tools-extra/clangd/index/remote/CMakeLists.txt @@ -1,17 +1,32 @@ if (CLANGD_ENABLE_REMOTE) - generate_protos(clangdRemoteIndexProto "Index.proto") - generate_protos(clangdMonitoringServiceProto "MonitoringService.proto" + generate_protos(clangdRemoteIndexProtoSource "Index.proto") + generate_protos(clangdMonitoringServiceProtoSource "MonitoringService.proto" GRPC) - generate_protos(clangdRemoteIndexServiceProto "Service.proto" + generate_protos(clangdRemoteIndexServiceProtoSource "Service.proto" DEPENDS "Index.proto" GRPC) - # FIXME: Move this into generate_protos. Currently we only mention proto - # filename as a dependency, but linking requires target name. - target_link_libraries(clangdRemoteIndexServiceProto + + add_clang_library(clangdRemoteIndexProto ${clangdRemoteIndexProtoSource} + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC grpc++ protobuf) + add_clang_library(clangdMonitoringServiceProto ${clangdMonitoringServiceProtoSource} + PARTIAL_SOURCES_INTENDED + LINK_LIBS PUBLIC grpc++ protobuf) + + add_clang_library(clangdRemoteIndexServiceProto + ${clangdRemoteIndexServiceProtoSource} + PARTIAL_SOURCES_INTENDED + + LINK_LIBS + PUBLIC + grpc++ + protobuf + PRIVATE clangdRemoteIndexProto clangdMonitoringServiceProto ) + include_directories(${CMAKE_CURRENT_BINARY_DIR}) # FIXME(kirillbobyrev): target_compile_definitions is not working with
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits