Skip to content

Commit

Permalink
[infra] Introduce FlatBuffers 23.5.26 cmake (#12617)
Browse files Browse the repository at this point in the history
This commit introduces FlatBuffers 23.5.26 cmake package config.
This commit includes FlatBuffers 2.0 cmake versioning to prepare migration.

ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Feb 8, 2024
1 parent 464327f commit 311d2df
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function(_FlatBuffersSource_import)
if(NOT DOWNLOAD_FLATBUFFERS)
set(FlatBuffersSource_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT DOWNLOAD_FLATBUFFERS)

nnas_include(ExternalSourceTools)
nnas_include(OptionTools)

envoption(EXTERNAL_DOWNLOAD_SERVER "https://github.com")
envoption(FLATBUFFERS_23_5_26_URL ${EXTERNAL_DOWNLOAD_SERVER}/google/flatbuffers/archive/v23.5.26.tar.gz)
ExternalSource_Download(FLATBUFFERS
DIRNAME FLATBUFFERS-23.5.26
CHECKSUM MD5=2ef00eaaa86ab5e9ad5eafe09c2e7b60
URL ${FLATBUFFERS_23_5_26_URL}
)

set(FlatBuffersSource_DIR ${FLATBUFFERS_SOURCE_DIR} PARENT_SCOPE)
set(FlatBuffersSource_FOUND TRUE PARENT_SCOPE)
endfunction(_FlatBuffersSource_import)

_FlatBuffersSource_import()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(PACKAGE_VERSION "23.5.26")
set(PACKAGE_VERSION_EXACT FALSE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_UNSUITABLE TRUE)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
set(PACKAGE_VERSION_UNSUITABLE FALSE)
endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(PACKAGE_VERSION "2.0")
set(PACKAGE_VERSION_EXACT FALSE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_UNSUITABLE TRUE)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
set(PACKAGE_VERSION_UNSUITABLE FALSE)
endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function(_FlatBuffers_import)

find_package(Flatbuffers QUIET)
if(Flatbuffers_FOUND)
set(FlatBuffers_FOUND TRUE PARENT_SCOPE)
return()
endif(Flatbuffers_FOUND)

nnas_find_package(FlatBuffersSource EXACT 23.5.26 QUIET)

if(NOT FlatBuffersSource_FOUND)
set(FlatBuffers_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT FlatBuffersSource_FOUND)

# From FlatBuffers's CMakeLists.txt
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/annotated_binary_text_gen.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/bfbs_gen_lua.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/bfbs_gen_nim.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/binary_annotator.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/code_generators.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/flatc.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_fbs.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/idl_gen_text.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/idl_parser.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/reflection.cpp")
list(APPEND FlatBuffers_Library_SRCS "${FlatBuffersSource_DIR}/src/util.cpp")

if(NOT TARGET flatbuffers::flatbuffers-23.5.26)
add_library(flatbuffers-23.5.26 ${FlatBuffers_Library_SRCS})
target_include_directories(flatbuffers-23.5.26 PUBLIC "${FlatBuffersSource_DIR}/include")
set_property(TARGET flatbuffers-23.5.26 PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_options(flatbuffers-23.5.26 PUBLIC $<$<CONFIG:Debug>:-Wno-sign-compare>)

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

set(FlatBuffers_FOUND TRUE PARENT_SCOPE)
endfunction(_FlatBuffers_import)

_FlatBuffers_import()
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(PACKAGE_VERSION "23.5.26")
set(PACKAGE_VERSION_EXACT FALSE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_UNSUITABLE TRUE)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
set(PACKAGE_VERSION_COMPATIBLE TRUE)
set(PACKAGE_VERSION_UNSUITABLE FALSE)
endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
2 changes: 1 addition & 1 deletion infra/nnfw/cmake/packages/TensorFlowGpuConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function(_Build_TfliteGpuDelagate_)
nnas_find_package(Egl_HeadersSource QUIET)
return_unless(Egl_HeadersSource_FOUND)

nnfw_find_package(FlatBuffers QUIET)
nnfw_find_package(FlatBuffers EXACT 2.0 QUIET)
return_unless(FlatBuffers_FOUND)

if(NOT TARGET TensorFlowGpu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if(BUILD_TENSORFLOW_LITE)
return_unless(Eigen_FOUND)
nnas_find_package(Farmhash QUIET)
return_unless(Farmhash_FOUND)
nnfw_find_package(FlatBuffers QUIET)
nnfw_find_package(FlatBuffers EXACT 2.0 QUIET)
return_unless(FlatBuffers_FOUND)
nnas_find_package(TensorFlowGEMMLowpSource EXACT 2.8.0 QUIET)
return_unless(TensorFlowGEMMLowpSource_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion runtime/libs/circle-schema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_library(circle_schema INTERFACE)

nnfw_find_package(FlatBuffers REQUIRED)
nnfw_find_package(FlatBuffers EXACT 2.0 REQUIRED)

target_link_libraries(circle_schema INTERFACE flatbuffers::flatbuffers)

Expand Down
2 changes: 1 addition & 1 deletion runtime/onert/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set_target_properties(onert_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_include_directories(onert_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Flatbuffer for loader
nnfw_find_package(FlatBuffers REQUIRED)
nnfw_find_package(FlatBuffers EXACT 2.0 REQUIRED)
target_link_libraries(onert_core PRIVATE flatbuffers::flatbuffers)
target_link_libraries(onert_core PRIVATE circle_schema)

Expand Down
2 changes: 1 addition & 1 deletion tests/custom_op/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if(NOT BUILD_ONERT)
return()
endif(NOT BUILD_ONERT)

nnfw_find_package(FlatBuffers QUIET)
nnfw_find_package(FlatBuffers EXACT 2.0 QUIET)
if(NOT FlatBuffers_FOUND)
message(STATUS "Skip build custom operation test: cannot find flatbuffers")
return()
Expand Down

0 comments on commit 311d2df

Please sign in to comment.