CMakeLists.txt 5.9 KB

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