De-duplicate .proto file processing

.proto files that are used by more than one target have their code
files generated multiple times, which causes issues with
add_custom_command(). De-duplicate them so they're only generated
once.
pull/20537/head
Kyle Edwards 5 years ago
parent d55596780b
commit ecdd1c915e
  1. 37
      templates/CMakeLists.txt.template

@ -68,6 +68,21 @@
return ''
return 'endif()\n'
%>
<%
# These files are added to a set so that they are not duplicated if multiple
# targets use them. Generating the same file multiple times with
# add_custom_command() is not allowed in CMake.
protobuf_gen_files = set()
for tgt in targets:
for src in tgt.src:
if proto_re.match(src):
protobuf_gen_files.add(src)
for lib in libs:
for src in lib.src:
if proto_re.match(src):
protobuf_gen_files.add(src)
%>
cmake_minimum_required(VERSION 3.5.1)
@ -295,6 +310,12 @@
add_custom_target(tools
DEPENDS tools_c tools_cxx)
% for src in sorted(protobuf_gen_files):
protobuf_generate_grpc_cpp(
${src}
)
% endfor
if (gRPC_BUILD_TESTS)
add_custom_target(buildtests_c)
% for tgt in targets:
@ -411,14 +432,6 @@
endif()
endif()
% for src in lib.src:
% if proto_re.match(src):
protobuf_generate_grpc_cpp(
${src}
)
% endif
% endfor
target_include_directories(${lib.name}
PUBLIC <%text>$<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include></%text>
PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
@ -501,14 +514,6 @@
% endif
)
% for src in tgt.src:
% if proto_re.match(src):
protobuf_generate_grpc_cpp(
${src}
)
% endif
% endfor
target_include_directories(${tgt.name}
PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include

Loading…
Cancel
Save