@@ -66,6 +66,8 @@ option(FIREBASE_CPP_BUILD_PACKAGE
66
66
"Bundle the Firebase C++ libraries into a zip file." OFF )
67
67
option (FIREBASE_CPP_USE_PRIOR_GRADLE_BUILD
68
68
"When building with Gradle, use the previously built libraries." OFF )
69
+ option (FIREBASE_USE_BORINGSSL
70
+ "Build against BoringSSL instead of using your system's OpenSSL." OFF )
69
71
70
72
set (FIREBASE_ANDROID_STL "" CACHE STRING "STL implementation to use." )
71
73
if (NOT FIREBASE_ANDROID_STL STREQUAL "" )
@@ -115,6 +117,13 @@ else()
115
117
set (DESKTOP OFF )
116
118
endif ()
117
119
120
+ if (DESKTOP AND NOT MSVC AND NOT APPLE )
121
+ # Linux-specific option.
122
+ add_definitions (-D_GLIBCXX_USE_CXX11_ABI=0 )
123
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0" )
124
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=0" )
125
+ endif ()
126
+
118
127
# Set directories needed by the Firebase subprojects
119
128
# Directory to store generated files.
120
129
set (FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR} /generated )
@@ -174,6 +183,87 @@ else()
174
183
set (FIRESTORE_SOURCE_DIR ${FIREBASE_BINARY_DIR} /external/src/firestore )
175
184
endif ()
176
185
186
+ if (DESKTOP )
187
+ # Use the static versions of the OpenSSL libraries.
188
+ set (OPENSSL_USE_STATIC_LIBS TRUE )
189
+ if (MSVC )
190
+ # Get the correct version of the OpenSSL libraries based on building for MT.
191
+ if ("${CMAKE_CXX_FLAGS_DEBUG} " MATCHES "/MTd" OR
192
+ "${CMAKE_CXX_FLAGS_RELEASE} " MATCHES "/MT" )
193
+ set (OPENSSL_MSVC_STATIC_RT TRUE )
194
+ else ()
195
+ set (OPENSSL_MSVC_STATIC_RT FALSE )
196
+ endif ()
197
+ endif ()
198
+
199
+ if (FIREBASE_USE_BORINGSSL )
200
+ # Use BoringSSL instead of OpenSSL.
201
+ set (BORINGSSL_ROOT_DIR ${PROJECT_BINARY_DIR} /external/src/boringssl/src CACHE STRING "" FORCE )
202
+ set (BORINGSSL_BINARY_DIR ${PROJECT_BINARY_DIR} /external/src/boringssl-build CACHE STRING "" FORCE )
203
+ set (OPENSSL_ROOT_DIR ${BORINGSSL_ROOT_DIR} CACHE STRING "" FORCE )
204
+
205
+ # The call below to build_external_dependencies will make sure that these
206
+ # libraries exist before the libraries are imported via add_library.
207
+ if (MSVC )
208
+ if (CMAKE_BUILD_TYPE )
209
+ set (BORINGSSL_LIB_SUBDIR "${CMAKE_BUILD_TYPE} " )
210
+ else ()
211
+ set (BORINGSSL_LIB_SUBDIR "Debug" )
212
+ endif ()
213
+ set (OPENSSL_SSL_LIBRARY ${BORINGSSL_BINARY_DIR} /ssl/${BORINGSSL_LIB_SUBDIR}/ssl.lib CACHE FILEPATH "" FORCE )
214
+ set (OPENSSL_CRYPTO_LIBRARY ${BORINGSSL_BINARY_DIR} /crypto/${BORINGSSL_LIB_SUBDIR}/crypto.lib CACHE FILEPATH "" FORCE )
215
+ else ()
216
+ set (OPENSSL_SSL_LIBRARY ${BORINGSSL_BINARY_DIR} /ssl/libssl.a CACHE FILEPATH "" FORCE )
217
+ set (OPENSSL_CRYPTO_LIBRARY ${BORINGSSL_BINARY_DIR} /crypto/libcrypto.a CACHE FILEPATH "" FORCE )
218
+ endif ()
219
+ endif ()
220
+ endif ()
221
+
222
+
223
+ if (DESKTOP )
224
+ message (STATUS "Building external project dependencies..." )
225
+ build_external_dependencies ()
226
+ message (STATUS "Build of external project dependencies complete." )
227
+
228
+ if (FIREBASE_USE_BORINGSSL )
229
+ set (OPENSSL_FOUND TRUE CACHE BOOL "" FORCE )
230
+ set (OPENSSL_NO_ASM TRUE ) # Force cross-platform BoringSSL, no ASM.
231
+ set (OPENSSL_INCLUDE_DIR ${BORINGSSL_ROOT_DIR} /include CACHE PATH "" FORCE )
232
+ set (OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY} )
233
+ set (OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} )
234
+ set (OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} )
235
+ set (OPENSSL_VERSION '1.1.0' CACHE STRING "" FORCE )
236
+
237
+ add_library (OpenSSL::SSL STATIC IMPORTED )
238
+ add_library (OpenSSL::Crypto STATIC IMPORTED )
239
+ set_target_properties (OpenSSL::SSL PROPERTIES
240
+ IMPORTED_LOCATION "${OPENSSL_SSL_LIBRARY} "
241
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR} "
242
+ INTERFACE_LINK_LIBRARIES OpenSSL::Crypto
243
+ )
244
+
245
+ set_target_properties (OpenSSL::Crypto PROPERTIES
246
+ IMPORTED_LOCATION "${OPENSSL_CRYPTO_LIBRARY} "
247
+ INTERFACE_INCLUDE_DIRECTORIES "${OPENSSL_INCLUDE_DIR} "
248
+ )
249
+ # Now if we do find_package(OpenSSL) it should give us BoringSSL.
250
+ find_package (OpenSSL )
251
+
252
+ if (NOT "${OPENSSL_INCLUDE_DIR} " MATCHES boringssl OR
253
+ NOT "${OPENSSL_SSL_LIBRARY} " MATCHES boringssl OR
254
+ NOT "${OPENSSL_CRYPTO_LIBRARY} " MATCHES boringssl )
255
+ message (FATAL_ERROR "BoringSSL was not configured correctly.\n INCLUDE_DIR=${OPENSSL_INCLUDE_DIR} \n SSL_LIBRARY=${OPENSSL_SSL_LIBRARY} \n CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY} " )
256
+ endif ()
257
+ else ()
258
+ # Don't use BoringSSL, use OpenSSL. If you are linking against the libraries directly
259
+ # from source, you probably want this instead.
260
+ #
261
+ # If the find_package fails to find OpenSSL, set OPENSSL_ROOT_DIR to OpenSSL'S install
262
+ # location on your system.
263
+ find_package (OpenSSL REQUIRED )
264
+ endif ()
265
+ endif ()
266
+
177
267
# Include Firestore's external build early to resolve conflicts on packages.
178
268
if (FIRESTORE_USE_EXTERNAL_CMAKE_BUILD )
179
269
set (FIRESTORE_BINARY_DIR ${FIRESTORE_SOURCE_DIR} -build )
@@ -223,37 +313,28 @@ endif()
223
313
224
314
# Some of the external libraries are not used for mobile.
225
315
if (DESKTOP )
226
- # Use the static versions of the OpenSSL libraries.
227
- set (OPENSSL_USE_STATIC_LIBS TRUE )
228
- if (MSVC )
229
- # Get the correct version of the OpenSSL libraries based on building for MT.
230
- if ("${CMAKE_CXX_FLAGS_DEBUG} " MATCHES "/MT" OR
231
- "${CMAKE_CXX_FLAGS_RELEASE} " MATCHES "/MT" )
232
- set (OPENSSL_MSVC_STATIC_RT TRUE )
233
- else ()
234
- set (OPENSSL_MSVC_STATIC_RT FALSE )
235
- endif ()
236
- endif ()
237
-
238
316
# Build curl as a static library
239
317
set (CURL_STATICLIB ON CACHE BOOL "" )
240
318
if (WIN32 )
241
- set (CMAKE_USE_WINSSL ON CACHE BOOL "" )
319
+ # Enable Windows native SSL/TLS in libcurl.
320
+ set (CMAKE_USE_SCHANNEL ON CACHE BOOL "" )
242
321
endif ()
322
+
323
+ # Current Curl library defaults to requiring some dependencies we don't need, disable them.
324
+ set (CMAKE_USE_LIBSSH2 OFF )
325
+ set (HTTP_ONLY ON )
326
+ set (BUILD_TESTING OFF )
243
327
add_external_library (curl )
244
328
245
329
add_external_library (libuv )
246
330
247
- find_package (OpenSSL )
248
-
249
331
add_external_library (zlib )
250
332
251
333
add_external_library (uWebSockets )
252
334
253
335
# Binutils on Mac doesn't support thread-local storage (required by
254
- # websockets), but because we only use websockets via the scheduler,
255
- # we don't need it.
256
-
336
+ # websockets), but because we only use websockets via the scheduler, we don't
337
+ # need it. Deactivate this by blanking out the __thread keyword.
257
338
set (websockets_additional_defines "-D__thread=" )
258
339
259
340
# uWebSockets does not come with a CMakeLists file, so define the target.
@@ -304,7 +385,8 @@ if(DESKTOP)
304
385
)
305
386
target_link_libraries (libuWS
306
387
PRIVATE
307
- ${OPENSSL_LIBRARIES}
388
+ OpenSSL::SSL
389
+ OpenSSL::Crypto
308
390
uv_a
309
391
zlibstatic
310
392
)
0 commit comments