Skip to content

Commit

Permalink
Fix/cmake build grpc (#7028)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lp35 authored Jan 26, 2022
1 parent 4421375 commit 1fbfaf5
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions CMake/BuildFlatBuffers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand All @@ -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}
Expand All @@ -278,6 +293,10 @@ function(flatbuffers_generate_headers)
TREE "${generated_target_dir}"
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"
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 1fbfaf5

Please sign in to comment.