告诉cmake采取另一个版本的包

时间:2015-07-27 11:52:45

标签: macos cmake homebrew

我通过Homebrew安装了OpenCV和OpenCV3。

OpenCV已链接,可通过cmake

访问
/usr/local/share/OpenCV

OpenCV3未链接且位于此处

/usr/local/Cellar/opencv3/3.0.0

我有这个CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

当我运行cmake时,它使用OpenCV的第一个版本。 如何告诉cmake使用第二个包?

更新

我试着指定

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/Cellar/opencv3/3.0.0/share/OpenCV")
find_package( OpenCV REQUIRED )

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "/usr/local/Cellar/opencv3/3.0.0/share/")
find_package( OpenCV REQUIRED )

但在CMakeCache.txt中,我仍然看到了这一点:

OpenCV_CONFIG_PATH:FILEPATH=/usr/local/share/OpenCV

这又不是我需要的......

谢谢。

2 个答案:

答案 0 :(得分:2)

有几种选择。

选项1

使用:

CMAKE_PREFIX_PATH=/usr/local/Cellar/opencv3  cmake ...

选项2

替换

find_package( OpenCV REQUIRED )

find_package(OpenCV HINTS /usr/local/opt/opencv3 /usr/local/Cellar/opencv3 REQUIRED)

答案 1 :(得分:1)

尝试取消链接opencv并链接opencv3:

> readlink /usr/local/share/OpenCV
  ../Cellar/opencv/2.4.11_2/share/OpenCV
> brew unlink opencv
> brew link opencv3 --force
> readlink /usr/local/share/OpenCV
  ../Cellar/opencv3/3.0.0/share/OpenCV

否则,您可能希望为CMake设置适当的变量:http://www.cmake.org/Wiki/CMake_Useful_Variables