Create an empty project:
$ xmake create -t qt.console test
$ xmake create -t qt.static test
$ xmake create -t qt.shared test
$ xmake create -t qt.quickapp test
$ xmake create -t qt.widgetapp test
For more project templates see: xmake create --help
xmake will detect Qt SDK automatically and we can also set the SDK directory manually.
$ xmake f --qt=~/Qt/Qt5.9.1
The MingW SDK specified above uses the environment that comes with the Tools directory under Qt. Of course, if there are other third-party MingW compilation environments, they can also be specified manually. For details, please refer to: MingW Configuration.
For more details, please refer to: #160
In addition, currently xmake also supports Qt/Wasm. For details, see: Wasm Configuration
$ xmake f -p wasm
::: tip NOTE
If you are using your own compiled static version of the QT SDK, you need to switch to the add_rules("qt.quickapp_static") static rule,
because the linked libraries are different and need to be statically linked.
:::
Next, we try to compile, usually, if you use the Qt installation package to install by default, and do not modify the installation path, then in most cases you can automatically detect the root path of the QT SDK, for example:
$ xmake
checking for the architecture ... x86_64
checking for the Xcode directory ... /Applications/Xcode.app
checking for the SDK version of Xcode ... 10.15
checking for the Qt SDK directory ... /Users/ruki/Qt5.13.2/5.13.2/clang_64
checking for the Qt SDK version ... 5.13.2
[0%]: cache compiling.release src/main.cpp
[49%]: compiling.qt.qrc src/qml.qrc
[100%]: linking.release test
Build ok!
Then we continue to run it:
$ xmake run
The effect is as follows:
::: tip NOTE
If you are using your own compiled static version of the QT SDK, you need to switch to the add_rules("qt.widgetapp_static") static rule,
because the linked libraries are different and need to be statically linked.
:::
The effect is as follows:
After the 2.2.6 version, you can directly switch to the android platform to compile the Quick/Widgets application, generate the apk package, and install it to the device via the xmake install command.
$ xmake create -t quickapp_qt -l c ++ appdemo
$ cd appdemo
$ xmake f -p android --ndk=~/Downloads/android-ndk-r19c/ --android_sdk=~/Library/Android/sdk/ -c
$ xmake
[0%]: compiling.qt.qrc src/qml.qrc
[ 50%]: cache compiling.release src/main.cpp
[100%]: linking.release libappdemo.so
[100%]: generating.qt.app appdemo.apk
Then install to the device:
$ xmake install
installing appdemo ...
installing build/android/release/appdemo.apk ..
success
install ok!👌
This is usually detected automatically on macos/windows, but it is possible to specify the Qt SDK path manually.
$ xmake f --qt=[qt sdk path]
After installing the Qt SDK using apt, xmake will also be able to detect it automatically.
$ sudo apt install -y qtcreator qtbase5-dev
$ xmake
xmake also supports the Qt Mingw SDK installed from pacman
$ pacman -S mingw-w64-x86_64-qt5 mingw-w64-x86_64-qt-creator
$ xmake
The Qt SDK installed by aqtinstall is based entirely on the official SDK structure and is therefore fully supported by xmake.
However, it is usually necessary to specify the SDK path yourself.
$ xmake f --qt=[Qt SDK]
For cross-platform Qt development, xmake supports using separate SDKs for host tools and the target platform. This is particularly useful when building Qt applications for a different platform than your development machine.
The --qt_host option allows you to specify the location of Qt tools that are compatible with your build machine, while --qt points to the SDK for the target platform:
$ xmake f --qt=[target Qt sdk] --qt_host=[host Qt sdk]
::: tip NOTE
windeployqt and macdeployqt must run on their respective platforms, so cross-platform tasks such as xmake install may fail.
:::xmake now officially provides a variety of modules for both the Qt5 and Qt6 SDKs that can be integrated automatically without any manual installation.
Just configure the integration packages and xmake will automatically handle the Qt installation and integration and compile the project automatically.
add_rules("mode.debug", "mode.release")
add_requires("qt5widgets")
target("test")
add_rules("qt.widgetapp")
add_packages("qt5widgets")
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_rules("mode.debug", "mode.release")
add_requires("qt6widgets")
target("test")
add_rules("qt.widgetapp")
add_packages("qt6widgets")
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")
In addition to the qt6widgets package, the repository also provides qt6gui, qt6network and other Qt6 packages that can be used.
Once configured, simply execute:
$ xmake
There is no time to support it yet, so please try to integrate the Qt SDK in the same way as above.