cmake 常用命令,生成可执行文件

#项目的名称
PROJECT(SAMPLE)

#cmake 的版本
cmake_minimum_required(VERSION 2.4)

# 查找是否安装了OpenCV
FIND_PACKAGE(OpenCV REQUIRED )
IF(${OpenCV_VERSION} VERSION_LESS 3.4.5)
    MESSGAE(FATAL_ERROR “OPENCV version is not compatible: ${OpenCV_VERSION}")
ENDIF()


# 设置include文件
INCLUDE_DIRECTORIES(
${OPENCV_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)

# 设置lib 文件
link_directories(${OpenCV_LIBRARY_DIR})


# 设置lib 输出目录
SET( LIBRARY_OUTPUT_PATH  ${SAMPLE_DIR}/../lib CACHE PATH
“Output directory for the sample library"
)

# 设置运行输出目录
SET(EXECUTABLE_OUTPUT_PATH 
${SAMPLE_DIR}/../bin CACHE PATH
“Output directory for the sample executables"
)

# 下一个CmakeLists.txt 文件包含进来
SUBDIRS(
src/ft  #相对路径
)
或着:
add_subdirectory(src/ft)

# lib 文件
SET(ft_sources  ft.hpp  ft_data.hpp  ft_data.cpp)
ADD_LIBRARY(ft ${ft_sources})
TARGET_LINK_LIBRARIES(ft ${OpenCV_LIBS})

#生成执行二进制文件
ADD_EXECUTABLE(main main.cpp context.cpp patten.cpp patten.hpp )
TARGET_LINK_LIBRARIES(main ${OpenCV_LIBS} ft)

#可以有
install(TARGETS main DESTINATION bin) 

你可能感兴趣的:(c-c++,cmake,Makefile)