Conflicts Between Libraries When Using FetchContent
include(FetchContent)
# Fetch OpenCV
FetchContent_Declare(
opencv
GIT_REPOSITORY https://gitee.com/aiproach/opencv.git
GIT_TAG 4.4.0
)
FetchContent_MakeAvailable(opencv)
set(OpenCV_DIR ${CMAKE_CURRENT_BINARY_DIR})
find_package(OpenCV REQUIRED)
When I use FetchContent to import only opencv, it works fine. But after I add:
# Fetch Eigen
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.3.9
)
FetchContent_MakeAvailable(eigen)
find_package(eigen3 REQUIRED)
It emits errors:
CMake Error at build/_deps/eigen-src/CMakeLists.txt:620 (add_custom_target):
add_custom_target cannot create target "uninstall" because another target
with the same name already exists. The existing target is a custom target
created in source directory
"...../build/_deps/opencv-src".
See documentation for policy CMP0002 for more details.
CMake Error at build/_deps/eigen-build/eigen3Config.cmake:20 (include):
The file
....../build/_deps/eigen-build/Eigen3Targets.cmake
was generated by the export() command. It may not be used as the argument
to the include() command. Use ALIAS targets instead to refer to targets by
alternative names.
Call Stack (most recent call first):
CMakeLists.txt:30 (find_package)
Not sure if it is a bug because I'm not very familiar with CMake. Hope someone can help me out.