-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
136 lines (116 loc) · 4.41 KB
/
CMakeLists.txt
File metadata and controls
136 lines (116 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cmake_minimum_required(VERSION 3.22)
# User settings for Firebase samples.
# Path to Firebase SDK.
# Try to read the path to the Firebase C++ SDK from an environment variable.
if (NOT "$ENV{FIREBASE_CPP_SDK_DIR}" STREQUAL "")
set(DEFAULT_FIREBASE_CPP_SDK_DIR "$ENV{FIREBASE_CPP_SDK_DIR}")
else()
set(DEFAULT_FIREBASE_CPP_SDK_DIR "firebase_cpp_sdk")
endif()
if ("${FIREBASE_CPP_SDK_DIR}" STREQUAL "")
set(FIREBASE_CPP_SDK_DIR ${DEFAULT_FIREBASE_CPP_SDK_DIR})
endif()
if(NOT EXISTS ${FIREBASE_CPP_SDK_DIR})
message(FATAL_ERROR "The Firebase C++ SDK directory does not exist: ${FIREBASE_CPP_SDK_DIR}. See the readme.md for more information")
endif()
# Windows runtime mode, either MD or MT depending on whether you are using
# /MD or /MT. For more information see:
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
set(MSVC_RUNTIME_MODE MD)
project(firebase_testapp)
# Sample source files.
set(FIREBASE_SAMPLE_COMMON_SRCS
src/main.h
src/common_main.cc
)
# The include directory for the testapp.
include_directories(src)
# Sample uses some features that require C++ 11, such as lambdas.
set (CMAKE_CXX_STANDARD 11)
if(ANDROID)
# Build an Android application.
# Source files used for the Android build.
set(FIREBASE_SAMPLE_ANDROID_SRCS
src/android/android_main.cc
)
# Build native_app_glue as a static lib
add_library(native_app_glue STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
# Export ANativeActivity_onCreate(),
# Refer to: https://github.com/android-ndk/ndk/issues/381.
# This also does a workaround that prevents numerous errors that occur when
# building using Android Studio. The errors look like:
# libfirebase_auth.a(auth.o): relocation R_386_GOTOFF against preemptible
# symbol <long_mangled_name> cannot be used when making a shared object.
# Taken from:
# https://github.com/opencv/opencv/issues/10229#issuecomment-359202825
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate \
-Wl,--exclude-libs,libfirebase_firestore.a \
-Wl,--exclude-libs,libfirebase_auth.a \
-Wl,--exclude-libs,libfirebase_app.a"
)
# Define the target as a shared library, as that is what gradle expects.
set(target_name "android_main")
add_library(${target_name} SHARED
${FIREBASE_SAMPLE_ANDROID_SRCS}
${FIREBASE_SAMPLE_COMMON_SRCS}
)
target_link_libraries(${target_name}
log android atomic native_app_glue
)
target_include_directories(${target_name} PRIVATE
${ANDROID_NDK}/sources/android/native_app_glue)
set(ADDITIONAL_LIBS)
else()
# Build a desktop application.
# Windows runtime mode, either MD or MT depending on whether you are using
# /MD or /MT. For more information see:
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
set(MSVC_RUNTIME_MODE MD)
# Platform abstraction layer for the desktop sample.
set(FIREBASE_SAMPLE_DESKTOP_SRCS
src/desktop/desktop_main.cc
)
set(target_name "desktop_testapp")
add_executable(${target_name}
${FIREBASE_SAMPLE_DESKTOP_SRCS}
${FIREBASE_SAMPLE_COMMON_SRCS}
)
if(APPLE)
set(ADDITIONAL_LIBS
gssapi_krb5
pthread
"-framework CoreFoundation"
"-framework Foundation"
"-framework GSS"
"-framework Security"
"-framework SystemConfiguration"
)
elseif(MSVC)
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 iphlpapi psapi userenv dbghelp bcrypt)
else()
set(ADDITIONAL_LIBS pthread)
endif()
# If a config file is present, copy it into the binary location so that it's
# possible to create the default Firebase app.
set(FOUND_JSON_FILE FALSE)
foreach(config "google-services-desktop.json" "google-services.json")
if (EXISTS ${config})
add_custom_command(
TARGET ${target_name} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${config} $<TARGET_FILE_DIR:${target_name}>)
set(FOUND_JSON_FILE TRUE)
break()
endif()
endforeach()
if(NOT FOUND_JSON_FILE)
message(WARNING "Failed to find either google-services-desktop.json or google-services.json. See the readme.md for more information.")
endif()
endif()
# Add the Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
# Note that firebase_app needs to be last in the list.
set(firebase_libs firebase_firestore firebase_auth firebase_app)
target_link_libraries(${target_name} "${firebase_libs}" ${ADDITIONAL_LIBS})