其他分享
首页 > 其他分享> > cmake引入opencv和qt

cmake引入opencv和qt

作者:互联网

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})

标签:set,CMAKE,qt,OpenCV,demo,REQUIRED,opencv,CMake,cmake
来源: https://www.cnblogs.com/lihanqing/p/16625453.html