//设置最低版本号
cmake_minimum_required(VERSION 3.5)
//设置项目名称
project (hello_headers)
//递归遍历文件夹src中的cpp文件放到变量SOURCES中
file(GLOB_RECURSE SOURCES src/*.cpp)
//设置目标exe名称
add_executable(hello_headers ${SOURCES})
//设置包含文件路径,这里设置了两个路径
target_include_directories(hello_headers
PRIVATE
${PROJECT_SOURCE_DIR}/include
PRIVATE
${PROJECT_SOURCE_DIR}/inc
)
//包含第三方头文件目录
include_directories("D:\\cmake_learn\\MSVC_cmp\\3rdParty\\include")
//链接第三方lib库目录
link_directories("D:\\cmake_learn\\MSVC_cmp\\3rdParty\\lib\\Debug")
//链接第三方库名称
target_link_libraries(main PRIVATE
opencv_calib3d249d
opencv_contrib249d
opencv_core249d
opencv_features2d249d
opencv_flann249d
opencv_gpu249d
opencv_haartraining_engined
opencv_highgui249d
opencv_imgproc249d
opencv_legacy249d
opencv_ml249d
opencv_nonfree249d
opencv_objdetect249d
opencv_ocl249d
opencv_photo249d
opencv_stitching249d
opencv_superres249d
opencv_ts249d
opencv_video249d
opencv_videostab249d
)
cmake_minimum_required(VERSION 3.10)
project(main)
# 引入opencv include 目录
include_directories("D:\\cmake_learn\\MSVC_cmp\\3rdParty\\include")
# 引入opencv lib 目录
link_directories("D:\\cmake_learn\\MSVC_cmp\\3rdParty\\lib\\Debug")
# 添加可执行程序exe名称
add_executable(main main.cpp)
# 链接 opencv 库名称
target_link_libraries(main PRIVATE
opencv_calib3d249d
opencv_contrib249d
opencv_core249d
opencv_features2d249d
opencv_flann249d
opencv_gpu249d
opencv_haartraining_engined
opencv_highgui249d
opencv_imgproc249d
opencv_legacy249d
opencv_ml249d
opencv_nonfree249d
opencv_objdetect249d
opencv_ocl249d
opencv_photo249d
opencv_stitching249d
opencv_superres249d
opencv_ts249d
opencv_video249d
opencv_videostab249d
)
# 设置 exe 输出路径(exe输出到 dll 目录下)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/3rdParty/bin)
# 设置 exe 执行路径(运行时加载 dll )
set(CMAKE_CURRENT_BINARY_DIR ${PROJECT_SOURCE_DIR}/3rdParty/bin)