CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. # Copyright 2017 Google LLC
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. include(CheckSymbolExists)
  15. include(CheckIncludeFiles)
  16. include(python_setup)
  17. FirebaseSetupPythonInterpreter(
  18. OUTVAR MY_PYTHON_EXECUTABLE
  19. KEY FirestoreCore
  20. )
  21. ## firestore_util
  22. # The set of sources to use for firestore_util are complex.
  23. file(
  24. GLOB util_sources
  25. src/util/*.cc
  26. src/util/*.h
  27. )
  28. if(APPLE)
  29. firebase_ios_glob(
  30. util_sources APPEND src/util/*.mm
  31. EXCLUDE src/util/*_win.cc
  32. )
  33. elseif(WIN32)
  34. firebase_ios_glob(
  35. util_sources EXCLUDE
  36. src/util/*_apple.*
  37. src/util/*_posix.*
  38. )
  39. else()
  40. # Linux and other UNIX systems.
  41. firebase_ios_glob(
  42. util_sources EXCLUDE
  43. src/util/*_apple.cc
  44. src/util/*_win.cc
  45. )
  46. endif()
  47. # Choose Executor implementation
  48. # Comment out this check on macOS to build with ExecutorStd instead of
  49. # ExecutorLibdispatch.
  50. check_symbol_exists(dispatch_async_f dispatch/dispatch.h HAVE_LIBDISPATCH)
  51. firebase_ios_glob(
  52. util_sources EXCLUDE src/util/executor_*
  53. )
  54. if(HAVE_LIBDISPATCH)
  55. firebase_ios_glob(
  56. util_sources APPEND src/util/executor_libdispatch.*
  57. )
  58. else()
  59. firebase_ios_glob(
  60. util_sources APPEND src/util/executor_std.*
  61. )
  62. endif()
  63. # Choose Logger implementation
  64. firebase_ios_glob(
  65. util_sources EXCLUDE src/util/log_*
  66. )
  67. # TODO(wilhuff): Can this be if(APPLE)?
  68. if(IOS)
  69. firebase_ios_glob(
  70. util_sources APPEND src/util/log_apple.mm
  71. )
  72. else()
  73. firebase_ios_glob(
  74. util_sources APPEND src/util/log_stdio.cc
  75. )
  76. endif()
  77. # Choose SecureRandom implementation
  78. check_symbol_exists(arc4random stdlib.h HAVE_ARC4RANDOM)
  79. if(TARGET OpenSSL::Crypto)
  80. get_target_property(
  81. CMAKE_REQUIRED_INCLUDES OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES
  82. )
  83. check_include_files(openssl/rand.h HAVE_OPENSSL_RAND_H)
  84. endif()
  85. firebase_ios_glob(
  86. util_sources EXCLUDE src/util/secure_random_*.cc
  87. )
  88. if(HAVE_ARC4RANDOM)
  89. firebase_ios_glob(
  90. util_sources APPEND
  91. src/util/secure_random_arc4random.cc
  92. )
  93. elseif(HAVE_OPENSSL_RAND_H)
  94. firebase_ios_glob(
  95. util_sources APPEND
  96. src/util/secure_random_openssl.cc
  97. )
  98. else()
  99. message(
  100. FATAL_ERROR
  101. "Don't know how to get high quality random numbers on this platform."
  102. )
  103. endif()
  104. configure_file(
  105. src/util/config_detected.h.in
  106. src/util/config_detected.h # NOLINT(generated)
  107. )
  108. firebase_ios_add_library(firestore_util EXCLUDE_FROM_ALL ${util_sources})
  109. target_compile_definitions(
  110. firestore_util PUBLIC
  111. FIRESTORE_HAVE_CONFIG_DETECTED_H
  112. )
  113. target_link_libraries(
  114. firestore_util PUBLIC
  115. absl::base
  116. absl::flat_hash_map
  117. absl::memory
  118. absl::meta
  119. absl::optional
  120. absl::strings
  121. absl::time
  122. )
  123. if(HAVE_OPENSSL_RAND_H)
  124. target_link_libraries(
  125. firestore_util PRIVATE
  126. OpenSSL::Crypto
  127. )
  128. endif()
  129. if(APPLE)
  130. target_link_libraries(
  131. firestore_util PUBLIC
  132. "-framework CoreFoundation"
  133. "-framework Foundation"
  134. FirebaseCore
  135. )
  136. endif()
  137. ## firestore_nanopb
  138. # Nanopb-related utilities that not specific to Firestore and are used from
  139. # generated nanopb messages.
  140. firebase_ios_glob(
  141. nanopb_sources
  142. src/nanopb/byte_string.*
  143. src/nanopb/nanopb_util.*
  144. src/nanopb/pretty_printing.*
  145. )
  146. firebase_ios_add_library(firestore_nanopb EXCLUDE_FROM_ALL ${nanopb_sources})
  147. target_link_libraries(
  148. firestore_nanopb PUBLIC
  149. absl_strings
  150. firestore_util
  151. protobuf-nanopb-static
  152. )
  153. ## firestore_core
  154. firebase_ios_glob(
  155. core_sources
  156. include/firebase/firestore/*.h
  157. src/*.cc
  158. src/*.h
  159. src/api/*.cc
  160. src/api/*.h
  161. src/bundle/*.cc
  162. src/bundle/*.h
  163. src/core/*.cc
  164. src/core/*.h
  165. src/credentials/*.cc
  166. src/credentials/*.h
  167. src/immutable/*.cc
  168. src/immutable/*.h
  169. src/index/*.cc
  170. src/index/*.h
  171. src/local/*.cc
  172. src/local/*.h
  173. src/model/*.cc
  174. src/model/*.h
  175. src/model/mutation/*.cc
  176. src/model/mutation/*.h
  177. src/nanopb/*.cc
  178. src/nanopb/*.h
  179. src/objc/*.h
  180. src/remote/*.cc
  181. src/remote/*.h
  182. EXCLUDE ${nanopb_sources}
  183. )
  184. if(APPLE)
  185. firebase_ios_glob(
  186. core_sources APPEND
  187. src/credentials/firebase_app_check_credentials_provider_apple.*
  188. src/credentials/firebase_auth_credentials_provider_apple.*
  189. src/remote/connectivity_monitor_apple.mm
  190. src/remote/firebase_metadata_provider_apple.mm
  191. )
  192. endif()
  193. firebase_ios_add_library(firestore_core ${core_sources})
  194. podspec_version(version ${PROJECT_SOURCE_DIR}/FirebaseFirestore.podspec)
  195. target_compile_definitions(
  196. firestore_core PRIVATE
  197. FIRFirestore_VERSION=${version}
  198. )
  199. target_include_directories(
  200. firestore_core PUBLIC
  201. ${PROJECT_SOURCE_DIR}/Firestore/core/include
  202. )
  203. target_link_libraries(
  204. firestore_core PUBLIC
  205. LevelDB::LevelDB
  206. absl::base
  207. absl::flat_hash_map
  208. absl::memory
  209. absl::meta
  210. absl::optional
  211. absl::strings
  212. firestore_nanopb
  213. firestore_protos_nanopb
  214. firestore_util
  215. grpc++
  216. protobuf-nanopb-static
  217. )
  218. if(APPLE)
  219. target_link_libraries(
  220. firestore_core PUBLIC
  221. "-framework Foundation"
  222. "-framework SystemConfiguration"
  223. FirebaseAuthInterop
  224. FirebaseCore
  225. )
  226. endif()
  227. ## gRPC Certificates
  228. # Source files should be generated in place so that the XCode build can pick
  229. # them up.
  230. set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/remote)
  231. set(
  232. GRPC_ROOT_CERTIFICATE_SOURCES
  233. ${OUTPUT_DIR}/grpc_root_certificates_generated.h # NOLINT(generated)
  234. ${OUTPUT_DIR}/grpc_root_certificates_generated.cc # NOLINT(generated)
  235. )
  236. # `roots.pem` is a file containing root certificates that is distributed
  237. # alongside gRPC and is necessary to establish SSL connections. Embed this file
  238. # into the binary by converting it to a char array.
  239. add_custom_command(
  240. COMMENT "Generating root certificates for embedding"
  241. OUTPUT
  242. ${GRPC_ROOT_CERTIFICATE_SOURCES}
  243. COMMAND
  244. ${MY_PYTHON_EXECUTABLE} ${FIREBASE_SOURCE_DIR}/scripts/binary_to_array.py
  245. --output_header=${OUTPUT_DIR}/grpc_root_certificates_generated.h
  246. --output_source=${OUTPUT_DIR}/grpc_root_certificates_generated.cc
  247. --cpp_namespace=firebase::firestore::remote
  248. --array=grpc_root_certificates_generated_data
  249. --array_size=grpc_root_certificates_generated_size
  250. ${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/etc/roots.pem
  251. VERBATIM
  252. DEPENDS
  253. grpc
  254. ${FIREBASE_SOURCE_DIR}/scripts/binary_to_array.py
  255. ${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/etc/roots.pem
  256. )
  257. # gRPC certificates have to be regenerated manually on each new gRPC release
  258. # (which typically has updated certificates).
  259. add_custom_target(
  260. firestore_gen_grpc_certs
  261. DEPENDS ${GRPC_ROOT_CERTIFICATE_SOURCES}
  262. )
  263. add_subdirectory(test/unit/testutil)
  264. add_subdirectory(test/unit)
  265. add_subdirectory(test/unit/api)
  266. add_subdirectory(test/unit/bundle)
  267. add_subdirectory(test/unit/credentials)
  268. add_subdirectory(test/unit/core)
  269. add_subdirectory(test/unit/immutable)
  270. add_subdirectory(test/unit/local)
  271. add_subdirectory(test/unit/model)
  272. add_subdirectory(test/unit/objc)
  273. add_subdirectory(test/unit/nanopb)
  274. add_subdirectory(test/unit/remote)
  275. add_subdirectory(test/unit/util)