diff options
| author | ruki <[email protected]> | 2026-08-09 18:25:05 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-08-09 18:25:05 +0800 |
| commit | ced7f2ae519bc9eca92bcf4f177fe177ddd0e747 (patch) | |
| tree | af4d584b3c7badc1df56038cdb29099b4f3e99fd /xmake/templates/c++ | |
| parent | 6ac4ea833193a4319a1eb6e5f588d1877fd48064 (diff) | |
| parent | 5f5daf64c504e1103a355f45bf925a5149b03e24 (diff) | |
Merge pull request #7699 from xmake-io/templates
move templates dir
Diffstat (limited to 'xmake/templates/c++')
54 files changed, 649 insertions, 0 deletions
diff --git a/xmake/templates/c++/console/src/main.cpp b/xmake/templates/c++/console/src/main.cpp new file mode 100644 index 000000000..9b6abffea --- /dev/null +++ b/xmake/templates/c++/console/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char **argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/xmake/templates/c++/console/xmake.lua b/xmake/templates/c++/console/xmake.lua new file mode 100644 index 000000000..c73be8724 --- /dev/null +++ b/xmake/templates/c++/console/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.cpp") + +${FAQ} diff --git a/xmake/templates/c++/module/binary/.gitignore b/xmake/templates/c++/module/binary/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c++/module/binary/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c++/module/binary/modules/binary/bar/.gitignore b/xmake/templates/c++/module/binary/modules/binary/bar/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c++/module/binary/modules/binary/bar/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c++/module/binary/modules/binary/bar/src/add.cpp b/xmake/templates/c++/module/binary/modules/binary/bar/src/add.cpp new file mode 100644 index 000000000..93fdf0ad8 --- /dev/null +++ b/xmake/templates/c++/module/binary/modules/binary/bar/src/add.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a + b); + return 0; +} diff --git a/xmake/templates/c++/module/binary/modules/binary/bar/src/sub.cpp b/xmake/templates/c++/module/binary/modules/binary/bar/src/sub.cpp new file mode 100644 index 000000000..ae7b6d1f2 --- /dev/null +++ b/xmake/templates/c++/module/binary/modules/binary/bar/src/sub.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a - b); + return 0; +} diff --git a/xmake/templates/c++/module/binary/modules/binary/bar/xmake.lua b/xmake/templates/c++/module/binary/modules/binary/bar/xmake.lua new file mode 100644 index 000000000..add3c6e97 --- /dev/null +++ b/xmake/templates/c++/module/binary/modules/binary/bar/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("add") + add_rules("module.binary") + add_files("src/add.cpp") + +target("sub") + add_rules("module.binary") + add_files("src/sub.cpp") + diff --git a/xmake/templates/c++/module/binary/src/main.cpp b/xmake/templates/c++/module/binary/src/main.cpp new file mode 100644 index 000000000..9b6abffea --- /dev/null +++ b/xmake/templates/c++/module/binary/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char **argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/xmake/templates/c++/module/binary/xmake.lua b/xmake/templates/c++/module/binary/xmake.lua new file mode 100644 index 000000000..d73d457d3 --- /dev/null +++ b/xmake/templates/c++/module/binary/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("binary.bar") + print("binary: 1 + 1 = %s", bar.add(1, 1)) + print("binary: 1 - 1 = %s", bar.sub(1, 1)) + end) + +${FAQ} + diff --git a/xmake/templates/c++/module/shared/.gitignore b/xmake/templates/c++/module/shared/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c++/module/shared/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp b/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp new file mode 100644 index 000000000..adde214ca --- /dev/null +++ b/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp @@ -0,0 +1,22 @@ +#include <xmi.h> + +static int add(lua_State *lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a + b); + return 1; +} + +static int sub(lua_State *lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a - b); + return 1; +} + +int luaopen(foo, lua_State *lua) { + static const luaL_Reg funcs[] = { { "add", add }, { "sub", sub }, { NULL, NULL } }; + lua_newtable(lua); + luaL_setfuncs(lua, funcs, 0); + return 1; +} diff --git a/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua b/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..9b3423d41 --- /dev/null +++ b/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + add_rules("module.shared") + add_files("src/foo.cpp") + diff --git a/xmake/templates/c++/module/shared/src/main.cpp b/xmake/templates/c++/module/shared/src/main.cpp new file mode 100644 index 000000000..9b6abffea --- /dev/null +++ b/xmake/templates/c++/module/shared/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char **argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/xmake/templates/c++/module/shared/xmake.lua b/xmake/templates/c++/module/shared/xmake.lua new file mode 100644 index 000000000..43aafe904 --- /dev/null +++ b/xmake/templates/c++/module/shared/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("shared.foo") + print("shared: 1 + 1 = %s", foo.add(1, 1)) + print("shared: 1 - 1 = %s", foo.sub(1, 1)) + end) + +${FAQ} + diff --git a/xmake/templates/c++/qt/console/src/main.cpp b/xmake/templates/c++/qt/console/src/main.cpp new file mode 100644 index 000000000..e876eea4f --- /dev/null +++ b/xmake/templates/c++/qt/console/src/main.cpp @@ -0,0 +1,7 @@ +#include <QCoreApplication> + +int main(int argc, char *argv[]) { + QCoreApplication a(argc, argv); + printf("hello xmake\n"); + return a.exec(); +} diff --git a/xmake/templates/c++/qt/console/xmake.lua b/xmake/templates/c++/qt/console/xmake.lua new file mode 100644 index 000000000..2ce5aa993 --- /dev/null +++ b/xmake/templates/c++/qt/console/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + add_rules("qt.console") + add_files("src/*.cpp") + +${FAQ} diff --git a/xmake/templates/c++/qt/quickapp/src/main.cpp b/xmake/templates/c++/qt/quickapp/src/main.cpp new file mode 100644 index 000000000..7d9cb80df --- /dev/null +++ b/xmake/templates/c++/qt/quickapp/src/main.cpp @@ -0,0 +1,17 @@ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) { +#if QT_VERSION >= 0x50601 + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/xmake/templates/c++/qt/quickapp/src/main.qml b/xmake/templates/c++/qt/quickapp/src/main.qml new file mode 100644 index 000000000..120cdbddd --- /dev/null +++ b/xmake/templates/c++/qt/quickapp/src/main.qml @@ -0,0 +1,18 @@ +import QtQuick 2.6 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.2 + +Window { + id: root + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + Button { + text: "Ok" + onClicked: { + root.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1); + } + } +} + diff --git a/xmake/templates/c++/qt/quickapp/src/qml.qrc b/xmake/templates/c++/qt/quickapp/src/qml.qrc new file mode 100644 index 000000000..5f6483ac3 --- /dev/null +++ b/xmake/templates/c++/qt/quickapp/src/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/xmake/templates/c++/qt/quickapp/xmake.lua b/xmake/templates/c++/qt/quickapp/xmake.lua new file mode 100644 index 000000000..3f71d1c15 --- /dev/null +++ b/xmake/templates/c++/qt/quickapp/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + add_rules("qt.quickapp") + add_headerfiles("src/*.h") + add_files("src/*.cpp") + add_files("src/qml.qrc") + +${FAQ} diff --git a/xmake/templates/c++/qt/quickapp_static/src/main.cpp b/xmake/templates/c++/qt/quickapp_static/src/main.cpp new file mode 100644 index 000000000..7d9cb80df --- /dev/null +++ b/xmake/templates/c++/qt/quickapp_static/src/main.cpp @@ -0,0 +1,17 @@ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) { +#if QT_VERSION >= 0x50601 + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#endif + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/xmake/templates/c++/qt/quickapp_static/src/main.qml b/xmake/templates/c++/qt/quickapp_static/src/main.qml new file mode 100644 index 000000000..120cdbddd --- /dev/null +++ b/xmake/templates/c++/qt/quickapp_static/src/main.qml @@ -0,0 +1,18 @@ +import QtQuick 2.6 +import QtQuick.Window 2.2 +import QtQuick.Controls 2.2 + +Window { + id: root + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + Button { + text: "Ok" + onClicked: { + root.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1); + } + } +} + diff --git a/xmake/templates/c++/qt/quickapp_static/src/qml.qrc b/xmake/templates/c++/qt/quickapp_static/src/qml.qrc new file mode 100644 index 000000000..5f6483ac3 --- /dev/null +++ b/xmake/templates/c++/qt/quickapp_static/src/qml.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> diff --git a/xmake/templates/c++/qt/quickapp_static/xmake.lua b/xmake/templates/c++/qt/quickapp_static/xmake.lua new file mode 100644 index 000000000..0d311a762 --- /dev/null +++ b/xmake/templates/c++/qt/quickapp_static/xmake.lua @@ -0,0 +1,16 @@ +add_rules("mode.debug", "mode.release") + +includes("@builtin/qt") + +target("${TARGET_NAME}") + add_rules("qt.quickapp_static") + add_headerfiles("src/*.h") + add_files("src/*.cpp") + add_files("src/qml.qrc") + add_frameworks("QtQuickControls2", "QtQuickTemplates2") + qt_add_static_plugins("QtQuick2Plugin", {linkdirs = "qml/QtQuick.2", links = "qtquick2plugin"}) + qt_add_static_plugins("QtQuick2WindowPlugin", {linkdirs = "qml/QtQuick/Window.2", links = "windowplugin"}) + qt_add_static_plugins("QtQuickControls2Plugin", {linkdirs = "qml/QtQuick/Controls.2", links = "qtquickcontrols2plugin"}) + qt_add_static_plugins("QtQuickTemplates2Plugin", {linkdirs = "qml/QtQuick/Templates.2", links = "qtquicktemplates2plugin"}) + +${FAQ} diff --git a/xmake/templates/c++/qt/shared/src/demo.cpp b/xmake/templates/c++/qt/shared/src/demo.cpp new file mode 100644 index 000000000..576c861f0 --- /dev/null +++ b/xmake/templates/c++/qt/shared/src/demo.cpp @@ -0,0 +1,4 @@ +#include "demo.h" + +QtDemo::QtDemo() { +} diff --git a/xmake/templates/c++/qt/shared/src/demo.h b/xmake/templates/c++/qt/shared/src/demo.h new file mode 100644 index 000000000..89f29ec46 --- /dev/null +++ b/xmake/templates/c++/qt/shared/src/demo.h @@ -0,0 +1,11 @@ +#ifndef QT_DEMO_H +#define QT_DEMO_H + +#include "demo_global.h" + +class QT_DEMOSHARED_EXPORT QtDemo { + public: + QtDemo(); +}; + +#endif // QT_DEMO_H diff --git a/xmake/templates/c++/qt/shared/src/demo_global.h b/xmake/templates/c++/qt/shared/src/demo_global.h new file mode 100644 index 000000000..d6b1ddf0b --- /dev/null +++ b/xmake/templates/c++/qt/shared/src/demo_global.h @@ -0,0 +1,12 @@ +#ifndef QT_DEMO_GLOBAL_H +#define QT_DEMO_GLOBAL_H + +#include <QtCore/qglobal.h> + +#if defined(QT_DEMO_LIBRARY) +#define QT_DEMOSHARED_EXPORT Q_DECL_EXPORT +#else +#define QT_DEMOSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // QT_DEMO_GLOBAL_H diff --git a/xmake/templates/c++/qt/shared/xmake.lua b/xmake/templates/c++/qt/shared/xmake.lua new file mode 100644 index 000000000..3b07153b9 --- /dev/null +++ b/xmake/templates/c++/qt/shared/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + add_rules("qt.shared") + add_headerfiles("src/*.h") + add_files("src/*.cpp") + add_defines("QT_DEMO_LIBRARY") + add_frameworks("QtGui") + +${FAQ} diff --git a/xmake/templates/c++/qt/static/src/demo.cpp b/xmake/templates/c++/qt/static/src/demo.cpp new file mode 100644 index 000000000..576c861f0 --- /dev/null +++ b/xmake/templates/c++/qt/static/src/demo.cpp @@ -0,0 +1,4 @@ +#include "demo.h" + +QtDemo::QtDemo() { +} diff --git a/xmake/templates/c++/qt/static/src/demo.h b/xmake/templates/c++/qt/static/src/demo.h new file mode 100644 index 000000000..24730c9d8 --- /dev/null +++ b/xmake/templates/c++/qt/static/src/demo.h @@ -0,0 +1,9 @@ +#ifndef QT_DEMO_H +#define QT_DEMO_H + +class QtDemo { + public: + QtDemo(); +}; + +#endif // QT_DEMO_H diff --git a/xmake/templates/c++/qt/static/xmake.lua b/xmake/templates/c++/qt/static/xmake.lua new file mode 100644 index 000000000..371bdf082 --- /dev/null +++ b/xmake/templates/c++/qt/static/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + add_rules("qt.static") + add_headerfiles("src/*.h") + add_files("src/*.cpp") + add_frameworks("QtGui") + +${FAQ} diff --git a/xmake/templates/c++/qt/widgetapp/src/main.cpp b/xmake/templates/c++/qt/widgetapp/src/main.cpp new file mode 100644 index 000000000..191ae18d2 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp/src/main.cpp @@ -0,0 +1,9 @@ +#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/xmake/templates/c++/qt/widgetapp/src/mainwindow.cpp b/xmake/templates/c++/qt/widgetapp/src/mainwindow.cpp new file mode 100644 index 000000000..c9c6a0d98 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp/src/mainwindow.cpp @@ -0,0 +1,10 @@ +#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/xmake/templates/c++/qt/widgetapp/src/mainwindow.h b/xmake/templates/c++/qt/widgetapp/src/mainwindow.h new file mode 100644 index 000000000..a4245aa42 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp/src/mainwindow.h @@ -0,0 +1,21 @@ +#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/xmake/templates/c++/qt/widgetapp/src/mainwindow.ui b/xmake/templates/c++/qt/widgetapp/src/mainwindow.ui new file mode 100644 index 000000000..1c59b695e --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp/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/xmake/templates/c++/qt/widgetapp/xmake.lua b/xmake/templates/c++/qt/widgetapp/xmake.lua new file mode 100644 index 000000000..e0f9f455e --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGET_NAME}") + add_rules("qt.widgetapp") + add_headerfiles("src/*.h") + add_files("src/*.cpp") + add_files("src/mainwindow.ui") + -- add files with Q_OBJECT meta (only for qt.moc) + add_files("src/mainwindow.h") + +${FAQ} diff --git a/xmake/templates/c++/qt/widgetapp_static/src/main.cpp b/xmake/templates/c++/qt/widgetapp_static/src/main.cpp new file mode 100644 index 000000000..db5b0cce8 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp_static/src/main.cpp @@ -0,0 +1,10 @@ +#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/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.cpp b/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.cpp new file mode 100644 index 000000000..c9c6a0d98 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.cpp @@ -0,0 +1,10 @@ +#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/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.h b/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.h new file mode 100644 index 000000000..a4245aa42 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.h @@ -0,0 +1,21 @@ +#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/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.ui b/xmake/templates/c++/qt/widgetapp_static/src/mainwindow.ui new file mode 100644 index 000000000..1c59b695e --- /dev/null +++ b/xmake/templates/c++/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/xmake/templates/c++/qt/widgetapp_static/xmake.lua b/xmake/templates/c++/qt/widgetapp_static/xmake.lua new file mode 100644 index 000000000..2c357e531 --- /dev/null +++ b/xmake/templates/c++/qt/widgetapp_static/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +includes("@builtin/qt") + +target("${TARGET_NAME}") + add_rules("qt.widgetapp_static") + add_headerfiles("src/*.h") + 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 plugin: QSvgPlugin (optional) + add_frameworks("QtSvg") + qt_add_static_plugins("QSvgPlugin", {linkdirs = "plugins/imageformats", links = {"qsvg"}}) + +${FAQ} diff --git a/xmake/templates/c++/shared/src/foo.cpp b/xmake/templates/c++/shared/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/xmake/templates/c++/shared/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/xmake/templates/c++/shared/src/foo.h b/xmake/templates/c++/shared/src/foo.h new file mode 100644 index 000000000..bd496c784 --- /dev/null +++ b/xmake/templates/c++/shared/src/foo.h @@ -0,0 +1,17 @@ +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) +#define __export __declspec(dllexport) +#elif defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) +#define __export __attribute__((visibility("default"))) +#else +#define __export +#endif + +__export int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/c++/shared/src/main.cpp b/xmake/templates/c++/shared/src/main.cpp new file mode 100644 index 000000000..3834ee4d3 --- /dev/null +++ b/xmake/templates/c++/shared/src/main.cpp @@ -0,0 +1,7 @@ +#include "foo.h" +#include <iostream> + +int main(int argc, char **argv) { + std::cout << "add(1, 2) = " << add(1, 2) << std::endl; + return 0; +} diff --git a/xmake/templates/c++/shared/xmake.lua b/xmake/templates/c++/shared/xmake.lua new file mode 100644 index 000000000..96bd36d7c --- /dev/null +++ b/xmake/templates/c++/shared/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + set_kind("shared") + add_files("src/foo.cpp") + +target("${TARGET_NAME}") + set_kind("binary") + add_deps("foo") + add_files("src/main.cpp") + +${FAQ} diff --git a/xmake/templates/c++/static/src/foo.cpp b/xmake/templates/c++/static/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/xmake/templates/c++/static/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/xmake/templates/c++/static/src/foo.h b/xmake/templates/c++/static/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/xmake/templates/c++/static/src/foo.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/xmake/templates/c++/static/src/main.cpp b/xmake/templates/c++/static/src/main.cpp new file mode 100644 index 000000000..3834ee4d3 --- /dev/null +++ b/xmake/templates/c++/static/src/main.cpp @@ -0,0 +1,7 @@ +#include "foo.h" +#include <iostream> + +int main(int argc, char **argv) { + std::cout << "add(1, 2) = " << add(1, 2) << std::endl; + return 0; +} diff --git a/xmake/templates/c++/static/xmake.lua b/xmake/templates/c++/static/xmake.lua new file mode 100644 index 000000000..2c15d36e8 --- /dev/null +++ b/xmake/templates/c++/static/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + set_kind("static") + add_files("src/foo.cpp") + +target("${TARGET_NAME}") + set_kind("binary") + add_deps("foo") + add_files("src/main.cpp") + +${FAQ} diff --git a/xmake/templates/c++/wxwidgets/src/main.cpp b/xmake/templates/c++/wxwidgets/src/main.cpp new file mode 100644 index 000000000..4b43fe6e3 --- /dev/null +++ b/xmake/templates/c++/wxwidgets/src/main.cpp @@ -0,0 +1,48 @@ +#include <wx/wx.h> + +namespace Examples { +class Frame : public wxFrame { + enum wxOwnedID { + ID_Hello = 2 + }; + + public: + Frame() : wxFrame(nullptr, wxID_ANY, "Hello World") { + auto menuFile = new wxMenu(); + menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", "Help string shown in status bar for this menu item"); + menuFile->AppendSeparator(); + menuFile->Append(wxID_EXIT); + + auto menuHelp = new wxMenu(); + menuHelp->Append(wxID_ABOUT); + auto menuBar = new wxMenuBar(); + + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuHelp, "&Help"); + SetMenuBar(menuBar); + + CreateStatusBar(); + SetStatusText("Welcome to wxWidgets!"); + + menuBar->Bind(wxEVT_MENU, [&](wxCommandEvent &event) { + if (event.GetId() == ID_Hello) + wxLogMessage("Hello world from wxWidgets!"); + else if (event.GetId() == wxID_ABOUT) + wxMessageBox("This is a wxWidgets Hello World example", "About Hello World", wxOK | wxICON_INFORMATION); + else if (event.GetId() == wxID_EXIT) + Close(true); + else + event.Skip(); + }); + } +}; + +class Application : public wxApp { + bool OnInit() override { + (new Frame())->Show(); + return true; + } +}; +} // namespace Examples + +wxIMPLEMENT_APP(Examples::Application);
\ No newline at end of file diff --git a/xmake/templates/c++/wxwidgets/xmake.lua b/xmake/templates/c++/wxwidgets/xmake.lua new file mode 100644 index 000000000..65a05c72c --- /dev/null +++ b/xmake/templates/c++/wxwidgets/xmake.lua @@ -0,0 +1,11 @@ +add_rules("mode.debug", "mode.release") + +add_requires("wxwidgets") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.cpp") + set_languages("c++14") + add_packages("wxwidgets") + +${FAQ}
\ No newline at end of file diff --git a/xmake/templates/c++/xmake/cli/src/lni/main.cpp b/xmake/templates/c++/xmake/cli/src/lni/main.cpp new file mode 100644 index 000000000..6dd5b81b1 --- /dev/null +++ b/xmake/templates/c++/xmake/cli/src/lni/main.cpp @@ -0,0 +1,23 @@ +extern "C" { +#include <xmake/xmake.h> + +extern tb_byte_t const _binary_luafiles_xmz_start[]; +extern tb_byte_t const _binary_luafiles_xmz_end[]; +} + +static tb_int_t lni_test_hello(lua_State *lua) { + lua_pushliteral(lua, "hello xmake!"); + return 1; +} + +static tb_void_t lni_initalizer(xm_engine_ref_t engine, lua_State *lua) { + static luaL_Reg const lni_test_funcs[] = { { "hello", lni_test_hello }, { tb_null, tb_null } }; + xm_engine_register(engine, "test", lni_test_funcs); + xm_engine_add_embedfiles(engine, _binary_luafiles_xmz_start, + (tb_size_t)(_binary_luafiles_xmz_end - _binary_luafiles_xmz_start)); +} + +tb_int_t main(tb_int_t argc, tb_char_t **argv) { + tb_char_t *taskargv[] = { "lua", "-D", "lua.main", tb_null }; + return xm_engine_run("${TARGET_NAME}", argc, argv, taskargv, lni_initalizer); +} diff --git a/xmake/templates/c++/xmake/cli/src/lua/main.lua b/xmake/templates/c++/xmake/cli/src/lua/main.lua new file mode 100644 index 000000000..d87daf102 --- /dev/null +++ b/xmake/templates/c++/xmake/cli/src/lua/main.lua @@ -0,0 +1,10 @@ +import("core.base.option") +import("lib.lni.test") + +function main () + print(test.hello()) + local argv = option.get("arguments") + if argv then + print(argv) + end +end diff --git a/xmake/templates/c++/xmake/cli/xmake.lua b/xmake/templates/c++/xmake/cli/xmake.lua new file mode 100644 index 000000000..cf1987c60 --- /dev/null +++ b/xmake/templates/c++/xmake/cli/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +add_requires("libxmake") + +target("${TARGET_NAME}") + add_rules("xmake.cli") + add_files("src/lni/*.cpp") + add_files("src/lua/*.lua", {rootdir = "src"}) + add_packages("libxmake") + +${FAQ} + |
