1
- # Copyright 2018 Google
1
+ # Copyright 2018 Google LLC
2
2
#
3
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
4
# you may not use this file except in compliance with the License.
@@ -90,7 +90,13 @@ endif()
90
90
# Occasionally ANDROID is not being set correctly when invoked by gradle, so
91
91
# set it manually if ANDROID_NDK has been defined.
92
92
if (DEFINED ANDROID_NDK )
93
- set (ANDROID 1 )
93
+ set (ANDROID ON )
94
+ endif ()
95
+
96
+ if (NOT ANDROID AND NOT IOS )
97
+ set (DESKTOP ON )
98
+ else ()
99
+ set (DESKTOP OFF )
94
100
endif ()
95
101
96
102
# Set directories needed by the Firebase subprojects
@@ -100,7 +106,7 @@ set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
100
106
set (FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR} )
101
107
102
108
if (FIREBASE_CPP_BUILD_TESTS AND MSVC )
103
- # Googletest requires MSVC to compile with the static version of the runtime
109
+ # GoogleTest requires MSVC to compile with the static version of the runtime
104
110
# library, so define the appropriate runtime flag, before adding libraries.
105
111
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd" )
106
112
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT" )
@@ -114,6 +120,20 @@ set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
114
120
set (FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR} /opt )
115
121
set (FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR} /downloads )
116
122
123
+ # Firestore is split into a public C++ component and the Firestore core, a
124
+ # non-public C++ API used for building other language bindings. Desktop
125
+ # platforms get the Firestore core from the CMake build in firebase-ios-sdk.
126
+ #
127
+ # Mobile platforms do not:
128
+ #
129
+ # * Android uses the Android SDK via JNI and does not use the Firestore
130
+ # core.
131
+ # * iOS gets the Firestore core from the FirebaseFirestore CocoaPod and
132
+ # does not build the core via CMake.
133
+ if (FIREBASE_INCLUDE_FIRESTORE AND DESKTOP )
134
+ set (FIRESTORE_USE_EXTERNAL_CMAKE_BUILD ON )
135
+ endif ()
136
+
117
137
if (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD )
118
138
# Figure out where app's binary_dir was.
119
139
string (REGEX REPLACE
@@ -132,7 +152,7 @@ else()
132
152
endif ()
133
153
134
154
# Include Firestore's external build early to resolve conflicts on packages.
135
- if (NOT ANDROID AND FIREBASE_INCLUDE_FIRESTORE )
155
+ if (FIRESTORE_USE_EXTERNAL_CMAKE_BUILD )
136
156
set (FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR} -build )
137
157
138
158
set (
@@ -151,7 +171,7 @@ set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
151
171
set (FLATBUFFERS_INSTALL OFF CACHE BOOL "" )
152
172
set (FLATBUFFERS_FLATHASH OFF CACHE BOOL "" )
153
173
154
- # Disable buliding flatc if cross compiling
174
+ # Disable building flatc if cross compiling
155
175
if (IOS OR ANDROID )
156
176
set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
157
177
endif ()
@@ -164,13 +184,19 @@ else()
164
184
add_external_library (flatbuffers )
165
185
endif ()
166
186
167
- if (FIREBASE_CPP_BUILD_TESTS AND NOT FIREBASE_INCLUDE_FIRESTORE )
168
- # Firestore's external build pulls in googletest
187
+ if (FIREBASE_CPP_BUILD_TESTS AND NOT FIRESTORE_USE_EXTERNAL_CMAKE_BUILD )
188
+ # Firestore's external build pulls in GoogleTest
169
189
add_external_library (googletest )
170
190
endif ()
171
191
192
+ if ((FIREBASE_INCLUDE_DATABASE AND DESKTOP ) AND NOT FIREBASE_INCLUDE_FIRESTORE )
193
+ # LevelDB is needed for Desktop and Firestore, but if firestore is being built
194
+ # LevelDB will already be included.
195
+ add_external_library (leveldb )
196
+ endif ()
197
+
172
198
# Some of the external libraries are not used for mobile.
173
- if ( NOT ANDROID AND NOT IOS )
199
+ if ( DESKTOP )
174
200
# Use the static versions of the OpenSSL libraries.
175
201
set (OPENSSL_USE_STATIC_LIBS TRUE )
176
202
if (MSVC )
@@ -255,8 +281,8 @@ if (NOT ANDROID AND NOT IOS)
255
281
endif ()
256
282
endif ()
257
283
258
- if (NOT ANDROID )
259
- if (FIREBASE_INCLUDE_FIRESTORE )
284
+ if (DESKTOP )
285
+ if (FIRESTORE_USE_EXTERNAL_CMAKE_BUILD )
260
286
# The Firestore build includes protobuf and nanopb already
261
287
list (APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR} /extra )
262
288
find_package (Nanopb REQUIRED )
@@ -281,7 +307,11 @@ if(NOT ANDROID)
281
307
endif ()
282
308
endif ()
283
309
284
- if (ANDROID OR IOS )
310
+ if (DESKTOP )
311
+ # Desktop platforms do not need to declare this dependency, as they will build
312
+ # flatc correctly when needed.
313
+ set (FIREBASE_FLATBUFFERS_DEPENDENCIES "" )
314
+ else ()
285
315
# Mobile platforms build flatc externally so that it works on the platform
286
316
# performing the build.
287
317
set (firebase_external_flatc_build_dir "${FLATBUFFERS_BINARY_DIR} -flatc" )
@@ -304,7 +334,7 @@ if(ANDROID OR IOS)
304
334
set (FLATBUFFERS_FLATC_EXECUTABLE ${firebase_external_flatc} CACHE STRING "" )
305
335
306
336
# Setup the flatc custom build target.
307
- # These commands are executed from within the currect context, which has set
337
+ # These commands are executed from within the current context, which has set
308
338
# variables for the target platform. We use "env -i" to clear these
309
339
# variables, and manually keep the PATH to regular bash path.
310
340
# If we didn't do this, we'd end up building flatc for the target platform
@@ -340,15 +370,17 @@ if(ANDROID OR IOS)
340
370
# Set a variable that the dependencies can use, to trigger the build before
341
371
# using flatbuffers.
342
372
set (FIREBASE_FLATBUFFERS_DEPENDENCIES "firebase_flatc_prebuild" )
343
- else ()
344
- # Other platforms do not need to declare this dependency, as they will build
345
- # flatc correctly when needed.
346
- set (FIREBASE_FLATBUFFERS_DEPENDENCIES "" )
347
373
endif ()
348
374
349
375
include (binary_to_array )
350
376
include (firebase_cpp_gradle )
351
377
378
+ # Ensure min/max macros don't get declared on Windows
379
+ # (so we can use std::min/max), before including the Firebase subdirectories.
380
+ if (MSVC )
381
+ add_definitions (-DNOMINMAX )
382
+ endif ()
383
+
352
384
add_subdirectory (ios_pod )
353
385
354
386
# If we're building tests, we need to include the 'testing' folder before any
0 commit comments