赞
踩
- #搜索源文件
- file(GLOB_RECURSE PROJECT_SOURCES
- ${PROJECT_SOURCE_DIR}/*.c
- ${PROJECT_SOURCE_DIR}/*.cpp
- ${PROJECT_SOURCE_DIR}/*.cc
- ${PROJECT_SOURCE_DIR}/*.h
- ${PROJECT_SOURCE_DIR}/*.hpp
- ${PROJECT_SOURCE_DIR}/*.ui
- ${PROJECT_SOURCE_DIR}/*.qrc
- ${PROJECT_SOURCE_DIR}/*.rc
- )
- #引入头文件目录
- include_directories(${PROJECT_SOURCE_DIR}/include)
-
- #引入头文件目录:opencv2
- include_directories(${PROJECT_SOURCE_DIR}/include/opencv2)
- //编码设置:指定utf-8编码
- add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
- add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
- find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTSWidgets)
-
- target_link_libraries(examples_rpa PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
//控件类库,添加这个模块可使用Qt基本控件 Widgets //网络模块,可使用这些类,QTcpSocket、QNetworkAccessManager Network //串口模块,可使用这些类,QSerialPort SerialPort //modbus库,可使用这些类,QModbusTcpClient SerialBus //该网络模块,可使用这些类,QWebEngineView WebEngineWidgets //该网络模块,可使用这些类,QMultimedia Multimedia //图表模块,可使用这些类,QChart Charts //音视频模块,视频等播放库 Multimedia MultimediaWidgets // AxContainer
link_libraries链接库文件:方法一
- //这个接口需要放在"add_executable()"前面
-
- //设置库目录路径
- set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib)
- //链接库文件:绝对路径
- link_libraries(${LIBINCLUDE_OPENCV}/opencv_img_hash452d.lib
- ${LIBINCLUDE_OPENCV}/opencv_world452d.lib)
link_libraries链接库文件:方法二
- //这两个接口需要放在"add_executable()"前面
-
- //设置库目录路径
- set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib)
- //添加库目录
- link_directories(${LIBINCLUDE_OPENCV})
- //链接库文件:相对库目录路径
- link_libraries(opencv_img_hash452d.lib opencv_world452d.lib)
target_link_libraries,链接库文件方法一
//这6个接口需要放在"add_executable()"前面 //设置库目录路径 set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib) //设置库目录 set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib) add_library(opencv_img_hash452d STATIC IMPORTED) set_property(TARGET opencv_img_hash452d PROPERTY IMPORTED_LOCATION ${LIBINCLUDE_OPENCV}/opencv_img_hash452d.lib) add_library(opencv_world452d STATIC IMPORTED) set_property(TARGET opencv_world452d PROPERTY IMPORTED_LOCATION ${LIBINCLUDE_OPENCV}/opencv_world452d.lib) //这1个接口需要放在"add_executable()"后面 //链接库文件 target_link_libraries(example_opencvcpp PRIVATE opencv_img_hash452d opencv_world452d )
target_link_libraries,链接库文件方法二
- //这1个接口需要放在"add_executable()"前面
- //设置库目录路径
- set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib)
-
- //这1个接口需要放在"add_executable()"后面
- //链接库文件
- target_link_libraries(example_opencvcpp PRIVATE
- ${LIBINCLUDE_OPENCV}/opencv_img_hash452d.lib
- ${LIBINCLUDE_OPENCV}/opencv_world452d.lib
- )
- //定义全局宏
- add_definitions(-DDEF_OPEN_MACRO)
- #设置库目录路径
- set(LIBINCLUDE_OPENCV ${PROJECT_SOURCE_DIR}/lib)
- //打印日志
- message(STATUS PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR})
- //打印日志:get_directory_property,设置的库目录
- get_directory_property(result LINK_DIRECTORIES)
- message("result: ${result}") # result: /C;/B;/A
- // #target_link_libraries,链接库文件方法一
- // ##设置库目录
- // #add_library(opencv_img_hash452d STATIC IMPORTED)
- // #set_property(TARGET opencv_img_hash452d PROPERTY IMPORTED_LOCATION
- // # ${LIBINCLUDE_OPENCV}/opencv_img_hash452d.lib)
- // #add_library(opencv_world452d STATIC IMPORTED)
- // #set_property(TARGET opencv_world452d PROPERTY IMPORTED_LOCATION
- // # ${LIBINCLUDE_OPENCV}/opencv_world452d.lib)
- // ##链接库文件
- // #target_link_libraries(example_opencvcpp PRIVATE
- // # opencv_img_hash452d opencv_world452d
- // # )
- //打印日志:get_directory_property(获取targer变量的属性)
- get_target_property(result opencv_world452d IMPORTED_LOCATION)
- message("result: ${result}") # result: /C;/B;/A
- //设置编译参数
- add_definitions(/EHa)
- string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
cmake_minimum_required(VERSION 3.5) project(example_opencv VERSION 0.1 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) #定义全局宏 add_definitions(-DDEF_OPEN_MACRO) #编码设置:指定utf-8编码 add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>") add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>") #设置库目录路径:根据debug和release模式选择 if(CMAKE_BUILD_TYPE) string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE) if (${BUILD_TYPE} STREQUAL "debug") set(OPENCVLIBINCLUDE ${PROJECT_SOURCE_DIR}/../lib/x64/debug/opencv2) message("1setLibIncluce: ${BUILD_TYPE}") elseif(${BUILD_TYPE} STREQUAL "release") message("2setLibIncluce: ${BUILD_TYPE}") set(OPENCVLIBINCLUDE ${PROJECT_SOURCE_DIR}/../lib/x64/release/opencv2) else() message("3setLibIncluce: ${BUILD_TYPE}") endif() else() message("11setLibIncluce: ${CMAKE_BUILD_TYPE}") endif() #引入头文件目录 include_directories(${PROJECT_SOURCE_DIR}/../Include) #引入头文件目录:opencv2 include_directories(${PROJECT_SOURCE_DIR}/../Include/opencv2) #搜索源文件 file(GLOB_RECURSE PROJECT_SOURCES ${PROJECT_SOURCE_DIR}/*.c ${PROJECT_SOURCE_DIR}/*.cpp ${PROJECT_SOURCE_DIR}/*.cc ${PROJECT_SOURCE_DIR}/*.h ${PROJECT_SOURCE_DIR}/*.hpp ${PROJECT_SOURCE_DIR}/*.ui ${PROJECT_SOURCE_DIR}/*.qrc ${PROJECT_SOURCE_DIR}/*.rc ) #set(PROJECT_SOURCES CPP_SOURCES) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(example_opencv MANUAL_FINALIZATION ${PROJECT_SOURCES} ) # Define target properties for Android with Qt 6 as: # set_property(TARGET example_opencv APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR # ${CMAKE_CURRENT_SOURCE_DIR}/android) # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation else() if(ANDROID) add_library(example_opencv SHARED ${PROJECT_SOURCES} ) # Define properties for Android with Qt 5 after find_package() calls as: # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") else() add_executable(example_opencv ${PROJECT_SOURCES} ) endif() endif() target_link_libraries(example_opencv PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) #链接库文件:根据debug和release模式选择 if(CMAKE_BUILD_TYPE STREQUAL "Debug") string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE) if (${BUILD_TYPE} STREQUAL "debug") target_link_libraries(example_opencv PRIVATE ${OPENCVLIBINCLUDE}/opencv_img_hash452d.lib ${OPENCVLIBINCLUDE}/opencv_world452d.lib ) message("1target_link_libraries: ${BUILD_TYPE}") elseif(${BUILD_TYPE} STREQUAL "release") #链接库文件:target_link_libraries target_link_libraries(example_opencv PRIVATE ${OPENCVLIBINCLUDE}/opencv_img_hash452.lib ${OPENCVLIBINCLUDE}/opencv_world452.lib ) message("2target_link_libraries: ${BUILD_TYPE}") else() message("3target_link_libraries: ${BUILD_TYPE}") endif() else() message("11target_link_libraries: ${CMAKE_BUILD_TYPE}") endif() set_target_properties(example_opencv PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) if(QT_VERSION_MAJOR EQUAL 6) qt_finalize_executable(example_opencv) endif()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。