c++ cmakelist 詳解
阿新 • • 發佈:2019-01-10
想要 sam 親測 dpa native 過程 gen diff 日誌庫
基本元素
首先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}