FindGRPC.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Copyright 2018 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. include(FindPackageHandleStandardArgs)
  15. include(FindZLIB)
  16. set(BINARY_DIR ${FIREBASE_INSTALL_DIR}/external/grpc)
  17. ## ZLIB
  18. # the grpc ExternalProject already figures out if zlib should be built or
  19. # referenced from its installed location. If it elected to allow grpc to build
  20. # zlib then it will be available at this location.
  21. find_library(
  22. ZLIB_LIBRARY
  23. NAMES z
  24. HINTS ${BINARY_DIR}/src/grpc-build/third_party/zlib
  25. )
  26. # If found above, the standard package will honor the ZLIB_LIBRARY variable.
  27. find_package(ZLIB REQUIRED)
  28. ## BoringSSL/OpenSSL
  29. find_path(
  30. OPENSSL_INCLUDE_DIR openssl/ssl.h
  31. HINTS ${BINARY_DIR}/src/grpc/third_party/boringssl/include
  32. )
  33. find_library(
  34. OPENSSL_SSL_LIBRARY
  35. NAMES ssl
  36. HINTS ${BINARY_DIR}/src/grpc-build/third_party/boringssl/ssl
  37. )
  38. find_library(
  39. OPENSSL_CRYPTO_LIBRARY
  40. NAMES crypto
  41. HINTS ${BINARY_DIR}/src/grpc-build/third_party/boringssl/crypto
  42. )
  43. find_package(OpenSSL REQUIRED)
  44. ## C-Ares
  45. find_library(
  46. CARES_LIBRARY
  47. NAMES cares
  48. HINTS ${BINARY_DIR}/src/grpc-build/third_party/cares/cares/lib
  49. )
  50. if(NOT (CARES_LIBRARY STREQUAL "CARES_LIBRARY-NOTFOUND"))
  51. if (NOT TARGET c-ares::ares)
  52. add_library(c-ares::ares UNKNOWN IMPORTED)
  53. set_target_properties(
  54. c-ares::ares PROPERTIES
  55. IMPORTED_LOCATION ${CARES_LIBRARY}
  56. )
  57. endif()
  58. endif()
  59. ## GRPC
  60. find_path(
  61. GRPC_INCLUDE_DIR grpc/grpc.h
  62. HINTS
  63. $ENV{GRPC_ROOT}/include
  64. ${GRPC_ROOT}/include
  65. ${BINARY_DIR}/src/grpc/include
  66. )
  67. find_library(
  68. GPR_LIBRARY
  69. NAMES gpr
  70. HINTS
  71. $ENV{GRPC_ROOT}/lib
  72. ${GRPC_ROOT}/lib
  73. ${BINARY_DIR}/src/grpc-build
  74. )
  75. find_library(
  76. GRPC_LIBRARY
  77. NAMES grpc
  78. HINTS
  79. $ENV{GRPC_ROOT}/lib
  80. ${GRPC_ROOT}/lib
  81. ${BINARY_DIR}/src/grpc-build
  82. )
  83. find_package_handle_standard_args(
  84. gRPC
  85. DEFAULT_MSG
  86. GRPC_INCLUDE_DIR
  87. GRPC_LIBRARY
  88. GPR_LIBRARY
  89. )
  90. if(GRPC_FOUND)
  91. set(GRPC_INCLUDE_DIRS ${GRPC_INCLUDE_DIR})
  92. set(GRPC_LIBRARIES ${GRPC_LIBRARY})
  93. if (NOT TARGET grpc::gpr)
  94. add_library(grpc::gpr UNKNOWN IMPORTED)
  95. set_target_properties(
  96. grpc::gpr PROPERTIES
  97. INTERFACE_INCLUDE_DIRECTORIES ${GRPC_INCLUDE_DIR}
  98. IMPORTED_LOCATION ${GPR_LIBRARY}
  99. )
  100. endif()
  101. if (NOT TARGET grpc::grpc)
  102. set(
  103. GRPC_LINK_LIBRARIES
  104. c-ares::ares
  105. grpc::gpr
  106. OpenSSL::SSL
  107. OpenSSL::Crypto
  108. ZLIB::ZLIB
  109. )
  110. add_library(grpc::grpc UNKNOWN IMPORTED)
  111. set_target_properties(
  112. grpc::grpc PROPERTIES
  113. INTERFACE_INCLUDE_DIRECTORIES ${GRPC_INCLUDE_DIR}
  114. INTERFACE_LINK_LIBRARIES "${GRPC_LINK_LIBRARIES}"
  115. IMPORTED_LOCATION ${GRPC_LIBRARY}
  116. )
  117. endif()
  118. endif(GRPC_FOUND)