forked from compnerd/swift-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
287 lines (272 loc) · 10.3 KB
/
CMakeLists.txt
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# SPDX-License-Identifier: BSD-3-Clause
cmake_minimum_required(VERSION 3.25)
project(swift-firebase
LANGUAGES Swift)
if(ANDROID)
enable_language(C)
include(FindJava)
include(FindJNI)
include(UseJava)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
include(FetchContent)
option(SWIFT_FIREBASE_BUILD_EXAMPLES "Build example UI" TRUE)
# ${TOOLCHAIN_ROOT}/usr/include allows us to access swift C++ interop headers.
cmake_path(GET CMAKE_Swift_COMPILER PARENT_PATH _SWIFT_INCLUDE_DIR)
cmake_path(GET _SWIFT_INCLUDE_DIR PARENT_PATH _SWIFT_INCLUDE_DIR)
include_directories(SYSTEM ${_SWIFT_INCLUDE_DIR}/include)
add_library(firebase INTERFACE)
target_compile_options(firebase INTERFACE
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -DSR69711 -Xcc -DSR74578>"
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -DINTERNAL_EXPERIMENTAL>")
target_include_directories(firebase INTERFACE
Sources/firebase/include
third_party/firebase-development/usr/include)
if(ANDROID)
target_link_directories(firebase INTERFACE
third_party/firebase-development/usr/libs/android/${CMAKE_ANDROID_ARCH_ABI})
# Add the compiler resource directory as a library search path explicitly as
# we do not use `clang` from the NDK but do require `libunwind.a` which is not
# in the sysroot (platform SDK) but rather placed into the resource directory
# on the Android platform.
if(CMAKE_ANDROID_ARCH STREQUAL arm64)
target_link_directories(firebase INTERFACE
$ENV{ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/windows-x86_64/lib/clang/17/lib/linux/aarch64)
elseif(CMAKE_ANDROID_ARCH STREQUAL arm)
target_link_directories(firebase INTERFACE
$ENV{ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/windows-x86_64/lib/clang/17/lib/linux/arm)
elseif(CMAKE_ANDROID_ARCH STREQUAL x86)
target_link_directories(firebase INTERFACE
$ENV{ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/windows-x86_64/lib/clang/17/lib/linux/i386)
elseif(CMAKE_ANDROID_ARCH STREQUAL x86_64)
target_link_directories(firebase INTERFACE
$ENV{ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/windows-x86_64/lib/clang/17/lib/linux/x86_64)
else()
message(SEND_ERROR "unsupported architecture for Android")
endif()
elseif(WIN32)
target_link_directories(firebase INTERFACE
third_party/firebase-development/usr/libs/windows
third_party/firebase-development/usr/libs/windows/deps/app
third_party/firebase-development/usr/libs/windows/deps/app/external)
else()
message(FATAL_ERROR "unsupported firebase-cpp-sdk platform")
endif()
if(ANDROID)
add_subdirectory(Sources/FirebaseAndroid)
endif()
add_library(FirebaseCore SHARED
Sources/FirebaseCore/FirebaseApp+Swift.swift
Sources/FirebaseCore/FirebaseConfiguration.swift
Sources/FirebaseCore/FirebaseLogging+Swift.swift
Sources/FirebaseCore/FirebaseOptions+Swift.swift
Sources/FirebaseCore/FutureProtocol.swift
Sources/FirebaseCore/Variant+Swift.swift)
target_compile_options(FirebaseCore PRIVATE
-cxx-interoperability-mode=default)
target_link_libraries(FirebaseCore PUBLIC
firebase)
target_link_libraries(FirebaseCore PRIVATE
firebase_app
flatbuffers
$<$<PLATFORM_ID:Android>:log>
$<$<PLATFORM_ID:Windows>:libcurl>
$<$<PLATFORM_ID:Windows>:zlibstatic>)
if(ANDROID)
target_link_libraries(FirebaseCore PUBLIC
FirebaseAndroidJNI)
endif()
add_library(FirebaseAuth SHARED
Sources/FirebaseAuth/AuthStateDidChangeListenerHandle.swift
Sources/FirebaseAuth/FIRActionCodeOperation.swift
Sources/FirebaseAuth/FIRAuthTokenResult.swift
Sources/FirebaseAuth/FirebaseAuth+Swift.swift
Sources/FirebaseAuth/FirebaseAuthError.swift
Sources/FirebaseAuth/FirebaseAuthResult+Swift.swift
Sources/FirebaseAuth/FirebaseEmailAuthProvider.swift
Sources/FirebaseAuth/FirebaseUser+Swift.swift)
target_compile_options(FirebaseAuth PRIVATE
-cxx-interoperability-mode=default)
target_link_libraries(FirebaseAuth PUBLIC
firebase
FirebaseCore)
target_link_libraries(FirebaseAuth PRIVATE
flatbuffers
$<$<PLATFORM_ID:Windows>:crypto>
$<$<PLATFORM_ID:Windows>:firebase_rest_lib>
$<$<PLATFORM_ID:Windows>:libcurl>
$<$<PLATFORM_ID:Windows>:ssl>
$<$<PLATFORM_ID:Windows>:zlibstatic>)
add_library(FirebaseFirestore SHARED
Sources/FirebaseFirestore/Vendor/Codable/CodableErrors.swift
Sources/FirebaseFirestore/Vendor/Codable/CodablePassThroughTypes.swift
Sources/FirebaseFirestore/Vendor/Codable/DocumentID.swift
Sources/FirebaseFirestore/Vendor/FirebaseDataEncoder/FirebaseDataEncoder.swift
Sources/FirebaseFirestore/Vendor/FirebaseDataEncoder/FirebaseRemoteConfigValueDecoding.swift
Sources/FirebaseFirestore/CollectionReference+Swift.swift
Sources/FirebaseFirestore/DocumentChange+Swift.swift
Sources/FirebaseFirestore/DocumentReference+Swift.swift
Sources/FirebaseFirestore/DocumentSnapshot+Swift.swift
Sources/FirebaseFirestore/FieldValue+Swift.swift
Sources/FirebaseFirestore/Firestore+Swift.swift
Sources/FirebaseFirestore/FirestoreDataConverter.swift
Sources/FirebaseFirestore/FirestoreErrorCode.swift
Sources/FirebaseFirestore/FirestoreSource+Swift.swift
Sources/FirebaseFirestore/ListenerRegistration.swift
Sources/FirebaseFirestore/Query+Swift.swift
Sources/FirebaseFirestore/QueryDocumentSnapshot.swift
Sources/FirebaseFirestore/QuerySnapshot+Swift.swift
Sources/FirebaseFirestore/Settings+Swift.swift
Sources/FirebaseFirestore/SnapshotMetadata+Swift.swift
Sources/FirebaseFirestore/Timestamp+Swift.swift
Sources/FirebaseFirestore/Transaction+Swift.swift
Sources/FirebaseFirestore/TransactionOptions+Swift.swift
Sources/FirebaseFirestore/WriteBatch+Swift.swift)
target_compile_options(FirebaseFirestore PRIVATE
-cxx-interoperability-mode=default)
target_link_libraries(FirebaseFirestore PUBLIC
FirebaseCore
$<$<PLATFORM_ID:Windows>:crypto>
$<$<PLATFORM_ID:Windows>:libcurl>
$<$<PLATFORM_ID:Windows>:ssl>
$<$<PLATFORM_ID:Windows>:zlibstatic>)
if(WIN32)
target_link_libraries(FirebaseFirestore PUBLIC
absl_bad_optional_access
absl_bad_variant_access
absl_base
absl_city
absl_cord
absl_cord_internal
absl_cordz_functions
absl_cordz_handle
absl_cordz_info
absl_crc_cord_state
absl_crc_cpu_detect
absl_crc_internal
absl_crc32c
absl_flags_commandlineflag_internal
absl_flags_commandlineflag
absl_flags_config
absl_flags_internal
absl_flags_marshalling
absl_flags_private_handle_accessor
absl_flags_program_name
absl_flags_reflection
absl_graphcycles_internal
absl_hash
absl_int128
absl_kernel_timeout_internal
absl_low_level_hash
absl_malloc_internal
absl_random_internal_platform
absl_random_internal_pool_urbg
absl_random_internal_randen
absl_random_internal_randen_hwaes
absl_random_internal_randen_hwaes_impl
absl_random_internal_randen_slow
absl_random_internal_seed_material
absl_random_seed_gen_exception
absl_raw_hash_set
absl_raw_logging_internal
absl_spinlock_wait
absl_stacktrace
absl_status
absl_statusor
absl_str_format_internal
absl_strerror
absl_string_view
absl_strings
absl_strings_internal
absl_symbolize
absl_synchronization
absl_throw_delegate
absl_time
absl_time_zone
address_sorting
cares
firebase
firebase_rest_lib
firestore_core
firestore_nanopb
firestore_protos_nanopb
firestore_util
flatbuffers
gpr
grpc
grpc++
leveldb
protobuf-nanopb
re2
snappy
upb_base_lib
upb_json_lib
upb_mem_lib
upb_message_lib
upb_textformat_lib
utf8_range_lib
utf8_validity)
endif()
add_library(FirebaseFunctions SHARED
Sources/FirebaseFunctions/FunctionsErrorCode.swift
Sources/FirebaseFunctions/Functions+Swift.swift
Sources/FirebaseFunctions/HTTPSCallable+Swift.swift
Sources/FirebaseFunctions/HTTPSCallableResult+Swift.swift)
target_compile_options(FirebaseFunctions PRIVATE
-cxx-interoperability-mode=default)
target_link_libraries(FirebaseFunctions PUBLIC
firebase
firebase_functions
FirebaseCore)
target_link_libraries(FirebaseFunctions PRIVATE
flatbuffers
$<$<PLATFORM_ID:Windows>:crypto>
$<$<PLATFORM_ID:Windows>:firebase_rest_lib>
$<$<PLATFORM_ID:Windows>:libcurl>
$<$<PLATFORM_ID:Windows>:ssl>
$<$<PLATFORM_ID:Windows>:zlibstatic>)
add_library(FirebaseStorage SHARED
Sources/FirebaseStorage/StorageErrorCode.swift
Sources/FirebaseStorage/Storage+Swift.swift
Sources/FirebaseStorage/StorageMetadata+Swift.swift
Sources/FirebaseStorage/StorageReference+Swift.swift)
target_compile_options(FirebaseStorage PRIVATE
-cxx-interoperability-mode=default)
target_link_libraries(FirebaseStorage PUBLIC
firebase
firebase_storage
FirebaseCore)
target_link_libraries(FirebaseStorage PRIVATE
flatbuffers
$<$<PLATFORM_ID:Windows>:crypto>
$<$<PLATFORM_ID:Windows>:firebase_rest_lib>
$<$<PLATFORM_ID:Windows>:libcurl>
$<$<PLATFORM_ID:Windows>:ssl>
$<$<PLATFORM_ID:Windows>:zlibstatic>)
if(SWIFT_FIREBASE_BUILD_EXAMPLES)
FetchContent_Declare(SwiftWin32
GIT_REPOSITORY https://github.com/compnerd/swift-win32
GIT_TAG 07e91e67e86f173743329c6753d9e66ac4727830) # Pinned for reproducibility and before Package@swift-#.#.swift symlinks
FetchContent_MakeAvailable(SwiftWin32)
add_executable(FireBaseUI
Examples/FireBaseUI/FireBaseUI.swift
Examples/FireBaseUI/FireBaseUIViewController.swift
Examples/FireBaseUI/FirestoreTestingViewController.swift
Examples/FireBaseUI/SceneDelegate.swift
Examples/FireBaseUI/SwiftWin32+Extensions.swift)
target_compile_options(FireBaseUI PRIVATE
-parse-as-library
-cxx-interoperability-mode=default)
target_link_libraries(FireBaseUI PRIVATE
FirebaseCore
FirebaseAuth
FirebaseFirestore
SwiftWin32)
add_custom_command(TARGET FireBaseUI POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Examples/FireBaseUI/Resources $<TARGET_FILE_DIR:FireBaseUI>/Resources
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Examples/FireBaseUI/Info.plist $<TARGET_FILE_DIR:FireBaseUI>/Info.plist
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Examples/FireBaseUI/$<TARGET_FILE_NAME:FireBaseUI>.manifest $<TARGET_FILE_DIR:FireBaseUI>/$<TARGET_FILE_NAME:FireBaseUI>.manifest)
endif()