Skip to content

Commit b8eb4e0

Browse files
authored
Add a CMake external build for c-ares (#1472)
* Add an external build for c-ares * Use installed c-ares package configuration * Adjust protobuf configuration to use the standard Protobuf_DIR variable. * Have grpc depend on c-ares * Drop UPDATE_COMMAND where it doesn't matter
1 parent 74fa22f commit b8eb4e0

File tree

9 files changed

+59
-25
lines changed

9 files changed

+59
-25
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ include(external/zlib)
5656
include(external/leveldb)
5757
include(external/protobuf)
5858
include(external/nanopb)
59+
include(external/c-ares)
5960
include(external/grpc)
6061
include(external/firestore)

cmake/FindGRPC.cmake

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,10 @@ find_package(OpenSSL REQUIRED)
5656

5757
## C-Ares
5858

59-
find_library(
60-
CARES_LIBRARY
61-
NAMES cares
62-
HINTS ${BINARY_DIR}/src/grpc-build/third_party/cares/cares/lib
63-
)
64-
if(NOT (CARES_LIBRARY STREQUAL "CARES_LIBRARY-NOTFOUND"))
65-
if (NOT TARGET c-ares::ares)
66-
add_library(c-ares::ares UNKNOWN IMPORTED)
67-
set_target_properties(
68-
c-ares::ares PROPERTIES
69-
IMPORTED_LOCATION ${CARES_LIBRARY}
70-
)
71-
endif()
59+
if(NOT c-ares_DIR)
60+
set(c-ares_DIR ${FIREBASE_INSTALL_DIR}/lib/cmake/c-ares)
7261
endif()
62+
find_package(c-ares CONFIG REQUIRED)
7363

7464

7565
## GRPC
@@ -124,7 +114,7 @@ if(GRPC_FOUND)
124114
if (NOT TARGET grpc::grpc)
125115
set(
126116
GRPC_LINK_LIBRARIES
127-
c-ares::ares
117+
c-ares::cares
128118
grpc::gpr
129119
OpenSSL::SSL
130120
OpenSSL::Crypto

cmake/external/c-ares.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
15+
include(ExternalProject)
16+
17+
ExternalProject_Add(
18+
c-ares
19+
20+
DOWNLOAD_DIR ${FIREBASE_DOWNLOAD_DIR}
21+
URL https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz
22+
URL_HASH SHA256=62dd12f0557918f89ad6f5b759f0bf4727174ae9979499f5452c02be38d9d3e8
23+
24+
PREFIX ${PROJECT_BINARY_DIR}/external/cares
25+
26+
CMAKE_ARGS
27+
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
28+
-DCMAKE_INSTALL_PREFIX:STRING=${FIREBASE_INSTALL_DIR}
29+
-DCARES_STATIC:BOOL=ON
30+
-DCARES_SHARED:BOOL=OFF
31+
-DCARES_STATIC_PIC:BOOL=ON
32+
33+
TEST_COMMAND ""
34+
)

cmake/external/googletest.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ ExternalProject_Add(
2727
CMAKE_CACHE_ARGS
2828
-DCMAKE_INSTALL_PREFIX:STRING=${FIREBASE_INSTALL_DIR}
2929

30-
UPDATE_COMMAND ""
3130
TEST_COMMAND ""
3231
)

cmake/external/grpc.cmake

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ else()
2424
set(
2525
GIT_SUBMODULES
2626
third_party/boringssl
27-
third_party/cares/cares
2827
)
2928

3029
set(
@@ -46,23 +45,37 @@ else()
4645
)
4746

4847

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+
4960
## protobuf
5061

5162
# Unlike other dependencies of gRPC, we control the protobuf version because we
5263
# have checked-in protoc outputs that must match the runtime.
5364

5465
# The location where protobuf-config.cmake will be installed varies by platform
55-
if (WIN32)
56-
set(PROTOBUF_CMAKE_DIR "${FIREBASE_INSTALL_DIR}/cmake")
57-
else()
58-
set(PROTOBUF_CMAKE_DIR "${FIREBASE_INSTALL_DIR}/lib/cmake/protobuf")
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()
5972
endif()
6073

6174
list(
6275
APPEND CMAKE_ARGS
6376
-DgRPC_PROTOBUF_PROVIDER:STRING=package
6477
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG
65-
-DProtobuf_DIR:PATH=${PROTOBUF_CMAKE_DIR}
78+
-DProtobuf_DIR:PATH=${Protobuf_DIR}
6679
)
6780

6881

@@ -94,6 +107,7 @@ else()
94107
ExternalProject_Add(
95108
grpc
96109
DEPENDS
110+
c-ares
97111
protobuf
98112
zlib
99113

cmake/external/leveldb.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ else()
6666

6767
INSTALL_DIR ${FIREBASE_INSTALL_DIR}
6868

69-
UPDATE_COMMAND ""
7069
INSTALL_COMMAND ""
7170
TEST_COMMAND ""
7271
)

cmake/external/nanopb.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ ExternalProject_Add(
3434
-Dnanopb_BUILD_GENERATOR:BOOL=ON
3535
-Dnanopb_PROTOC_PATH:STRING=${NANOPB_PROTOC_BIN}
3636

37-
UPDATE_COMMAND ""
3837
TEST_COMMAND ""
3938
)

cmake/external/protobuf.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,5 @@ ExternalProject_Add(
105105

106106
${commands}
107107

108-
UPDATE_COMMAND ""
109108
TEST_COMMAND ""
110109
)

cmake/external/zlib.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ else()
3535
-DCMAKE_INSTALL_PREFIX:STRING=${FIREBASE_INSTALL_DIR}
3636
-DBUILD_SHARED_LIBS:BOOL=OFF
3737

38-
UPDATE_COMMAND ""
3938
TEST_COMMAND ""
4039
)
4140
endif()

0 commit comments

Comments
 (0)