[英]Issue building opencv using FetchContent cmake command
I really need your help because I really don't understand what I am doing wrong.我真的需要你的帮助,因为我真的不明白我做错了什么。
Using the very simple attached CMakeLists.txt, I got the following error (a lot of times):使用非常简单的附加 CMakeLists.txt,我收到以下错误(很多次):
CMake Error in build/_deps/opencv-src/modules/core/CMakeLists.txt:
Target "opencv_core" INTERFACE_INCLUDE_DIRECTORIES property contains path:
"/home/myuser/tmp/build"
which is prefixed in the build directory.
Can you help me fix it?你能帮我修一下吗?
Thank you for the help.感谢您的帮助。
The CMakeLists.txt I am using:我正在使用的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(TEST_PROJECT)
set(CMAKE_CXX_STANDARD 14)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif ()
include(FetchContent)
FetchContent_Declare(
opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 4.6.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(opencv)
set(OpenCV_DIR ${CMAKE_CURRENT_BINARY_DIR})
find_package(OpenCV REQUIRED)
Tried the same on a Windows system - with no success either.在 Windows 系统上尝试过同样的方法——也没有成功。
In the end, I installed OpenCV outside of the build and source tree.最后,我在构建和源代码树之外安装了 OpenCV。 Then used only find_package in the CMakeList.txt.
然后只使用 CMakeList.txt 中的 find_package。
I had problems passing varibales to the OpenCV build when using FetchContent too.我在使用 FetchContent 时也遇到了将变量传递给 OpenCV 构建的问题。 Eg for using TBB or CUDA.
例如使用 TBB 或 CUDA。
As @sweenish guessed, the problem was the OpenCV_DIR
variable definition.正如@sweenish 猜测的那样,问题出在
OpenCV_DIR
变量定义上。 So I remove this line and add the OVERRIDE_FIND_PACKAGE
in the FetchContent_Declare
call.所以我删除了这一行并在
FetchContent_Declare
调用中添加了OVERRIDE_FIND_PACKAGE
。 And now it works fine on both systems, Linux and Windows.现在它在 Linux 和 Windows 两个系统上都能正常工作。
My CMakeLists.txt now looks like:我的 CMakeLists.txt 现在看起来像:
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(TEST_PROJECT)
set(CMAKE_CXX_STANDARD 14)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif ()
include(FetchContent)
FetchContent_Declare(
opencv
GIT_REPOSITORY https://github.com/opencv/opencv.git
GIT_TAG 4.6.0
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(opencv)
find_package(OpenCV REQUIRED)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.