Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert qmake to cmake?

Tags:

cmake

qt

qmake

I have a .pro file on my project, but now I want to port it to a CMakeLists.txt file. How can I do this?

QT += core
QT -= gui
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QT += network
SOURCES += main.cpp \
    test_interface.cpp \
    motomanlibrary.cpp \
    processing.cpp
SOURCES += main.cpp \
    test_interface.h \
    motomanlibrary.h \
    processing.h
like image 635
Ana Catarina Simões Avatar asked May 03 '17 14:05

Ana Catarina Simões


People also ask

What is difference between qmake and CMake?

CMake is an alternative to qmake for automating the generation of build configurations. Qbs is an all-in-one build tool that generates a build graph from a high-level project description (like qmake or CMake do) and executes the commands in the low-level build graph (like make does).

Is qmake deprecated?

The developers hoped to eventually push for Qbs to replace qmake as Qt's own build system. However, in October 2018 it was deprecated in favor of qmake and/or cmake.

What is qmake file?

qmake provides a number of built-in functions to enable the contents of variables to be processed. The most commonly used function in simple project files is the include() function which takes a filename as an argument.

Does Qt come with CMake?

Introduction. CMake can find and use Qt 4 and Qt 5 libraries. The Qt 4 libraries are found by the FindQt4 find-module shipped with CMake, whereas the Qt 5 libraries are found using "Config-file Packages" shipped with Qt 5.


2 Answers

QMake: The required libraries.

QT += core
QT -= gui
QT += network

CMake: only the add is necessary. An exclude (QT -= gui) is not required.

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 \
    test_interface.cpp \
    motomanlibrary.cpp \
    processing.cpp

CMake: Create a list of source files

set(SOURCES
    main.cpp
    test_interface.cpp
    motomanlibrary.cpp
    processing.cpp
)

QMake: The header to be included:

SOURCES += main.cpp \
    test_interface.h \
    motomanlibrary.h \
    processing.h

CMake: Just show where the header files are.

include_directory(.) #  or include_directory(${CMAKE_CURRENT_SOURCE_DIR})
include_directory(some/where/else)

QMake: The target to be 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 the Qt version

# Should not be necessary
#CONFIG += console
#CONFIG -= app_bundle
#TEMPLATE = app

See further details on Convert qmake to cmake

like image 195
Th. Thielemann Avatar answered Oct 19 '22 07:10

Th. Thielemann


There is a python script to convert QMake to CMake on a WIP branch of Qt Base: https://code.qt.io/cgit/qt/qtbase.git/tree/util/cmake/pro2cmake.py?h=wip/cmake

It will probably be released with Qt 6 when CMake will become the main build system.

like image 28
Andrea Ricchi Avatar answered Oct 19 '22 06:10

Andrea Ricchi