瀏覽代碼

Add support for Qt6 (again) (#2281)

* Add Qt6 libraries

* Update xmake.lua

* fontconfig: add ninja dep

* qtbase: add debug print

* Update xmake.lua

* Try to fix Qt6

* qt6: Disable Windows ARM, Android and iOS for now
Jérôme Leclercq 2 年之前
父節點
當前提交
4628fcd76e

+ 1 - 1
packages/f/fontconfig/xmake.lua

@@ -9,7 +9,7 @@ package("fontconfig")
     add_versions("2.13.94", "246d1640a7e54fba697b28e4445f4d9eb63dda1b511d19986249368ee7191882")
     add_versions("2.14.0", "b8f607d556e8257da2f3616b4d704be30fd73bd71e367355ca78963f9a7f0434")
 
-    add_deps("meson", "pkg-config", "freetype >=2.9", "expat")
+    add_deps("meson", "pkg-config", "freetype >=2.9", "expat", "ninja >=1.8.2")
     add_deps("python 3.x", {kind = "binary"})
     if is_plat("macosx") then
         add_deps("gettext")

+ 11 - 0
packages/q/qt6base/xmake.lua

@@ -0,0 +1,11 @@
+package("qt6base")
+    set_kind("phony")
+    set_base("qtbase")
+
+    add_versions("6.3.0", "dummy")
+    add_versions("6.5.1", "dummy")
+    add_versions("6.6.0", "dummy")
+
+    on_install("windows|x64", "linux|x86_64", "macosx|x86_64", "mingw|x86_64", function (package)
+        package:base():script("install")(package)
+    end)

+ 30 - 0
packages/q/qt6core/xmake.lua

@@ -0,0 +1,30 @@
+package("qt6core")
+    set_base("qt6lib")
+    set_kind("library")
+
+    on_load(function (package)
+        package:data_set("libname", "Core")
+        if package:is_plat("android") then
+            package:data_set("syslinks", "z")
+        elseif package:is_plat("iphoneos") then
+            package:data_set("frameworks", {"UIKit", "CoreText", "CoreGraphics", "CoreServices", "CoreFoundation"})
+            package:data_set("syslinks", "z")
+        end
+
+        package:base():script("load")(package)
+    end)
+
+    on_test(function (package)
+        local cxflags
+        if package:is_plat("windows") then
+            cxflags = {"/Zc:__cplusplus", "/permissive-"}
+        else
+            cxflags = "-fPIC"
+        end
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QCoreApplication app (argc, argv);
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++17", cxflags = cxflags}, includes = {"QCoreApplication"}}))
+    end)

+ 34 - 0
packages/q/qt6gui/xmake.lua

@@ -0,0 +1,34 @@
+package("qt6gui")
+    set_base("qt6lib")
+    set_kind("library")
+
+    on_load(function (package)
+        package:add("deps", "qt6core", {debug = package:is_debug(), version = package:version_str()})
+        package:data_set("libname", "Gui")
+
+        if package:is_plat("linux") then 
+            package:add("deps", "freetype", "fontconfig", "libxkbcommon")
+        elseif package:is_plat("android") then
+            package:data_set("syslinks", "GLESv2")
+        elseif package:is_plat("iphoneos") then
+            package:data_set("links", "qtharfbuzz")
+            package:data_set("syslinks", {"qtlibpng", "z"})
+        end
+    
+        package:base():script("load")(package)
+    end)
+
+    on_test(function (package)
+        local cxflags
+        if package:is_plat("windows") then
+            cxflags = {"/Zc:__cplusplus", "/permissive-"}
+        else
+            cxflags = "-fPIC"
+        end
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QGuiApplication app (argc, argv);
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++17", cxflags = cxflags}, includes = {"QGuiApplication"}}))
+    end)

+ 78 - 0
packages/q/qt6lib/xmake.lua

@@ -0,0 +1,78 @@
+package("qt6lib")
+    set_kind("template")
+    set_homepage("https://www.qt.io")
+    set_description("Qt is the faster, smarter way to create innovative devices, modern UIs & applications for multiple screens. Cross-platform software development at its best.")
+    set_license("LGPL-3")
+
+    add_configs("shared", {description = "Download shared binaries.", default = true, type = "boolean", readonly = true})
+    add_configs("vs_runtime", {description = "Set vs compiler runtime.", default = "MD", readonly = true})
+
+    add_versions("6.3.0", "dummy")
+    add_versions("6.5.1", "dummy")
+    add_versions("6.6.0", "dummy")
+
+    on_load(function (package)
+        package:add("deps", "qt6base", {debug = package:is_debug(), version = package:version_str()})
+    end)
+
+    on_fetch(function (package)
+        local qt = package:dep("qt6base"):fetch()
+        if not qt then
+            return
+        end
+
+        local libname = assert(package:data("libname"), "this package must not be used directly")
+
+        local links = table.wrap(package:data("links"))
+        local includedirs = {qt.includedir}
+        local linkname
+        local frameworks
+        if package:is_plat("windows") then
+            linkname = "Qt6" .. libname
+            if package:is_debug() then
+                linkname = linkname .. "d"
+            end
+            table.insert(includedirs, path.join(qt.includedir, "Qt" .. libname))
+        elseif package:is_plat("android") then
+            linkname = "Qt6" .. libname
+            if package:is_arch("x86_64", "x64") then
+                linkname = linkname .. "_x86_64"
+            elseif package:is_arch("arm64", "arm64-v8a") then
+                linkname = linkname .. "_arm64-v8a"
+            elseif package:is_arch("armv7", "armeabi-v7a", "armeabi", "armv7-a", "armv5te") then
+                linkname = linkname .. "_armeabi-v7a"
+            elseif package:is_arch("x86") then
+                linkname = linkname .. "_x86"
+            end
+            table.insert(includedirs, path.join(qt.includedir, "Qt" .. libname))
+        elseif package:is_plat("macosx") then
+            table.insert(includedirs, path.join(qt.libdir, "Qt" .. libname .. ".framework", "Headers"))
+            frameworks = "Qt" .. libname
+        else
+            linkname = "Qt6" .. libname
+            table.insert(includedirs, path.join(qt.includedir, "Qt" .. libname))
+        end
+
+        table.insert(links, 1, linkname)
+        if frameworks then
+            table.join2(frameworks, package:data("frameworks"))
+        else
+            frameworks = package:data("frameworks")
+        end
+
+        return {
+            qtdir = qt,
+            version = qt.version,
+            includedirs = includedirs,
+            links = links,
+            linkdirs = qt.libdir,
+            frameworks = frameworks,
+            frameworkdirs = qt.libdir,
+            syslinks = package:data("syslinks")
+        }
+    end)
+
+    on_install("windows|x64", "linux|x86_64", "macosx|x86_64", "mingw|x86_64", function (package)
+        local qt = package:dep("qt6base"):data("qt")
+        assert(qt, "qt6base is required")
+    end)

+ 42 - 0
packages/q/qt6network/xmake.lua

@@ -0,0 +1,42 @@
+package("qt6network")
+    set_base("qt6lib")
+    set_kind("library")
+
+    on_load(function (package)
+        package:add("deps", "qt6core", {debug = package:is_debug(), version = package:version_str()})
+        package:data_set("libname", "Network")
+
+        if package:is_plat("linux") then
+            -- we need system openssl with evp-kdf
+            -- @see https://github.com/xmake-io/xmake-repo/pull/1057#issuecomment-1069006866
+            if linuxos.name() == "fedora" then
+                package:add("deps", "openssl", {system = true})
+            else
+                package:add("deps", "openssl")
+            end
+        elseif package:is_plat("iphoneos") then
+            package:data_set("frameworks", {"GSS", "IOKit", "Security", "SystemConfiguration"})
+        end
+
+        package:base():script("load")(package)
+    end)
+
+    on_test(function (package)
+        local cxflags
+        if package:is_plat("windows") then
+            cxflags = {"/Zc:__cplusplus", "/permissive-"}
+        else
+            cxflags = "-fPIC"
+        end
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QCoreApplication app(argc, argv);
+
+                QByteArray datagram = "Hello from xmake!";
+                QUdpSocket udpSocket;
+                udpSocket.writeDatagram(datagram, QHostAddress::Broadcast, 45454);
+
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++17", cxflags = cxflags}, includes = {"QCoreApplication", "QByteArray", "QUdpSocket"}}))
+    end)

+ 27 - 0
packages/q/qt6widgets/xmake.lua

@@ -0,0 +1,27 @@
+package("qt6widgets")
+    set_base("qt6lib")
+    set_kind("library")
+
+    on_load(function (package)
+        package:add("deps", "qt6core", "qt6gui", {debug = package:is_debug(), version = package:version_str()})
+        package:data_set("libname", "Widgets")
+
+        package:base():script("load")(package)
+    end)
+
+    on_test(function (package)
+        local cxflags
+        if package:is_plat("windows") then
+            cxflags = {"/Zc:__cplusplus", "/permissive-"}
+        else
+            cxflags = "-fPIC"
+        end
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QApplication app (argc, argv);
+                QPushButton button ("Hello world !");
+                button.show();
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++17", cxflags = cxflags}, includes = {"QApplication", "QPushButton"}}))
+    end)

+ 6 - 3
packages/q/qtbase/xmake.lua

@@ -145,9 +145,11 @@ package("qtbase")
         os.rmdir(path.join(installdir, versionstr))
 
         -- special case for cross-compilation since we need binaries we can run on the host
-        if package:is_plat("mingw") and not is_host("windows") then
+        if package:is_cross() then
             local runhost
-            if is_host("linux") then
+            if is_host("windows") or package:is_plat("mingw") then
+                runhost = "windows"
+            elseif is_host("linux") then
                 runhost = "linux"
             elseif is_host("macosx") then
                 runhost = "mac"
@@ -227,6 +229,7 @@ package("qtbase")
 
         os.vrun(getbin("qmake") .. " -v")
         os.vrun(getbin("moc") .. " -v")
-        os.vrun(getbin("rcc") .. " -v")
+        -- rcc -v and uic -v seems to hang CI forever
+        --os.vrun(getbin("rcc") .. " -v") -- rcc -v hangs CI 
         --os.vrun(getbin("uic") .. " -v") -- uic -v seems to hang on CI
     end)