CMakeLists配置模板¶
基本配置¶
cmake_minimum_required(VERSION 3.14)
project(XXX_Project)
# 设置CMAKE版本
set(CMAKE_CXX_STANDARD 14)
# 设置输出目录为 build/bin build/lib 可根据需要追加/${CMAKE_BUILD_TYPE}
set(OUTPUT_DIRECTORY_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY_ROOT}/bin" CACHE PATH "Runtime directory" FORCE)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY_ROOT}/lib" CACHE PATH "Library directory" FORCE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIRECTORY_ROOT}/lib" CACHE PATH "Archive directory" FORCE)
# 添加src子目录
add_subdirectory(src)
依赖库相关配置¶
OpenCV依赖库¶
将OpenCV依赖库下的share/OpenCV中,OpenCVConfig.cmake
复制一份叫FindOpenCV.cmake
,然后在根目录的CMakeLists.txt添加如下配置
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ~/3rdparty/OpenCV-3.4.9/share/OpenCV)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
给执行程序添加链接库
add_executable(XXXXMain main.cpp)
target_link_libraries(XXXXMain ${OpenCV_LIBS})