Vyacheslav
Vyacheslav

Reputation: 3244

How to use a build system other than qmake with a Qt project?

In qtcreator a template qt project has a simple .pro configuration file. From .pro file qmake utility generates Makefiles each of which contains lots of includes for every qt dependent source file:

release/moc_MainWindow.cpp: src/controller/Controller.hpp \
...
        ../../../../Qt/5.6/mingw49_32/include/QtWidgets/QMainWindow \
        ../../../../Qt/5.6/mingw49_32/include/QtWidgets/qmainwindow.h \
... 100 lines here ...
        ../../../../Qt/5.6/mingw49_32/include/QtWidgets/qpushbutton.h \
        ../../../../Qt/5.6/mingw49_32/include/QtWidgets/qabstractbutton.h \
        src/view/qt/MainWindow.hpp

I have difficulties configuring .pro files so I decided to configure a qt project with another build system: make, automake, cmake for example.

Is there a way to configure any build system automatically for including lots of qt header files? Or to not include them but build qt project without qtcreator?

My question is different from Using Cmake with Qt Creator because i don't need a qt creator to present to solve my problem

Upvotes: 1

Views: 844

Answers (1)

Velkan
Velkan

Reputation: 7592

My CMake template:

cmake_minimum_required (VERSION 2.8)

project(qttest)
set(PROJECT_VERSION 0.0.1)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -pthread -fno-permissive -pedantic -Wall -Wextra -fPIC")
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

set(QT_VERSION_REQ "5.2")

find_package(Qt5Core ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Quick ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Widgets ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5DBus ${QT_VERSION_REQ} REQUIRED)

set(CMAKE_AUTOMOC ON)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

list(APPEND SOURCES
)

list(APPEND MAIN_SOURCES
    main.cpp
    ${SOURCES}
)

list(APPEND LIBS
    Qt5::Core
    Qt5::Quick
    Qt5::Widgets
    Qt5::DBus
)

add_executable(${PROJECT_NAME} ${MAIN_SOURCES})
target_link_libraries(${PROJECT_NAME} ${LIBS})

Upvotes: 1

Related Questions