When I use CMake FetchContent to import OpenCV, it works fine:
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)
But after I add Eigen:
# 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)
I was told that this is caused by namespace collision, but I don't know how to solve that issue. I searched for "FetchContent" on GitHub, but it seems everybody is using it the same way as mine. Is there a general way to fetch everything using FetchContent with just the effort to insert the project name and URL?