@@ -20,32 +20,52 @@ set (CMAKE_CXX_STANDARD 11)
20
20
# Turn on virtual folders for visual studio
21
21
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
22
22
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 )
23
27
# Different options to enable/disable each library being included during
24
28
# 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} )
26
31
option (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} )
29
36
option (FIREBASE_INCLUDE_DATABASE
30
- "Include the Firebase Realtime Database library." ON )
37
+ "Include the Firebase Realtime Database library."
38
+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
31
39
option (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} )
33
45
option (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} )
35
48
option (FIREBASE_INCLUDE_INSTANCE_ID
36
- "Include the Firebase Instance ID library." ON )
49
+ "Include the Firebase Instance ID library."
50
+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
37
51
option (FIREBASE_INCLUDE_MESSAGING
38
- "Include the Firebase Cloud Messaging library." ON )
52
+ "Include the Firebase Cloud Messaging library."
53
+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
39
54
option (FIREBASE_INCLUDE_REMOTE_CONFIG
40
- "Include the Firebase Remote Config library." ON )
55
+ "Include the Firebase Remote Config library."
56
+ ${FIREBASE_INCLUDE_LIBRARY_DEFAULT} )
41
57
option (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
+
43
61
option (FIREBASE_CPP_BUILD_TESTS
44
62
"Enable the Firebase C++ Build Tests." OFF )
45
63
option (FIREBASE_FORCE_FAKE_SECURE_STORAGE
46
64
"Disable use of platform secret store and use fake impl." OFF )
47
65
option (FIREBASE_CPP_BUILD_PACKAGE
48
66
"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 )
49
69
50
70
# Define this directory to be the root of the C++ SDK, which the libraries can
51
71
# then refer to.
@@ -94,10 +114,37 @@ set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
94
114
set (FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR} /opt )
95
115
set (FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR} /downloads )
96
116
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 ()
101
148
102
149
# Disable the Flatbuffer build tests, install and flathash
103
150
set (FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" )
@@ -109,13 +156,17 @@ if(IOS OR ANDROID)
109
156
set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
110
157
endif ()
111
158
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 ()
115
166
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
117
169
add_external_library (googletest )
118
- add_external_library (absl )
119
170
endif ()
120
171
121
172
# Some of the external libraries are not used for mobile.
@@ -202,15 +253,31 @@ if (NOT ANDROID AND NOT IOS)
202
253
zlibstatic
203
254
)
204
255
endif ()
256
+ endif ()
205
257
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 ()
214
281
endif ()
215
282
endif ()
216
283
@@ -290,8 +357,24 @@ if(FIREBASE_CPP_BUILD_TESTS)
290
357
add_subdirectory (testing )
291
358
endif ()
292
359
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
+
295
378
if (FIREBASE_INCLUDE_ADMOB )
296
379
add_subdirectory (admob )
297
380
endif ()
@@ -307,6 +390,9 @@ endif()
307
390
if (FIREBASE_INCLUDE_DYNAMIC_LINKS )
308
391
add_subdirectory (dynamic_links )
309
392
endif ()
393
+ if (FIREBASE_INCLUDE_FIRESTORE )
394
+ add_subdirectory (firestore )
395
+ endif ()
310
396
if (FIREBASE_INCLUDE_FUNCTIONS )
311
397
add_subdirectory (functions )
312
398
endif ()
0 commit comments