Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt: enhance cross-compilation support for desktop platforms #6208

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

Doekin
Copy link
Contributor

@Doekin Doekin commented Jan 21, 2025

This PR improves cross-compilation workflows by introducing a new qt-tools package, which provides the essential host tools required for building Qt applications in cross-compilation environments.

Example Usage

For a simple Qt Widgets application created using the command:

xmake create -l c++ -t qt.widgetapp

Update the xmake.lua file as follows:

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")

To build the project for MinGW on Linux, run:

xmake f -c -vD -p mingw

This command will automatically install all required packages, including qt6base, qt6core, qt6gui, and qt-tools.

Alternatively, we can specify a host Qt SDK using the --qt_host option:

xmake f -c -vD -p mingw --qt_host=<host Qt>
  • If the host Qt SDK version matches the target Qt SDK version, the host tools will be used directly.
  • If the versions differ, the qt-tools package will be installed to ensure compatibility.

@Doekin Doekin force-pushed the cross-qt branch 10 times, most recently from 29f31f9 to b2bba4d Compare January 23, 2025 04:56
@Doekin Doekin marked this pull request as ready for review January 23, 2025 09:17
@waruqi waruqi requested a review from SirLynix January 23, 2025 10:10
@SirLynix
Copy link
Member

I'm not sure what qttools package brings here, cross-compilation is supported by qtcore by having it install the tools when cross-compiling, why not just extend this logic?

@Doekin
Copy link
Contributor Author

Doekin commented Jan 23, 2025

The main reasons for using qt-tools are:

  1. Reusing Host Tools: This avoids downloading the full Qt SDK every time we cross-compile for different platforms.
  2. Leveraging Existing SDKs: If a suitable SDK is already installed, it can be detected and used directly, skipping redundant installations.

I hope this clarifies your concerns.

@SirLynix
Copy link
Member

Thanks for the clarification, it seems like a nice change indeed.

@Doekin
Copy link
Contributor Author

Doekin commented Jan 23, 2025

I just noticed a potential issue in both the dev branch and my PR. If qt6base is installed, qt6core, qt6gui, and qt6widgets are considered installed as well, though their dependencies may still be missing. I'll mark my PR as a draft to investigate and address this. Suggestions are welcome—thank you!

@Doekin Doekin marked this pull request as draft January 23, 2025 16:01
@Doekin Doekin marked this pull request as ready for review January 23, 2025 16:48
@Doekin
Copy link
Contributor Author

Doekin commented Jan 23, 2025

If qt6base is installed, qt6core, qt6gui, and qt6widgets are considered installed as well, though their dependencies may still be missing.

Resolved by adding the following check to on_fetch in qt6lib:

for _, dep in ipairs(package:plaindeps()) do
    if not dep:fetch() and dep:parents(package:name()) then
        return
    end
end

@waruqi waruqi merged commit 2619d9f into xmake-io:dev Jan 24, 2025
71 checks passed
@Doekin Doekin deleted the cross-qt branch January 28, 2025 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants