CMakeLists.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. protobuf-nanopb-static
  123. firestore_protos_nanopb
  124. grpc++
  125. )
  126. if(HAVE_OPENSSL_RAND_H)
  127. target_link_libraries(
  128. firestore_util PRIVATE
  129. OpenSSL::Crypto
  130. )
  131. endif()
  132. if(APPLE)
  133. target_link_libraries(
  134. firestore_util PUBLIC
  135. "-framework CoreFoundation"
  136. "-framework Foundation"
  137. FirebaseCore
  138. )
  139. endif()
  140. ## firestore_nanopb
  141. # Nanopb-related utilities that not specific to Firestore and are used from
  142. # generated nanopb messages.
  143. firebase_ios_glob(
  144. nanopb_sources
  145. src/nanopb/byte_string.*
  146. src/nanopb/nanopb_util.*
  147. src/nanopb/pretty_printing.*
  148. )
  149. firebase_ios_add_library(firestore_nanopb EXCLUDE_FROM_ALL ${nanopb_sources})
  150. target_link_libraries(
  151. firestore_nanopb PUBLIC
  152. absl_strings
  153. firestore_util
  154. protobuf-nanopb-static
  155. )
  156. ## firestore_core
  157. firebase_ios_glob(
  158. core_sources
  159. include/firebase/firestore/*.h
  160. src/*.cc
  161. src/*.h
  162. src/api/*.cc
  163. src/api/*.h
  164. src/bundle/*.cc
  165. src/bundle/*.h
  166. src/core/*.cc
  167. src/core/*.h
  168. src/credentials/*.cc
  169. src/credentials/*.h
  170. src/immutable/*.cc
  171. src/immutable/*.h
  172. src/index/*.cc
  173. src/index/*.h
  174. src/local/*.cc
  175. src/local/*.h
  176. src/model/*.cc
  177. src/model/*.h
  178. src/model/mutation/*.cc
  179. src/model/mutation/*.h
  180. src/nanopb/*.cc
  181. src/nanopb/*.h
  182. src/objc/*.h
  183. src/remote/*.cc
  184. src/remote/*.h
  185. EXCLUDE ${nanopb_sources}
  186. )
  187. if(APPLE)
  188. firebase_ios_glob(
  189. core_sources APPEND
  190. src/credentials/firebase_app_check_credentials_provider_apple.*
  191. src/credentials/firebase_auth_credentials_provider_apple.*
  192. src/remote/connectivity_monitor_apple.mm
  193. src/remote/firebase_metadata_provider_apple.mm
  194. )
  195. endif()
  196. firebase_ios_add_library(firestore_core ${core_sources})
  197. podspec_version(version ${PROJECT_SOURCE_DIR}/FirebaseFirestore.podspec)
  198. target_compile_definitions(
  199. firestore_core PRIVATE
  200. FIRFirestore_VERSION=${version}
  201. )
  202. target_include_directories(
  203. firestore_core PUBLIC
  204. ${PROJECT_SOURCE_DIR}/Firestore/core/include
  205. )
  206. target_link_libraries(
  207. firestore_core PUBLIC
  208. LevelDB::LevelDB
  209. absl::base
  210. absl::flat_hash_map
  211. absl::memory
  212. absl::meta
  213. absl::optional
  214. absl::strings
  215. firestore_nanopb
  216. firestore_protos_nanopb
  217. firestore_util
  218. grpc++
  219. protobuf-nanopb-static
  220. )
  221. if(APPLE)
  222. target_link_libraries(
  223. firestore_core PUBLIC
  224. "-framework Foundation"
  225. "-framework SystemConfiguration"
  226. FirebaseAuthInterop
  227. FirebaseCore
  228. )
  229. endif()
  230. ## gRPC Certificates
  231. # Source files should be generated in place so that the XCode build can pick
  232. # them up.
  233. set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/remote)
  234. set(
  235. GRPC_ROOT_CERTIFICATE_SOURCES
  236. ${OUTPUT_DIR}/grpc_root_certificates_generated.h # NOLINT(generated)
  237. ${OUTPUT_DIR}/grpc_root_certificates_generated.cc # NOLINT(generated)
  238. )
  239. # `roots.pem` is a file containing root certificates that is distributed
  240. # alongside gRPC and is necessary to establish SSL connections. Embed this file
  241. # into the binary by converting it to a char array.
  242. add_custom_command(
  243. COMMENT "Generating root certificates for embedding"
  244. OUTPUT
  245. ${GRPC_ROOT_CERTIFICATE_SOURCES}
  246. COMMAND
  247. ${MY_PYTHON_EXECUTABLE} ${FIREBASE_SOURCE_DIR}/scripts/binary_to_array.py
  248. --output_header=${OUTPUT_DIR}/grpc_root_certificates_generated.h
  249. --output_source=${OUTPUT_DIR}/grpc_root_certificates_generated.cc
  250. --cpp_namespace=firebase::firestore::remote
  251. --array=grpc_root_certificates_generated_data
  252. --array_size=grpc_root_certificates_generated_size
  253. ${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/etc/roots.pem
  254. VERBATIM
  255. DEPENDS
  256. grpc
  257. ${FIREBASE_SOURCE_DIR}/scripts/binary_to_array.py
  258. ${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/etc/roots.pem
  259. )
  260. # gRPC certificates have to be regenerated manually on each new gRPC release
  261. # (which typically has updated certificates).
  262. add_custom_target(
  263. firestore_gen_grpc_certs
  264. DEPENDS ${GRPC_ROOT_CERTIFICATE_SOURCES}
  265. )
  266. add_subdirectory(test/unit/testutil)
  267. add_subdirectory(test/unit)
  268. add_subdirectory(test/unit/api)
  269. add_subdirectory(test/unit/bundle)
  270. add_subdirectory(test/unit/credentials)
  271. add_subdirectory(test/unit/core)
  272. add_subdirectory(test/unit/immutable)
  273. add_subdirectory(test/unit/local)
  274. add_subdirectory(test/unit/model)
  275. add_subdirectory(test/unit/objc)
  276. add_subdirectory(test/unit/nanopb)
  277. add_subdirectory(test/unit/remote)
  278. add_subdirectory(test/unit/util)