|
14 | 14 |
|
15 | 15 | include(ExternalProject)
|
16 | 16 | include(ExternalProjectFlags)
|
| 17 | +include(external/c-ares) |
| 18 | +include(external/protobuf) |
| 19 | +include(external/zlib) |
| 20 | + |
| 21 | +if(TARGET grpc) |
| 22 | + return() |
| 23 | +endif() |
17 | 24 |
|
18 | 25 | if(GRPC_ROOT)
|
19 | 26 | # If the user has supplied a GRPC_ROOT then just use it. Add an empty custom
|
20 | 27 | # target so that the superbuild dependencies still work.
|
21 | 28 | add_custom_target(grpc)
|
22 |
| - |
23 |
| -else() |
24 |
| - set( |
25 |
| - GIT_SUBMODULES |
26 |
| - third_party/boringssl |
27 |
| - ) |
28 |
| - |
29 |
| - set( |
30 |
| - CMAKE_ARGS |
31 |
| - -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} |
32 |
| - -DBUILD_SHARED_LIBS:BOOL=OFF |
33 |
| - -DgRPC_BUILD_TESTS:BOOL=OFF |
34 |
| - |
35 |
| - # TODO(rsgowman): We're currently building nanopb twice; once via grpc, and |
36 |
| - # once via nanopb. The version from grpc is the one that actually ends up |
37 |
| - # being used. We need to fix this such that either: |
38 |
| - # a) we instruct grpc to use our nanopb |
39 |
| - # b) we rely on grpc's nanopb instead of using our own. |
40 |
| - # For now, we'll pass in the necessary nanopb cflags into grpc. (We require |
41 |
| - # 16 bit fields. Without explicitly requesting this, nanopb uses 8 bit |
42 |
| - # fields.) |
43 |
| - -DCMAKE_C_FLAGS=-DPB_FIELD_16BIT |
44 |
| - -DCMAKE_CXX_FLAGS=-DPB_FIELD_16BIT |
45 |
| - ) |
46 |
| - |
47 |
| - |
48 |
| - ## c-ares |
49 |
| - if(NOT c-ares_DIR) |
50 |
| - set(c-ares_DIR ${FIREBASE_INSTALL_DIR}/lib/cmake/c-ares) |
51 |
| - endif() |
52 |
| - |
53 |
| - list( |
54 |
| - APPEND CMAKE_ARGS |
55 |
| - -DgRPC_CARES_PROVIDER:STRING=package |
56 |
| - -Dc-ares_DIR:PATH=${c-ares_DIR} |
57 |
| - ) |
58 |
| - |
59 |
| - |
60 |
| - ## protobuf |
61 |
| - |
62 |
| - # Unlike other dependencies of gRPC, we control the protobuf version because we |
63 |
| - # have checked-in protoc outputs that must match the runtime. |
64 |
| - |
65 |
| - # The location where protobuf-config.cmake will be installed varies by platform |
66 |
| - if(NOT Protobuf_DIR) |
67 |
| - if(WIN32) |
68 |
| - set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/cmake") |
69 |
| - else() |
70 |
| - set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/lib/cmake/protobuf") |
71 |
| - endif() |
| 29 | + return() |
| 30 | +endif() |
| 31 | + |
| 32 | +set( |
| 33 | + GIT_SUBMODULES |
| 34 | + third_party/boringssl |
| 35 | +) |
| 36 | + |
| 37 | +set( |
| 38 | + CMAKE_ARGS |
| 39 | + -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE} |
| 40 | + -DBUILD_SHARED_LIBS:BOOL=OFF |
| 41 | + -DgRPC_BUILD_TESTS:BOOL=OFF |
| 42 | + |
| 43 | + # TODO(rsgowman): We're currently building nanopb twice; once via grpc, and |
| 44 | + # once via nanopb. The version from grpc is the one that actually ends up |
| 45 | + # being used. We need to fix this such that either: |
| 46 | + # a) we instruct grpc to use our nanopb |
| 47 | + # b) we rely on grpc's nanopb instead of using our own. |
| 48 | + # For now, we'll pass in the necessary nanopb cflags into grpc. (We require |
| 49 | + # 16 bit fields. Without explicitly requesting this, nanopb uses 8 bit |
| 50 | + # fields.) |
| 51 | + -DCMAKE_C_FLAGS=-DPB_FIELD_16BIT |
| 52 | + -DCMAKE_CXX_FLAGS=-DPB_FIELD_16BIT |
| 53 | +) |
| 54 | + |
| 55 | + |
| 56 | +## c-ares |
| 57 | +if(NOT c-ares_DIR) |
| 58 | + set(c-ares_DIR ${FIREBASE_INSTALL_DIR}/lib/cmake/c-ares) |
| 59 | +endif() |
| 60 | + |
| 61 | +list( |
| 62 | + APPEND CMAKE_ARGS |
| 63 | + -DgRPC_CARES_PROVIDER:STRING=package |
| 64 | + -Dc-ares_DIR:PATH=${c-ares_DIR} |
| 65 | +) |
| 66 | + |
| 67 | + |
| 68 | +## protobuf |
| 69 | + |
| 70 | +# Unlike other dependencies of gRPC, we control the protobuf version because we |
| 71 | +# have checked-in protoc outputs that must match the runtime. |
| 72 | + |
| 73 | +# The location where protobuf-config.cmake will be installed varies by platform |
| 74 | +if(NOT Protobuf_DIR) |
| 75 | + if(WIN32) |
| 76 | + set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/cmake") |
| 77 | + else() |
| 78 | + set(Protobuf_DIR "${FIREBASE_INSTALL_DIR}/lib/cmake/protobuf") |
72 | 79 | endif()
|
73 |
| - |
74 |
| - list( |
75 |
| - APPEND CMAKE_ARGS |
76 |
| - -DgRPC_PROTOBUF_PROVIDER:STRING=package |
77 |
| - -DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG |
78 |
| - -DProtobuf_DIR:PATH=${Protobuf_DIR} |
79 |
| - ) |
80 |
| - |
81 |
| - |
82 |
| - ## zlib |
83 |
| - |
84 |
| - # cmake/external/zlib.cmake figures out whether or not to build zlib. Either |
85 |
| - # way, from the gRPC build's point of view it's a package. |
| 80 | +endif() |
| 81 | + |
| 82 | +list( |
| 83 | + APPEND CMAKE_ARGS |
| 84 | + -DgRPC_PROTOBUF_PROVIDER:STRING=package |
| 85 | + -DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG |
| 86 | + -DProtobuf_DIR:PATH=${Protobuf_DIR} |
| 87 | +) |
| 88 | + |
| 89 | + |
| 90 | +## zlib |
| 91 | + |
| 92 | +# cmake/external/zlib.cmake figures out whether or not to build zlib. Either |
| 93 | +# way, from the gRPC build's point of view it's a package. |
| 94 | +list( |
| 95 | + APPEND CMAKE_ARGS |
| 96 | + -DgRPC_ZLIB_PROVIDER:STRING=package |
| 97 | +) |
| 98 | +if(ZLIB_FOUND) |
| 99 | + # Propagate possible user configuration to FindZLIB.cmake in the sub-build. |
86 | 100 | list(
|
87 | 101 | APPEND CMAKE_ARGS
|
88 |
| - -DgRPC_ZLIB_PROVIDER:STRING=package |
| 102 | + -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} |
| 103 | + -DZLIB_LIBRARY=${ZLIB_LIBRARY} |
89 | 104 | )
|
90 |
| - if(ZLIB_FOUND) |
91 |
| - # Propagate possible user configuration to FindZLIB.cmake in the sub-build. |
92 |
| - list( |
93 |
| - APPEND CMAKE_ARGS |
94 |
| - -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIR} |
95 |
| - -DZLIB_LIBRARY=${ZLIB_LIBRARY} |
96 |
| - ) |
97 |
| - endif() |
| 105 | +endif() |
98 | 106 |
|
99 | 107 |
|
100 |
| - ExternalProject_GitSource( |
101 |
| - GRPC_GIT |
102 |
| - GIT_REPOSITORY "https://github.com/grpc/grpc.git" |
103 |
| - GIT_TAG "v1.8.3" |
104 |
| - GIT_SUBMODULES ${GIT_SUBMODULES} |
105 |
| - ) |
| 108 | +ExternalProject_GitSource( |
| 109 | + GRPC_GIT |
| 110 | + GIT_REPOSITORY "https://github.com/grpc/grpc.git" |
| 111 | + GIT_TAG "v1.8.3" |
| 112 | + GIT_SUBMODULES ${GIT_SUBMODULES} |
| 113 | +) |
106 | 114 |
|
107 |
| - ExternalProject_Add( |
108 |
| - grpc |
109 |
| - DEPENDS |
110 |
| - c-ares |
111 |
| - protobuf |
112 |
| - zlib |
| 115 | +ExternalProject_Add( |
| 116 | + grpc |
| 117 | + DEPENDS |
| 118 | + c-ares |
| 119 | + protobuf |
| 120 | + zlib |
113 | 121 |
|
114 |
| - ${GRPC_GIT} |
| 122 | + ${GRPC_GIT} |
115 | 123 |
|
116 |
| - PREFIX ${PROJECT_BINARY_DIR}/external/grpc |
| 124 | + PREFIX ${PROJECT_BINARY_DIR}/external/grpc |
117 | 125 |
|
118 |
| - CMAKE_ARGS |
119 |
| - ${CMAKE_ARGS} |
120 |
| - |
121 |
| - BUILD_COMMAND |
122 |
| - ${CMAKE_COMMAND} --build . --target grpc |
123 |
| - |
124 |
| - UPDATE_COMMAND "" |
125 |
| - TEST_COMMAND "" |
126 |
| - INSTALL_COMMAND "" |
127 |
| - ) |
| 126 | + CMAKE_ARGS |
| 127 | + ${CMAKE_ARGS} |
128 | 128 |
|
129 |
| -endif(GRPC_ROOT) |
| 129 | + BUILD_COMMAND |
| 130 | + ${CMAKE_COMMAND} --build . --target grpc |
130 | 131 |
|
| 132 | + UPDATE_COMMAND "" |
| 133 | + TEST_COMMAND "" |
| 134 | + INSTALL_COMMAND "" |
| 135 | +) |
0 commit comments