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ù)控:用大數(shù)據(jù)改變商業(yè)、生活和思維方式
- 復(fù)雜性思考:復(fù)雜性科學(xué)和計算模型(原書第2版)
- Developing Mobile Games with Moai SDK
- Access 2007數(shù)據(jù)庫應(yīng)用上機指導(dǎo)與練習(xí)
- 圖解機器學(xué)習(xí)算法
- 算法與數(shù)據(jù)中臺:基于Google、Facebook與微博實踐
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第3版)
- 算法設(shè)計與分析
- 大數(shù)據(jù)分析:R基礎(chǔ)及應(yīng)用
- Spring Boot 2.0 Cookbook(Second Edition)
- Access 2016數(shù)據(jù)庫應(yīng)用基礎(chǔ)
- 云工作時代:科技進化必將帶來的新工作方式
- 數(shù)字化轉(zhuǎn)型方法論:落地路徑與數(shù)據(jù)中臺
- AI Crash Course
- Access 2010數(shù)據(jù)庫應(yīng)用技術(shù)教程(第二版)