abseil/abseil-cpp

[Bug]: Unusable for installable projects whose other dependencies also define a `check` target

Opened this issue ยท 4 comments

Describe the issue

I am working on a project that depends on LLVM. LLVM uses installable targets (using CMake's install command), which forces my project to do the same. If I want to use abseil-cpp or any project that depends on it, I thus need to set ABSL_ENABLE_INSTALL=ON.

Furthermore, LLVM also defines a check target in its CMake files. This clashes with the check target of Abseil.

This only happens with ABSL_ENABLE_INSTALL=ON. Otherwise, the target names are prefixed with absl_, see the definition of absl_cc_library.

Steps to reproduce the problem

What version of Abseil are you using?

Any version from about four years ago until today.

What operating system and version are you using?

Any.

What compiler and version are you using?

Any.

What build system are you using?

Any version of CMake older than 2.6.0.

Additional context

Of course, the clash is also due to to LLVM using a non-prefixed target name. However, I'd argue that this doesn't absolve abseil-cpp from being well-behaved and prefix it's target names as an effort to keep them unique no matter what other project it is used with.

Steps to reproduce the problem is not filled in. Please do so.

You also say that this is relevant to any version of CMake older than 2.6.0. I just want to confirm that this is correct as our minimum supported CMake version is 3.13. Does this work still not work with a supported CMake version?

Clone this project to abseil-cpp and create CMakeLists.txt with the following content:

add_custom_target(check)
add_subdirectory(abseil-cpp)

Create an empty folder, cd into the folder, and run cmake .. -DABSL_ENABLE_INSTALL=ON, observe the following error:

CMake Error at abseil-cpp/CMake/AbseilHelpers.cmake:317 (add_library):
  add_library cannot create target "check" because another target with the
  same name already exists.  The existing target is a custom target created
  in source directory
  "/.../".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  abseil-cpp/absl/log/CMakeLists.txt:424 (absl_cc_library)

Stumbled upon a similar problem too, but this time when trying to use crc32c along with abseil.

When ABSL_ENABLE_INSTALL is set to ON, it creates a library named "crc32c" which introduces conflicts.

CMake Error at build/_deps/absl-src/CMake/AbseilHelpers.cmake:251 (add_library):
  add_library cannot create target "crc32c" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory
  "/build/_deps/crc32c-src".  See
  documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/_deps/absl-src/absl/crc/CMakeLists.txt:54 (absl_cc_library)

I also encountered this in nghttp2/nghttp2#2204