使用CMAKE查找包到开发库

时间:2014-12-20 11:00:33

标签: c++ opencv cmake

这是一个完整的cmake noob问题我确定。

我正在开发一个OpenCV项目,并希望使用最新的beta版本进行测试。如何在不将它们安装到我的系统上的情况下指定beta库?我的beta opencv已成功构建于:

/Users/paul/hacking/robotics/opencv/build/lib/

我目前的cmake基本上已从opencv样本中解除,看起来像这样:

    # cmake for Stereo Vision App
# your opencv/build directory should be in your system PATH

# set minimum required version for cmake
cmake_minimum_required(VERSION 2.8)

# define the project name
set(project_name "Stereo")

# set the project namee
project("${project_name}")

# add opencv package to the project
find_package( OpenCV REQUIRED )
MESSAGE("OpenCV version : ${OpenCV_VERSION}")

# add opencv include directories to the project
include_directories( ${OpenCV_INCLUDE_DIRS} ) 
# add include directory
include_directories (${Stereo_SOURCE_DIR}) 

# add library
add_library( CameraCalibrator CameraCalibrator.cpp)

# add executable
#add_executable( videoprocessing videoprocessing.cpp)
#add_executable( tracking tracking.cpp)
#add_executable( foreground foreground.cpp)
add_executable( calibrate calibrate.cpp)
add_executable( rightsideup rightsideup.cpp)
add_executable( live live.cpp)
add_executable( live2 live2.cpp)
add_executable( stereo-tune stereo-tune.cpp)
add_executable( project project.cpp)
add_executable( stereo_calibrate stereo_calibrate.cpp)
add_executable( capture_two_camera_chessboards capture_two_camera_chessboards.cpp)
add_executable( capture_stereo_chessboards capture_stereo_chessboards.cpp)

# link libraries
#target_link_libraries( videoprocessing ${OpenCV_LIBS})
#target_link_libraries( tracking ${OpenCV_LIBS})
#target_link_libraries( foreground ${OpenCV_LIBS})
target_link_libraries( rightsideup ${OpenCV_LIBS})
target_link_libraries( live ${OpenCV_LIBS})
target_link_libraries( live2 ${OpenCV_LIBS})
target_link_libraries( stereo-tune ${OpenCV_LIBS})
target_link_libraries( project ${OpenCV_LIBS})
target_link_libraries( stereo_calibrate ${OpenCV_LIBS})
target_link_libraries( capture_two_camera_chessboards ${OpenCV_LIBS})
target_link_libraries( capture_stereo_chessboards ${OpenCV_LIBS})
target_link_libraries( calibrate ${OpenCV_LIBS} CameraCalibrator)

我尝试过使用link_libraries并将find包中的版本设置为3.0,但是它总是找到系统安装的库2.4.10

编辑1:

cmake -DPCL_DIR:PATH="../../pcl/build" -DOpenCV_DIR:PATH="../../opencv/build" ..

出于某种原因不适合我。同样,当我尝试在CMake脚本中设置这些变量时,它也不起作用。

set(PCL_DIR "../../pcl/build" CACHE PATH "")
set(OpenCV_DIR "../../opencv/build" CACHE PATH "")

非常感谢! 保罗

2 个答案:

答案 0 :(得分:1)

你正朝着正确的方向前进。除非另有说明,否则cmake的查找脚本首先会查看标准系统路径。每个FIND脚本都有自己的一组cmake变量,您可以设置这些变量来改变行为。

对于FindOpenCV.cmake,它似乎是OPENCV_BASE_DIR。

这是指向某些源代码的链接:

https://github.com/rpavlik/cmake-modules/blob/master/FindOpenCV.cmake

答案 1 :(得分:0)

编辑:

我不完全理解,但以下似乎适用于绝对路径

set(OpenCV_DIR "/Users/paul/hacking/robotics/opencv/build" CACHE PATH "")
set(PCL_DIR "/Users/paul/hacking/robotics/pcl/build" CACHE PATH "")
set(VTK_DIR "/Users/paul/hacking/robotics/VTK/build" CACHE PATH "")

如果命令行错误,至少会出现问题,我不再需要记住执行以下操作:

 OpenCV_DIR=../../opencv/build cmake ..

在PCL文档中,它说要使用:

set(PCL_DIR "/path/to/PCLConfig.cmake")

但这对我没用。