How to convert qmake to cmake?

I have a file .proin my project, but now I want to transfer it to a file CMakeLists.txt. 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
+14
source share
2 answers

QMake: required libraries.

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

CMake: you only need to add. An exception (QT - = gui) is not required.

find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)

QMake: additional compiler flags:

CONFIG += c++11

CMake: expand the list of compiler flags as needed.

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

QMake: 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: header to include:

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 goal to build:

TARGET = test

CMake: set the name of the target, add sources, link the necessary libraries.

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

. qmake cmake.

+22
+2

Source: https://habr.com/ru/post/1676268/


All Articles