Skip to content

Commit b08a3fd

Browse files
fergushendersoncopybara-github
authored andcommitted
Some clean ups for the 3P C++ API's Gradle / CMake integration.
In particular: - Use `list(PREPEND ...)` rather than `set(...)` to prepend to `CMAKE_MODULE_PATH`. - Clarify the distinction between `tflite_cc_DIR` and `tflite_cc_INCLUDE_DIR`, and use the former rather than the latter for the call to `add_subdirectory`. - Define `tflite_cc_api_DIR` in the same place where `tflite_cc_INCLUDE_DIR` is defined, i.e. in `Findtflite_cc_api.cmake`, rather than in a different file. - In `Findtflite_cc_api.cmake`, verify that the appropriate files exist in the specified directory, and report error(s) if they don't. (If CMake is invoked via Gradle, then the Gradle file should already ensure that those files exist there, by unpacking the contents of the AAR file and copying the `cc_sdk` directory there; but having explicit checks here means we'll fail earlier, and hopefully with a better error message, if CMake is invoked in some other way or if future changes break things.) PiperOrigin-RevId: 706640601
1 parent 1e00002 commit b08a3fd

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

lite/examples/native_api/android_play_services/cc_api/app/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ find_package(tensorflowlite_jni_gms_client REQUIRED CONFIG)
4747
#-----------------------------------------------------------------------------
4848
# Set up TFLite in Play services C++ API (tflite_cc_api) dependency.
4949

50-
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Modules" ${CMAKE_MODULE_PATH})
51-
set(tflite_cc_api_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
50+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Modules")
5251

5352
find_package(tflite_cc_api REQUIRED MODULE)
5453
include_directories(${tflite_cc_api_INCLUDE_DIR})
55-
add_subdirectory(${tflite_cc_api_INCLUDE_DIR} tflite_cc_api_build)
54+
add_subdirectory(${tflite_cc_api_DIR} tflite_cc_api_build)
5655

5756
#-----------------------------------------------------------------------------
5857
# Set up compile definitions to enable use of TFLite in Play services
Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# This CMake code fragment determines the location of the tflite_cc_api package.
2-
set(tflite_cc_api_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
2+
3+
# tflite_cc_api_DIR is the directory containing the CMakeLists.txt file
4+
# for building the TFLite-in-Play-services C++ API client SDK source files.
5+
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/tflite_cc_sdk/CMakeLists.txt")
6+
message(SEND_ERROR "CMakeLists.txt not found in ${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
7+
elseif (NOT EXISTS "${CMAKE_SOURCE_DIR}/tflite_cc_sdk/tensorflow/lite/abi/cc/interpreter.cc")
8+
message(SEND_ERROR "tensorflow/lite/abi/cc/interpreter.cc not found in ${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
9+
else()
10+
set(tflite_cc_api_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
11+
endif()
12+
13+
# tflite_cc_api_INCLUDE_DIR is the include directory containing the header
14+
# files for the TFLite-in-Play-services C++ API.
15+
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/tflite_cc_sdk/tensorflow/lite/interpreter.h")
16+
message(SEND_ERROR "tensorflow/lite/interpreter.h not found in ${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
17+
elseif (NOT EXISTS "${CMAKE_SOURCE_DIR}/tflite_cc_sdk/tensorflow/lite/abi/cc/interpreter.h")
18+
message(SEND_ERROR "tensorflow/lite/abi/cc/interpreter.h not found in ${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
19+
else()
20+
set(tflite_cc_api_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
21+
endif()
22+
323
include(FindPackageHandleStandardArgs)
424
find_package_handle_standard_args(tflite_cc_api DEFAULT_MSG
5-
tflite_cc_api_INCLUDE_DIR)
25+
tflite_cc_api_DIR tflite_cc_api_INCLUDE_DIR)

0 commit comments

Comments
 (0)