cmake_minimum_required(VERSION 3.20)
project(test)
include(FetchContent)
# snappy
FetchContent_Declare(
snappy
GIT_REPOSITORY https://github.com/google/snappy.git
GIT_TAG 1.2.1
)
# leveldb
FetchContent_Declare(
leveldb
GIT_REPOSITORY https://github.com/google/leveldb.git
GIT_TAG 1.23
)
FetchContent_MakeAvailable(snappy leveldb)
add_executable(test main.cpp)
target_link_libraries(test PUBLIC leveldb)
leveldb depends on snappy, and both leveldb and snappy depend on benchmark, which causes cmake configuration failure.
[build] CMake Error at build/_deps/leveldb-src/third_party/benchmark/src/CMakeLists.txt:20 (add_library):
[build] add_library cannot create target "benchmark" because another target with
[build] the same name already exists. The existing target is a static library
[build] created in source directory
[build] "/workspaces/build/_deps/snappy-src/third_party/benchmark/src".
[build] See documentation for policy CMP0002 for more details.
[build]
[build]
[build] CMake Error at build/_deps/leveldb-src/third_party/benchmark/src/CMakeLists.txt:35 (target_link_libraries):
[build] The keyword signature for target_link_libraries has already been used with
[build] the target "benchmark". All uses of target_link_libraries with a target
[build] must be either all-keyword or all-plain.
[build]
[build] The uses of the keyword signature are here:
[build]
[build] * build/_deps/snappy-src/third_party/benchmark/src/CMakeLists.txt:38 (target_link_libraries)
[build] * build/_deps/snappy-src/third_party/benchmark/src/CMakeLists.txt:43 (target_link_libraries)
[build]
[build]
[build]
[build] CMake Error at build/_deps/leveldb-src/third_party/benchmark/src/CMakeLists.txt:57 (add_library):
[build] add_library cannot create target "benchmark_main" because another target
[build] with the same name already exists. The existing target is a static library
[build] created in source directory
[build] "/workspaces/build/_deps/snappy-src/third_party/benchmark/src".
[build] See documentation for policy CMP0002 for more details.
[build]
[build]
[build] CMake Error at build/_deps/leveldb-src/third_party/benchmark/src/CMakeLists.txt:67 (target_link_libraries):
[build] The keyword signature for target_link_libraries has already been used with
[build] the target "benchmark_main". All uses of target_link_libraries with a
[build] target must be either all-keyword or all-plain.
[build]
[build] The uses of the keyword signature are here:
[build]
[build] * build/_deps/snappy-src/third_party/benchmark/src/CMakeLists.txt:70 (target_link_libraries)
[build]
[build]
[build] -- Configuring incomplete, errors occurred!
How should this situation be handled?