grpc as submodule conflicts with existing abseil submodule (C++ / CMake)

24 views
Skip to first unread message

pieter.k...@gmail.com

unread,
Jan 20, 2020, 12:36:25 AM1/20/20
to grpc.io
My project already has abseil-cpp, which works just fine in my external directory and the following in CMakeLists.txt
add_subdirectory(abseil-cpp EXCLUDE_FROM_ALL)

If I then also add grpc, I get build errors like this:
 CMake Error at external/grpc/third_party/abseil-cpp/CMake/AbseilHelpers.cmake:148 (add_library):
  add_library cannot create target
"absl_atomic_hook" because another target
 
with the same name already exists.  The existing target is an interface
  library created
in source directory
 
"/path/to/project/external/abseil-cpp/absl/base".  See
  documentation
for policy CMP0002 for more details.
Call Stack (most recent call first):
  external
/grpc/third_party/abseil-cpp/absl/base/CMakeLists.txt:19 (absl_cc_library)

Clearly duplicate targets.

Looking at the abseil cmake files in grpc/cmake, I tried setting ABSL_ROOT_DIR so that grpc can use my abseil-cpp submodule instead of its own.
set(ABSL_ROOT_DIR "${PROJECT_SOURCE_DIR}/external/abseil-cpp")

But that yields the following similar error:

CMake Error at external/abseil-cpp/CMake/AbseilHelpers.cmake:148 (add_library):
  add_library cannot create target
"absl_atomic_hook" because another target
 
with the same name already exists.  The existing target is an interface
  library created
in source directory
 
"/path/to/project/external/abseil-cpp/absl/base".  See
  documentation
for policy CMP0002 for more details.
Call Stack (most recent call first):
  external
/abseil-cpp/absl/base/CMakeLists.txt:19 (absl_cc_library)


Because grpc always adds abseil-cpp in grpc/cmake/abseil-cpp.cmake, there's no clean way to avoid this double-add.

So far the only way I have found is to set gRPC_ABSL_PROVIDER to something other than "module" or "package", since that will cause it just not include absl at all, but with the top project including it separately it's still found. 
Would be nice if abseil-cpp.cmake could detect if abseil was already available before trying to add it locally.

Nicolas Noble

unread,
Jan 20, 2020, 12:43:04 AM1/20/20
to pieter.k...@gmail.com, grpc.io
This probably should be an issue filed on github.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/9e00fef9-343d-43bf-b42a-827565903975%40googlegroups.com.

pieter.k...@gmail.com

unread,
Jan 20, 2020, 12:47:58 AM1/20/20
to grpc.io
Ok, I'll file one.
Reply all
Reply to author
Forward
0 new messages