cmake find_package指定路径 [英] cmake find_package specify path
问题描述
我的机器上安装了2个版本的OpenCV. /usr/local/opencv3.1
中有一个.我假设另一个(版本3.4)的安装位置是/usr/local
.无论如何,find_package(OpenCV 3.0 REQUIRED)
设置OpenCV_DIR:PATH=/usr/local/share/OpenCV
.该文件夹包含:
I have 2 versions of OpenCV installed on my machine. One is in /usr/local/opencv3.1
. I presume the install location of the other one (version 3.4) is /usr/local
. Anyway, find_package(OpenCV 3.0 REQUIRED)
sets OpenCV_DIR:PATH=/usr/local/share/OpenCV
. This folder contains:
haarcascades OpenCVConfig.cmake OpenCVModules-release.cmake
java OpenCVConfig-version.cmake valgrind_3rdparty.supp
lbpcascades OpenCVModules.cmake valgrind.supp
在这种情况下,使用版本3.4.在知道其安装位置的情况下,如何在CMakeLists.txt中指定使用其他版本(3.1)?我尝试过:
In this case, version 3.4 is used. How can I specify in CMakeLists.txt to use the other version (3.1) knowing its install location? I've tried:
find_package(OpenCV 3.0 REQUIRED PATH /usr/local/opencv3.1)
哪个返回错误:
Could NOT find OpenCV (missing: PATH /usr/local/opencv3.1) (found suitable version "3.4.1", minimum required is "3.0")
和
set(OpenCV_DIR /usr/local/opencv3.1/OpenCV/*) # also tried OpenCV_ROOT_DIR, OPENCV_ROOT_DIR
find_package(OpenCV 3.0 REQUIRED)
什么都不做.仍然可以找到版本3.4.我将不胜感激.谢谢.
Which does nothing. It still finds version 3.4. I'd be grateful for any help. Thank you.
推荐答案
In the find_package documentation you have that you can set a path to be searched with PATHS
you were missing the S... also you can do something like:
find_package (<package> PATHS paths... NO_DEFAULT_PATH)
find_package (<package>)
这将检查您首先编写的路径,如果找到,则将其设置为true,然后跳过第二条指令.
Which will check for the path you wrote first, the if it is found it will set found to true and the second instruction will be skipped.
此外,您可以使用EXACT
选项来匹配特定版本,以防它由于是较新版本而试图选择3.4.
Also, you can use the EXACT
option to match an specific version, in case it tries to select 3.4 due to being a newer version.
find_package(OpenCV 3.1 EXACT REQUIRED PATHS /usr/local/opencv3.1)
我希望这会有所帮助,如果不能的话,请写评论
I hope this helps, if not, write a comment
这篇关于cmake find_package指定路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!