summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-24 00:12:18 +0800
committerruki <[email protected]>2019-02-24 00:12:18 +0800
commit28a830e6baec04094a2f4933421a216c87025272 (patch)
tree0fd98b241f7061138aa84142a6995bcf2d0f1b3a
parent85a7d6d728348b22254abb1a1bf4e5b1402cba2f (diff)
add static qt projects
-rw-r--r--tests/projects/qt/console_static/src/main.cpp9
-rw-r--r--tests/projects/qt/console_static/xmake.lua13
-rw-r--r--tests/projects/qt/quickapp_static/src/main.cpp25
-rw-r--r--tests/projects/qt/quickapp_static/src/main.qml9
-rw-r--r--tests/projects/qt/quickapp_static/src/qml.qrc5
-rw-r--r--tests/projects/qt/quickapp_static/xmake.lua34
-rw-r--r--tests/projects/qt/widgetapp/xmake.lua1
-rw-r--r--tests/projects/qt/widgetapp_static/src/main.cpp11
-rw-r--r--tests/projects/qt/widgetapp_static/src/mainwindow.cpp14
-rw-r--r--tests/projects/qt/widgetapp_static/src/mainwindow.h22
-rw-r--r--tests/projects/qt/widgetapp_static/src/mainwindow.ui24
-rw-r--r--tests/projects/qt/widgetapp_static/xmake.lua39
-rw-r--r--xmake/rules/qt/load.lua38
13 files changed, 237 insertions, 7 deletions
diff --git a/tests/projects/qt/console_static/src/main.cpp b/tests/projects/qt/console_static/src/main.cpp
new file mode 100644
index 000000000..de25444ff
--- /dev/null
+++ b/tests/projects/qt/console_static/src/main.cpp
@@ -0,0 +1,9 @@
+#include <QCoreApplication>
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+
+ printf("hello xmake\n");
+ return a.exec();
+}
diff --git a/tests/projects/qt/console_static/xmake.lua b/tests/projects/qt/console_static/xmake.lua
new file mode 100644
index 000000000..249f52cdd
--- /dev/null
+++ b/tests/projects/qt/console_static/xmake.lua
@@ -0,0 +1,13 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("qt_console")
+
+ -- add rules
+ add_rules("qt.console")
+
+ -- add files
+ add_files("src/*.cpp")
+
diff --git a/tests/projects/qt/quickapp_static/src/main.cpp b/tests/projects/qt/quickapp_static/src/main.cpp
new file mode 100644
index 000000000..05e41f5e1
--- /dev/null
+++ b/tests/projects/qt/quickapp_static/src/main.cpp
@@ -0,0 +1,25 @@
+#include <QGuiApplication>
+#include <QQmlApplicationEngine>
+#include <QQmlExtensionPlugin>
+#include <QtPlugin>
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+
+ QGuiApplication app(argc, argv);
+
+ QQmlApplicationEngine engine;
+
+ Q_IMPORT_PLUGIN(QtQuick2Plugin)
+// Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
+
+ qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2Plugin().instance())->registerTypes("QtQuick");
+ qobject_cast<QQmlExtensionPlugin*>(qt_static_plugin_QtQuick2Plugin().instance()) ->initializeEngine( &engine, "QtQuick");
+
+ engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+ if (engine.rootObjects().isEmpty())
+ return -1;
+
+ return app.exec();
+}
diff --git a/tests/projects/qt/quickapp_static/src/main.qml b/tests/projects/qt/quickapp_static/src/main.qml
new file mode 100644
index 000000000..188049dae
--- /dev/null
+++ b/tests/projects/qt/quickapp_static/src/main.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.9
+import QtQuick.Window 2.2
+
+Window {
+ visible: true
+ width: 640
+ height: 480
+ title: qsTr("Hello World")
+}
diff --git a/tests/projects/qt/quickapp_static/src/qml.qrc b/tests/projects/qt/quickapp_static/src/qml.qrc
new file mode 100644
index 000000000..ca3fce67a
--- /dev/null
+++ b/tests/projects/qt/quickapp_static/src/qml.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>
diff --git a/tests/projects/qt/quickapp_static/xmake.lua b/tests/projects/qt/quickapp_static/xmake.lua
new file mode 100644
index 000000000..03232c822
--- /dev/null
+++ b/tests/projects/qt/quickapp_static/xmake.lua
@@ -0,0 +1,34 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("qt_demo")
+
+ -- add rules
+ add_rules("qt.application")
+
+ -- add headers
+ add_headerfiles("src/*.h")
+
+ -- add files
+ add_files("src/*.cpp")
+ add_files("src/qml.qrc")
+
+ -- add frameworks
+ add_frameworks("QtQuick")
+
+ -- add plugin: platforms
+ add_values("qt.linkdirs", "plugins/platforms")
+ if is_plat("macosx") then
+ add_values("qt.links", "qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "Qt5Widgets", "cups")
+ add_values("qt.plugins", "QCocoaIntegrationPlugin")
+ elseif is_plat("windows") then
+ add_values("qt.links", "Qt5PrintSupport", "Qt5PlatformSupport", "cups")
+ add_values("qt.plugins", "QWindowsIntegrationPlugin")
+ end
+
+ -- add plugin: qml.QtQuick
+ add_values("qt.linkdirs", "qml/QtQuick.2")
+ add_values("qt.links", "qtquick2plugin")
+
diff --git a/tests/projects/qt/widgetapp/xmake.lua b/tests/projects/qt/widgetapp/xmake.lua
index dc052f202..2b0217835 100644
--- a/tests/projects/qt/widgetapp/xmake.lua
+++ b/tests/projects/qt/widgetapp/xmake.lua
@@ -20,3 +20,4 @@ target("qt_demo")
-- add frameworks
add_frameworks("QtWidgets")
+
diff --git a/tests/projects/qt/widgetapp_static/src/main.cpp b/tests/projects/qt/widgetapp_static/src/main.cpp
new file mode 100644
index 000000000..b48f94ec8
--- /dev/null
+++ b/tests/projects/qt/widgetapp_static/src/main.cpp
@@ -0,0 +1,11 @@
+#include "mainwindow.h"
+#include <QApplication>
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainWindow w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/projects/qt/widgetapp_static/src/mainwindow.cpp b/tests/projects/qt/widgetapp_static/src/mainwindow.cpp
new file mode 100644
index 000000000..49d64fce7
--- /dev/null
+++ b/tests/projects/qt/widgetapp_static/src/mainwindow.cpp
@@ -0,0 +1,14 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+
+MainWindow::MainWindow(QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow)
+{
+ ui->setupUi(this);
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
diff --git a/tests/projects/qt/widgetapp_static/src/mainwindow.h b/tests/projects/qt/widgetapp_static/src/mainwindow.h
new file mode 100644
index 000000000..8e06f4918
--- /dev/null
+++ b/tests/projects/qt/widgetapp_static/src/mainwindow.h
@@ -0,0 +1,22 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QWidget *parent = 0);
+ ~MainWindow();
+
+private:
+ Ui::MainWindow *ui;
+};
+
+#endif // MAINWINDOW_H
diff --git a/tests/projects/qt/widgetapp_static/src/mainwindow.ui b/tests/projects/qt/widgetapp_static/src/mainwindow.ui
new file mode 100644
index 000000000..1c59b695e
--- /dev/null
+++ b/tests/projects/qt/widgetapp_static/src/mainwindow.ui
@@ -0,0 +1,24 @@
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow" >
+ <property name="geometry" >
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle" >
+ <string>MainWindow</string>
+ </property>
+ <widget class="QMenuBar" name="menuBar" />
+ <widget class="QToolBar" name="mainToolBar" />
+ <widget class="QWidget" name="centralWidget" />
+ <widget class="QStatusBar" name="statusBar" />
+ </widget>
+ <layoutDefault spacing="6" margin="11" />
+ <pixmapfunction></pixmapfunction>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/projects/qt/widgetapp_static/xmake.lua b/tests/projects/qt/widgetapp_static/xmake.lua
new file mode 100644
index 000000000..b6142ef03
--- /dev/null
+++ b/tests/projects/qt/widgetapp_static/xmake.lua
@@ -0,0 +1,39 @@
+
+-- add modes: debug and release
+add_rules("mode.debug", "mode.release")
+
+-- add target
+target("qt_demo")
+
+ -- add rules
+ add_rules("qt.application")
+
+ -- add headers
+ add_headerfiles("src/*.h")
+
+ -- add files
+ add_files("src/*.cpp")
+ add_files("src/mainwindow.ui")
+
+ -- add files with Q_OBJECT meta (only for qt.moc)
+ add_files("src/mainwindow.h")
+
+ -- add frameworks
+ add_frameworks("QtWidgets")
+
+ -- add plugin: platforms
+ add_values("qt.linkdirs", "plugins/platforms")
+ if is_plat("macosx") then
+ add_values("qt.links", "qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "cups")
+ add_values("qt.plugins", "QCocoaIntegrationPlugin")
+ elseif is_plat("windows") then
+ add_values("qt.links", "Qt5PrintSupport", "Qt5PlatformSupport", "cups")
+ add_values("qt.plugins", "QWindowsIntegrationPlugin")
+ end
+
+ -- add plugin: imageformats.QSvgPlugin (optional)
+ --[[
+ add_values("qt.linkdirs", "plugins/imageformats")
+ add_values("qt.links", "qsvg", "Qt5Svg")
+ add_values("qt.plugins", "QSvgPlugin")
+ ]]
diff --git a/xmake/rules/qt/load.lua b/xmake/rules/qt/load.lua
index f42dccf4a..b8f162672 100644
--- a/xmake/rules/qt/load.lua
+++ b/xmake/rules/qt/load.lua
@@ -23,6 +23,7 @@
--
-- imports
+import("core.project.config")
import("core.project.target")
-- make link for framework
@@ -34,12 +35,12 @@ function _link(framework, major)
return framework
end
--- find the static third-party links from qt link directories, e.g. libqt*.a
-function _find_static_links_3rd(linkdirs)
+-- find the static links from the given qt link directories, e.g. libqt*.a
+function _find_static_links(linkdirs, libpattern)
local links = {}
local debug_suffix = is_plat("windows") and "d" or "_debug"
for _, linkdir in ipairs(linkdirs) do
- for _, libpath in ipairs(os.files(path.join(linkdir, is_plat("windows") and "qt*.lib" or "libqt*.a"))) do
+ for _, libpath in ipairs(os.files(path.join(linkdir, libpattern))) do
local basename = path.basename(libpath)
if (is_mode("debug") and basename:endswith(debug_suffix)) or not basename:endswith(debug_suffix) then
table.insert(links, target.linkname(path.filename(libpath)))
@@ -92,6 +93,30 @@ function main(target, opt)
-- deprecated API in order to know how to port your code away from it.
target:add("defines", "QT_DEPRECATED_WARNINGS")
+ -- add plugins
+ local plugins = target:values("qt.plugins")
+ if plugins then
+ local importfile = path.join(config.buildir(), ".qt", "plugin", target:name(), "static_import.cpp")
+ local file = io.open(importfile, "w")
+ if file then
+ file:print("#include <QtPlugin>")
+ for _, plugin in ipairs(plugins) do
+ file:print("Q_IMPORT_PLUGIN(%s)", plugin)
+ end
+ file:close()
+ target:add("files", importfile)
+ end
+ end
+
+ -- add qt links and directories
+ for _, qt_linkdir in ipairs(target:values("qt.linkdirs")) do
+ local linkdir = path.join(qt.sdkdir, qt_linkdir)
+ if os.isdir(linkdir) then
+ target:add("linkdirs", linkdir)
+ end
+ end
+ target:add("links", target:values("qt.links"))
+
-- add frameworks
if opt.frameworks then
target:add("frameworks", opt.frameworks)
@@ -126,7 +151,7 @@ function main(target, opt)
-- add includedirs, linkdirs
if is_plat("macosx") then
- target:add("frameworks", "DiskArbitration", "IOKit", "CoreFoundation", "CoreGraphics")
+ target:add("frameworks", "DiskArbitration", "IOKit", "CoreFoundation", "CoreGraphics", "OpenGL")
target:add("frameworks", "Carbon", "Foundation", "AppKit", "Security", "SystemConfiguration")
if useframeworks then
target:add("frameworkdirs", qt.linkdirs)
@@ -147,8 +172,7 @@ function main(target, opt)
end
target:add("includedirs", path.join(qt.sdkdir, "mkspecs/macx-clang"))
target:add("linkdirs", qt.linkdirs)
- target:add("linkdirs", path.join(qt.sdkdir, "plugins", "platforms"))
- target:add("links", "qcocoa")
+
elseif is_plat("linux") then
target:set("frameworks", nil)
target:add("includedirs", path.join(qt.sdkdir, "include"))
@@ -169,6 +193,6 @@ function main(target, opt)
end
-- add some static third-party links if exists
- target:add("links", _find_static_links_3rd(qt.linkdirs))
+ target:add("links", _find_static_links(qt.linkdirs, is_plat("windows") and "qt*.lib" or "libqt*.a"))
end