Tup
Under Construction |
Introduction
According to the homepage Tup is a file-based build system for Linux, OSX, and Windows. It inputs a list of file changes and a directed acyclic graph (DAG), then processes the DAG to execute the appropriate commands required to update dependent files. Updates are performed with very little overhead since tup implements powerful build algorithms to avoid doing unnecessary work. This means you can stay focused on your project rather than on your build system.
This article is going to show how tup can be used to build Qt GUI projects. Creating a project based on tup primarily evolves around creating and editing a Tupfile followed by some tup commands.
Lets assume the following small Qt project, a QtWidget containing a label, nothing fancy:
main.cpp
#include "mainwindow.hpp"
void MainWindow::initialize() {
setWindowTitle("Small QWidget Example");
QWidget *wCmdBar = new QWidget(this);
QHBoxLayout *layoutCmdBar = new QHBoxLayout;
wCmdBar->setLayout(layoutCmdBar);
mBtnClose = new QPushButton("Close",this);
layoutCmdBar->addStretch();
layoutCmdBar->addWidget(mBtnClose);
QVBoxLayout *layoutCentral = new QVBoxLayout;
mLabelInfo = new QLabel( "This is a label in a QWidget", this );
layoutCentral->addWidget(mLabelInfo);
layoutCentral->addWidget(wCmdBar);
setLayout(layoutCentral);
connect( mBtnClose, SIGNAL(clicked()), this, SLOT(handleQuit()) );
}
void MainWindow::handleQuit() {
if ( QMessageBox::question(this, "Question", "Really quit?") == QMessageBox::Yes ) {
qApp->quit();
}
}
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
MainWindow w;
w.initialize();
w.show();
return app.exec();
}
mainwindow.hpp
#ifndef __mainwindow_hpp
#define __mainwindow_hpp
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>
class MainWindow : public QWidget {
Q_OBJECT
public:
void initialize();
private slots:
void handleQuit();
private:
QPushButton *mBtnClose;
QLabel *mLabelInfo;
};
#endif
When the user clicks the close button a QMessageBox shall ask for confirmation. A slot handle_quit() is responsible for that.
Directory Structure
For this howto the following directory structure is assumed:
. ├── src │ ├── main.cpp │ └── mainwindow.hpp └── Tupfile
The Tupfile
Analogous to a Makefile in a make project for tup we need a Tupfile. Unlike in cmake, qmake or qbs where things like moc files get generated automatically we need to take some extra steps in tup but nothing too difficult.
Create the Tupfile in the root directory of your project and start with some variables for the Qt installation location:
# Change the base directory to your Qt installation
qt_base=/opt/qt5
qt_include_base = $(qt_base)/include
qt_lib = $(qt_base)/lib
I built my own Qt5.8 and installed it to /opt/qt5.