Skip to content

Commit 652ee34

Browse files
fergushendersoncopybara-github
authored andcommitted
Some more clean ups for the 3P C++ API's Gradle / CMake integration.
In particular: - Copy the extracted SDK sources into $projectDir/build rather than into $projectDir/src/... - Remove the unnecessary `addTfLiteNativeDeps` task, which is empty apart from its dependencies. PiperOrigin-RevId: 707074726
1 parent b08a3fd commit 652ee34

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

lite/examples/native_api/android_play_services/cc_api/app/src/main/cpp/Modules/Findtflite_cc_api.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
# This CMake code fragment determines the location of the tflite_cc_api package.
22

3+
set(gradle_src_root "${CMAKE_SOURCE_DIR}/../../..")
4+
35
# tflite_cc_api_DIR is the directory containing the CMakeLists.txt file
46
# 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")
7+
if (NOT EXISTS "${gradle_src_root}/build/tflite_cc_sdk/CMakeLists.txt")
8+
message(SEND_ERROR "CMakeLists.txt not found in ${gradle_src_root}/build/tflite_cc_sdk")
9+
elseif (NOT EXISTS "${gradle_src_root}/build/tflite_cc_sdk/tensorflow/lite/abi/cc/interpreter.cc")
10+
message(SEND_ERROR "tensorflow/lite/abi/cc/interpreter.cc not found in ${gradle_src_root}/build/tflite_cc_sdk")
911
else()
10-
set(tflite_cc_api_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
12+
set(tflite_cc_api_DIR "${gradle_src_root}/build/tflite_cc_sdk")
1113
endif()
1214

1315
# tflite_cc_api_INCLUDE_DIR is the include directory containing the header
1416
# 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")
17+
if (NOT EXISTS "${gradle_src_root}/build/tflite_cc_sdk/tensorflow/lite/interpreter.h")
18+
message(SEND_ERROR "tensorflow/lite/interpreter.h not found in ${gradle_src_root}/build/tflite_cc_sdk")
19+
elseif (NOT EXISTS "${gradle_src_root}/build/tflite_cc_sdk/tensorflow/lite/abi/cc/interpreter.h")
20+
message(SEND_ERROR "tensorflow/lite/abi/cc/interpreter.h not found in ${gradle_src_root}/build/tflite_cc_sdk")
1921
else()
20-
set(tflite_cc_api_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/tflite_cc_sdk")
22+
set(tflite_cc_api_INCLUDE_DIR "${gradle_src_root}/tflite_cc_sdk")
2123
endif()
2224

2325
include(FindPackageHandleStandardArgs)

lite/examples/native_api/android_play_services/cc_api/app/tflite-java-extract-cpp-sdk.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,16 @@ task extractAarContent(dependsOn: copyAarToBuildDir, type: Copy) {
2626
}
2727
}
2828

29-
task copySdkSourcesToProjectDir(dependsOn: extractAarContent, type: Copy) {
29+
task copySdkSourcesToProjectBuildDir(dependsOn: extractAarContent, type: Copy) {
3030
from "$buildDir/$LIBRARY_NAME/content/cc_sdk"
31-
into "$projectDir/src/main/cpp/tflite_cc_sdk"
31+
into "$projectDir/build/tflite_cc_sdk"
3232
doLast {
33-
println("copySdkSourcesToProjectDir: copied sdk to $projectDir/src/main/cpp/tflite_cc_sdk")
33+
println("copySdkSourcesToProjectBuildDir: copied sdk to $projectDir/build/tflite_cc_sdk")
3434
}
3535
}
3636

37-
task addTfLiteNativeDeps(dependsOn: ["copySdkSourcesToProjectDir"]) {
38-
doLast {
39-
println("addTfLiteNativeDeps: completed")
40-
}
41-
}
42-
43-
preBuild.dependsOn addTfLiteNativeDeps
37+
preBuild.dependsOn copySdkSourcesToProjectBuildDir
4438

4539
clean {
46-
delete "$projectDir/src/main/cpp/tflite_cc_sdk"
40+
delete "$projectDir/build/tflite_cc_sdk"
4741
}

0 commit comments

Comments
 (0)