Skip to content

Commit

Permalink
[infra/cmake] Revise runtime flatbuffers config (Samsung#3031)
Browse files Browse the repository at this point in the history
- Remove duplicated FlatBuffersSourceConfig
- Remove unused flatc build
- Link flatbuffers lib with tensorflow lite

Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Jul 14, 2020
1 parent 0b725f6 commit 540af63
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 81 deletions.
60 changes: 3 additions & 57 deletions infra/nnfw/cmake/packages/FlatBuffersConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function(_FlatBuffers_import)
return()
endif(Flatbuffers_FOUND)

nnfw_find_package(FlatBuffersSource QUIET)
# NOTE Tizen uses 1.11
nnas_find_package(FlatBuffersSource EXACT 1.11 QUIET)

if(NOT FlatBuffersSource_FOUND)
set(FlatBuffers_FOUND FALSE PARENT_SCOPE)
Expand All @@ -20,70 +21,15 @@ function(_FlatBuffers_import)
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/reflection.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/util.cpp")

# From FlatBuffers's CMakeLists.txt
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_cpp.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_dart.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_fbs.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_general.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_go.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_grpc.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_js.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_json_schema.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_lobster.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_lua.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_php.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_python.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/flatc.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/src/flatc_main.cpp")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/grpc/src/compiler/cpp_generator.cc")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/grpc/src/compiler/go_generator.cc")
list(APPEND FlatBuffers_Compiler_SRCS "${FlatBuffersSource_DIR}/grpc/src/compiler/java_generator.cc")

if(NOT TARGET flatbuffers::flatbuffers)
add_library(flatbuffers ${FlatBuffers_Library_SRCS})
target_include_directories(flatbuffers PUBLIC "${FlatBuffersSource_DIR}/include")
set_property(TARGET flatbuffers PROPERTY POSITION_INDEPENDENT_CODE ON)

add_library(flatbuffers::flatbuffers ALIAS flatbuffers)
endif(NOT TARGET flatbuffers::flatbuffers)


if(NOT TARGET flatbuffers::flatc)
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
target_include_directories(flatc PRIVATE "${FlatBuffersSource_DIR}/grpc")
target_link_libraries(flatc flatbuffers)

add_executable(flatbuffers::flatc ALIAS flatc)
endif(NOT TARGET flatbuffers::flatc)

set(FlatBuffers_FOUND TRUE PARENT_SCOPE)
endfunction(_FlatBuffers_import)

_FlatBuffers_import()

if(FlatBuffers_FOUND)
function(FlatBuffers_Generate PREFIX OUTPUT_DIR SCHEMA_DIR)
get_filename_component(abs_output_dir ${OUTPUT_DIR} ABSOLUTE)
get_filename_component(abs_schema_dir ${SCHEMA_DIR} ABSOLUTE)

foreach(schema ${ARGN})
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()

add_custom_command(OUTPUT ${OUTPUT_FILES}
COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}"
COMMAND "$<TARGET_FILE:flatc>" -c --no-includes
--no-union-value-namespacing
--gen-object-api -o "${abs_output_dir}"
${SCHEMA_FILES}
DEPENDS flatbuffers::flatc)

set(${PREFIX}_SOURCES ${OUTPUT_FILES} PARENT_SCOPE)
set(${PREFIX}_INCLUDE_DIRS ${abs_output_dir} PARENT_SCOPE)
endfunction(FlatBuffers_Generate)
endif(FlatBuffers_FOUND)
19 changes: 0 additions & 19 deletions infra/nnfw/cmake/packages/FlatBuffersSourceConfig.cmake

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ list(APPEND TFLITE_INCLUDES "${TensorFlowSource_DIR}")
list(APPEND TFLITE_INCLUDES "${AbseilSource_DIR}")
list(APPEND TFLITE_INCLUDES "${GEMMLowpSource_DIR}")
list(APPEND TFLITE_INCLUDES "${FarmhashSource_DIR}/src")
list(APPEND TFLITE_INCLUDES "${FlatBuffersSource_DIR}/include")

if(NEON2SSESource_FOUND)
list(APPEND TFLITE_INCLUDES "${NEON2SSESource_DIR}")
Expand All @@ -55,7 +54,7 @@ add_library(tensorflow-lite STATIC ${TFLITE_SRCS})
target_include_directories(tensorflow-lite SYSTEM PUBLIC ${TFLITE_INCLUDES})
target_compile_definitions(tensorflow-lite PUBLIC "GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK")
set_property(TARGET tensorflow-lite PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(tensorflow-lite eigen ${LIB_PTHREAD} dl)
target_link_libraries(tensorflow-lite eigen flatbuffers::flatbuffers ${LIB_PTHREAD} dl)

if(ANDROID)
target_link_libraries(tensorflow-lite log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ if(BUILD_TENSORFLOW_LITE)
return_unless(Eigen_FOUND)
nnfw_find_package(FarmhashSource QUIET)
return_unless(FarmhashSource_FOUND)
nnfw_find_package(FlatBuffersSource QUIET)
return_unless(FlatBuffersSource_FOUND)
nnfw_find_package(FlatBuffers QUIET)
return_unless(FlatBuffers_FOUND)
nnfw_find_package(GEMMLowpSource QUIET)
return_unless(GEMMLowpSource_FOUND)
nnas_find_package(TensorFlowSource EXACT 1.13.1 QUIET)
Expand Down
2 changes: 1 addition & 1 deletion runtime/contrib/android_benchmark_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ target_link_libraries(android_benchmark_native nnfw_lib_tflite)
target_link_libraries(android_benchmark_native nnfw_lib_misc)
target_link_libraries(android_benchmark_native log)

nnfw_find_package(FlatBuffersSource REQUIRED)
nnas_find_package(FlatBuffersSource EXACT 1.11 REQUIRED)
target_include_directories(android_benchmark_native PUBLIC ${FlatBuffersSource_DIR}/include .)

add_custom_target(android-benchmark-apk ALL
Expand Down

0 comments on commit 540af63

Please sign in to comment.