@@ -180,6 +180,7 @@ endif()
180
180
# Set directories needed by the Firebase subprojects
181
181
# Directory to store generated files.
182
182
set (FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR} /generated )
183
+
183
184
# Directory for any shared scripts.
184
185
set (FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR} )
185
186
@@ -227,20 +228,34 @@ set(FIRESTORE_INCLUDE_OBJC OFF CACHE BOOL "Disabled for the CPP SDK")
227
228
set (RE2_BUILD_TESTING OFF CACHE BOOL "" )
228
229
229
230
if (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
230
- # Quote meta characters in ${CMAKE_CURRENT_LIST_DIR} so we can
231
- # match it in a regex.
232
- # For example, '/path/with/+meta/char.acters' will become
233
- # '/path/with/\+meta/char\.acters'.
234
- string (REGEX REPLACE
235
- "([][+.*()^])" "\\\\\\ 1" # Yes, this many \'s is correct.
236
- current_list_dir_regex
237
- "${CMAKE_CURRENT_LIST_DIR} " )
238
- # Figure out where app's binary_dir was.
239
- string (REGEX REPLACE
240
- "${current_list_dir_regex} /[^/]+/(.*)"
241
- "${CMAKE_CURRENT_LIST_DIR} /app/\\ 1"
242
- APP_BINARY_DIR "${FIREBASE_BINARY_DIR} " )
243
-
231
+ # Gradle now adds a random hash to each separate NDK cmake build.
232
+ # Scan the previously built directories to find the one containing app's header.
233
+ set (header_to_scan_for "generated/app/src/include/firebase/version.h" )
234
+ set (prev_build_path "${CMAKE_BINARY_DIR} /../../../../../app/.cxx/${CMAKE_BUILD_TYPE} /*/${CMAKE_ANDROID_ARCH_ABI} " )
235
+ file (GLOB possible_prev_build_dirs "${prev_build_path} " )
236
+ # In case there are multiple matches, take the one with the newest timestamp.
237
+ set (newest_timestamp 0)
238
+ foreach (possible_prev_build_dir IN LISTS possible_prev_build_dirs)
239
+ message ("CONSIDERING ${possible_prev_build_dir} " )
240
+ if (IS_DIRECTORY ${possible_prev_build_dir} )
241
+ if (EXISTS "${possible_prev_build_dir} /${header_to_scan_for} " )
242
+ # Check if it's newer than any other files.
243
+ message ("FOUND ${possible_prev_build_dir} /${header_to_scan_for} " )
244
+ file (TIMESTAMP "${possible_prev_build_dir} /${header_to_scan_for} " timestamp "%s" )
245
+ message ("GOT TIMESTAMP: ${timestamp} " )
246
+ if (${timestamp} GREATER ${newest_timestamp} )
247
+ message ("USING ${possible_prev_build_dir} " )
248
+ set (APP_BINARY_DIR ${possible_prev_build_dir} )
249
+ set (newest_timestamp ${timestamp} )
250
+ endif ()
251
+ endif ()
252
+ endif ()
253
+ endforeach ()
254
+ if (IS_DIRECTORY "${APP_BINARY_DIR} " )
255
+ message ("Found previous Firebase App build in ${APP_BINARY_DIR} " )
256
+ else ()
257
+ message (FATAL_ERROR "Could not find previous Firebase App build under ${prev_build_path} " )
258
+ endif ()
244
259
set (FIRESTORE_SOURCE_DIR ${APP_BINARY_DIR} /external/src/firestore)
245
260
else ()
246
261
# Run the CMake build logic that will download all the external dependencies.
@@ -579,6 +594,7 @@ if(NOT FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
579
594
else ()
580
595
# Add firebase_app as a target on the previously built app.
581
596
add_library (firebase_app STATIC IMPORTED GLOBAL )
597
+
582
598
file (MAKE_DIRECTORY "${APP_BINARY_DIR} /generated" )
583
599
file (MAKE_DIRECTORY "${FIREBASE_BINARY_DIR} /generated" )
584
600
set (app_include_dirs
0 commit comments