Add Firebase to your C++ projectplat_iosplat_androidplat_cpp

Power up your C++ games with our Firebase C++ SDKs which provide a C++
interface on top of Firebase for iOS and for Android.

Access Firebase entirely from your C++ code, without having to write any
platform-native code. The Firebase SDK also translates many language-specific
idioms used by Firebase into an interface more familiar to C++ developers.

Find out more information about powering up your games with Firebase at our
Firebase games page.

Have you already added Firebase to your C++ project? Make sure that you're
using the latest version of the Firebase C++ SDK.

Select a platform tab below to display platform-specific instructions
in this guide.

If you're releasing your game on both iOS and Android platforms:
You can register one build target of your C++ project now, then return to
the setup workflow later to register the other build target, too.

Find this bundle ID from your open project in XCode. Select the
top-level app in the project navigator at the left, then access the
General tab. The Bundle Identifier value is the iOS bundle ID
(for example, com.yourcompany.ios-app-name).

(Optional) Enter other app information as prompted by the setup workflow.

The nickname is an internal, convenience identifier and is only visible to
you in the Firebase console.

To your Podfile, add the Firebase pods that you want to use in your
app.

Analytics enabled

# Add the Firebase pod for Google Analytics
pod 'Firebase/Analytics'
# Add the pods for any other Firebase products you want to use in your app
# For example, to use Firebase Authentication and Firebase Realtime Database
pod 'Firebase/Auth'
pod 'Firebase/Database'

Analytics not enabled

# Add the pods for the Firebase products you want to use in your app
# For example, to use Firebase Authentication and Firebase Realtime Database
pod 'Firebase/Auth'
pod 'Firebase/Database'

The easiest way to add these frameworks is usually to drag them from a
Finder window directly into Xcode's Project Navigator pane (the
far-left pane, by default; or click the file icon in the top-left of Xcode).

Add the Firebase C++ framework firebase.framework, which is
required to use any Firebase product.

Add the framework for each Firebase product that you want to use. For
example, to use Firebase Authentication, add firebase_auth.framework.

Important: Make sure that you add the frameworks to your project and
not to the Pods project!

Back in the Firebase console, in the setup workflow, click Next.

If you added Analytics, run your app to send verification to Firebase
that you've successfully integrated Firebase. Otherwise, you can skip this
verification step.

Your device logs will display the Firebase verification that initialization
is complete. If you ran your app on an emulator that has network access,
the Firebase console notifies you that your app connection is complete.

You’re all set! Your C++ app is registered and configured to use Firebase
products.

Available libraries for iOS

Each Firebase product has different dependencies. Be sure to add all the
listed dependencies for the desired Firebase product to your Podfile and
C++ project.

You no longer need to add the iOS pod
Firebase/Core. This SDK included the Firebase SDK
for Google Analytics. Now, to use Analytics (or any of the Firebase
products that require or recommend the use of Analytics), you need to
explicitly add the Analytics pod: Firebase/Analytics.

Additional information for mobile setup

Method swizzling

On iOS, some application events (such as opening URLs and receiving
notifications) require your application delegate to implement specific
methods. For example, receiving a notification might require your application
delegate to implement application:didReceiveRemoteNotification:. Because
each iOS application has its own app delegate, Firebase uses
method swizzling, which allows the replacement of one method with another,
to attach its own handlers in addition to any that you might have implemented.

The Firebase Invites, Dynamic Links, and Cloud Messaging libraries need
to attach handlers to the application delegate using method swizzling. If
you're using any of these Firebase products, at load time, Firebase will
identify your AppDelegate class and swizzle the required methods onto it,
chaining a call back to your existing method implementation.

Set up a desktop workflow (beta)

Caution: Firebase C++ SDK desktop support is a beta feature. This feature is
intended only for workflows during the development of your game, not for
publicly shipping code.

When you're creating a game, it's often much easier to test your game on desktop
platforms first, then deploy and test on mobile devices later in development. To
support this workflow, we provide a
subset of the Firebase C++ SDKs which can run on
Windows, OS X, Linux, and from within the C++ editor.

If you added the Android google-services.json file — When you run
your app, Firebase locates this mobile file, then automatically
generates a desktop Firebase config file
(google-services-desktop.json).

If you added the iOS GoogleService-Info.plist file — Before you run
your app, you need to convert this mobile file to a desktop Firebase
config file. To convert the file, run the following command from the same
directory as your GoogleService-Info.plist file:

This desktop config file contains the C++ project ID that you entered in
the Firebase console setup workflow. Visit
Understand Firebase Projects
to learn more about config files.

Add Firebase SDKs to your C++ project.

The steps below serve as an example of how to add any
supported Firebase product to
your C++ project. In this example, we walk through adding
Firebase Authentication and Firebase Realtime Database.

Set your FIREBASE_CPP_SDK_DIR environment variable to the location of
the unzipped Firebase C++ SDK.

To your project's CMakeLists.txt file, add the following content,
including the libraries for
the Firebase products that you want to use. For example, to use
Firebase Authentication and Firebase Realtime Database:

# Add Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
# The Firebase C++ library `firebase_app` is required,
# and it must always be listed last.
# Add the Firebase SDKs for the products you want to use in your app
# For example, to use Firebase Authentication and Firebase Realtime Database
set(firebase_libs firebase_auth firebase_database firebase_app)
target_link_libraries(${target_name} "${firebase_libs}")

Run your C++ app.

Available libraries (desktop)

The Firebase C++ SDK includes desktop workflow support
for a subset of features, enabling certain parts of Firebase to be used in
standalone desktop builds on Windows, OS X, and Linux.

Caution: Firebase C++ SDK desktop support is a beta feature. This feature
is intended only for workflows during the development of your game, not for
publicly shipping code.

Firebase provides the remaining desktop libraries as stub (non-functional)
implementations for convenience when building for Windows, OS X, and Linux.
Therefore, you don't need to conditionally compile code to target the desktop.

Realtime Database desktop

The Realtime Database Desktop SDK uses REST to access your database, so you must
declare the indexes you use
with Query::OrderByChild() on desktop or your listeners will fail.

Note that the following libraries were tested using Visual Studio 2015 and 2017.

When building C++ desktop apps on Windows, link the following Windows SDK
libraries to your project. Consult your compiler documentation for more
information.

Firebase C++ Library

Windows SDK library dependencies

Authentication

advapi32, ws2_32, crypt32

Cloud Functions

advapi32, ws2_32, crypt32, rpcrt4, ole32

Cloud Storage

advapi32, ws2_32, crypt32

Realtime Database

advapi32, ws2_32, crypt32, iphlpapi, psapi, userenv

Remote Config

advapi32, ws2_32, crypt32, rpcrt4, ole32

OS X libraries

For OS X (Darwin), library versions are provided for the 64-bit (x86_64)
platform. Frameworks are also provided for your convenience.

Note that the OS X libraries have been tested using Xcode
10.1.0.

When building C++ desktop apps on OS X, link the following to your project:

pthread system library

CoreFoundation OS X system framework

Foundation OS X system framework

Security OS X system framework

GSS OS X system framework

Kerberos OS X system framework

Consult your compiler documentation for more information.

Linux libraries

For Linux, library versions are provided for 32-bit (i386) and 64-bit (x86_64)
platforms.

Note that the Linux libraries were tested using GCC 4.8.0, GCC 7.2.0, and
Clang 5.0 on Ubuntu.

When building C++ desktop apps on Linux, link the pthread system library to
your project. Consult your compiler documentation for more information. If
you're building with GCC 5 or later, define -D_GLIBCXX_USE_CXX11_ABI=0.