@@ -20,32 +20,52 @@ set (CMAKE_CXX_STANDARD 11)
2020# Turn on virtual folders for visual studio
2121set_property (GLOBAL PROPERTY USE_FOLDERS ON )
2222
23+ # Top level option that determines the default behavior of the include options
24+ # below. Useful for turning off all at once, and then turning on a specific one.
25+ option (FIREBASE_INCLUDE_LIBRARY_DEFAULT
26+ "Should each library be included by default." ON )
2327# Different options to enable/disable each library being included during
2428# configuration.
25- option (FIREBASE_INCLUDE_ADMOB "Include the AdMob library." ON )
29+ option (FIREBASE_INCLUDE_ADMOB "Include the AdMob library."
30+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
2631option (FIREBASE_INCLUDE_ANALYTICS
27- "Include the Google Analytics for Firebase library." ON )
28- option (FIREBASE_INCLUDE_AUTH "Include the Firebase Authentication library." ON )
32+ "Include the Google Analytics for Firebase library."
33+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
34+ option (FIREBASE_INCLUDE_AUTH "Include the Firebase Authentication library."
35+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
2936option (FIREBASE_INCLUDE_DATABASE
30- "Include the Firebase Realtime Database library." ON )
37+ "Include the Firebase Realtime Database library."
38+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
3139option (FIREBASE_INCLUDE_DYNAMIC_LINKS
32- "Include the Firebase Dynamic Links library." ON )
40+ "Include the Firebase Dynamic Links library."
41+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
42+ option (FIREBASE_INCLUDE_FIRESTORE
43+ "Include the Cloud Firestore library."
44+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
3345option (FIREBASE_INCLUDE_FUNCTIONS
34- "Include the Cloud Functions for Firebase library." ON )
46+ "Include the Cloud Functions for Firebase library."
47+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
3548option (FIREBASE_INCLUDE_INSTANCE_ID
36- "Include the Firebase Instance ID library." ON )
49+ "Include the Firebase Instance ID library."
50+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
3751option (FIREBASE_INCLUDE_MESSAGING
38- "Include the Firebase Cloud Messaging library." ON )
52+ "Include the Firebase Cloud Messaging library."
53+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
3954option (FIREBASE_INCLUDE_REMOTE_CONFIG
40- "Include the Firebase Remote Config library." ON )
55+ "Include the Firebase Remote Config library."
56+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
4157option (FIREBASE_INCLUDE_STORAGE
42- "Include the Cloud Storage for Firebase library." ON )
58+ "Include the Cloud Storage for Firebase library."
59+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
60+
4361option (FIREBASE_CPP_BUILD_TESTS
4462 "Enable the Firebase C++ Build Tests." OFF )
4563option (FIREBASE_FORCE_FAKE_SECURE_STORAGE
4664 "Disable use of platform secret store and use fake impl." OFF )
4765option (FIREBASE_CPP_BUILD_PACKAGE
4866 "Bundle the Firebase C++ libraries into a zip file." OFF )
67+ option (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD
68+ "When building with Gradle, use the previously built libraries." OFF )
4969
5070# Define this directory to be the root of the C++ SDK, which the libraries can
5171# then refer to.
@@ -94,10 +114,37 @@ set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
94114set (FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR} /opt)
95115set (FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR} /downloads)
96116
97- # Run the CMake build logic that will download all the external dependencies.
98- message (STATUS "Downloading external project dependencies..." )
99- download_external_sources()
100- message (STATUS "Download complete." )
117+ if (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
118+ # Figure out where app's binary_dir was.
119+ string (REGEX REPLACE
120+ "${CMAKE_CURRENT_LIST_DIR} /[^/]+/(.*)"
121+ "${CMAKE_CURRENT_LIST_DIR} /app/\\ 1"
122+ APP_BINARY_DIR "${FIREBASE_BINARY_DIR} " )
123+
124+ set (FIRESTORE_SOURCE_DIR ${APP_BINARY_DIR} /external/src/firestore)
125+ else ()
126+ # Run the CMake build logic that will download all the external dependencies.
127+ message (STATUS "Downloading external project dependencies..." )
128+ download_external_sources()
129+ message (STATUS "Download complete." )
130+
131+ set (FIRESTORE_SOURCE_DIR ${FIREBASE_BINARY_DIR} /external/src/firestore)
132+ endif ()
133+
134+ # Include Firestore's external build early to resolve conflicts on packages.
135+ if (NOT ANDROID AND FIREBASE_INCLUDE_FIRESTORE)
136+ set (FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR} -build )
137+
138+ set (
139+ FIREBASE_IOS_BUILD_TESTS
140+ ${FIREBASE_CPP_BUILD_TESTS}
141+ CACHE BOOL "Force Firestore build tests to match"
142+ )
143+
144+ add_subdirectory (${FIRESTORE_SOURCE_DIR} ${FIRESTORE_BINARY_DIR} )
145+
146+ copy_subdirectory_definition(${FIRESTORE_SOURCE_DIR} NANOPB_SOURCE_DIR)
147+ endif ()
101148
102149# Disable the Flatbuffer build tests, install and flathash
103150set (FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" )
@@ -109,13 +156,17 @@ if(IOS OR ANDROID)
109156 set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
110157endif ()
111158
112- # Add flatbuffers as a subdirectory, and set the directory variables for it,
113- # so that the sub Firebase projects can depend upon it if necessary.
114- add_external_library(flatbuffers)
159+ if (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
160+ message (STATUS "flatbuffers is added with APP_BINARY_DIR ${APP_BINARY_DIR} " )
161+ add_external_library(flatbuffers BINARY_DIR "${APP_BINARY_DIR} " )
162+ else ()
163+ message (STATUS "flatbuffers is added normally" )
164+ add_external_library(flatbuffers)
165+ endif ()
115166
116- if (FIREBASE_CPP_BUILD_TESTS)
167+ if (FIREBASE_CPP_BUILD_TESTS AND NOT FIREBASE_INCLUDE_FIRESTORE)
168+ # Firestore's external build pulls in googletest
117169 add_external_library(googletest)
118- add_external_library(absl)
119170endif ()
120171
121172# Some of the external libraries are not used for mobile.
@@ -202,15 +253,31 @@ if (NOT ANDROID AND NOT IOS)
202253 zlibstatic
203254 )
204255 endif ()
256+ endif ()
205257
206- find_package (Protobuf)
207- if (PROTOBUF_FOUND)
208- # NanoPB requires Protobuf to be present, so only add it if it was found.
209- add_external_library(nanopb)
210- # NanoPB has a FindNanopb which defines the function to generate files, so
211- # add it to the module path, and use that.
212- list (INSERT CMAKE_MODULE_PATH 0 ${NANOPB_SOURCE_DIR} /extra)
213- find_package (Nanopb)
258+ if (NOT ANDROID)
259+ if (FIREBASE_INCLUDE_FIRESTORE)
260+ # The Firestore build includes protobuf and nanopb already
261+ list (APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR} /extra)
262+ find_package (Nanopb REQUIRED)
263+
264+ set (PROTOBUF_FOUND ON )
265+ else ()
266+ find_package (Protobuf)
267+ if (PROTOBUF_FOUND)
268+ # NanoPB requires Protobuf to be present, so only add it if it was found.
269+ add_external_library(nanopb)
270+
271+ # NanoPB has a FindNanopb which defines the function to generate files,
272+ # so add it to the module path, and use that.
273+ list (APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR} /extra)
274+ find_package (Nanopb)
275+
276+ target_compile_definitions (
277+ protobuf-nanopb-static
278+ PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
279+ )
280+ endif ()
214281 endif ()
215282endif ()
216283
@@ -290,8 +357,24 @@ if(FIREBASE_CPP_BUILD_TESTS)
290357 add_subdirectory (testing)
291358endif ()
292359
293- # App needs to come first, since other libraries will depend upon it.
294- add_subdirectory (app)
360+ if (NOT FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
361+ add_subdirectory (app)
362+ else ()
363+ # Add firebase_app as a target on the previously built app.
364+ add_library (firebase_app STATIC IMPORTED GLOBAL )
365+ file (MAKE_DIRECTORY "${APP_BINARY_DIR} /generated" )
366+ file (MAKE_DIRECTORY "${FIREBASE_BINARY_DIR} /generated" )
367+ set (app_include_dirs
368+ "${CMAKE_CURRENT_LIST_DIR} /app/src/include"
369+ "${APP_BINARY_DIR} /generated"
370+ "${FIREBASE_BINARY_DIR} /generated"
371+ )
372+ set_target_properties (firebase_app PROPERTIES
373+ IMPORTED_LOCATION "${APP_BINARY_DIR} /libfirebase_app.a"
374+ INTERFACE_INCLUDE_DIRECTORIES "${app_include_dirs} "
375+ )
376+ endif ()
377+
295378if (FIREBASE_INCLUDE_ADMOB)
296379 add_subdirectory (admob)
297380endif ()
@@ -307,6 +390,9 @@ endif()
307390if (FIREBASE_INCLUDE_DYNAMIC_LINKS)
308391 add_subdirectory (dynamic_links)
309392endif ()
393+ if (FIREBASE_INCLUDE_FIRESTORE)
394+ add_subdirectory (firestore)
395+ endif ()
310396if (FIREBASE_INCLUDE_FUNCTIONS)
311397 add_subdirectory (functions)
312398endif ()
0 commit comments