CMakeLists.txt 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 2.8.11)
  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. # Defer enabling any languages.
  37. project(firebase NONE)
  38. if(WIN32)
  39. # On Windows, prefer cl over gcc if both are available. By default most of
  40. # the CMake generators prefer gcc, even on Windows.
  41. set(CMAKE_GENERATOR_CC cl)
  42. endif()
  43. enable_language(C)
  44. enable_language(CXX)
  45. list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake)
  46. include(cc_rules)
  47. include(compiler_id)
  48. include(external_rules)
  49. include(podspec_rules)
  50. include(sanitizer_options)
  51. include(fuzzing_options)
  52. # If no build type is specified, make it a debug build
  53. if(NOT CMAKE_BUILD_TYPE)
  54. set(CMAKE_BUILD_TYPE Debug)
  55. endif()
  56. set(FIREBASE_SOURCE_DIR ${PROJECT_SOURCE_DIR})
  57. set(FIREBASE_BINARY_DIR ${PROJECT_BINARY_DIR})
  58. set(FIREBASE_INSTALL_DIR ${PROJECT_BINARY_DIR}/opt)
  59. set(
  60. FIREBASE_DOWNLOAD_DIR
  61. ${PROJECT_BINARY_DIR}/downloads
  62. CACHE PATH "Where to store downloaded files"
  63. )
  64. set(
  65. FIREBASE_EXTERNAL_SOURCE_DIR
  66. ${FIREBASE_BINARY_DIR}/external/src
  67. CACHE PATH "Root directory of source code of the external dependencies"
  68. )
  69. download_external_sources()
  70. # Googletest
  71. set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
  72. add_external_subdirectory(googletest)
  73. add_alias(GTest::GTest gtest)
  74. add_alias(GTest::Main gtest_main)
  75. add_alias(GMock::GMock gmock)
  76. # Benchmark
  77. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
  78. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
  79. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
  80. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")
  81. add_external_subdirectory(benchmark)
  82. # Abseil-cpp
  83. # Force disable Abseil's tests, which don't compile under VS2017.
  84. set(old_build_testing ${BUILD_TESTING})
  85. set(ABSL_RUN_TESTS OFF CACHE BOOL "Disable Abseil tests" FORCE)
  86. add_subdirectory(
  87. Firestore/third_party/abseil-cpp
  88. EXCLUDE_FROM_ALL
  89. )
  90. # gRPC
  91. find_package(OpenSSL QUIET)
  92. if(OPENSSL_FOUND)
  93. set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
  94. endif()
  95. find_package(ZLIB QUIET)
  96. if(ZLIB_FOUND)
  97. set(gRPC_ZLIB_PROVIDER package CACHE STRING "Use external ZLIB")
  98. endif()
  99. set(gRPC_BUILD_TESTS OFF CACHE BOOL "Disable gRPC tests")
  100. add_external_subdirectory(grpc)
  101. # Fix up targets included by gRPC's build
  102. if(OPENSSL_FOUND)
  103. # gRPC's CMakeLists.txt does not account for finding OpenSSL in a directory
  104. # that's not in the default search path.
  105. target_include_directories(grpc PRIVATE ${OPENSSL_INCLUDE_DIR})
  106. if(CXX_CLANG OR CXX_GNU)
  107. if((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR
  108. (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
  109. # gRPC uses some features deprecated in OpenSSL 1.1.0
  110. target_compile_options(
  111. grpc
  112. PRIVATE -Wno-deprecated-declarations
  113. )
  114. endif()
  115. endif()
  116. else()
  117. # Not using outboard OpenSSL so set up BoringSSL to look like it.
  118. add_alias(OpenSSL::Crypto crypto)
  119. target_include_directories(
  120. crypto
  121. INTERFACE
  122. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  123. )
  124. add_alias(OpenSSL::SSL ssl)
  125. target_include_directories(
  126. ssl
  127. INTERFACE
  128. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/boringssl/include>
  129. )
  130. endif()
  131. add_alias(protobuf::libprotobuf libprotobuf)
  132. if(CXX_CLANG OR CXX_GNU)
  133. target_compile_options(
  134. libprotobuf
  135. PUBLIC -Wno-unused-parameter
  136. )
  137. endif()
  138. if(CXX_CLANG)
  139. target_compile_options(
  140. libprotobuf
  141. PRIVATE -Wno-invalid-offsetof
  142. )
  143. endif()
  144. if(NOT ZLIB_FOUND)
  145. target_include_directories(
  146. zlibstatic
  147. INTERFACE $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/grpc/third_party/zlib>
  148. )
  149. endif()
  150. # LevelDB
  151. if(NOT WIN32)
  152. set(HAVE_LEVELDB ON)
  153. endif()
  154. if(HAVE_LEVELDB)
  155. set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "Firestore disabled")
  156. set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Firestore disabled")
  157. set(LEVELDB_INSTALL OFF CACHE BOOL "Firestore disabled")
  158. add_external_subdirectory(leveldb)
  159. add_alias(LevelDB::LevelDB leveldb)
  160. endif()
  161. # nanopb
  162. set(nanopb_BUILD_GENERATOR ON CACHE BOOL "Enable the nanopb generator")
  163. set(nanopb_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries")
  164. add_external_subdirectory(nanopb)
  165. target_compile_definitions(
  166. protobuf-nanopb-static
  167. PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
  168. )
  169. # Enable #include <nanopb/pb.h>
  170. target_include_directories(
  171. protobuf-nanopb-static
  172. INTERFACE
  173. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}>
  174. $<BUILD_INTERFACE:${FIREBASE_EXTERNAL_SOURCE_DIR}/nanopb>
  175. )
  176. enable_testing()
  177. include(compiler_setup)
  178. # Firebase packages
  179. # Set variables that CocoaPods expects to be able to expand in values it
  180. # includes in the xcconfigs it generates.
  181. set(PODS_TARGET_SRCROOT ${FIREBASE_SOURCE_DIR})
  182. podspec_framework(
  183. ${FIREBASE_SOURCE_DIR}/GoogleUtilities.podspec
  184. SPECS Logger
  185. )
  186. podspec_framework(${FIREBASE_SOURCE_DIR}/FirebaseCore.podspec)
  187. podspec_framework(${FIREBASE_SOURCE_DIR}/FirebaseAuthInterop.podspec)
  188. if(APPLE)
  189. # FirebaseAuthInterop has no source files but CMake can't build frameworks
  190. # that don't have sources. Generate an inconsequential source file so that
  191. # the library can be linked.
  192. file(
  193. WRITE ${CMAKE_CURRENT_BINARY_DIR}/FirebaseAuthInteropDummy.c
  194. "// generated file for header-only CMake support.
  195. __attribute__((unused))
  196. static void FirebaseAuthInteropFakeSymbol() {}
  197. "
  198. )
  199. target_sources(
  200. FirebaseAuthInterop
  201. PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/FirebaseAuthInteropDummy.c
  202. )
  203. endif()
  204. add_subdirectory(Firestore)