A sample CMakeLists.txt code
cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE "Release")
# 添加c++ 11标准支持
set(CMAKE_CXX_FLAGS "-std=c++11 -O2")
project(imageBasics)
set(OpenCV_DIR /usr/opencv3/share/OpenCV)
find_package(OpenCV REQUIRED)
include_directories(${
OpenCV_INCLUDE_DIRS})
# message("Opencv_LIBS:"${
OpenCV_LIBS})
add_executable(imageBasics imageBasics.cpp)
# 链接OpenCV库
target_link_libraries(imageBasics ${
OpenCV_LIBS})
add_executable(undistortImage undistortImage.cpp)
# 链接OpenCV库
target_link_libraries(undistortImage ${
OpenCV_LIBS})
we see it
set(OpenCV_DIR /usr/opencv3/share/OpenCV)
This statement sets the location of Opencv_DIR of our cmake project, which is another version of opencv3 that we compiled. When compiling opencv3, customize the location of install.
and then use
find_package(OpenCV REQUIRED)
He can find some files in the OpenCV_DIR directory set earlier, such as OpenCVConfig.cmake, these files will guide Opencv to automatically set the path behind, you can see that the OpenCV_INCLUDE_DIRS behind is automatically set.
At this point, there is no difference from the normal installation.
This is the easiest way! Others are called to change OpenCV_INCLUDE_DIRS, OpenCV_LIBS, too troublesome, just change one OpenCV_DIR, of course, the same is true for other projects, just add in front
set(XXXXXX_DIR .cmake文件所在路径)
on the line