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




相关文章
|
4天前
|
Unix C++
在VS2019中CMake生成出现报错
在VS2019中CMake生成出现报错
162 0
在VS2019中CMake生成出现报错
|
6月前
|
Shell C++ Windows
[√]尝试使用cmake编译使用vld
[√]尝试使用cmake编译使用vld
47 0
|
6月前
|
编译器
[√]cmake 编译选项
[√]cmake 编译选项
35 0
|
9月前
问题解决:CMake Error at /home/sjh/anaconda3/lib/cmake/Boost-1.73.0/BoostConfig.cmake:141的问题
问题解决:CMake Error at /home/sjh/anaconda3/lib/cmake/Boost-1.73.0/BoostConfig.cmake:141的问题
296 0
|
11月前
|
机器人 Linux 编译器
替代notepad++,notepad--介绍及插件cmake编译
替代notepad++,notepad--介绍及插件cmake编译
cmake编译出错:No CMAKE_CXX_COMPILER could be found.
cmake编译出错:No CMAKE_CXX_COMPILER could be found.
360 0
CMake教程4:最简单的CMake Library
CMake教程4:最简单的CMake Library
75 0
|
数据可视化 编译器 Windows
CMake“cmake is not able to compile a simple test program”错误 的解决方法
CMake“cmake is not able to compile a simple test program”错误 的解决方法
381 0
|
数据可视化 编译器 Windows
关于 CMake“cmake is not able to compile a simple test program”错误 的解决方法
关于 CMake“cmake is not able to compile a simple test program”错误 的解决方法
关于 CMake“cmake is not able to compile a simple test program”错误 的解决方法
|
IDE 编译器 Linux
浅谈Qt的编译方式:qmake/cmake/qbs及qbs被弃用的原因
浅谈Qt的编译方式:qmake/cmake/qbs及qbs被弃用的原因
1216 0