QMake 工程 转换为CMake 工程

2024-06-01 22:48
文章标签 转换 工程 cmake qmake

本文主要是介绍QMake 工程 转换为CMake 工程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

QMake 工程 转换为CMake 工程

源码目录结构

.
├── build.sh
├── businesscontrol.cpp
├── businesscontrol.h
├── globaldef.h
├── lib
│   └── x86_64
├── log
│   ├── LogFileManager.cpp
│   ├── LogFileManager.h
├── main.cpp
├── mqtt
│   ├── mqttclient.cpp
│   ├── mqttclient.h
├── demo.pro
├── CMakeList.txt
├── res
│   ├── closea.png
│   ├── closeb.png
│   ├── close.png
├── tapplication.cpp
├── tapplication.h
├── util
│   ├── json.cpp
│   ├── json.h
└── widget├── mainwidget.cpp├── mainwidget.h

QMake Demo

#-------------------------------------------------
#
# Project created by QtCreator 2021-01-04T09:37:29
#
#-------------------------------------------------QT       += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsTARGET = demo
TEMPLATE = app# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += LINUX_OS_VERSION==$$QT_ARCH
DEFINES += QT_MESSAGELOGCONTEXT# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0message($$QT_ARCH)
message($$QT_VERSION)contains(QT_ARCH, x86_64){message("LINUX_OS_X86_64")DEFINES += LINUX_OS_X86_64
}else{message("LINUX_OS_ARM64")DEFINES += LINUX_OS_ARM64
}exists (../.git) {GIT_BRANCH   = $$system(git rev-parse --abbrev-ref HEAD)GIT_TIME     = $$system(git show --oneline --format=\"%ci%H\" -s HEAD)APP_VERSION = "VersionInfo: $${GIT_BRANCH} : $${GIT_TIME}"
} else {APP_VERSION     = None
}
DEFINES += APP_VERSION=\"\\\"$$APP_VERSION\\\"\"
message($$APP_VERSION)INCLUDEPATH += widget \log\mqtt\utilSOURCES += \main.cpp \tapplication.cpp \log/LogFileManager.cpp \widget/mainwidget.cpp \mqtt/mqttclient.cpp \util/json.cpp \businesscontrol.cpp 
HEADERS += \tapplication.h \widget/mainwidget.h \log/LogFileManager.h \globaldef.h \mqtt/mqttclient.h \util/json.h \businesscontrol.h     
FORMS += \widget/toolbar.ui \#LIBRARY options
QMAKE_CC += -g
QMAKE_CXX += -g
QMAKE_LINK += -gmessage($$PWD)
message($$QT_SYSROOT)INCLUDEPATH += $$QT_SYSROOT/usr/local/include/***** \LIBS +=  -lpaho-mqtt3a DISTFILES +=

CMake Demo

cmake_minimum_required(VERSION 3.5)project(demo LANGUAGES CXX) #项目名,语言 C++set(CMAKE_INCLUDE_CURRENT_DIR ON) #当前include 打开set(CMAKE_AUTOUIC ON)  # ui转换支持打开
set(CMAKE_AUTOMOC ON)  # moc转换支持打开 
set(CMAKE_AUTORCC ON)  # 资源文件支持 打开set(CMAKE_CXX_STANDARD 11) # C++11
set(CMAKE_CXX_STANDARD_REQUIRED ON)# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check https://doc.qt.io/qt/deployment-android.html for more information.
# They need to be set before the find_package( ...) calls below.#if(ANDROID)
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
#    if (ANDROID_ABI STREQUAL "armeabi-v7a")
#        set(ANDROID_EXTRA_LIBS
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
#            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
#    endif()
#endif()set(QT_MESSAGELOGCONTEXT TRUE) # Qt消息打开,默认关闭。需要打开QLog release/debug 消息打印相关
add_definitions(-DQT_MESSAGELOGCONTEXT) #添加QtMessage 宏定义,默认关闭#Git相关(可删除)
set(GIT_COMMIT_HASH "")
set(GIT_BRANCH_NAME "")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(#Format %ci time yyyy-mm-dd hh:mm:ss %H commitIDCOMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ci%HOUTPUT_VARIABLE GIT_COMMIT_HASHOUTPUT_STRIP_TRAILING_WHITESPACEERROR_QUIETWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEADOUTPUT_VARIABLE GIT_BRANCH_NAMEOUTPUT_STRIP_TRAILING_WHITESPACEERROR_QUIETWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
set(APP_VERSION "VersionInfo: ${GIT_BRANCH_NAME}:${GIT_COMMIT_HASH}")
message(STATUS  ${APP_VERSION}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ver.h.ini${CMAKE_BINARY_DIR}/ver.h@ONLY
)
#Git相关,默认没有,可删除#系统信息打印(可删除)
message(STATUS  "cmake-version:" ${CMAKE_VERSION}) #CMake版本信息
message(STATUS  "system_name:" ${CMAKE_HOST_SYSTEM_NAME}) #系统名称
message(STATUS  "system_version:" ${CMAKE_HOST_SYSTEM_PROCESSOR}) #系统版本
message(STATUS  "system_kernel:" ${CMAKE_HOST_SYSTEM_VERSION}) #系统内核版本set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2")if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") #Linux 平台判断 x86还是arm64(可删除)message(STATUS "LINUX_OS_X86_64")set(LINUX_OS_X86_64 TRUE)add_definitions(-DLINUX_OS_X86_64)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AARCH64")message(STATUS "LINUX_OS_ARM64")set(LINUX_OS_ARM64 TRUE)add_definitions(-DLINUX_OS_ARM64)
endif()
#头文件包含
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/widget${CMAKE_CURRENT_SOURCE_DIR}/log${CMAKE_CURRENT_SOURCE_DIR}/mqtt${CMAKE_CURRENT_SOURCE_DIR}/util
)
#系统头文件包含
include_directories(/usr/local/include/****
)
#库查找
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
#源文件包含
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} PROJECT_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/widget WIDGET_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/mqtt MQTT_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/util UTIL_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/log LOG_SOURCES)
#第三方链接库包含
set(PROJECT_LIBSpaho-mqtt3a                    
)
#可执行文件生成
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)qt_add_executable(demo${PROJECT_SOURCES} ${WIDGET_SOURCES} ${MQTT_SOURCES} ${LOG_SOURCES} ${UTIL_SOURCES} ${SPICEUSB_SOURCES})
else()if(ANDROID)add_library(demo SHARED${PROJECT_SOURCES} ${WIDGET_SOURCES} ${MQTT_SOURCES} ${LOG_SOURCES} ${UTIL_SOURCES} ${SPICEUSB_SOURCES})else()add_executable(demo${PROJECT_SOURCES} ${WIDGET_SOURCES} ${MQTT_SOURCES} ${LOG_SOURCES} ${UTIL_SOURCES} ${SPICEUSB_SOURCES})endif()
endif()
#库文件链接
target_link_libraries(demo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${PROJECT_LIBS})

QMake CMake 对照转换表

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
------------------------------------
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Gui REQUIRED)
#find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
TARGET = demo
TEMPLATE = app
------------------------------
project(demo LANGUAGES CXX) #项目名,语言 C++
DEFINES += QT_MESSAGELOGCONTEXT
--------------------------------
set(QT_MESSAGELOGCONTEXT TRUE) # Qt消息打开,默认关闭。需要打开QLog release/debug 消息打印相关
add_definitions(-DQT_MESSAGELOGCONTEXT) #添加QtMessage 宏定义,默认关闭
DEFINES += LINUX_OS_VERSION==$$QT_ARCH
message($$QT_ARCH)
message($$QT_VERSION)contains(QT_ARCH, x86_64){message("LINUX_OS_X86_64")DEFINES += LINUX_OS_X86_64
}else{message("LINUX_OS_ARM64")DEFINES += LINUX_OS_ARM64
}
---------------------------------
message(STATUS  "cmake-version:" ${CMAKE_VERSION}) #CMake版本信息
message(STATUS  "system_name:" ${CMAKE_HOST_SYSTEM_NAME}) #系统名称
message(STATUS  "system_version:" ${CMAKE_HOST_SYSTEM_PROCESSOR}) #系统版本
message(STATUS  "system_kernel:" ${CMAKE_HOST_SYSTEM_VERSION}) #系统内核版本
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") #Linux 平台判断 x86还是arm64message(STATUS "LINUX_OS_X86_64")set(LINUX_OS_X86_64 TRUE)add_definitions(-DLINUX_OS_X86_64)
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AARCH64")message(STATUS "LINUX_OS_ARM64")set(LINUX_OS_ARM64 TRUE)add_definitions(-DLINUX_OS_ARM64)
endif()
exists (../.git) {GIT_BRANCH   = $$system(git rev-parse --abbrev-ref HEAD)GIT_TIME     = $$system(git show --oneline --format=\"%ci%H\" -s HEAD)APP_VERSION = "VersionInfo: $${GIT_BRANCH} : $${GIT_TIME}"
} else {APP_VERSION     = None
}
DEFINES += APP_VERSION=\"\\\"$$APP_VERSION\\\"\"
message($$APP_VERSION)
--------------------------------------------------------------
set(GIT_COMMIT_HASH "")
set(GIT_BRANCH_NAME "")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(#Format %ci time yyyy-mm-dd hh:mm:ss %H commitIDCOMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%ci%HOUTPUT_VARIABLE GIT_COMMIT_HASHOUTPUT_STRIP_TRAILING_WHITESPACEERROR_QUIETWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
execute_process(COMMAND ${GIT_EXECUTABLE} symbolic-ref --short -q HEADOUTPUT_VARIABLE GIT_BRANCH_NAMEOUTPUT_STRIP_TRAILING_WHITESPACEERROR_QUIETWORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif()
set(APP_VERSION "VersionInfo: ${GIT_BRANCH_NAME}:${GIT_COMMIT_HASH}")
message(STATUS  ${APP_VERSION}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ver.h.ini${CMAKE_BINARY_DIR}/ver.h@ONLY
)
INCLUDEPATH += widget \log\mqtt \util
-----------------------------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/widget${CMAKE_CURRENT_SOURCE_DIR}/log${CMAKE_CURRENT_SOURCE_DIR}/mqtt${CMAKE_CURRENT_SOURCE_DIR}/util
)
SOURCES += \main.cpp \tapplication.cpp \log/LogFileManager.cpp \widget/mainwidget.cpp \mqtt/mqttclient.cpp \util/json.cpp \businesscontrol.cpp 
HEADERS += \tapplication.h \widget/mainwidget.h \log/LogFileManager.h \globaldef.h \mqtt/mqttclient.h \util/json.h \businesscontrol.h     
FORMS += \widget/toolbar.ui \
------------------------------------------
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} PROJECT_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/widget WIDGET_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/mqtt MQTT_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/util UTIL_SOURCES)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/log LOG_SOURCES)
#LIBRARY options
QMAKE_CC += -g
QMAKE_CXX += -g
QMAKE_LINK += -g
-----------------------------
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2")
INCLUDEPATH += $$QT_SYSROOT/usr/local/include/***** \
------------------------------------------------------
include_directories(/usr/local/include/****
)
LIBS +=  -lpaho-mqtt3a 
---------------------------
set(PROJECT_LIBSpaho-mqtt3a                    
)

其他的可参考Qt6.0CMake工程生成时默认文件内容。

这篇关于QMake 工程 转换为CMake 工程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1022316

相关文章

Java实现时间与字符串互相转换详解

《Java实现时间与字符串互相转换详解》这篇文章主要为大家详细介绍了Java中实现时间与字符串互相转换的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录一、日期格式化为字符串(一)使用预定义格式(二)自定义格式二、字符串解析为日期(一)解析ISO格式字符串(二)解析自定义

在java中如何将inputStream对象转换为File对象(不生成本地文件)

《在java中如何将inputStream对象转换为File对象(不生成本地文件)》:本文主要介绍在java中如何将inputStream对象转换为File对象(不生成本地文件),具有很好的参考价... 目录需求说明问题解决总结需求说明在后端中通过POI生成Excel文件流,将输出流(outputStre

python+opencv处理颜色之将目标颜色转换实例代码

《python+opencv处理颜色之将目标颜色转换实例代码》OpenCV是一个的跨平台计算机视觉库,可以运行在Linux、Windows和MacOS操作系统上,:本文主要介绍python+ope... 目录下面是代码+ 效果 + 解释转HSV: 关于颜色总是要转HSV的掩膜再标注总结 目标:将红色的部分滤

利用Python开发Markdown表格结构转换为Excel工具

《利用Python开发Markdown表格结构转换为Excel工具》在数据管理和文档编写过程中,我们经常使用Markdown来记录表格数据,但它没有Excel使用方便,所以本文将使用Python编写一... 目录1.完整代码2. 项目概述3. 代码解析3.1 依赖库3.2 GUI 设计3.3 解析 Mark

C语言中的数据类型强制转换

《C语言中的数据类型强制转换》:本文主要介绍C语言中的数据类型强制转换方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C语言数据类型强制转换自动转换强制转换类型总结C语言数据类型强制转换强制类型转换:是通过类型转换运算来实现的,主要的数据类型转换分为自动转换

Java实现XML与JSON的互相转换详解

《Java实现XML与JSON的互相转换详解》这篇文章主要为大家详细介绍了如何使用Java实现XML与JSON的互相转换,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. XML转jsON1.1 代码目的1.2 代码实现2. JSON转XML3. JSON转XML并输出成指定的

Java实现将Markdown转换为纯文本

《Java实现将Markdown转换为纯文本》这篇文章主要为大家详细介绍了两种在Java中实现Markdown转纯文本的主流方法,文中的示例代码讲解详细,大家可以根据需求选择适合的方案... 目录方法一:使用正则表达式(轻量级方案)方法二:使用 Flexmark-Java 库(专业方案)1. 添加依赖(Ma

Java实现将byte[]转换为File对象

《Java实现将byte[]转换为File对象》这篇文章将通过一个简单的例子为大家演示Java如何实现byte[]转换为File对象,并将其上传到外部服务器,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言1. 问题背景2. 环境准备3. 实现步骤3.1 从 URL 获取图片字节数据3.2 将字节数组

Java中数组转换为列表的两种实现方式(超简单)

《Java中数组转换为列表的两种实现方式(超简单)》本文介绍了在Java中将数组转换为列表的两种常见方法使用Arrays.asList和Java8的StreamAPI,Arrays.asList方法简... 目录1. 使用Java Collections框架(Arrays.asList)1.1 示例代码1.

Python使用PIL库将PNG图片转换为ICO图标的示例代码

《Python使用PIL库将PNG图片转换为ICO图标的示例代码》在软件开发和网站设计中,ICO图标是一种常用的图像格式,特别适用于应用程序图标、网页收藏夹图标等场景,本文将介绍如何使用Python的... 目录引言准备工作代码解析实践操作结果展示结语引言在软件开发和网站设计中,ICO图标是一种常用的图像