cmake_minimum_required(VERSION 3.14)
project(CMake_demo LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
#设置opencv库目录
set(OpenCV_DIR "C:/opencv/build")
#自动寻找OpenCV依赖
find_package(OpenCV REQUIRED)
#包含头文件目录
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(CMake_demo
main.cpp
test.cpp
)
include_directories(test.h)
target_link_libraries(CMake_demo Qt${QT_VERSION_MAJOR}::Core)
#链接库文件,放到add_executable之后
target_link_libraries(CMake_demo ${OpenCV_LIBS})
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/282231.html