CMakeLists.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. # Copyright 2017 Google
  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 uber build 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_TESTS
  54. "Enable building of C++ and Objective-C tests for this project"
  55. ON
  56. )
  57. list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)
  58. include(compiler_id)
  59. include(archive_options)
  60. include(sanitizer_options)
  61. include(fuzzing_options)
  62. # rules depend on properties and options set above
  63. include(external_rules)
  64. include(podspec_rules)
  65. include(cc_rules)
  66. # If no build type is specified, make it a debug build
  67. if(NOT CMAKE_BUILD_TYPE)
  68. set(CMAKE_BUILD_TYPE Debug)
  69. endif()
  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. set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
  86. add_external_subdirectory(googletest)
  87. add_alias(GTest::GTest gtest)
  88. add_alias(GTest::Main gtest_main)
  89. add_alias(GMock::GMock gmock)
  90. # Benchmark
  91. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
  92. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
  93. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
  94. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")
  95. add_external_subdirectory(benchmark)
  96. # Abseil-cpp
  97. # Force disable Abseil's tests, which don't compile under VS2017.
  98. set(old_build_testing ${BUILD_TESTING})
  99. set(ABSL_RUN_TESTS OFF CACHE BOOL "Disable Abseil tests" FORCE)
  100. add_external_subdirectory(abseil-cpp)
  101. if(CXX_CLANG)
  102. target_compile_options(
  103. absl_time_zone
  104. PRIVATE
  105. -Wno-unused-template
  106. -Wno-shadow
  107. -Wno-tautological-type-limit-compare
  108. )
  109. endif()
  110. if(MSVC)
  111. # Disable warnings about unsafe use of std::copy
  112. target_compile_definitions(
  113. absl_strings
  114. PUBLIC
  115. _SCL_SECURE_NO_WARNINGS=1
  116. )
  117. endif()
  118. # gRPC
  119. # libcurl and c-ares conflict in their usage of this variable. Prevent
  120. # libcurl's setting of this variable from affecting the c-ares build that's
  121. # pulled in indirectly via gRPC.
  122. unset(RANDOM_FILE CACHE)
  123. find_package(OpenSSL QUIET)
  124. if(OPENSSL_FOUND)
  125. set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
  126. endif()
  127. find_package(ZLIB QUIET)
  128. if(ZLIB_FOUND)
  129. set(gRPC_ZLIB_PROVIDER package CACHE STRING "Use external ZLIB")
  130. endif()
  131. set(gRPC_BUILD_TESTS OFF CACHE BOOL "Disable gRPC tests")
  132. add_external_subdirectory(grpc)
  133. # Fix up targets included by gRPC's build
  134. if(OPENSSL_FOUND)
  135. # gRPC's CMakeLists.txt does not account for finding OpenSSL in a directory
  136. # that's not in the default search path.
  137. target_include_directories(grpc PRIVATE ${OPENSSL_INCLUDE_DIR})
  138. if(CXX_CLANG OR CXX_GNU)
  139. if((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR
  140. (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
  141. # gRPC uses some features deprecated in OpenSSL 1.1.0
  142. target_compile_options(
  143. grpc
  144. PRIVATE -Wno-deprecated-declarations
  145. )
  146. endif()
  147. endif()
  148. else()
  149. # Not using outboard OpenSSL so set up BoringSSL to look like it.
  150. add_alias(OpenSSL::Crypto crypto)
  151. target_include_directories(
  152. crypto
  153. INTERFACE
  154. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  155. )
  156. add_alias(OpenSSL::SSL ssl)
  157. target_include_directories(
  158. ssl
  159. INTERFACE
  160. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  161. )
  162. endif()
  163. if(CXX_CLANG OR CXX_GNU)
  164. target_compile_options(
  165. libprotobuf
  166. PUBLIC -Wno-unused-parameter
  167. )
  168. endif()
  169. if(CXX_CLANG)
  170. target_compile_options(
  171. libprotobuf
  172. PRIVATE
  173. -Wno-inconsistent-missing-override
  174. -Wno-invalid-offsetof
  175. )
  176. endif()
  177. if(NOT ZLIB_FOUND)
  178. target_include_directories(
  179. zlibstatic
  180. INTERFACE $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/zlib>
  181. )
  182. endif()
  183. # LevelDB
  184. set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "Firestore disabled")
  185. set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Firestore disabled")
  186. set(LEVELDB_INSTALL OFF CACHE BOOL "Firestore disabled")
  187. add_external_subdirectory(leveldb)
  188. add_alias(LevelDB::LevelDB leveldb)
  189. # nanopb
  190. set(nanopb_BUILD_GENERATOR ON CACHE BOOL "Enable the nanopb generator")
  191. set(nanopb_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries")
  192. add_external_subdirectory(nanopb)
  193. target_compile_definitions(
  194. protobuf-nanopb-static
  195. PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
  196. )
  197. # Enable #include <nanopb/pb.h>
  198. target_include_directories(
  199. protobuf-nanopb-static
  200. INTERFACE
  201. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}>
  202. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/nanopb>
  203. )
  204. # XCTest
  205. if(APPLE)
  206. find_package(XCTest)
  207. endif()
  208. if(FIREBASE_IOS_BUILD_TESTS)
  209. enable_testing()
  210. endif()
  211. include(compiler_setup)
  212. add_subdirectory(FirebaseCore)
  213. add_subdirectory(Firestore)
  214. add_subdirectory(GoogleUtilities)
  215. add_subdirectory(Interop/Auth)
  216. add_subdirectory(Interop/CoreDiagnostics)