wentbackward
wentbackward

Reputation: 546

find-package to a development library using CMAKE

This is a total cmake noob question I'm sure.

I'm working on an OpenCV project and wish to test something using the latest beta release. How can I specify the beta libraries without installing them onto my system? My beta opencv has been successfully built in:

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

My current cmake has basically been lifted from the opencv samples and looks like this:

    # 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)

I've tried using link_libraries and setting the version on the find package line to 3.0, however it always finds the system installed libraries 2.4.10

Edit 1:

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

Is not working for me for some reason. Likewise when I try to set these variables inside the CMake script it also does not work.

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

Many thanks! Paul

Upvotes: 1

Views: 842

Answers (2)

wentbackward
wentbackward

Reputation: 546

Edit:

I don't fully understand, but the following seems to work with absolute paths

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 "")

At least less things to go wrong if I get the command line wrong, I no longer need to remember to do the following:

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

In the PCL documentation it says to use:

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

But this doesn't work for me.

Upvotes: 0

Richard Hodges
Richard Hodges

Reputation: 69854

You're going in the right direction. cmake's Find scripts look in the standard system paths first unless told otherwise. Each FIND script has its own set of cmake variables which you can set to alter the behaviour.

For FindOpenCV.cmake it seems to be OPENCV_BASE_DIR.

Here's a link to some source code:

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

Upvotes: 1

Related Questions