Generating a CMake script file
Before we start creating our source file, we are going to generate the CMakeLists.txt file to allow us to compile our project, structure it, and execute it. The following CMake script is simple and basic but enough to compile and generate the executable:
cmake_minimum_required (VERSION 3.0)
PROJECT(Chapter4_Phototool)
set (CMAKE_CXX_STANDARD 11)
# Requires OpenCV
FIND_PACKAGE( OpenCV 4.0.0 REQUIRED )
MESSAGE("OpenCV version : ${OpenCV_VERSION}")
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS})
The first line indicates the minimum CMake version required to generate our project, the second one sets the project name that we can use as the ${PROJECT_NAME} variable, and the third one sets the required C++ version; in our case, we require the C++11 version, as we can see in the next snippet:
cmake_minimum_required (VERSION 3.0)
PROJECT(Chapter4_Phototool)
set (CMAKE_CXX_STANDARD 11)
Moreover, we require the OpenCV library. First, we need to find the library, and then we'll show a message on the OpenCV library version found with the MESSAGE function:
# Requires OpenCV FIND_PACKAGE( OpenCV 4.0.0 REQUIRED ) MESSAGE("OpenCV version : ${OpenCV_VERSION}")
If the library, with a minimum version of 4.0, is found, then we include the headers and library files in our project:
include_directories(${OpenCV_INCLUDE_DIRS}) link_directories(${OpenCV_LIB_DIR})
Now, we only need to add the source files to compile and link with the OpenCV library. The project name variable is used as the executable name, and we use only a single source file, called main.cpp:
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS})
- 同步:秩序如何從混沌中涌現
- 大數據可視化
- 大數據:從概念到運營
- 大話Oracle Grid:云時代的RAC
- Hadoop大數據開發案例教程與項目實戰(在線實驗+在線自測)
- 視覺大數據智能分析算法實戰
- 計算機組裝與維護(微課版)
- 聯動Oracle:設計思想、架構實現與AWR報告
- SIEMENS數控技術應用工程師:SINUMERIK 840D-810D數控系統功能應用與維修調整教程
- MySQL技術內幕:InnoDB存儲引擎
- Node.js High Performance
- Spring Boot 2.0 Cookbook(Second Edition)
- 改進的群智能算法及其應用
- 大數據測試技術:數據采集、分析與測試實踐(在線實驗+在線自測)
- 數據產品經理寶典:大數據時代如何創造卓越產品