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})
- 數(shù)據(jù)浪潮
- 有趣的二進(jìn)制:軟件安全與逆向分析
- SQL Server 2008數(shù)據(jù)庫(kù)應(yīng)用技術(shù)(第二版)
- Libgdx Cross/platform Game Development Cookbook
- Mastering Machine Learning with R(Second Edition)
- 數(shù)據(jù)驅(qū)動(dòng):從方法到實(shí)踐
- “互聯(lián)網(wǎng)+”時(shí)代立體化計(jì)算機(jī)組
- LabVIEW 完全自學(xué)手冊(cè)
- 數(shù)據(jù)庫(kù)原理與應(yīng)用
- Splunk智能運(yùn)維實(shí)戰(zhàn)
- SAS金融數(shù)據(jù)挖掘與建模:系統(tǒng)方法與案例解析
- 大數(shù)據(jù)測(cè)試技術(shù):數(shù)據(jù)采集、分析與測(cè)試實(shí)踐(在線實(shí)驗(yàn)+在線自測(cè))
- 數(shù)據(jù)之美:一本書(shū)學(xué)會(huì)可視化設(shè)計(jì)
- 實(shí)用預(yù)測(cè)分析
- Unity 4.x Game AI Programming