Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra/fb] Introduce FlatBuffersMuteable_Target #13687

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions infra/cmake/packages/FlatBuffers-23.5.26/FlatBuffersConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,53 @@ if(FlatBuffers_FOUND)
target_include_directories(${TGT} PUBLIC "${ARG_INCLUDE_DIR}")
target_link_libraries(${TGT} PUBLIC flatbuffers-23.5.26)
endfunction(FlatBuffers_Target)

function(FlatBuffersMuteable_Target TGT)
set(oneValueArgs OUTPUT_DIR SCHEMA_DIR INCLUDE_DIR)
set(multiValueArgs SCHEMA_FILES)
cmake_parse_arguments(ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Use OUTPUT_DIR as INCLUDE_DIR if INCLUDE_DIR is not specified
if(NOT ARG_INCLUDE_DIR)
set(ARG_INCLUDE_DIR ${ARG_OUTPUT_DIR})
endif(NOT ARG_INCLUDE_DIR)

get_filename_component(abs_output_dir ${ARG_OUTPUT_DIR} ABSOLUTE)
get_filename_component(abs_include_dir ${ARG_INCLUDE_DIR} ABSOLUTE)
get_filename_component(abs_schema_dir ${ARG_SCHEMA_DIR} ABSOLUTE)

# Let's reset list variables before using them
# NOTE THIS DOES NOT AFFECT parent scope
unset(SCHEMA_FILES)
unset(OUTPUT_FILES)

foreach(schema ${ARG_SCHEMA_FILES})
get_filename_component(schema_fn "${schema}" NAME)
get_filename_component(dir "${schema}" DIRECTORY)

get_filename_component(schema_fn_we "${schema_fn}" NAME_WE)

list(APPEND SCHEMA_FILES "${abs_schema_dir}/${schema}")
list(APPEND OUTPUT_FILES "${abs_output_dir}/${schema_fn_we}_generated.h")
endforeach()

# Generate headers
add_custom_command(OUTPUT ${OUTPUT_FILES}
COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}"
COMMAND "${FLATC_PATH}" -c --no-includes
--no-union-value-namespacing
--gen-object-api
--gen-mutable
Copy link
Contributor Author

@seanshpark seanshpark Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is same as FlatBuffers_Target with additional --gen-mutable option

-o "${abs_output_dir}"
${SCHEMA_FILES}
DEPENDS ${SCHEMA_FILES}
COMMENT "Generate '${TGT}' headers")

# NOTE This header-only library is deliberately declared as STATIC library
# to avoid possible scope issues related with generated files
add_library(${TGT} STATIC ${OUTPUT_FILES})
set_target_properties(${TGT} PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(${TGT} PUBLIC "${ARG_INCLUDE_DIR}")
target_link_libraries(${TGT} PUBLIC flatbuffers-23.5.26)
endfunction(FlatBuffersMuteable_Target)
endif(FlatBuffers_FOUND)