ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.06k stars 437 forks source link

Import target cmake error when using range-v3 as dependency #1703

Open sjahr opened 2 years ago

sjahr commented 2 years ago

I've installed range-v3 via apt-get install on Ubuntu 20.04 and run into the following error when I try to build a project with colcon that has multiple dependencies that depend on range-v3:

CMake Error at /usr/lib/cmake/range-v3/range-v3-config.cmake:2 (add_library):
  add_library cannot create imported target "range-v3::meta" because another
  target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)

CMake Error at /usr/lib/cmake/range-v3/range-v3-config.cmake:3 (add_library):
  add_library cannot create imported target "range-v3::concepts" because
  another target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)

CMake Error at /usr/lib/cmake/range-v3/range-v3-config.cmake:4 (add_library):
  add_library cannot create imported target "range-v3::range-v3" because
  another target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/sebastian/min_range_v3_error/build/CMakeFiles/CMakeOutput.log".

After investigating the error a bit, I figured out that colcon uses a custom CMake macro that calls find_package(range-v3 REQUIRED) multiple times in the same context. From my understanding, this should not cause any problems, so I am wondering if the error is somewhere within range-v3's CMake files.

You can reproduce the error on Ubuntu 20.04 after installing sudo apt-get install librange-v3-dev and try to build the minimal example you find attached (min_range_v3_error.zip) with

cd min_range_v3_error
mkdir build
cd build
cmake ..

In the CMakeLists.txt file, I call find_package twice which causes the error

find_package(range-v3 REQUIRED)
find_package(range-v3 REQUIRED)

Do you think this is a small bug on the range-v3 side or are we including range-v3 incorrect as a dependency? Thanks in advance for your help!

JohelEGP commented 2 years ago

This shouldn't happen after https://github.com/ericniebler/range-v3/commit/4abf6d6149c6c845d3ff84b395a37de01b104372.

sjahr commented 2 years ago

It seems like this commit is not part of any released version, or am I mistaken? The Debian release in focal is 0.10.0 and on jamming 0.11.0. Are there any plans to create a new release in the future that includes this fix?