-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
214 lines (183 loc) · 6.88 KB
/
Copy pathCMakeLists.txt
File metadata and controls
214 lines (183 loc) · 6.88 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright 2019 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# CMake file for the firebase_analytics library
# Analytics generates header files for default events, parameters, and
# properties based on the iOS SDK, that are used across all platforms.
set(analytics_generated_headers_dir
"${FIREBASE_GEN_FILE_DIR}/analytics/src/include/firebase/analytics")
set(event_names_header "${analytics_generated_headers_dir}/event_names.h")
set(parameter_names_header
"${analytics_generated_headers_dir}/parameter_names.h")
set(user_property_names_header
"${analytics_generated_headers_dir}/user_property_names.h")
file(MAKE_DIRECTORY ${analytics_generated_headers_dir})
# Generate the header file by invoking the generate_constants python script.
function(generate_analytics_header OBJC_FILE CPP_FILE)
add_custom_command(
OUTPUT ${CPP_FILE}
COMMAND ${FIREBASE_PYTHON_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/generate_constants.py"
"--objc_header=${OBJC_FILE}"
"--cpp_header=${CPP_FILE}"
DEPENDS ${OBJC_FILE}
COMMENT "Generating ${CPP_FILE}"
)
endfunction()
# Call the above function for all of the header files to generate.
generate_analytics_header(
"${CMAKE_CURRENT_LIST_DIR}/ios_headers/FIREventNames.h"
"${event_names_header}"
)
generate_analytics_header(
"${CMAKE_CURRENT_LIST_DIR}/ios_headers/FIRParameterNames.h"
"${parameter_names_header}"
)
generate_analytics_header(
"${CMAKE_CURRENT_LIST_DIR}/ios_headers/FIRUserPropertyNames.h"
"${user_property_names_header}"
)
add_custom_target(FIREBASE_ANALYTICS_GENERATED_HEADERS
DEPENDS
"${user_property_names_header}"
"${parameter_names_header}"
"${event_names_header}"
)
# Common source files used by all platforms
set(common_SRCS
src/analytics_common.cc
# List the generated files, so that they are generated for the build.
${event_names_header}
${parameter_names_header}
${user_property_names_header})
# Source files used by the Android implementation.
set(android_SRCS
src/analytics_android.cc)
# Source files used by the iOS implementation.
set(ios_SRCS
src/analytics_ios.mm
src/ios/swift/AppleTransactionVerifier.swift)
# Source files used by the desktop / stub implementation.
set(desktop_SRCS
src/analytics_desktop.cc
src/analytics_desktop_dynamic.c)
if(WIN32)
# Add Windows-specific sources for desktop builds.
list(APPEND desktop_SRCS src/analytics_windows.cc)
endif()
if(ANDROID)
set(analytics_platform_SRCS
"${android_SRCS}")
elseif(IOS)
if(CMAKE_GENERATOR STREQUAL "Unix Makefiles")
message(FATAL_ERROR "Swift is not supported by the 'Unix Makefiles' generator on iOS. Please use the Xcode generator (-G Xcode) or Ninja (-G Ninja).")
endif()
set(analytics_platform_SRCS
"${ios_SRCS}")
else()
set(analytics_platform_SRCS
"${desktop_SRCS}")
endif()
add_library(firebase_analytics STATIC
${common_SRCS}
${analytics_platform_SRCS})
add_dependencies(firebase_analytics FIREBASE_ANALYTICS_GENERATED_HEADERS)
set_property(TARGET firebase_analytics PROPERTY FOLDER "Firebase Cpp")
# Set up the dependency on Firebase App.
target_link_libraries(firebase_analytics
PUBLIC firebase_app)
if(WIN32)
target_link_libraries(firebase_analytics PRIVATE Crypt32.lib)
endif()
# Public headers all refer to each other relative to the src/include directory,
# while private headers are relative to the entire C++ SDK directory.
target_include_directories(firebase_analytics
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/include
${FIREBASE_GEN_FILE_DIR}/analytics/src/include
PRIVATE
${FIREBASE_CPP_SDK_ROOT_DIR}
${FIREBASE_GEN_FILE_DIR}
)
target_compile_definitions(firebase_analytics
PRIVATE
-DINTERNAL_EXPERIMENTAL=1
)
if(ANDROID)
firebase_cpp_proguard_file(analytics)
elseif(IOS)
# Enable Automatic Reference Counting (ARC) and Bitcode specifically for Objective-C++ files.
# Note: -fembed-bitcode is placed here for src/analytics_ios.mm so that it is not passed
# to the Swift compiler, which does not support the flag.
set_source_files_properties(src/analytics_ios.mm PROPERTIES COMPILE_OPTIONS "-fobjc-arc;-fembed-bitcode")
if(CMAKE_GENERATOR STREQUAL "Xcode")
target_include_directories(firebase_analytics PRIVATE "$(DERIVED_FILE_DIR)")
target_compile_options(firebase_analytics PRIVATE
"-I$(OBJECT_FILE_DIR_normal)/$(CURRENT_ARCH)"
)
else()
target_include_directories(firebase_analytics PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
endif()
# Swift needs to find the FirebaseAnalytics module from CocoaPods
set(pods_dir "${FIREBASE_POD_DIR}/Pods")
# Point to the base directories containing the .xcframework folders.
# Xcode natively handles XCFrameworks and will pick the right slice automatically.
# Determine the xcframework architecture slice based on the target platform
# and if it is running on simulator or device.
string(TOLOWER "${CMAKE_OSX_SYSROOT}" sysroot_lower)
if(CMAKE_SYSTEM_NAME STREQUAL "tvOS")
if(sysroot_lower MATCHES "simulator")
set(analytics_slice "tvos-arm64_x86_64-simulator")
else()
set(analytics_slice "tvos-arm64")
endif()
else()
if(sysroot_lower MATCHES "simulator")
set(analytics_slice "ios-arm64_x86_64-simulator")
else()
set(analytics_slice "ios-arm64")
endif()
endif()
set(analytics_framework_dir "${pods_dir}/FirebaseAnalytics/Frameworks/FirebaseAnalytics.xcframework/${analytics_slice}")
set(measurement_framework_dir "${pods_dir}/GoogleAppMeasurement/Frameworks/GoogleAppMeasurement.xcframework/${analytics_slice}")
target_compile_options(firebase_analytics
PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-F${analytics_framework_dir}>
$<$<COMPILE_LANGUAGE:Swift>:-F${measurement_framework_dir}>
)
target_link_options(firebase_analytics
PUBLIC
"-F${analytics_framework_dir}"
"-F${measurement_framework_dir}"
)
# Prevent Xcode from trying to build or evaluate headers for unused architectures
set_target_properties(firebase_analytics PROPERTIES
XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES"
)
setup_pod_headers(
firebase_analytics
POD_NAMES
FirebaseCore
FirebaseAnalytics
)
if (FIREBASE_XCODE_TARGET_FORMAT STREQUAL "frameworks")
set_target_properties(firebase_analytics PROPERTIES
FRAMEWORK TRUE
)
endif()
endif()
if(FIREBASE_CPP_BUILD_TESTS)
# Add the tests subdirectory
add_subdirectory(tests)
endif()
cpp_pack_library(firebase_analytics "")
cpp_pack_public_headers()