Missing abseil includes after buiding and linking gRPC

  abseil, c++, cmake, grpc, protocol-buffers

I am building a C++ project that uses gRPC. The layout of the source code is basically

/protos
  foo.proto
/includes
  *.h
/src
  client.cpp
  server.cpp
CMakeLists.txt

To generate my cpp and gRPC files I’m using the protobuf_generate CMake function like

find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)

add_library(foo ${proto_files})
target_link_libraries(foo
  PUBLIC
    protobuf::libprotobuf
    gRPC::grpc++
)

then

protobuf_generate(
  TARGET
    foo
  LANGUAGE
    cpp
  IMPORT_DIRS
    ${PROJECT_SOURCE_DIR}/protos
  PROTOC_OUT_DIR
    ${generated_dir}
)

protobuf_generate(
  TARGET
    foo
  LANGUAGE
    grpc
  GENERATE_EXTENSIONS
    .grpc.pb.h
    .grpc.pb.cc
  PLUGIN
    "protoc-gen-grpc=${grpc_cpp_plugin_location}"
  IMPORT_DIRS
    ${PROJECT_SOURCE_DIR}/protos
  PROTOC_OUT_DIR
    ${generated_dir}
)

where I built gRPC from source using CMake then installed locally.

Then later for the client and server

add_executable(server ${PROJECT_SOURCE_DIR}/src/scenario_server.cpp)
target_link_libraries(server
  PUBLIC
    gRPC::grpc++_reflection
    protobuf::libprotobuf
    foo
)

After this I can CMake generate successfully, but when I go to compile, it seems to be missing includes for abseil. These seem to get included as implementation details within grpcpp internally.

grpcpp/impl/codegen/sync.h(35): fatal error C1083: Cannot open include file: ‘absl/synchronization/mutex.h’: No such file or directory

Is there some CMake flag I have to use when building gRPC to resolve this? Or is there something in my project’s CMake to make sure these end up in my project’s "Additional Include Directories"?

Source: Windows Questions C++

LEAVE A COMMENT