c++ cmakelist 详解
Posted navysummer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++ cmakelist 详解相关的知识,希望对你有一定的参考价值。
基本元素
首先cmaklist必须包括以下几个部分:
#工程名
project(study_case)
#cmake最低版本需求
cmake_minimum_required(VERSION 2.8.3)
#添加添加需要的库
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/usr/local/share/OpenCV")
find_package(OpenCV 3.2.0 REQUIRED)
#确定需要的头文件
include_directories(
include
)
#确定编译语言
#1
set(CMAKE_CXX_STANDARD 11)
#2. or
add_definitions(-std=c++11)
#设置二进制文件目录
SET(BIN_DESTINATION ${PROJECT_SOURCE_DIR}/bin)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_DESTINATION})
#如果多个文件相关,则添加源代码(可选)
set(SRC
${PROJECT_SOURCE_DIR}/src/detector.cpp
${PROJECT_SOURCE_DIR}/src/demo.cpp
${PROJECT_SOURCE_DIR}/src/test.cpp
)
#如果需要编译动态库并链接库文件(可选)
link_directories(${PROJECT_SOURCE_DIR})
add_library(overload SHARED ${SRC})
target_link_libraries(overload -llianghao -lpthread -lm -lstdc++)
#生成可执行文件
link_directories(${PROJECT_SOURCE_DIR})
#添加可执行文件
#1. 如果文件之间没有关联
add_executable(overload src/overload.cpp)
#2. or 如果多个文件相关
add_executable(overload src/overload.cpp ${SRC})