[CMake] Using different installs/versions of the OpenCV library
Bart Vandewoestyne
Bart.Vandewoestyne at telenet.be
Thu Feb 14 06:48:42 EST 2013
On 02/14/2013 12:26 PM, Andreas Haferburg wrote:
> Does CMake find 2.4.3 if you remove 2.3.1? CMake probably doesn't even
> look in /tmp/. You could try moving it to /usr/share/OpenCV-2.4.3/.
>
> If the version arg doesn't work, I think your best bet is to use a
> naming convention for the library directories (or create symlinks), e.g.
> <lib>-<version>-<arch>, then use that directory in the find script.
>
> Andreas
The link_directories() command seems to do the trick...
I'm currently at this, which seems to work:
----------------------------------------------------------------------------
# Change this depending on what you need.
set(USE_TMP_OPENCV TRUE)
if(USE_TMP_OPENCV)
#Manual setting: OpenCV from /tmp/opencv_install
set(OpenCV_INCLUDE_DIR "/tmp/opencv_install/include/opencv")
include_directories(${OpenCV_INCLUDE_DIR})
set(OpenCV_LIBS
"opencv_gpu;opencv_contrib;opencv_legacy;opencv_objdetect;opencv_calib3d;opencv_features2d;opencv_video;opencv_highgui;opencv_ml;opencv_imgproc;opencv_flann;opencv_core")
link_directories(/tmp/opencv_install/lib)
elseif(USE_FAT_OPENCV)
# Manual setting: OpenCV from FAT
set(OpenCV_INCLUDE_DIR "/bla/bla/bla/opencv")
include_directories(${OpenCV_INCLUDE_DIR})
set(OpenCV_LIBS
"opencv_gpu;opencv_contrib;opencv_legacy;opencv_objdetect;opencv_calib3d;opencv_features2d;opencv_video;opencv_highgui;opencv_ml;opencv_imgproc;opencv_flann;opencv_core")
link_directories(/bla/bla/bla/lib)
else()
# Automatic discovery.
find_package( OpenCV REQUIRED )
endif()
----------------------------------------------------------------------------
This still has the disadvantage that I have to change my CMakeLists.txt
each time I want to switch. I would like to be able to switch using
command-line arguments. I tried with cmake -d USE_TMP_OPENCV and stuff
like that, but somehow the wrong version was used if i did not specify a
-D argument (hoping for the automatic discovery). I guess I'll have to
freshen up my understanding of if-elseif-else control flow and
specifying variables on the cmake command line... tim to rtfm! ;-)
Regards,
Bart
More information about the CMake
mailing list