Skip to content

Commit f5138d9

Browse files
committed
Adds initial logic for packaging the C++ libraries with open source
Adds logic to zip the firebase libraries using cpack, and their desktop dependencies for blastdoor. Needed for moving to use the open source build logic for the prebuilt version. PiperOrigin-RevId: 288796467
1 parent 183cfaf commit f5138d9

File tree

15 files changed

+153
-8
lines changed

15 files changed

+153
-8
lines changed

CMakeLists.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@ option(FIREBASE_CPP_BUILD_TESTS
4444
"Enable the Firebase C++ Build Tests." OFF)
4545
option(FIREBASE_FORCE_FAKE_SECURE_STORAGE
4646
"Disable use of platform secret store and use fake impl." OFF)
47+
option(FIREBASE_CPP_BUILD_PACKAGE
48+
"Bundle the Firebase C++ libraries into a zip file." OFF)
49+
50+
# Define this directory to be the root of the C++ SDK, which the libraries can
51+
# then refer to.
52+
set(FIREBASE_CPP_SDK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
53+
54+
project (firebase NONE)
55+
enable_language(C)
56+
enable_language(CXX)
4757

4858
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake)
4959
include(external_rules)
60+
include(cpp_pack)
5061

5162
if(FIREBASE_CPP_BUILD_TESTS)
5263
enable_testing()
@@ -68,10 +79,6 @@ set(FIREBASE_GEN_FILE_DIR ${CMAKE_BINARY_DIR}/generated)
6879
# Directory for any shared scripts.
6980
set(FIREBASE_SCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR})
7081

71-
project (firebase NONE)
72-
enable_language(C)
73-
enable_language(CXX)
74-
7582
if (FIREBASE_CPP_BUILD_TESTS AND MSVC)
7683
# Googletest requires MSVC to compile with the static version of the runtime
7784
# library, so define the appropriate runtime flag, before adding libraries.
@@ -258,10 +265,6 @@ else()
258265
set(FIREBASE_FLATBUFFERS_DEPENDENCIES "")
259266
endif()
260267

261-
# Define this directory to be the root of the C++ SDK, which the libraries can
262-
# then refer to.
263-
set(FIREBASE_CPP_SDK_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
264-
265268
include(binary_to_array)
266269
include(firebase_cpp_gradle)
267270

@@ -305,3 +308,10 @@ endif()
305308
if (FIREBASE_INCLUDE_STORAGE)
306309
add_subdirectory(storage)
307310
endif()
311+
312+
# Place the CMake and gradle build files provided to easily link against the
313+
# prebuilt libraries at the root of the package.
314+
cpp_pack_dir(
315+
"${CMAKE_CURRENT_LIST_DIR}/release_build_files/"
316+
.
317+
)

admob/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ elseif(IOS)
120120
# accomplish that.
121121
symlink_pod_headers(firebase_admob Google-Mobile-Ads-SDK GoogleMobileAds)
122122
endif()
123+
124+
cpp_pack_library(firebase_admob "")

analytics/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ if(FIREBASE_CPP_BUILD_TESTS)
133133
# Add the tests subdirectory
134134
add_subdirectory(tests)
135135
endif()
136+
137+
cpp_pack_library(firebase_analytics "")

app/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,8 @@ if(FIREBASE_CPP_BUILD_TESTS)
365365
# Add the tests subdirectory
366366
add_subdirectory(tests)
367367
endif()
368+
369+
cpp_pack_library(firebase_app "")
370+
if (NOT ANDROID AND NOT IOS)
371+
cpp_pack_library(flatbuffers "deps/app/external")
372+
endif()

app/instance_id/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ target_compile_definitions(firebase_instance_id_desktop_impl
5858
PRIVATE
5959
-DINTERNAL_EXPERIMENTAL=1
6060
)
61+
62+
cpp_pack_library(firebase_instance_id_desktop_impl "deps/app")

app/rest/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,9 @@ if(FIREBASE_CPP_BUILD_TESTS)
126126
# Add the tests subdirectory
127127
add_subdirectory(tests)
128128
endif()
129+
130+
cpp_pack_library(firebase_rest_lib "deps/app")
131+
cpp_pack_library(libcurl "deps/app/external")
132+
cpp_pack_library(zlibstatic "deps/app/external")
133+
cpp_pack_library_file(${OPENSSL_SSL_LIBRARY} "deps/app/external")
134+
cpp_pack_library_file(${OPENSSL_CRYPTO_LIBRARY} "deps/app/external")

auth/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,5 @@ if(FIREBASE_CPP_BUILD_TESTS)
209209
# Add the tests subdirectory
210210
add_subdirectory(tests)
211211
endif()
212+
213+
cpp_pack_library(firebase_auth "")

cmake/cpp_pack.cmake

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright 2019 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Handles creation of the C++ package zip using cpack
16+
17+
# All functions do nothing unless FIREBASE_CPP_BUILD_PACKAGE is enabled.
18+
if(${FIREBASE_CPP_BUILD_PACKAGE})
19+
# Including CPack multiple times can cause it to break, so guard against that.
20+
if(DEFINED CPACK_GENERATOR)
21+
return()
22+
endif()
23+
24+
# iOS will get the platform name of Darwin if we dont change it here
25+
if(IOS)
26+
set(CPACK_SYSTEM_NAME "iOS")
27+
endif()
28+
29+
set(CPACK_GENERATOR "ZIP")
30+
if(NOT DEFINED FIREBASE_CPP_VERSION OR FIREBASE_CPP_VERSION STREQUAL "")
31+
# Parse the version number from the json file.
32+
file(STRINGS ${FIREBASE_CPP_SDK_ROOT_DIR}/cpp_sdk_version.json version_file)
33+
string(REGEX MATCH "[0-9\.]+" FIREBASE_CPP_VERSION "${version_file}")
34+
endif()
35+
set(CPACK_PACKAGE_VERSION "${FIREBASE_CPP_VERSION}")
36+
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0) # DO NOT pack the root directory.
37+
38+
include(CPack)
39+
40+
if(ANDROID)
41+
set(FIREBASE_LIB_CONFIG_PATH "android")
42+
elseif(IOS)
43+
set(FIREBASE_LIB_CONFIG_PATH "ios")
44+
elseif(MSVC)
45+
set(FIREBASE_LIB_CONFIG_PATH "windows")
46+
elseif(APPLE)
47+
set(FIREBASE_LIB_CONFIG_PATH "darwin")
48+
else()
49+
set(FIREBASE_LIB_CONFIG_PATH "linux")
50+
endif()
51+
endif()
52+
53+
# Packs the given target library into the libs folder, under the correct config
54+
# and given subdirectory.
55+
function(cpp_pack_library TARGET SUBDIRECTORY)
56+
if(NOT ${FIREBASE_CPP_BUILD_PACKAGE})
57+
return()
58+
endif()
59+
60+
install(
61+
TARGETS "${TARGET}"
62+
ARCHIVE DESTINATION "libs/${FIREBASE_LIB_CONFIG_PATH}/${SUBDIRECTORY}"
63+
)
64+
endfunction()
65+
66+
# Packs the given file into the libs folder, under the correct config
67+
# and given subdirectory.
68+
function(cpp_pack_library_file FILE_TO_PACK SUBDIRECTORY)
69+
cpp_pack_file(${FILE_TO_PACK}
70+
"libs/${FIREBASE_LIB_CONFIG_PATH}/${SUBDIRECTORY}")
71+
endfunction()
72+
73+
# Packs the given file into the given destination.
74+
function(cpp_pack_file FILE_TO_PACK DESTINATION)
75+
if(NOT ${FIREBASE_CPP_BUILD_PACKAGE})
76+
return()
77+
endif()
78+
79+
# Get the real file path, for cases like symlinks.
80+
get_filename_component(path_to_file ${FILE_TO_PACK} REALPATH)
81+
82+
install(
83+
FILES ${path_to_file}
84+
DESTINATION ${DESTINATION}
85+
)
86+
endfunction()
87+
88+
# Packs the given directory into the given destination.
89+
function(cpp_pack_dir DIR_TO_PACK DESTINATION)
90+
if(NOT ${FIREBASE_CPP_BUILD_PACKAGE})
91+
return()
92+
endif()
93+
94+
install(
95+
DIRECTORY ${DIR_TO_PACK}
96+
DESTINATION ${DESTINATION}
97+
)
98+
endfunction()

database/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,9 @@ if(FIREBASE_CPP_BUILD_TESTS)
209209
# Add the tests subdirectory
210210
add_subdirectory(tests)
211211
endif()
212+
213+
cpp_pack_library(firebase_database "")
214+
if (NOT ANDROID AND NOT IOS)
215+
cpp_pack_library(uv_a "deps/database/external")
216+
cpp_pack_library(libuWS "deps/database/external")
217+
endif()

dynamic_links/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ elseif(IOS)
8686
FirebaseDynamicLinks
8787
)
8888
endif()
89+
90+
cpp_pack_library(firebase_dynamic_links "")

0 commit comments

Comments
 (0)