Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to point cmake at specific directory for library?

Tags:

I have a CMake project where I am using a library and now I want to test my code with a different version of that library. I can set INCLUDE_DIRECTORIES (and possibly later also linking) in the below example. But because I only want to do this temporarily, I'd like to manually set this path with ccmake/cmake-gui.

How do I do this?

project(min_example)
cmake_minimum_required(VERSION 2.8)

find_package(OpenCV REQUIRED)
# Without the following line please:
INCLUDE_DIRECTORIES("/home/me/src/opencv/install/include")
add_executable(min_example main.cpp)
target_link_libraries(min_example ${OpenCV_LIBS})
like image 882
Unapiedra Avatar asked Aug 11 '11 16:08

Unapiedra


People also ask

Where does CMake look for libraries on Windows?

CMake looks into the paths stored in the ${CMAKE_MODULE_PATH} variable for the files with the find-instructions.


2 Answers

This should be possible by setting the CMAKE_PREFIX_PATH variable upon configuring your build. In your project directory generate a test_build directory and run:

mkdir test_build cd test_build cmake -DCMAKE_PREFIX_PATH=/home/me/src/opencv/install .. 

Setting the CMAKE_PREFIX_PATH variable will make the find_package(OpenCV REQUIRED) command pick your OpenCV installation in /home/me/src/opencv and set the OpenCV_LIBS and OpenCV_INCLUDE_DIR variables accordingly.

Alternatively you can edit a CMakeCache.txt file of an existing build directory with the CMake GUI editor and add the CMAKE_PREFIX_PATH definition there. You have to re-configure your project then.

like image 127
sakra Avatar answered Sep 28 '22 06:09

sakra


Using config in find_package will restrict search path to OpenCV_DIR. This will use the cmake config that opencv generates at build time to setup paths to include and libs

set(OpenCV_DIR "<cusompath>" CACHE PATH '' ${SHOULD_FORCE_CACHE}) find_package(OpenCV REQUIRED CONFIG) 
like image 44
r11 Avatar answered Sep 28 '22 06:09

r11