CMakeLists.txt 6.5 KB

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