summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouisP <lpdev@cordier.org>2022-01-26 05:57:31 +0100
committerGitHub <noreply@github.com>2022-01-25 20:57:31 -0800
commit1fbfaf5c5e03d9262de9abe70c9fc85e65f58e52 (patch)
treea29f5e0a58b4083dbf073f141e0d27acf94e5447
parent4421375bb6e754541dc4adb371f0a2265b1b0e58 (diff)
downloadflatbuffers-1fbfaf5c5e03d9262de9abe70c9fc85e65f58e52.tar.gz
flatbuffers-1fbfaf5c5e03d9262de9abe70c9fc85e65f58e52.tar.bz2
flatbuffers-1fbfaf5c5e03d9262de9abe70c9fc85e65f58e52.zip
Fix/cmake build grpc (#7028)
* BuildFlatbuffers.cmake: add verbose on build * BuildFlatbuffers.cmake: properly add *.fb.* files with --grpc argument When "--grpc" argument is provided as an extra flag, resulting grpc files should be added as part of the interface library. This prevent adding .fb.cc files manually to the build. V2: fix dependency on grpc files
-rw-r--r--CMake/BuildFlatBuffers.cmake26
1 files changed, 23 insertions, 3 deletions
diff --git a/CMake/BuildFlatBuffers.cmake b/CMake/BuildFlatBuffers.cmake
index b94c7ed1..b0c5c8fb 100644
--- a/CMake/BuildFlatBuffers.cmake
+++ b/CMake/BuildFlatBuffers.cmake
@@ -230,16 +230,30 @@ function(flatbuffers_generate_headers)
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
get_filename_component(filename ${schema} NAME_WE)
set(generated_include "${generated_include_dir}/${filename}_generated.h")
+
+ # Generate files for grpc if needed
+ set(generated_source_file)
+ if("${FLATBUFFERS_GENERATE_HEADERS_FLAGS}" MATCHES "--grpc")
+ # Check if schema file contain a rpc_service definition
+ file(STRINGS ${schema} has_grpc REGEX "rpc_service")
+ if(has_grpc)
+ list(APPEND generated_include "${generated_include_dir}/${filename}.grpc.fb.h")
+ set(generated_source_file "${generated_include_dir}/${filename}.grpc.fb.cc")
+ endif()
+ endif()
+
add_custom_command(
- OUTPUT ${generated_include}
+ OUTPUT ${generated_include} ${generated_source_file}
COMMAND ${FLATC} ${FLATC_ARGS}
-o ${generated_include_dir}
${include_params}
-c ${schema}
${FLATBUFFERS_GENERATE_HEADERS_FLAGS}
DEPENDS ${FLATC_TARGET} ${schema}
- WORKING_DIRECTORY "${working_dir}")
+ WORKING_DIRECTORY "${working_dir}"
+ COMMENT "Building ${schema} flatbuffers...")
list(APPEND all_generated_header_files ${generated_include})
+ list(APPEND all_generated_source_files ${generated_source_file})
# Geneate the binary flatbuffers schemas if instructed to.
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
@@ -264,6 +278,7 @@ function(flatbuffers_generate_headers)
INTERFACE
${all_generated_header_files}
${all_generated_binary_files}
+ ${all_generated_source_files}
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
add_dependencies(
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
@@ -279,6 +294,10 @@ function(flatbuffers_generate_headers)
PREFIX "Flatbuffers/Generated/Headers Files"
FILES ${all_generated_header_files})
source_group(
+ TREE "${generated_target_dir}"
+ PREFIX "Flatbuffers/Generated/Source Files"
+ FILES ${all_generated_source_files})
+ source_group(
TREE ${working_dir}
PREFIX "Flatbuffers/Schemas"
FILES ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
@@ -371,7 +390,8 @@ function(flatbuffers_generate_binary_files)
-b ${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA} ${json_file}
${FLATBUFFERS_GENERATE_BINARY_FILES_FLAGS}
DEPENDS ${FLATC_TARGET} ${json_file}
- WORKING_DIRECTORY "${working_dir}")
+ WORKING_DIRECTORY "${working_dir}"
+ COMMENT "Building ${json_file} binary flatbuffers...")
list(APPEND all_generated_binary_files ${generated_binary_file})
endforeach()