From 289ba7f54b34c31111286f279969630ace238cc5 Mon Sep 17 00:00:00 2001 From: Terry Heo Date: Fri, 30 Oct 2020 19:18:51 -0700 Subject: [PATCH] Update cmake support of TFLite minimal example Created a CMakeLists.txt under the lite/examples/minimal Usage) $ git clone https://github.com/tensorflow/tensorflow.git tensorflow_src $ mkdir minimal_build $ cd miniaml_build $ cmake ../tensorflow_src/tensorflow/lite/examples/minimal $ cmake --build . -j PiperOrigin-RevId: 339977906 Change-Id: I85cada5430407e72354d0a31a17584c48407db2f --- tensorflow/lite/CMakeLists.txt | 9 ---- .../lite/examples/minimal/CMakeLists.txt | 44 +++++++++++++++++++ tensorflow/lite/examples/minimal/README.md | 37 ++++++++++++++++ 3 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 tensorflow/lite/examples/minimal/CMakeLists.txt create mode 100644 tensorflow/lite/examples/minimal/README.md diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt index faf461d4031..c0fc2ae2502 100644 --- a/tensorflow/lite/CMakeLists.txt +++ b/tensorflow/lite/CMakeLists.txt @@ -450,12 +450,3 @@ target_link_libraries(benchmark_model ${TFLITE_BENCHMARK_LIBS} ) -# TFLite minimal example -add_executable(minimal - EXCLUDE_FROM_ALL - ${TFLITE_SOURCE_DIR}/examples/minimal/minimal.cc -) -target_link_libraries(minimal - tensorflow-lite - ${CMAKE_DL_LIBS} -) diff --git a/tensorflow/lite/examples/minimal/CMakeLists.txt b/tensorflow/lite/examples/minimal/CMakeLists.txt new file mode 100644 index 00000000000..d48a8104f73 --- /dev/null +++ b/tensorflow/lite/examples/minimal/CMakeLists.txt @@ -0,0 +1,44 @@ +# +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# Builds the minimal Tensorflow Lite example. + +cmake_minimum_required(VERSION 3.16) +project(minimal C CXX) + +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 +) + +add_executable(minimal + minimal.cc +) +target_link_libraries(minimal + tensorflow-lite + ${CMAKE_DL_LIBS} +) diff --git a/tensorflow/lite/examples/minimal/README.md b/tensorflow/lite/examples/minimal/README.md new file mode 100644 index 00000000000..76a44d463f4 --- /dev/null +++ b/tensorflow/lite/examples/minimal/README.md @@ -0,0 +1,37 @@ +# TensorFlow Lite C++ minimal example + +This example shows how you can build a simple TensorFlow Lite application. + +#### Step 1. Install CMake tool + +It requires CMake 3.16 or higher. On Ubuntu, you can simply run the following +command. + +```sh +sudo apt-get install cmake +``` + +Or you can follow +[the official cmake installation guide](https://cmake.org/install/) + +#### Step 2. Clone TensorFlow repository + +```sh +git clone https://github.com/tensorflow/tensorflow.git tensorflow_src +``` + +#### Step 3. Create CMake build directory and run CMake tool + +```sh +mkdir minimal_build +cd minimal_build +cmake ../tensorflow_src/tensorflow/lite/examples/minimal +``` + +#### Step 4. Build TensorFlow Lite + +In the minimal_build directory, + +```sh +cmake --build . -j +```