如何将cmake指向库的特定目录? [英] How to point cmake at specific directory for library?
问题描述
我有一个CMake项目,我使用一个库,现在我想测试我的代码与该库的不同版本。我可以在下面的示例中设置INCLUDE_DIRECTORIES(可能还有以后也链接)。但是因为我只想临时这样做,我想手动设置这个路径与ccmake / cmake-gui。
如何做?
没有下面的行,请:
cmake_minimum_required(VERSION 2.8)
find_package(OpenCV REQUIRED)
#
INCLUDE_DIRECTORIES(/ home / me / src / opencv / install / include)
add_executable(min_example main.cpp)
target_link_libraries(min_example $ {OpenCV_LIBS})
test_build
目录并运行: mkdir test_build
cd test_build
cmake -DCMAKE_PREFIX_PATH = / home / me / src / opencv / install ..
设置 CMAKE_PREFIX_PATH
变量将使 find_package(OpenCV REQUIRED)
命令选择您的OpenCV安装 / home / me / src / opencv
并设置 OpenCV_LIBS
和 OpenCV_INCLUDE_DIR $ c $
或者,您可以使用CMake编辑现有构建目录的 CMakeCache.txt
文件GUI编辑器并添加 CMAKE_PREFIX_PATH
定义。您必须重新配置您的项目。
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})
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.
这篇关于如何将cmake指向库的特定目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!