Skip to content

Commit dda9321

Browse files
wilhuffa-maurice
authored andcommitted
Build Firestore with CMake
PiperOrigin-RevId: 297731635
1 parent 396d8b4 commit dda9321

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

CMakeLists.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ option(FIREBASE_INCLUDE_DATABASE
3939
option(FIREBASE_INCLUDE_DYNAMIC_LINKS
4040
"Include the Firebase Dynamic Links library."
4141
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
42+
option(FIREBASE_INCLUDE_FIRESTORE
43+
"Include the Cloud Firestore library."
44+
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
4245
option(FIREBASE_INCLUDE_FUNCTIONS
4346
"Include the Cloud Functions for Firebase library."
4447
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
@@ -122,6 +125,22 @@ else()
122125
message(STATUS "Downloading external project dependencies...")
123126
download_external_sources()
124127
message(STATUS "Download complete.")
128+
129+
# Include Firestore's external build early to resolve conflicts on packages.
130+
if(FIREBASE_INCLUDE_FIRESTORE)
131+
set(FIRESTORE_SOURCE_DIR ${FIREBASE_BINARY_DIR}/external/src/firestore)
132+
set(FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR}-build)
133+
134+
set(
135+
FIREBASE_IOS_BUILD_TESTS
136+
${FIREBASE_CPP_BUILD_TESTS}
137+
CACHE BOOL "Force Firestore build tests to match"
138+
)
139+
140+
add_subdirectory(${FIRESTORE_SOURCE_DIR} ${FIRESTORE_BINARY_DIR})
141+
142+
copy_subdirectory_definition(${FIRESTORE_SOURCE_DIR} NANOPB_SOURCE_DIR)
143+
endif()
125144
endif()
126145

127146
# Disable the Flatbuffer build tests, install and flathash
@@ -142,9 +161,9 @@ else()
142161
add_external_library(flatbuffers)
143162
endif()
144163

145-
if(FIREBASE_CPP_BUILD_TESTS)
164+
if(FIREBASE_CPP_BUILD_TESTS AND NOT FIREBASE_INCLUDE_FIRESTORE)
165+
# Firestore's external build pulls in googletest
146166
add_external_library(googletest)
147-
add_external_library(absl)
148167
endif()
149168

150169
# Some of the external libraries are not used for mobile.
@@ -231,15 +250,30 @@ if (NOT ANDROID AND NOT IOS)
231250
zlibstatic
232251
)
233252
endif()
253+
endif()
254+
255+
if(FIREBASE_INCLUDE_FIRESTORE)
256+
# The Firestore build includes protobuf and nanopb already
257+
list(APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR}/extra)
258+
find_package(Nanopb REQUIRED)
234259

260+
set(PROTOBUF_FOUND ON)
261+
262+
else()
235263
find_package(Protobuf)
236264
if (PROTOBUF_FOUND)
237265
# NanoPB requires Protobuf to be present, so only add it if it was found.
238266
add_external_library(nanopb)
267+
239268
# NanoPB has a FindNanopb which defines the function to generate files, so
240269
# add it to the module path, and use that.
241-
list(INSERT CMAKE_MODULE_PATH 0 ${NANOPB_SOURCE_DIR}/extra)
270+
list(APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR}/extra)
242271
find_package(Nanopb)
272+
273+
target_compile_definitions(
274+
protobuf-nanopb-static
275+
PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
276+
)
243277
endif()
244278
endif()
245279

@@ -352,6 +386,9 @@ endif()
352386
if (FIREBASE_INCLUDE_DYNAMIC_LINKS)
353387
add_subdirectory(dynamic_links)
354388
endif()
389+
if (FIREBASE_INCLUDE_FIRESTORE)
390+
add_subdirectory(firestore)
391+
endif()
355392
if (FIREBASE_INCLUDE_FUNCTIONS)
356393
add_subdirectory(functions)
357394
endif()

cmake/external_rules.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,13 @@ function(add_external_library NAME)
134134
add_subdirectory(${${UPPER_NAME}_SOURCE_DIR} ${${UPPER_NAME}_BINARY_DIR}
135135
EXCLUDE_FROM_ALL)
136136
endif()
137-
endfunction()
137+
endfunction()
138+
139+
# Copies a variable definition from a subdirectory into the parent scope
140+
macro(copy_subdirectory_definition DIRECTORY VARIABLE)
141+
get_directory_property(
142+
${VARIABLE}
143+
DIRECTORY ${DIRECTORY}
144+
DEFINITION ${VARIABLE}
145+
)
146+
endmacro()

0 commit comments

Comments
 (0)