How to convert QMake to CMake

简介: How to convert QMake to CMake

CMake会成为Qt6重点发展的编译手段。



1、先看官方文档


https://doc.qt.io/qt-5/cmake-manual.html


https://doc.qt.io/qt-5/cmake-get-started.html


https://doc.qt.io/qt-5/cmake-command-reference.html



2、再来看一篇文档《How to convert QMake to CMake》


http://www.th-thielemann.de/development/cmake/cmake_qmake_to_cmake.html


Assume you want to convert the following qmake .pro file to cmake:


QT += core

QT -= gui

CONFIG += c++11

TARGET = test

CONFIG += console

CONFIG -= app_bundle

TEMPLATE = app

QT += network

SOURCES += main.cpp \

   interface.cpp \

   motomanlibrary.cpp \

   processing.cpp

SOURCES += main.cpp \

   interface.h \

   motomanlibrary.h \

   processing.h

Copy the content of your qmake .pro into a CMakeLists.txt and start to convert.


QMake: The required libraries.


QT += core

QT -= gui

QT += network

CMake: only add is necessary. The is no default set. Thus the remove of libraries is not necessary.


find_package(Qt5Core REQUIRED)

find_package(Qt5Network REQUIRED)

QMake: Additional Compiler flags:


CONFIG += c++11

CMake: Extend the list of compiler flags as required


set(CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -std=c++0x")

QMake: The source files


SOURCES += main.cpp \

   interface.cpp \

   library.cpp \

   processing.cpp

CMake: Create a list of source files


set(SOURCES

   main.cpp

   interface.cpp

   library.cpp

   processing.cpp

)

QMake: The header to include:


SOURCES += main.cpp \

   interface.h \

   library.h \

   processing.h

CMake: Just show where the header files are. Add header files without am cpp-file to SOURCES.


include_directory(.) #  or include_directory(${CMAKE_CURRENT_SOURCE_DIR})

QMake: The target to built:


TARGET = test

CMake: Set the name of the target, add the sources, link the required libs.


add_executable(test ${SOURCES} )

qt5_use_modules(test Core Network) # This macro depends from Qt version

# Should not be necessary

#CONFIG += console

#CONFIG -= app_bundle

#TEMPLATE = app


3、最后来看看我在Qt论坛发的帖子


https://forum.qt.io/topic/112403/is-there-a-tool-for-converting-qmake-and-cmake-files-to-each-other-one-click-conversion-easy-to-use


里面有网友说,qt有提供pro2cmake的转换工具:


https://code.qt.io/cgit/qt/qtbase.git/tree/util/cmake/pro2cmake.py


https://code.qt.io/cgit/qt/qtbase.git/tree/util/cmake/run_pro2cmake.py




相关文章
|
Unix 编译器 Linux
CMake Install:深度解析与实践(一)
CMake Install:深度解析与实践
1551 0
|
编译器 API C语言
深入探究Qt与C++标准的兼容之旅
深入探究Qt与C++标准的兼容之旅
1879 3
|
Ubuntu Linux 网络安全
使用Kali Linux虚拟机破解WiFi密码的一波三折及详细操作步骤
使用Kali Linux虚拟机破解WiFi密码的一波三折及详细操作步骤
6000 0
使用Kali Linux虚拟机破解WiFi密码的一波三折及详细操作步骤
|
6月前
|
人工智能 自然语言处理 安全
千问大模型是什么?阿里云千问大模型入门到精通:核心功能、价格配置与实操全解
阿里云千问(通义千问,Qwen)是阿里云自研的全栈式大模型家族,依托百炼平台提供服务,覆盖从个人日常对话到企业级复杂应用的全场景需求。2026年,千问已迭代至Qwen3.7系列,形成旗舰、均衡、轻量、多模态等完整矩阵,具备强中文理解、超长上下文、智能体执行、多模态融合等核心能力,搭配免费试用、按量付费、Token Plan订阅等灵活计费模式,是个人与企业落地AI能力的主流选择。本文从千问大模型的基础定义、核心功能、模型矩阵、价格配置、使用方法与场景选型六大维度,提供全面解析,帮助用户快速理解与高效使用。
2648 0
|
测试技术 应用服务中间件 nginx
解决:http: TLS handshake error from *
今天以容器的形式在公网上一个部署了一个云服务,在测试环境是没有问题的,不知道为什么部署到 beta 环境就出现了问题,导致 https 协议文件访问失败。
8170 0
|
11月前
|
IDE Linux 开发工具
Qt Creator 18.0.2 发布 - Qt、QML 与 C++ 的 跨平台 IDE
Qt Creator 18.0.2 (macOS, Linux, Windows) - Qt、QML 与 C++ 的 跨平台 IDE
754 2
Qt Creator 18.0.2 发布 - Qt、QML 与 C++ 的 跨平台 IDE
WK
|
机器学习/深度学习 人工智能 算法
那C++适合开发哪些项目
C++ 是一种功能强大、应用广泛的编程语言,适合开发多种类型的项目。它在游戏开发、操作系统、嵌入式系统、科学计算、金融、图形图像处理、数据库管理、网络通信、人工智能、虚拟现实、航空航天等领域都有广泛应用。C++ 以其高性能、内存管理和跨平台兼容性等优势,成为众多开发者的选择。
WK
1402 1
|
Ubuntu Java Linux
update-alternatives命令如何使用?
【8月更文挑战第5天】update-alternatives命令如何使用?
2165 5
|
缓存 安全 应用服务中间件
Nginx七层(应用层)反向代理:HTTP反向代理proxy_pass篇(二)
Nginx七层(应用层)反向代理:HTTP反向代理proxy_pass篇(二)
1309 1
|
存储 算法 数据可视化
Python 金融交易实用指南(一)(1)
Python 金融交易实用指南(一)
609 2