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




相关文章
|
监控 前端开发 JavaScript
Qt Quick调试之道:跟踪、输出与打印信息的全面攻略
Qt Quick调试之道:跟踪、输出与打印信息的全面攻略
1087 0
Qt提升控件类为自定义类
Qt提升控件类为自定义类
564 0
|
5月前
|
前端开发 数据可视化 关系型数据库
如何开发设备管理系统中的设备保修维修板块 ?(附架构图+流程图+代码参考)
设备管理系统中的保修维修模块对提升企业效率至关重要。本文详解该模块的设计与实现,涵盖功能规划、业务流程、开发技巧及效果展示,助力企业高效管理设备维修与报废流程。
|
10月前
|
安全 Shell API
FileCodeBox:像拿快递一样轻松分享文件
FileCodeBox 是一个基于 FastAPI + Vue3 开发的轻量级文件分享工具。它允许用户通过简单的方式分享文本和文件,接收者只需要一个提取码就可以取得文件,就像从快递柜取出快递一样简单。
346 17
FileCodeBox:像拿快递一样轻松分享文件
|
安全 测试技术 C++
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
最近用到了gRPC,配置了很长时间,分享一下配置过程。先来看一下我准备的文件包(资源我放在最后)
Windows下C++使用gRPC(Qt和VS,含文件包和使用方法)
|
小程序 JavaScript API
微信小程序开发学习之页面导航(声明式导航和编程式导航)
这篇文章介绍了微信小程序中页面导航的两种方式:声明式导航和编程式导航,包括如何导航到tabBar页面、非tabBar页面、后退导航,以及如何在导航过程中传递参数和获取传递的参数。
微信小程序开发学习之页面导航(声明式导航和编程式导航)
|
编译器 C语言 C++
VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统---保姆级教程
VSCode上搭建C/C++开发环境(vscode配置c/c++环境)Windows系统---保姆级教程
11783 0
|
缓存 Java 开发工具
简记一个错误
简记一个错误
1304 0
|
C++
Visual Studio 2019 设置手动触发 clang-format 格式化
合作开发时,.clang-format 文件会在编写代码的过程中自动执行格式化,触发某些条件将自动格式化整个文件,有可能导致代码冲突的概率提升,也会造成编码时的不便。
1828 0
Visual Studio 2019 设置手动触发 clang-format 格式化
|
存储 固态存储 安全
NAS打造自己的私有云存储
NAS打造自己的私有云存储
1631 0
NAS打造自己的私有云存储