CMakeLists.txt 6.7 KB

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