forked from firebase/firebase-cpp-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
417 lines (364 loc) · 14.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
# Copyright 2018 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Top level CMake file that defines the entire Firebase C++ SDK build.
cmake_minimum_required (VERSION 3.1)
set (CMAKE_CXX_STANDARD 11)
# Turn on virtual folders for visual studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Top level option that determines the default behavior of the include options
# below. Useful for turning off all at once, and then turning on a specific one.
option(FIREBASE_INCLUDE_LIBRARY_DEFAULT
"Should each library be included by default." ON)
# Different options to enable/disable each library being included during
# configuration.
option(FIREBASE_INCLUDE_ADMOB "Include the AdMob library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_ANALYTICS
"Include the Google Analytics for Firebase library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_AUTH "Include the Firebase Authentication library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_DATABASE
"Include the Firebase Realtime Database library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_DYNAMIC_LINKS
"Include the Firebase Dynamic Links library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_FIRESTORE
"Include the Cloud Firestore library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_FUNCTIONS
"Include the Cloud Functions for Firebase library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_INSTANCE_ID
"Include the Firebase Instance ID library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_MESSAGING
"Include the Firebase Cloud Messaging library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_REMOTE_CONFIG
"Include the Firebase Remote Config library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_INCLUDE_STORAGE
"Include the Cloud Storage for Firebase library."
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
option(FIREBASE_CPP_BUILD_TESTS
"Enable the Firebase C++ Build Tests." OFF)
option(FIREBASE_FORCE_FAKE_SECURE_STORAGE
"Disable use of platform secret store and use fake impl." OFF)
option(FIREBASE_CPP_BUILD_PACKAGE
"Bundle the Firebase C++ libraries into a zip file." OFF)
option(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD
"When building with Gradle, use the previously built libraries." OFF)
# Define this directory to be the root of the C++ SDK, which the libraries can
# then refer to.
set(FIREBASE_CPP_SDK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
project (firebase NONE)
enable_language(C)
enable_language(CXX)
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(external_rules)
include(cpp_pack)
if(FIREBASE_CPP_BUILD_TESTS)
enable_testing()
include(test_rules)
# Copy the custom CTest file into the binary directory, so that it is used.
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/CTestCustom.cmake
${CMAKE_BINARY_DIR})
endif()
# Occasionally ANDROID is not being set correctly when invoked by gradle, so
# set it manually if ANDROID_NDK has been defined.
if(DEFINED ANDROID_NDK)
set(ANDROID 1)
endif()
# Set directories needed by the Firebase subprojects
# Directory to store generated files.
set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
# Directory for any shared scripts.
set(FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
if (FIREBASE_CPP_BUILD_TESTS AND MSVC)
# Googletest requires MSVC to compile with the static version of the runtime
# library, so define the appropriate runtime flag, before adding libraries.
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
endif()
# Set variables that are used by download_external_sources.
set(FIREBASE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR}/opt)
set(FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/downloads)
if(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
# Figure out where app's binary_dir was.
string(REGEX REPLACE
"${CMAKE_CURRENT_LIST_DIR}/[^/]+/(.*)"
"${CMAKE_CURRENT_LIST_DIR}/app/\\1"
APP_BINARY_DIR "${FIREBASE_BINARY_DIR}")
set(FIRESTORE_SOURCE_DIR ${APP_BINARY_DIR}/external/src/firestore)
else()
# Run the CMake build logic that will download all the external dependencies.
message(STATUS "Downloading external project dependencies...")
download_external_sources()
message(STATUS "Download complete.")
set(FIRESTORE_SOURCE_DIR ${FIREBASE_BINARY_DIR}/external/src/firestore)
endif()
# Include Firestore's external build early to resolve conflicts on packages.
if(NOT ANDROID AND FIREBASE_INCLUDE_FIRESTORE)
set(FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR}-build)
set(
FIREBASE_IOS_BUILD_TESTS
${FIREBASE_CPP_BUILD_TESTS}
CACHE BOOL "Force Firestore build tests to match"
)
add_subdirectory(${FIRESTORE_SOURCE_DIR} ${FIRESTORE_BINARY_DIR})
copy_subdirectory_definition(${FIRESTORE_SOURCE_DIR} NANOPB_SOURCE_DIR)
endif()
# Disable the Flatbuffer build tests, install and flathash
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "")
set(FLATBUFFERS_FLATHASH OFF CACHE BOOL "")
# Disable buliding flatc if cross compiling
if(IOS OR ANDROID)
set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "")
endif()
if(FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
message(STATUS "flatbuffers is added with APP_BINARY_DIR ${APP_BINARY_DIR}")
add_external_library(flatbuffers BINARY_DIR "${APP_BINARY_DIR}")
else()
message(STATUS "flatbuffers is added normally")
add_external_library(flatbuffers)
endif()
if(FIREBASE_CPP_BUILD_TESTS AND NOT FIREBASE_INCLUDE_FIRESTORE)
# Firestore's external build pulls in googletest
add_external_library(googletest)
endif()
# Some of the external libraries are not used for mobile.
if (NOT ANDROID AND NOT IOS)
# Use the static versions of the OpenSSL libraries.
set(OPENSSL_USE_STATIC_LIBS TRUE)
if (MSVC)
# Get the correct version of the OpenSSL libraries based on building for MT.
if ("${CMAKE_CXX_FLAGS_DEBUG}" MATCHES "/MT" OR
"${CMAKE_CXX_FLAGS_RELEASE}" MATCHES "/MT")
set(OPENSSL_MSVC_STATIC_RT TRUE)
else()
set(OPENSSL_MSVC_STATIC_RT FALSE)
endif()
endif()
# Build curl as a static library
set(CURL_STATICLIB ON CACHE BOOL "")
if (WIN32)
set(CMAKE_USE_WINSSL ON CACHE BOOL "")
endif()
add_external_library(curl)
add_external_library(libuv)
find_package(OpenSSL)
add_external_library(zlib)
add_external_library(uWebSockets)
set(websockets_additional_defines "")
# uWebSockets does not come with a CMakeLists file, so define the target.
# Note that since it depends on OpenSSL, only do so if that was found.
if (OPENSSL_FOUND)
if (MSVC OR APPLE)
set(uWebSockets_extra_src)
else()
# Epoll is only used on Linux, otherwise LibUV is used.
set(uWebSockets_extra_src
${UWEBSOCKETS_SOURCE_DIR}/src/Epoll.cpp)
endif()
add_library(libuWS STATIC
${uWebSockets_extra_src}
${UWEBSOCKETS_SOURCE_DIR}/src/Extensions.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/Group.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/HTTPSocket.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/Hub.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/Networking.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/Node.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/Socket.cpp
${UWEBSOCKETS_SOURCE_DIR}/src/WebSocket.cpp)
if(MSVC)
set(websockets_additional_defines
-DWIN32_LEAN_AND_MEAN # Ensure that windows doesn't include winsock.h by
# default, as it can cause issues when libraries try
# to include winsock2.h later on in the process.
-DUSE_LIBUV=1
)
elseif(APPLE)
set(websockets_additional_defines
-DUSE_LIBUV=1
)
endif()
target_compile_definitions(libuWS
PRIVATE
${websockets_additional_defines}
)
target_include_directories(libuWS
PUBLIC
${LIBUV_SOURCE_DIR}/include
${UWEBSOCKETS_SOURCE_DIR}
${ZLIB_SOURCE_DIR}
${ZLIB_BINARY_DIR}
PRIVATE
${OPENSSL_INCLUDE_DIR}
)
target_link_libraries(libuWS
PRIVATE
${OPENSSL_LIBRARIES}
uv_a
zlibstatic
)
endif()
endif()
if(NOT ANDROID)
if(FIREBASE_INCLUDE_FIRESTORE)
# The Firestore build includes protobuf and nanopb already
list(APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR}/extra)
find_package(Nanopb REQUIRED)
set(PROTOBUF_FOUND ON)
else()
find_package(Protobuf)
if (PROTOBUF_FOUND)
# NanoPB requires Protobuf to be present, so only add it if it was found.
add_external_library(nanopb)
# NanoPB has a FindNanopb which defines the function to generate files,
# so add it to the module path, and use that.
list(APPEND CMAKE_MODULE_PATH ${NANOPB_SOURCE_DIR}/extra)
find_package(Nanopb)
target_compile_definitions(
protobuf-nanopb-static
PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
)
endif()
endif()
endif()
if(ANDROID OR IOS)
# Mobile platforms build flatc externally so that it works on the platform
# performing the build.
set(firebase_external_flatc_build_dir "${FLATBUFFERS_BINARY_DIR}-flatc")
set(firebase_external_flatc "${firebase_external_flatc_build_dir}/flatc")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# Fix path slash direction (windows paths use '\' instead of '/')
string(REPLACE "/" "\\"
firebase_external_flatc_build_dir_win
${firebase_external_flatc_build_dir})
set(firebase_external_flatc_build_dir
${firebase_external_flatc_build_dir_win})
unset(firebase_external_flatc_build_dir_win)
# Building on Windows places the executable in a /Debug/ folder
set(firebase_external_flatc
"${firebase_external_flatc_build_dir}/Debug/flatc")
endif()
set(FLATBUFFERS_FLATC_EXECUTABLE ${firebase_external_flatc} CACHE STRING "")
# Setup the flatc custom build target.
# These commands are executed from within the currect context, which has set
# variables for the target platform. We use "env -i" to clear these
# variables, and manually keep the PATH to regular bash path.
# If we didn't do this, we'd end up building flatc for the target platform
# instead of the building platform, and thus couldn't use flatc on the
# building platform.
set(firebase_command_line_path "$ENV{PATH}")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
# OS - Specific Command Joiner
set(COMMAND_CONCAT &)
#Windows doesn't have an 'env' command
set(ENV_COMMAND "")
else()
set(COMMAND_CONCAT &&)
set(ENV_COMMAND env -i PATH=${firebase_command_line_path})
endif()
# Build flatc by invoking the cmake build, with only the flatc target.
file(MAKE_DIRECTORY ${firebase_external_flatc_build_dir})
add_custom_command(
OUTPUT ${firebase_external_flatc}
COMMAND cd ${firebase_external_flatc_build_dir} ${COMMAND_CONCAT}
${ENV_COMMAND} cmake ${FLATBUFFERS_SOURCE_DIR} ${COMMAND_CONCAT}
${ENV_COMMAND} cmake --build . --target flatc
COMMENT "Building flatc (the FlatBuffer schema compiler)")
# Add a target so that we can run the custom commands before the code build.
add_custom_target(
firebase_flatc_prebuild
DEPENDS ${firebase_external_flatc})
# Set a variable that the dependencies can use, to trigger the build before
# using flatbuffers.
set(FIREBASE_FLATBUFFERS_DEPENDENCIES "firebase_flatc_prebuild")
else()
# Other platforms do not need to declare this dependency, as they will build
# flatc correctly when needed.
set(FIREBASE_FLATBUFFERS_DEPENDENCIES "")
endif()
include(binary_to_array)
include(firebase_cpp_gradle)
add_subdirectory(ios_pod)
# If we're building tests, we need to include the 'testing' folder before any
# of the tests actually get built.
if(FIREBASE_CPP_BUILD_TESTS)
add_subdirectory(testing)
endif()
if(NOT FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD)
add_subdirectory(app)
else()
# Add firebase_app as a target on the previously built app.
add_library(firebase_app STATIC IMPORTED GLOBAL)
file(MAKE_DIRECTORY "${APP_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${FIREBASE_BINARY_DIR}/generated")
set(app_include_dirs
"${CMAKE_CURRENT_LIST_DIR}/app/src/include"
"${APP_BINARY_DIR}/generated"
"${FIREBASE_BINARY_DIR}/generated"
)
set_target_properties(firebase_app PROPERTIES
IMPORTED_LOCATION "${APP_BINARY_DIR}/libfirebase_app.a"
INTERFACE_INCLUDE_DIRECTORIES "${app_include_dirs}"
)
endif()
if (FIREBASE_INCLUDE_ADMOB)
add_subdirectory(admob)
endif()
if (FIREBASE_INCLUDE_ANALYTICS)
add_subdirectory(analytics)
endif()
if (FIREBASE_INCLUDE_AUTH)
add_subdirectory(auth)
endif()
if (FIREBASE_INCLUDE_DATABASE)
add_subdirectory(database)
endif()
if (FIREBASE_INCLUDE_DYNAMIC_LINKS)
add_subdirectory(dynamic_links)
endif()
if (FIREBASE_INCLUDE_FIRESTORE)
add_subdirectory(firestore)
endif()
if (FIREBASE_INCLUDE_FUNCTIONS)
add_subdirectory(functions)
endif()
if (FIREBASE_INCLUDE_INSTANCE_ID)
add_subdirectory(instance_id)
endif()
if (FIREBASE_INCLUDE_MESSAGING)
add_subdirectory(messaging)
endif()
if (FIREBASE_INCLUDE_REMOTE_CONFIG)
add_subdirectory(remote_config)
endif()
if (FIREBASE_INCLUDE_STORAGE)
add_subdirectory(storage)
endif()
# Place the CMake and gradle build files provided to easily link against the
# prebuilt libraries at the root of the package.
cpp_pack_dir(
"${CMAKE_CURRENT_LIST_DIR}/release_build_files/"
.
)