CMakeLists.txt 7.6 KB

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