1- # Copyright 2018 Google
1+ # Copyright 2018 Google LLC
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
@@ -90,7 +90,13 @@ endif()
9090# Occasionally ANDROID is not being set correctly when invoked by gradle, so
9191# set it manually if ANDROID_NDK has been defined.
9292if (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 )
94100endif ()
95101
96102# Set directories needed by the Firebase subprojects
@@ -100,7 +106,7 @@ set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
100106set (FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR} )
101107
102108if (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
104110 # library, so define the appropriate runtime flag, before adding libraries.
105111 set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd" )
106112 set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT" )
@@ -114,6 +120,20 @@ set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
114120set (FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR} /opt)
115121set (FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR} /downloads)
116122
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+
117137if (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
118138 # Figure out where app's binary_dir was.
119139 string (REGEX REPLACE
@@ -132,7 +152,7 @@ else()
132152endif ()
133153
134154# 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 )
136156 set (FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR} -build )
137157
138158 set (
@@ -151,7 +171,7 @@ set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
151171set (FLATBUFFERS_INSTALL OFF CACHE BOOL "" )
152172set (FLATBUFFERS_FLATHASH OFF CACHE BOOL "" )
153173
154- # Disable buliding flatc if cross compiling
174+ # Disable building flatc if cross compiling
155175if (IOS OR ANDROID)
156176 set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
157177endif ()
@@ -164,13 +184,19 @@ else()
164184 add_external_library(flatbuffers)
165185endif ()
166186
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
169189 add_external_library(googletest)
170190endif ()
171191
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+
172198# Some of the external libraries are not used for mobile.
173- if ( NOT ANDROID AND NOT IOS )
199+ if (DESKTOP )
174200 # Use the static versions of the OpenSSL libraries.
175201 set (OPENSSL_USE_STATIC_LIBS TRUE )
176202 if (MSVC )
@@ -255,8 +281,8 @@ if (NOT ANDROID AND NOT IOS)
255281 endif ()
256282endif ()
257283
258- if (NOT ANDROID )
259- if (FIREBASE_INCLUDE_FIRESTORE )
284+ if (DESKTOP )
285+ if (FIRESTORE_USE_EXTERNAL_CMAKE_BUILD )
260286 # The Firestore build includes protobuf and nanopb already
261287 list (APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR} /extra)
262288 find_package (Nanopb REQUIRED)
@@ -281,7 +307,11 @@ if(NOT ANDROID)
281307 endif ()
282308endif ()
283309
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 ()
285315 # Mobile platforms build flatc externally so that it works on the platform
286316 # performing the build.
287317 set (firebase_external_flatc_build_dir "${FLATBUFFERS_BINARY_DIR} -flatc" )
@@ -304,7 +334,7 @@ if(ANDROID OR IOS)
304334 set (FLATBUFFERS_FLATC_EXECUTABLE ${firebase_external_flatc} CACHE STRING "" )
305335
306336 # 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
308338 # variables for the target platform. We use "env -i" to clear these
309339 # variables, and manually keep the PATH to regular bash path.
310340 # If we didn't do this, we'd end up building flatc for the target platform
@@ -340,15 +370,17 @@ if(ANDROID OR IOS)
340370 # Set a variable that the dependencies can use, to trigger the build before
341371 # using flatbuffers.
342372 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 "" )
347373endif ()
348374
349375include (binary_to_array)
350376include (firebase_cpp_gradle)
351377
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+
352384add_subdirectory (ios_pod)
353385
354386# If we're building tests, we need to include the 'testing' folder before any
0 commit comments