CMakeLists.txt 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. # Superbuild for Firebase
  15. cmake_minimum_required(VERSION 3.5.1)
  16. # Disallow mixing keyword and non-keyword forms of target_link_libraries
  17. if(POLICY CMP0023)
  18. cmake_policy(SET CMP0023 NEW)
  19. endif()
  20. # Report AppleClang separately from Clang. Their version numbers are different.
  21. # https://cmake.org/cmake/help/v3.0/policy/CMP0025.html
  22. if(POLICY CMP0025)
  23. cmake_policy(SET CMP0025 NEW)
  24. endif()
  25. # Enable rpath by default
  26. if(POLICY CMP0042)
  27. cmake_policy(SET CMP0042 NEW)
  28. endif()
  29. # Generate Ninja phony rules for unknown dependencies in the build tree and
  30. # don't complain about doing so. Our dependencies aren't good about declaring
  31. # BYPRODUCTS and we mix them all into a single superbuild so we can't enable
  32. # this policy until all dependencies are capable of doing so.
  33. if(POLICY CMP0058)
  34. cmake_policy(SET CMP0058 OLD)
  35. endif()
  36. # Enable the ccache compilation cache, if available.
  37. find_program(CCACHE_PROGRAM ccache)
  38. if(CCACHE_PROGRAM)
  39. message(STATUS "Found ccache: ${CCACHE_PROGRAM}")
  40. set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
  41. set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
  42. endif()
  43. # Defer enabling any languages.
  44. project(firebase NONE)
  45. if(WIN32)
  46. # On Windows, prefer cl over gcc if both are available. By default most of
  47. # the CMake generators prefer gcc, even on Windows.
  48. set(CMAKE_GENERATOR_CC cl)
  49. endif()
  50. enable_language(C)
  51. enable_language(CXX)
  52. option(
  53. FIREBASE_IOS_BUILD_BENCHMARKS
  54. "Enable building of C++ and Objective-C benchmarks for this project"
  55. OFF
  56. )
  57. option(
  58. FIREBASE_IOS_BUILD_TESTS
  59. "Enable building of C++ and Objective-C tests for this project"
  60. ON
  61. )
  62. list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)
  63. include(compiler_setup)
  64. include(sanitizer_options)
  65. include(fuzzing_options)
  66. # rules depend on properties and options set above
  67. include(external_rules)
  68. include(podspec_rules)
  69. include(cc_rules)
  70. set(FIREBASE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
  71. set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
  72. set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR}/opt)
  73. set(
  74. FIREBASE_DOWNLOAD_DIR
  75. ${PROJECT_BINARY_DIR}/downloads
  76. CACHE PATH "Where to store downloaded files"
  77. )
  78. set(
  79. FIREBASE_EXTERNAL_SOURCE_DIR
  80. ${FIREBASE_BINARY_DIR}/external/src
  81. CACHE PATH "Root directory of source code of the external dependencies"
  82. )
  83. download_external_sources()
  84. # Googletest
  85. if(FIREBASE_IOS_BUILD_TESTS)
  86. set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
  87. add_external_subdirectory(googletest)
  88. firebase_ios_add_alias(GTest::GTest gtest)
  89. firebase_ios_add_alias(GTest::Main gtest_main)
  90. firebase_ios_add_alias(GMock::GMock gmock)
  91. endif()
  92. # Benchmark
  93. if(FIREBASE_IOS_BUILD_BENCHMARKS)
  94. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
  95. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
  96. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
  97. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")
  98. if(IOS)
  99. # benchmark uses CMake's try_run, which doesn't work out of the box when
  100. # compiling for iOS.
  101. set(HAVE_STD_REGEX ON CACHE BOOL "iOS has std::regex")
  102. set(HAVE_POSIX_REGEX ON CACHE BOOL "iOS has POSIX regex.h")
  103. set(HAVE_STEADY_CLOCK ON CACHE BOOL "iOS has std::chrono::steady_clock")
  104. endif()
  105. add_external_subdirectory(benchmark)
  106. endif()
  107. # Abseil-cpp
  108. # Force disable Abseil's tests, which don't compile under VS2017.
  109. set(old_build_testing ${BUILD_TESTING})
  110. set(ABSL_RUN_TESTS OFF CACHE BOOL "Disable Abseil tests" FORCE)
  111. add_external_subdirectory(abseil-cpp)
  112. if(CXX_CLANG)
  113. target_compile_options(
  114. absl_time_zone
  115. PRIVATE
  116. -Wno-unused-template
  117. -Wno-shadow
  118. -Wno-tautological-type-limit-compare
  119. )
  120. endif()
  121. if(MSVC)
  122. # Disable warnings about unsafe use of std::copy
  123. target_compile_definitions(
  124. absl_strings
  125. PUBLIC
  126. _SCL_SECURE_NO_WARNINGS=1
  127. )
  128. endif()
  129. # gRPC
  130. # libcurl and c-ares conflict in their usage of this variable. Prevent
  131. # libcurl's setting of this variable from affecting the c-ares build that's
  132. # pulled in indirectly via gRPC.
  133. unset(RANDOM_FILE CACHE)
  134. set(CARES_INSTALL OFF CACHE BOOL "Disabled")
  135. set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disabled")
  136. if(IOS OR ANDROID)
  137. # C-Ares includes a number of example binaries (e.g. `ahost`) that fail to
  138. # build when compiling for non-host targets.
  139. set(gRPC_CARES_PROVIDER none CACHE STRING "Don't use C-Ares")
  140. # protoc needs to be built for the host to be able to invoke it during the
  141. # build.
  142. set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Disabled")
  143. endif()
  144. if(NOT ANDROID AND NOT IOS)
  145. find_package(OpenSSL QUIET)
  146. if(OPENSSL_FOUND)
  147. set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
  148. endif()
  149. endif()
  150. find_package(ZLIB QUIET)
  151. if(ZLIB_FOUND)
  152. set(gRPC_ZLIB_PROVIDER package CACHE STRING "Use external ZLIB")
  153. endif()
  154. set(gRPC_BUILD_TESTS OFF CACHE BOOL "Disable gRPC tests")
  155. add_external_subdirectory(grpc)
  156. # Fix up targets included by gRPC's build
  157. if(OPENSSL_FOUND)
  158. # gRPC's CMakeLists.txt does not account for finding OpenSSL in a directory
  159. # that's not in the default search path.
  160. target_include_directories(grpc PRIVATE ${OPENSSL_INCLUDE_DIR})
  161. if(CXX_CLANG OR CXX_GNU)
  162. if((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR
  163. (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
  164. # gRPC uses some features deprecated in OpenSSL 1.1.0
  165. target_compile_options(
  166. grpc
  167. PRIVATE -Wno-deprecated-declarations
  168. )
  169. endif()
  170. endif()
  171. else()
  172. # Not using outboard OpenSSL so set up BoringSSL to look like it.
  173. firebase_ios_add_alias(OpenSSL::Crypto crypto)
  174. target_include_directories(
  175. crypto
  176. INTERFACE
  177. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  178. )
  179. firebase_ios_add_alias(OpenSSL::SSL ssl)
  180. target_include_directories(
  181. ssl
  182. INTERFACE
  183. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  184. )
  185. endif()
  186. if(CXX_CLANG OR CXX_GNU)
  187. target_compile_options(
  188. libprotobuf
  189. PUBLIC -Wno-unused-parameter
  190. )
  191. endif()
  192. if(CXX_CLANG)
  193. target_compile_options(
  194. libprotobuf
  195. PRIVATE
  196. -Wno-inconsistent-missing-override
  197. -Wno-invalid-offsetof
  198. )
  199. endif()
  200. if(NOT ZLIB_FOUND)
  201. target_include_directories(
  202. zlibstatic
  203. INTERFACE $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/zlib>
  204. )
  205. endif()
  206. # LevelDB
  207. set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "Firestore disabled")
  208. set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Firestore disabled")
  209. set(LEVELDB_INSTALL OFF CACHE BOOL "Firestore disabled")
  210. add_external_subdirectory(leveldb)
  211. firebase_ios_add_alias(LevelDB::LevelDB leveldb)
  212. # nanopb
  213. set(nanopb_BUILD_GENERATOR ON CACHE BOOL "Enable the nanopb generator")
  214. set(nanopb_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries")
  215. add_external_subdirectory(nanopb)
  216. target_compile_definitions(
  217. protobuf-nanopb-static
  218. PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
  219. )
  220. # Enable #include <nanopb/pb.h>
  221. target_include_directories(
  222. protobuf-nanopb-static
  223. INTERFACE
  224. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/nanopb>
  225. )
  226. # XCTest
  227. if(APPLE)
  228. find_package(XCTest)
  229. endif()
  230. if(FIREBASE_IOS_BUILD_TESTS)
  231. enable_testing()
  232. endif()
  233. add_subdirectory(FirebaseCore)
  234. add_subdirectory(Firestore)
  235. add_subdirectory(GoogleUtilities)
  236. add_subdirectory(Interop/Auth)
  237. add_subdirectory(Interop/CoreDiagnostics)