Skip to content

Commit 5a6e152

Browse files
Googlera-maurice
authored andcommitted
Initial import of the Firebase Unity SDK
PiperOrigin-RevId: 365082327
1 parent 87df1db commit 5a6e152

File tree

291 files changed

+41668
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+41668
-0
lines changed

.gitallowed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# app/src/AppOptions.cs allows a fake secret to be used in code example
2+
AIzaSyDdVgKwhZl0sTTTLZ7iTmt1r3N2cJLnaDk

CMakeLists.txt

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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+
# CMake file for the firebase_unity plugin
16+
17+
# Higher CMake version needed for improvments in UseSwig.cmake and string join
18+
cmake_minimum_required (VERSION 3.13.4)
19+
set (CMAKE_CXX_STANDARD 11)
20+
21+
# Turn on virtual folders for visual studio
22+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
23+
24+
# Disable adding "-d" to debug dll filename as CSharp uses dll name for pinvoke
25+
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Set debug library postfix")
26+
27+
option(FIREBASE_INCLUDE_UNITY "Build unity libraries" ON)
28+
option(FIREBASE_INCLUDE_MONO "Build mono libraries" OFF)
29+
option(FIREBASE_UNI_LIBRARY "Link all firebase libraries into one shared object" ON)
30+
31+
# Different options to enable/disable each library being included during
32+
# configuration.
33+
option(FIREBASE_INCLUDE_ANALYTICS
34+
"Include the Google Analytics for Firebase library." ON)
35+
option(FIREBASE_INCLUDE_AUTH
36+
"Include the Firebase Authentication library." ON)
37+
option(FIREBASE_INCLUDE_CRASHLYTICS
38+
"Include the Firebase Crashlytics library." ON)
39+
option(FIREBASE_INCLUDE_DATABASE
40+
"Include the Firebase Realtime Database library." ON)
41+
option(FIREBASE_INCLUDE_DYNAMIC_LINKS
42+
"Include the Firebase Dynamic Links library." ON)
43+
option(FIREBASE_INCLUDE_FUNCTIONS
44+
"Include the Cloud Functions for Firebase library." ON)
45+
option(FIREBASE_INCLUDE_INSTANCE_ID
46+
"Include the Firebase Instance ID library." ON)
47+
option(FIREBASE_INCLUDE_MESSAGING
48+
"Include the Firebase Cloud Messaging library." ON)
49+
option(FIREBASE_INCLUDE_REMOTE_CONFIG
50+
"Include the Firebase Remote Config library." ON)
51+
option(FIREBASE_INCLUDE_STORAGE
52+
"Include the Cloud Storage for Firebase library." ON)
53+
54+
option(FIREBASE_UNITY_BUILD_TESTS
55+
"Enable the Firebase Unity Build Tests." OFF)
56+
57+
# These options allow selecting what built outputs go into the CPack zip file
58+
# as we merge the different platform zip's together for unity package
59+
# For example: only packing dotnet libraries on linux builds
60+
option(FIREBASE_PACK_NATIVE "Add C++ libraries to CPack output" ON)
61+
option(FIREBASE_PACK_DOTNET "Add CSharp libraries to CPack output" ON)
62+
63+
set(FIREBASE_CPP_SDK_DIR "" CACHE STRING "Directory to the firebase cpp sdk")
64+
65+
# UseSWIG generates standard target names.
66+
cmake_policy(SET CMP0078 NEW)
67+
68+
if (FIREBASE_INCLUDE_MONO AND FIREBASE_INCLUDE_UNITY)
69+
message(WARNING "Both Mono and Unity build set to ON. Disabling Unity.")
70+
set(FIREBASE_INCLUDE_UNITY OFF)
71+
endif()
72+
73+
# Darwin library for security
74+
if(APPLE AND NOT FIREBASE_IOS_BUILD)
75+
set(FIREBASE_SYSTEM_DEPS
76+
"-framework Foundation"
77+
"-framework Security"
78+
)
79+
else()
80+
set(FIREBASE_SYSTEM_DEPS)
81+
endif()
82+
83+
if(NOT FIREBASE_IOS_BUILD) # besides iOS build, don't need lib prefix
84+
set(CMAKE_SHARED_LIBRARY_PREFIX "")
85+
set(CMAKE_STATIC_LIBRARY_PREFIX "")
86+
endif()
87+
88+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
89+
90+
if(DEFINED CMAKE_TOOLCHAIN_FILE AND NOT ANDROID)
91+
# Force using the toolchain file, as otherwise it loads it later in the
92+
# process, after several of the checks against it have failed.
93+
if(IS_ABSOLUTE ${CMAKE_TOOLCHAIN_FILE})
94+
message("Using Toolchain File: ${CMAKE_TOOLCHAIN_FILE}")
95+
include("${CMAKE_TOOLCHAIN_FILE}")
96+
else()
97+
message("Using Toolchain File: ${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}")
98+
include("${CMAKE_BINARY_DIR}/${CMAKE_TOOLCHAIN_FILE}")
99+
endif()
100+
endif()
101+
102+
project(firebase_unity NONE)
103+
enable_language(C)
104+
enable_language(CXX)
105+
106+
include(FindPkgConfig)
107+
include(android_dependencies)
108+
include(build_universal)
109+
include(external_rules)
110+
include(firebase_swig)
111+
include(firebase_unity_version)
112+
include(ios_pack)
113+
include(play_services_resolver_deps)
114+
include(unity_mono)
115+
include(unity_pack)
116+
117+
# Set variables that are used by download_external_sources.
118+
set(FIREBASE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
119+
set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
120+
set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR}/opt)
121+
set(FIREBASE_DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/downloads)
122+
123+
# Try to read the path to the Firebase C++ SDK from an environment variable.
124+
# Do this before downloading external sources, as if it is missing, it will be
125+
# downloaded as part of that step.
126+
if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
127+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
128+
else()
129+
set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
130+
endif()
131+
132+
if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
133+
set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
134+
endif()
135+
if (NOT IS_ABSOLUTE ${FIREBASE_CPP_SDK_DIR})
136+
set(FIREBASE_CPP_SDK_DIR "${PROJECT_BINARY_DIR}/${FIREBASE_CPP_SDK_DIR}")
137+
endif()
138+
139+
# Run the CMake build logic that will download all the external dependencies.
140+
download_external_sources()
141+
142+
# Shared libraries on linux and mac need position independent code to link
143+
# properly. Force it here for all projects.
144+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
145+
146+
if(NOT MSVC AND NOT ANDROID)
147+
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "x64" OR
148+
"${CMAKE_GENERATOR_PLATFORM}" STREQUAL "")
149+
add_compile_options(-m64)
150+
else()
151+
add_compile_options(-m32)
152+
endif()
153+
endif()
154+
155+
if(UNIX AND NOT APPLE) # we only need this for linux
156+
# Report undefined symbols
157+
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined")
158+
endif()
159+
160+
if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
161+
message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: \
162+
${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
163+
endif()
164+
165+
if(MSVC AND NOT EXISTS ${MONO_DIR})
166+
message(FATAL_ERROR "Mono directory doesn't exist: \
167+
${MONO_DIR}. See the readme.md for more information")
168+
endif()
169+
170+
# Add the Firebase libraries to the target using the function from the SDK.
171+
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
172+
173+
# Windows runtime mode, either MD or MT depending on whether you are using
174+
# /MD or /MT. For more information see:
175+
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
176+
set(MSVC_RUNTIME_MODE MD)
177+
178+
set(FIREBASE_UNITY_DIR ${CMAKE_CURRENT_SOURCE_DIR})
179+
180+
if(FIREBASE_INCLUDE_UNITY)
181+
add_external_library(google_unity_jar_resolver)
182+
endif()
183+
184+
add_external_library(minijson)
185+
add_external_library(parse)
186+
187+
# External mono library and dll setup for CSharp projects
188+
add_subdirectory(external)
189+
190+
string(REPLACE "." "_" version_string ${FIREBASE_UNITY_SDK_VERSION})
191+
set(FIREBASE_APP_UNI_VERSIONED "FirebaseCppApp-${version_string}")
192+
193+
# Setup override of the CSharp import library for uni builds
194+
if(FIREBASE_UNI_LIBRARY)
195+
set(FIREBASE_SWIG_OVERRIDE_IMPORT_MODULE "${FIREBASE_APP_UNI_VERSIONED}")
196+
endif()
197+
198+
# Includes platform which needs to be invoked first
199+
add_subdirectory(app)
200+
set(TARGET_LINK_LIB_NAMES "firebase_app" "firebase_app_swig" "flatbuffers")
201+
set(PROJECT_LIST_HEADER "#define PROJECT_LIST(X)")
202+
list(APPEND PROJECT_LIST_HEADER " X(App)")
203+
204+
if (FIREBASE_INCLUDE_ANALYTICS)
205+
add_subdirectory(analytics)
206+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_analytics" "firebase_analytics_swig")
207+
list(APPEND PROJECT_LIST_HEADER " X(Analytics)")
208+
endif()
209+
if (FIREBASE_INCLUDE_AUTH)
210+
add_subdirectory(auth)
211+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_auth" "firebase_auth_swig")
212+
list(APPEND PROJECT_LIST_HEADER " X(Auth)")
213+
endif()
214+
if (FIREBASE_INCLUDE_CRASHLYTICS AND FIREBASE_INCLUDE_UNITY)
215+
add_subdirectory(crashlytics)
216+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_crashlytics" "firebase_crashlytics_swig")
217+
list(APPEND PROJECT_LIST_HEADER " X(Crashlytics)")
218+
endif()
219+
if (FIREBASE_INCLUDE_DATABASE)
220+
add_subdirectory(database)
221+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_database" "firebase_database_swig")
222+
list(APPEND PROJECT_LIST_HEADER " X(Database)")
223+
endif()
224+
if (FIREBASE_INCLUDE_DYNAMIC_LINKS)
225+
add_subdirectory(dynamic_links)
226+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_dynamic_links" "firebase_dynamic_links_swig")
227+
list(APPEND PROJECT_LIST_HEADER " X(DynamicLinks)")
228+
endif()
229+
if (FIREBASE_INCLUDE_FUNCTIONS)
230+
add_subdirectory(functions)
231+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_functions" "firebase_functions_swig")
232+
list(APPEND PROJECT_LIST_HEADER " X(Functions)")
233+
endif()
234+
if (FIREBASE_INCLUDE_INSTANCE_ID)
235+
add_subdirectory(instance_id)
236+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_instance_id" "firebase_instance_id_swig")
237+
list(APPEND PROJECT_LIST_HEADER " X(InstanceId)")
238+
endif()
239+
if (FIREBASE_INCLUDE_MESSAGING)
240+
add_subdirectory(messaging)
241+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_messaging" "firebase_messaging_swig")
242+
list(APPEND PROJECT_LIST_HEADER " X(Messaging)")
243+
endif()
244+
if (FIREBASE_INCLUDE_REMOTE_CONFIG)
245+
add_subdirectory(remote_config)
246+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_remote_config" "firebase_remote_config_swig")
247+
list(APPEND PROJECT_LIST_HEADER " X(RemoteConfig)")
248+
endif()
249+
if (FIREBASE_INCLUDE_STORAGE)
250+
add_subdirectory(storage)
251+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_storage" "firebase_storage_swig")
252+
list(APPEND PROJECT_LIST_HEADER " X(Storage)")
253+
endif()
254+
255+
if(FIREBASE_UNI_LIBRARY)
256+
if(FIREBASE_IOS_BUILD)
257+
ios_pack(firebase_lib_uni libFirebaseCppApp DEPS ${TARGET_LINK_LIB_NAMES})
258+
else()
259+
build_uni(
260+
"${TARGET_LINK_LIB_NAMES}"
261+
PROJECT_LIST_HEADER
262+
)
263+
endif()
264+
endif()
265+
266+
if(FIREBASE_INCLUDE_MONO)
267+
add_subdirectory(samples/mono_app)
268+
endif()

0 commit comments

Comments
 (0)