@@ -15,88 +15,97 @@ if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
15
15
message (FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR} . See the readme.md for more information" )
16
16
endif ()
17
17
18
- # Windows runtime mode, either MD or MT depending on whether you are using
19
- # /MD or /MT. For more information see:
20
- # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
21
- set (MSVC_RUNTIME_MODE MD )
22
-
23
- project (firebase_testapp )
24
-
25
18
# Sample source files.
26
19
set (FIREBASE_SAMPLE_COMMON_SRCS
27
20
src/main.h
28
21
src/common_main.cc
29
22
)
30
23
31
- # Platform abstraction layer for the sample.
32
- set (FIREBASE_SAMPLE_DESKTOP_SRCS
33
- src/desktop/desktop_main.cc
34
- )
24
+ # The include directory for the testapp.
25
+ include_directories (src )
35
26
36
27
# Sample uses some features that require C++ 11, such as lambdas.
37
28
set (CMAKE_CXX_STANDARD 11 )
38
29
39
- # Determine the path to the library based on the platform and configuration.
40
- if (APPLE )
41
- set (FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR} /libs/darwin/universal )
42
- set (ADDITIONAL_LIBS pthread )
43
- elseif (MSVC )
44
- if (${CMAKE_CL_64} )
45
- set (MSVC_CPU x64 )
46
- else ()
47
- set (MSVC_CPU x86 )
48
- endif ()
49
- if (CMAKE_BUILD_TYPE EQUAL Release )
50
- set (MSVC_CONFIG Release )
51
- else ()
52
- set (MSVC_CONFIG Debug )
53
- endif ()
54
- set (MSVC_VS_VERSION VS2015 )
55
- set (FIREBASE_SDK_LIBDIR
56
- ${FIREBASE_CPP_SDK_DIR} /libs/windows/${MSVC_VS_VERSION}/${MSVC_RUNTIME_MODE}/${MSVC_CPU}/${MSVC_CONFIG} )
30
+ if (ANDROID )
31
+ # Build an Android application.
32
+
33
+ # Source files used for the Android build.
34
+ set (FIREBASE_SAMPLE_ANDROID_SRCS
35
+ src/android/android_main.cc
36
+ )
37
+
38
+ # Build native_app_glue as a static lib
39
+ add_library (native_app_glue STATIC
40
+ ${ANDROID_NDK} /sources/android/native_app_glue/android_native_app_glue.c )
41
+
42
+ # Export ANativeActivity_onCreate(),
43
+ # Refer to: https://github.com/android-ndk/ndk/issues/381.
44
+ set (CMAKE_SHARED_LINKER_FLAGS
45
+ "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate" )
46
+
47
+ # Define the target as a shared library, as that is what gradle expects.
48
+ set (target_name "android_main" )
49
+ add_library (${target_name} SHARED
50
+ ${FIREBASE_SAMPLE_ANDROID_SRCS}
51
+ ${FIREBASE_SAMPLE_COMMON_SRCS}
52
+ )
53
+
54
+ target_link_libraries (${target_name}
55
+ log android atomic native_app_glue
56
+ )
57
+
58
+ target_include_directories (${target_name} PRIVATE
59
+ ${ANDROID_NDK} /sources/android/native_app_glue )
60
+
57
61
set (ADDITIONAL_LIBS )
58
62
else ()
59
- # The Firebase libraries are not built with glibcxx11, so disable the ABI.
60
- add_definitions (-D_GLIBCXX_USE_CXX11_ABI=0 )
61
- set (LINUX_CPU x86_64 )
62
- set (FIREBASE_SDK_LIBDIR ${FIREBASE_CPP_SDK_DIR} /libs/linux/${LINUX_CPU} )
63
- set (ADDITIONAL_LIBS pthread )
64
- endif ()
63
+ # Build a desktop application.
65
64
66
- # Link Firebase libraries.
67
- # NOTE: firebase_app needs to be after all other Firebase libraries.
68
- link_directories ( ${FIREBASE_SDK_LIBDIR} )
69
- set (FIREBASE_LIBS firebase_admob firebase_app )
65
+ # Windows runtime mode, either MD or MT depending on whether you are using
66
+ # /MD or /MT. For more information see:
67
+ # https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
68
+ set (MSVC_RUNTIME_MODE MD )
70
69
71
- # Add the Firebase include directory.
72
- set (FIREBASE_SDK_INCLUDEDIR ${FIREBASE_CPP_SDK_DIR} /include )
73
- include_directories (${FIREBASE_SDK_INCLUDEDIR} )
70
+ # Platform abstraction layer for the desktop sample.
71
+ set (FIREBASE_SAMPLE_DESKTOP_SRCS
72
+ src/desktop/desktop_main.cc
73
+ )
74
74
75
- # The include directory for the testapp.
76
- include_directories (src )
75
+ set (target_name "desktop_testapp" )
76
+ add_executable (${target_name}
77
+ ${FIREBASE_SAMPLE_DESKTOP_SRCS}
78
+ ${FIREBASE_SAMPLE_COMMON_SRCS}
79
+ )
77
80
78
- add_executable (desktop_testapp
79
- ${FIREBASE_SAMPLE_DESKTOP_SRCS}
80
- ${FIREBASE_SAMPLE_COMMON_SRCS}
81
- )
82
- target_link_libraries (desktop_testapp
83
- ${FIREBASE_LIBS}
84
- ${ADDITIONAL_LIBS}
85
- )
81
+ if (APPLE )
82
+ set (ADDITIONAL_LIBS pthread )
83
+ elseif (MSVC )
84
+ set (ADDITIONAL_LIBS )
85
+ else ()
86
+ set (ADDITIONAL_LIBS pthread )
87
+ endif ()
86
88
87
- # If a config file is present, copy it into the binary location so that it's
88
- # possible to create the default Firebase app.
89
- set (FOUND_JSON_FILE FALSE )
90
- foreach (config "google-services-desktop.json" "google-services.json" )
91
- if (EXISTS ${config} )
92
- add_custom_command (
93
- TARGET desktop_testapp POST_BUILD
94
- COMMAND ${CMAKE_COMMAND} -E copy
95
- ${config} $< TARGET_FILE_DIR:desktop_testapp> )
96
- set (FOUND_JSON_FILE TRUE )
97
- break ()
89
+ # If a config file is present, copy it into the binary location so that it's
90
+ # possible to create the default Firebase app.
91
+ set (FOUND_JSON_FILE FALSE )
92
+ foreach (config "google-services-desktop.json" "google-services.json" )
93
+ if (EXISTS ${config} )
94
+ add_custom_command (
95
+ TARGET ${target_name} POST_BUILD
96
+ COMMAND ${CMAKE_COMMAND} -E copy
97
+ ${config} $< TARGET_FILE_DIR:${target_name} > )
98
+ set (FOUND_JSON_FILE TRUE )
99
+ break ()
100
+ endif ()
101
+ endforeach ()
102
+ if (NOT FOUND_JSON_FILE )
103
+ message (WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information." )
98
104
endif ()
99
- endforeach ()
100
- if (NOT FOUND_JSON_FILE )
101
- message (WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information." )
102
105
endif ()
106
+
107
+ # Add the Firebase libraries to the target using the function from the SDK.
108
+ add_subdirectory (${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL )
109
+ # Note that firebase_app needs to be last in the list.
110
+ set (firebase_libs firebase_admob firebase_app )
111
+ target_link_libraries (${target_name} "${firebase_libs} " ${ADDITIONAL_LIBS} )
0 commit comments