CMakeLists.txt 6.6 KB

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