How to convert QMake to CMake

Last changes: 28.10.2017

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




© 2003-2017 th-thielemann.de