grpc.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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(ExternalProject)
  15. include(ExternalProjectFlags)
  16. include(FindZLIB)
  17. if(GRPC_ROOT)
  18. # If the user has supplied a GRPC_ROOT then just use it. Add an empty custom
  19. # target so that the superbuild dependencies still work.
  20. add_custom_target(grpc)
  21. else()
  22. set(
  23. GIT_SUBMODULES
  24. third_party/boringssl
  25. third_party/cares/cares
  26. )
  27. set(
  28. CMAKE_ARGS
  29. -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
  30. -DgRPC_BUILD_TESTS:BOOL=OFF
  31. -DBUILD_SHARED_LIBS:BOOL=OFF
  32. )
  33. # zlib can be built by grpc but we can avoid it on platforms that provide it
  34. # by default.
  35. find_package(ZLIB)
  36. if(ZLIB_FOUND)
  37. list(
  38. APPEND CMAKE_ARGS
  39. -DgRPC_ZLIB_PROVIDER:STRING=package
  40. -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR}
  41. -DZLIB_LIBRARY=${ZLIB_LIBRARY}
  42. )
  43. else()
  44. list(
  45. APPEND GIT_SUBMODULES
  46. third_party/zlib
  47. )
  48. endif(ZLIB_FOUND)
  49. ExternalProject_GitSource(
  50. GRPC_GIT
  51. GIT_REPOSITORY "https://github.com/grpc/grpc.git"
  52. GIT_TAG "v1.8.3"
  53. GIT_SUBMODULES ${GIT_SUBMODULES}
  54. )
  55. ExternalProject_Add(
  56. grpc
  57. ${GRPC_GIT}
  58. PREFIX ${PROJECT_BINARY_DIR}/external/grpc
  59. # TODO(rsgowman): We're currently building nanopb twice; once via grpc, and
  60. # once via nanopb. The version from grpc is the one that actually ends up
  61. # being used. We need to fix this such that either:
  62. # a) we instruct grpc to use our nanopb
  63. # b) we rely on grpc's nanopb instead of using our own.
  64. # For now, we'll pass in the necessary nanopb cflags into grpc. (We require
  65. # 16 bit fields. Without explicitly requesting this, nanopb uses 8 bit
  66. # fields.)
  67. CMAKE_ARGS ${CMAKE_ARGS};-DCMAKE_C_FLAGS=-DPB_FIELD_16BIT;DCMAKE_CXX_FLAGS=-DPB_FIELD_16BIT
  68. BUILD_COMMAND
  69. ${CMAKE_COMMAND} --build . --target grpc
  70. UPDATE_COMMAND ""
  71. TEST_COMMAND ""
  72. INSTALL_COMMAND ""
  73. )
  74. endif(GRPC_ROOT)