CMakeLists.txt 7.0 KB

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