Skip to content

Commit

Permalink
fix qt5 support for MinGW #31
Browse files Browse the repository at this point in the history
  • Loading branch information
pustotnik committed Feb 16, 2022
1 parent c024833 commit 3cbf73d
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ jobs:
python -m pip install --upgrade aqtinstall
# there is no win64_msvc2019_64 for Qt 5.12.12
aqt install-qt --outputdir C:\Qt windows desktop 5.15.2 win64_msvc2019_64
aqt install-qt --outputdir C:\Qt windows desktop 5.15.2 win64_mingw81
# aqt install-qt --outputdir C:\Qt windows desktop 5.12.12 win64_msvc2017_64
# aqt install-qt --outputdir C:\Qt windows desktop 5.15.2 win64_mingw81
fi
shell: bash

Expand Down
2 changes: 1 addition & 1 deletion demos/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ MS Windows:
- pyyaml (optional)
- msvc (Microsoft Visual C++)
- boost
- qt5 (in C:\Qt)
- qt5 (msvc and mingw versions in C:\Qt)
40 changes: 40 additions & 0 deletions demos/qt5/03-simple-nomsvc/appwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <QToolBar>
#include <QIcon>
#include <QAction>
#include <QMenu>
#include <QMenuBar>
#include <QStatusBar>
#include <QTextEdit>
#include <QApplication>

#include "appwindow.h"

AppWindow::AppWindow()
{
auto* newAct = new QAction(tr("&New"), this);
auto* openAct = new QAction(tr("&Open"), this);
auto* quitAct = new QAction(tr("&Quit"), this);
quitAct->setShortcuts(QKeySequence::Quit);
quitAct->setStatusTip(tr("Exit the application"));

connect(quitAct, &QAction::triggered, qApp, &QApplication::quit);

auto* menu = menuBar()->addMenu(tr("&File"));
menu->addAction(newAct);
menu->addAction(openAct);
menu->addAction(quitAct);

auto* toolbar = addToolBar(tr("Main toolbar"));
toolbar->addAction(newAct);
toolbar->addAction(openAct);
toolbar->addSeparator();
toolbar->addAction(quitAct);

auto* edit = new QTextEdit(this);
edit->setText("Hello, world!");
edit->append(QString("Qt version: ") + qVersion());

setCentralWidget(edit);

statusBar()->showMessage(tr("Ready"));
}
9 changes: 9 additions & 0 deletions demos/qt5/03-simple-nomsvc/appwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <QMainWindow>

class AppWindow : public QMainWindow
{
public:
AppWindow();
};
20 changes: 20 additions & 0 deletions demos/qt5/03-simple-nomsvc/buildconf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

tasks:
main:
features : cxxprogram qt5
source : appwindow.cpp main.cpp
use : QtWidgets

GCC_BASE_FLAGS: -std=c++11 -fPIC

buildtypes:
debug:
cxxflags: $GCC_BASE_FLAGS -O0 -g
toolchain: g++ # force use of gcc

release:
cxxflags: $GCC_BASE_FLAGS -O2
toolchain: g++ # force use of gcc

default: debug

17 changes: 17 additions & 0 deletions demos/qt5/03-simple-nomsvc/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

#include <QApplication>

#include "appwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

AppWindow window;

window.resize(500, 300);
window.setWindowTitle("Simple example");
window.show();

return app.exec();
}
14 changes: 12 additions & 2 deletions src/zenmake/zm/features/qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,20 @@ def _findSingleQt5LibAsIs(conf, qtlibname, qtlibDeps, forceStatic):
qtLibDir = env.QTLIBS
uselib = qtlibname.upper()

isMSVC = conf.env.CXX_NAME == 'msvc'

if forceStatic:
exts = ('.a', '.lib')
envPrefix = 'STLIB'
else:
exts = ('.so', '.lib')
if isMSVC:
exts = ('.lib', )
elif env.DEST_OS == 'win32':
# MinGW g++/clang++
# .a files from mingw version of Qt5 are not static libs
exts = ('.a', )
else:
exts = ('.so', '.lib')
envPrefix = 'LIB'

def libPrefixExt():
Expand All @@ -413,7 +422,8 @@ def setUpLib(prefix, module, ext):
if not _pathexists(_joinpath(qtLibDir, libFileName)):
return False

libval = prefix + basename if env.DEST_OS == 'win32' else basename
#libval = prefix + basename if env.DEST_OS == 'win32' else basename
libval = basename
env.append_unique('%s_%s' % (envPrefix, uselib), libval)
addModuleDefine(module)
return True
Expand Down
2 changes: 2 additions & 0 deletions tests/func_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
RE_ALL_GTK3 = '^gtk3/'
RE_ALL_SDL2 = '^sdl2/'
RE_ALL_QT5 = '^qt5/'
RE_QT5_WINONLY = '^qt5/03-simple-nomsvc'
RE_EXT_DEPS = '^external-deps/'

TEST_CONDITIONS = {
Expand All @@ -48,6 +49,7 @@
dict(regexp = RE_ALL_DBUS, condition = dict( os = ['linux'], )),
dict(regexp = RE_ALL_GTK3, condition = dict( os = ['linux'], )),
dict(regexp = RE_ALL_SDL2, condition = dict( os = ['linux'], )),
dict(regexp = RE_QT5_WINONLY, condition = dict( os = ['windows'], )),
dict(regexp = RE_ALL_QT5, condition = dict( os = ['linux', 'windows'], )),
dict(regexp = RE_EXT_DEPS + '1-makefile',
condition = dict( os = ['linux', 'darwin'], )),
Expand Down

0 comments on commit 3cbf73d

Please sign in to comment.