CMakeLists.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. download_external_sources()
  50. # Googletest
  51. set(gtest_force_shared_crt ON CACHE BOOL "Use shared run-time")
  52. add_external_subdirectory(googletest)
  53. add_alias(GTest::GTest gtest)
  54. add_alias(GTest::Main gtest_main)
  55. add_alias(GMock::GMock gmock)
  56. # Benchmark
  57. set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Firestore disabled")
  58. set(BENCHMARK_ENABLE_EXCEPTIONS OFF CACHE BOOL "Firestore disabled")
  59. set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Firestore disabled")
  60. set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Firestore disabled")
  61. add_external_subdirectory(benchmark)
  62. # Abseil-cpp
  63. # Force disable Abseil's tests, which don't compile under VS2017.
  64. set(old_build_testing ${BUILD_TESTING})
  65. set(BUILD_TESTING OFF CACHE BOOL "Disable Abseil tests" FORCE)
  66. add_subdirectory(
  67. Firestore/third_party/abseil-cpp
  68. )
  69. set(BUILD_TESTING ${old_build_testing} CACHE BOOL "Restore BUILD_TESTING" FORCE)
  70. # gRPC
  71. find_package(OpenSSL)
  72. if(OPENSSL_FOUND)
  73. set(gRPC_SSL_PROVIDER package CACHE STRING "Use external OpenSSL")
  74. endif()
  75. find_package(ZLIB)
  76. if(ZLIB_FOUND)
  77. set(gRPC_ZLIB_PROVIDER package CACHE STRING "Use external ZLIB")
  78. endif()
  79. set(gRPC_BUILD_TESTS OFF CACHE BOOL "Disable gRPC tests")
  80. add_external_subdirectory(grpc)
  81. # Fix up targets included by gRPC's build
  82. set(external_src_dir ${FIREBASE_BINARY_DIR}/external/src)
  83. if(OPENSSL_FOUND)
  84. # gRPC's CMakeLists.txt does not account for finding OpenSSL in a directory
  85. # that's not in the default search path.
  86. target_include_directories(grpc PRIVATE ${OPENSSL_INCLUDE_DIR})
  87. if(CXX_CLANG OR CXX_GNU)
  88. if((OPENSSL_VERSION VERSION_EQUAL "1.1.0") OR
  89. (OPENSSL_VERSION VERSION_GREATER "1.1.0"))
  90. # gRPC uses some features deprecated in OpenSSL 1.1.0
  91. target_compile_options(
  92. grpc
  93. PRIVATE -Wno-deprecated-declarations
  94. )
  95. endif()
  96. endif()
  97. else()
  98. # Not using outboard OpenSSL so set up BoringSSL to look like it.
  99. add_alias(OpenSSL::Crypto crypto)
  100. target_include_directories(
  101. crypto
  102. INTERFACE
  103. $<BUILD_INTERFACE:${external_src_dir}/grpc/third_party/boringssl/include>
  104. )
  105. add_alias(OpenSSL::SSL ssl)
  106. target_include_directories(
  107. ssl
  108. INTERFACE
  109. $<BUILD_INTERFACE:${external_src_dir}/grpc/third_party/boringssl/include>
  110. )
  111. endif()
  112. add_alias(protobuf::libprotobuf libprotobuf)
  113. if(CXX_CLANG OR CXX_GNU)
  114. target_compile_options(
  115. libprotobuf
  116. PUBLIC -Wno-unused-parameter
  117. )
  118. endif()
  119. if(CXX_CLANG)
  120. target_compile_options(
  121. libprotobuf
  122. PRIVATE -Wno-invalid-offsetof
  123. )
  124. endif()
  125. if(NOT ZLIB_FOUND)
  126. target_include_directories(
  127. zlibstatic
  128. INTERFACE $<BUILD_INTERFACE:${external_src_dir}/grpc/third_party/zlib>
  129. )
  130. endif()
  131. # LevelDB
  132. if(NOT WIN32)
  133. set(HAVE_LEVELDB ON)
  134. endif()
  135. if(HAVE_LEVELDB)
  136. set(LEVELDB_BUILD_TESTS OFF CACHE BOOL "Firestore disabled")
  137. set(LEVELDB_BUILD_BENCHMARKS OFF CACHE BOOL "Firestore disabled")
  138. set(LEVELDB_INSTALL OFF CACHE BOOL "Firestore disabled")
  139. add_external_subdirectory(leveldb)
  140. add_alias(LevelDB::LevelDB leveldb)
  141. endif()
  142. # nanopb
  143. set(nanopb_BUILD_GENERATOR ON CACHE BOOL "Enable the nanopb generator")
  144. set(nanopb_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries")
  145. add_external_subdirectory(nanopb)
  146. target_compile_definitions(
  147. protobuf-nanopb
  148. PUBLIC -DPB_FIELD_32BIT -DPB_ENABLE_MALLOC
  149. )
  150. target_include_directories(
  151. protobuf-nanopb
  152. INTERFACE $<BUILD_INTERFACE:${external_src_dir}/nanopb>
  153. )
  154. enable_testing()
  155. include(compiler_setup)
  156. # Firebase packages
  157. podspec_framework(
  158. ${FIREBASE_SOURCE_DIR}/GoogleUtilities.podspec
  159. SPECS Logger
  160. )
  161. podspec_framework(${FIREBASE_SOURCE_DIR}/FirebaseCore.podspec)
  162. podspec_framework(${FIREBASE_SOURCE_DIR}/FirebaseAuthInterop.podspec)
  163. if(APPLE)
  164. # FirebaseAuthInterop has no source files but CMake can't build frameworks
  165. # that don't have sources. Generate an inconsequential source file so that
  166. # the library can be linked.
  167. file(
  168. WRITE ${CMAKE_CURRENT_BINARY_DIR}/FirebaseAuthInteropDummy.c
  169. "// generated file for header-only CMake support.
  170. __attribute__((unused))
  171. static void FirebaseAuthInteropFakeSymbol() {}
  172. "
  173. )
  174. target_sources(
  175. FirebaseAuthInterop
  176. PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/FirebaseAuthInteropDummy.c
  177. )
  178. endif()
  179. add_subdirectory(Firestore)