Skip to content

Commit

Permalink
TFLite C API: add cmake support
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuyie committed Feb 3, 2021
1 parent 59fcbe5 commit be6e4f5
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tensorflow/lite/c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.16)
project(tensorflow-lite-c C CXX)

option(TFLITE_C_BUILD_SHARED_LIBS "Build shared libraries" ON)

set(TENSORFLOW_SOURCE_DIR "" CACHE PATH
"Directory that contains the TensorFlow project"
)
if (NOT TENSORFLOW_SOURCE_DIR)
get_filename_component(TENSORFLOW_SOURCE_DIR
"${CMAKE_CURRENT_LIST_DIR}/../../../"
ABSOLUTE
)
endif()

add_subdirectory(
"${TENSORFLOW_SOURCE_DIR}/tensorflow/lite"
"${CMAKE_CURRENT_BINARY_DIR}/tensorflow-lite"
EXCLUDE_FROM_ALL
)

set(CMAKE_CXX_STANDARD 11)

set(TFLITE_C_LIBTYPE STATIC)
if (TFLITE_C_BUILD_SHARED_LIBS)
set(TFLITE_C_LIBTYPE SHARED)
endif()

add_library(tensorflowlite_c ${TFLITE_C_LIBTYPE}
builtin_op_data.h
common.h
common.c
c_api_types.h
c_api.h
c_api.cc
c_api_experimental.h
c_api_experimental.cc
c_api_internal.h
)

if (TFLITE_C_BUILD_SHARED_LIBS)
if (UNIX)
if (APPLE)
target_link_options(tensorflowlite_c PRIVATE "-Wl,-exported_symbols_list,${TENSORFLOW_SOURCE_DIR}/tensorflow/lite/c/exported_symbols.lds")
else ()
target_link_options(tensorflowlite_c PRIVATE "-Wl,--version-script,${TENSORFLOW_SOURCE_DIR}/tensorflow/lite/c/version_script.lds")
endif()
endif()
if (WIN32)
target_compile_definitions(tensorflowlite_c PRIVATE TFL_COMPILE_LIBRARY)
endif()
endif()

target_link_libraries(tensorflowlite_c
tensorflow-lite
${CMAKE_DL_LIBS}
)

0 comments on commit be6e4f5

Please sign in to comment.