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.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/9e00fef9-343d-43bf-b42a-827565903975%40googlegroups.com.

Reply via email to