1

I'm trying to integrate gRPC in existing project. It already has directory containing all gRPC's dependencies installed (ssl, c-ares, protobuf and zlib). I want to use them while building gRPC, and install gRPC into the same directory. I downloaded gRPC archive (without cloning submodules located in grpc/third_party/), and tried to generate build system for building and installing gRPC into my destination folder (using cmake).

I used following command:

cmake -DCMAKE_INSTALL_PREFIX=$PREFIX -DgRPC_ZLIB_PROVIDER=package -DgRPC_PROTOBUF_PROVIDER=package -DgRPC_SSL_PROVIDER=package -DgRPC_CARES_PROVIDER=package

and got an error:

CMake Error at cmake/cares.cmake:34 (find_package):
Could not find a package configuration file provided by "c-ares" with any
of the following names:

c-aresConfig.cmake
c-ares-config.cmake
Add the installation prefix of "c-ares" to CMAKE_PREFIX_PATH or set
"c-ares_DIR" to a directory containing one of the above files.  If "c-ares"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:116 (include)
-- Configuring incomplete, errors occurred!

I have c-ares of version 1.14.0 (from https://c-ares.haxx.se/), it is built using

./configure --prefix=$PREFIX
make && make install

and it doesn't provide any of the above files (c-aresConfig.cmake, c-ares-config.cmake).

I tried to get c-ares from github and to build it using cmake, and have succeed: requested files appeared in installation directory, so gRPC build system was generated successfully.

My question is: can I build and install gRPC without updating c-ares to github-version?

If this can't be done easily, maybe it is possible to disable usage of c-ares in gRPC somehow (use native dns resolver instead)?

  • 1
    `can I build and install gRPC without updating c-ares to github-version?` - You may write "config" file by yourself, and place it into appropriate directory, near the package. Alternatively, you may write "Find" script, which finds the package. That script should be placed somewhere, add its directory should be passed to cmake via `CMAKE_MODULE_PATH` parameter. – Tsyvarev Jun 15 '18 at 12:37

2 Answers2

5

c-ares has two build systems that are being used here, CMake and autotools. It supports both, but you need to choose one. The autotools one has been around longer and is the one traditionally used in UNIX environments. Binary packages of c-ares from Linux distros will use autotools, e.g. if you dnf install c-ares-devel, you'll get an autotools based build of c-ares.

The autotools build system installs a pkgconfig file, libcares.pc, to provide information about how to use c-ares. The CMake system installs c-ares-config.cmake to do this.

So the problem here is that you are building c-ares with autotools but gRPC only considered the possibility that CMake would have been used to build c-ares.

So you can either switch to building c-ares with CMake or patch gRPC to have a better find module for c-ares that works with pkgconfig files. CMake supports pkgconfig files, as they were widely used before CMake existed and still are widely used, so the latter is not that hard.

Or, trying defining -D_gRPC_CARES_LIBRARIES=cares and -DgRPC_CARES_PROVIDER=kludge when running cmake for gRPC. This fakes out the gRPC CMake code into not looking for c-ares and assuming that "-lcares" will find it.

TrentP
  • 4,240
  • 24
  • 35
-1

Please find the package gRPC in the Cmakelists of your project. If possible also find the package cares . So the addition would look like

find_package(gRPC REQUIRED) find_package(c-ares REQUIRED)

Also have a look at the link : CMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?

User001
  • 91
  • 8