gpt4 book ai didi

opencv - CMake:无法设置变量以关闭 OpenCV

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:41 24 4
gpt4 key购买 nike

我有以下CMake代码段

#OpenCV
option(USE_OPENCV "Use OpenCV data sources" ON)

这里我默认打开 OpenCV 的使用,然后我有:

if(USE_OPENCV)
find_package( OpenCV REQUIRED )
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
else(OpenCV_FOUND)
set(USE_OPENCV OFF)
message("OpenCV could not be found. Turning OPENCV OFF.")
endif(OpenCV_FOUND)
endif(USE_OPENCV)

所以我在没有 OpenCV 的配置上运行它,我从 CMake 收到消息:“找不到 OpenCV。关闭 OPENCV”。但是,退出屏幕后,我看到 CMake USE_OPENCV 变量仍处于打开状态。我期待它被设置为关闭。

我做错了什么吗?

[编辑]可以产生该行为的完整 CMakeLists 文件是:

project(Test)
cmake_minimum_required(VERSION 2.8)

#OpenCV
option(USE_OPENCV "Use OpenCV data sources" ON)

if(USE_OPENCV)
find_package( OpenCV REQUIRED )
if(OpenCV_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS})
else(OpenCV_FOUND)
set(USE_OPENCV OFF)
message(FATAL_ERROR "OpenCV could not be found. Turning OpenCV OFF.")
endif(OpenCV_FOUND)
endif(USE_OPENCV)

做一些简单而毫无意义的事情,比如:

project(Test2)
cmake_minimum_required(VERSION 2.8)

#OpenCV
option(USE_OPENCV "Use OpenCV data sources" ON)

if(USE_OPENCV)
message("Turn it OFF!")
set(USE_OPENCV OFF)
endif(USE_OPENCV)

即使这样也行不通...

最佳答案

好的,所以必须缓存值。所以,我做了类似的事情:

set(USE_OPENCV OFF CACHE BOOL "ON OFF" FORCE)

这似乎有效。如果有人有更好的解决方案,请更新线程。

关于opencv - CMake:无法设置变量以关闭 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28856877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com