Jelajahi Sumber

Add Qt5 packages (using aqt installer) (#1031)

* Add Qt5 packages (using aqt installer)

* Improve qt5 packages

* Revert usage of find_qt (can't work with mingw)

* Fix Qt for android and mingw@macosx

* Improve Qt

* Qt: fix android

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

Co-authored-by: ruki <[email protected]>
Jérôme Leclercq 3 tahun lalu
induk
melakukan
a5f86837ce

+ 1 - 1
packages/a/aqt/xmake.lua

@@ -25,7 +25,7 @@ package("aqt")
             os.mv(package:originfile(), path.join(package:installdir("bin"), "aqt.exe"))
         else
             -- ensurepip has been dropped in recent releases
-            try{function () os.vrunv("python3", {"-m", "ensurepip"}) end}
+            try {function () os.vrunv("python3", {"-m", "ensurepip"}) end}
 
             os.vrunv("python3", {"-m", "pip", "install", "-U", "pip"})
             os.vrunv("python3", {"-m", "pip", "install", "aqtinstall"})

+ 217 - 0
packages/q/qt5base/xmake.lua

@@ -0,0 +1,217 @@
+local function qt_table(sdkdir, version)
+    return {
+        version = version,
+        sdkdir = sdkdir,
+        sdkver = version,
+        bindir = path.join(sdkdir, "bin"),
+        includedir = path.join(sdkdir, "include"),
+        libdir = path.join(sdkdir, "lib"),
+        libexecdir = path.join(sdkdir, "libexec"),
+        mkspecsdir = path.join(sdkdir, "mkspecs"),
+        qmldir = path.join(sdkdir, "qml"),
+        pluginsdir = path.join(sdkdir, "plugins")
+    }
+end
+
+package("qt5base")
+    set_kind("phony")
+    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("5.15.2", "dummy")
+    add_versions("5.12.5", "dummy")
+
+    add_deps("aqt")
+
+    on_fetch(function (package, opt)
+        import("core.base.semver")
+        import("core.cache.localcache")
+        import("detect.sdks.find_qt")
+
+        local qt = package:data("qt")
+        if qt then
+            return qt
+        end
+
+        if os.isfile(package:manifest_file()) then
+            local installdir = package:installdir()
+            local qt = qt_table(installdir, package:version():shortstr())
+            package:data_set("qt", qt)
+            return qt
+        end
+
+        if not opt.system then
+            return
+        end
+
+        local qt = find_qt()
+        if not qt then
+            return
+        end
+
+        local qtversion = semver.new(qt.sdkver)
+        if not qtversion:satisfies("5.x") then
+            return
+        end
+        qt.version = qt.sdkver
+        package:data_set("qt", qt)
+        return qt
+    end)
+
+    on_install("windows", "linux", "macosx", "mingw", "android", "iphoneos", function (package)
+        import("core.base.semver")
+        import("core.project.config")
+        import("core.tool.toolchain")
+
+        local version = package:version()
+
+        local host
+        if is_host("windows") or package:is_plat("mingw") then
+            host = "windows"
+        elseif is_host("linux") then
+            host = "linux"
+        elseif is_host("macosx") then
+            host = "mac"
+        else
+            raise("unhandled host " .. os.host())
+        end
+
+        local target
+        if package:is_plat("windows", "mingw", "linux", "macosx") then
+            target = "desktop"
+        elseif package:is_plat("android") then
+            target = "android"
+        elseif package:is_plat("iphoneos") then
+            target = "ios"
+        else
+            raise("unhandled plat " .. package:plat())
+        end
+
+        local arch
+        if package:is_plat("windows", "mingw") then
+            local winarch
+            if package:is_arch("x64", "x86_64") then
+                winarch = "64"
+            elseif package:is_arch("x86", "i386") then
+                winarch = "32"
+            else
+                raise("unhandled arch " .. package:targetarch())
+            end
+
+            local compiler_version
+            if package:is_plat("windows") then
+                local vs = toolchain.load("msvc"):config("vs")
+                if tonumber(vs) >= 2019 then
+                    compiler_version = "msvc2019"
+                elseif vs == "2017" or vs == "2015" then
+                    compiler_version = "msvc" .. vs
+                else
+                    raise("unhandled msvc version " .. vs)
+                end
+
+                if package:is_arch("x64", "x86_64") then
+                    compiler_version = compiler_version .. "_64"
+                end
+            else
+                local cc = package:tool("cc")
+                local version = os.iorunv(cc, {"-dumpversion"}):trim()
+                local mingw_version = semver.new(version)
+                if mingw_version:ge("8.1") then
+                    compiler_version = "mingw81"
+                elseif mingw_version:ge("7.3") then
+                    compiler_version = "mingw73"
+                elseif mingw_version:ge("5.3") then
+                    compiler_version = "mingw53"
+                else
+                    raise("unhandled mingw version " .. version)
+                end
+            end
+            arch = "win" .. winarch .. "_" .. compiler_version
+        elseif package:is_plat("linux") then
+            arch = "gcc_64"
+        elseif package:is_plat("macosx") then
+            arch = "clang_64"
+        elseif package:is_plat("android") then
+            if package:version():le("5.13") then
+                if package:is_arch("x86_64", "x64") then
+                    arch = "android_x86_64"
+                elseif package:is_arch("arm64", "arm64-v8a") then
+                    arch = "android_arm64_v8a"
+                elseif package:is_arch("armv7", "armv7-a") then
+                    arch = "android_armv7"
+                elseif package:is_arch("x86") then
+                    arch = "android_x86"
+                end
+            else
+                arch = "android"
+            end
+        end
+
+        local installdir = package:installdir()
+        os.vrunv("aqt", {"install-qt", "-O", installdir, host, target, version:shortstr(), arch})
+
+        -- move files to root
+        local subdirs = {}
+        if package:is_plat("linux") then
+            table.insert(subdirs, package:is_arch("x86_64") and "gcc_64" or "gcc_32")
+            table.insert(subdirs, package:is_arch("x86_64") and "clang_64" or "clang_32")
+        elseif package:is_plat("macosx") then
+            table.insert(subdirs, package:is_arch("x86_64") and "clang_64" or "clang_32")
+        elseif package:is_plat("windows") then
+            local vs = config.get("vs")
+            if vs then
+                table.insert(subdirs, package:is_arch("x64") and "msvc" .. vs .. "_64" or "msvc" .. vs .. "_32")
+                table.insert(subdirs, "msvc" .. vs)
+            end
+            table.insert(subdirs, package:is_arch("x64") and "msvc*_64" or "msvc*_32")
+            table.insert(subdirs, "msvc*")
+        elseif package:is_plat("mingw") then
+            table.insert(subdirs, package:is_arch("x86_64") and "mingw*_64" or "mingw*_32")
+        elseif package:is_plat("android") then
+            local subdir
+            if package:is_arch("arm64-v8a") then
+                subdir = "android_arm64_v8a"
+            elseif package:is_arch("armeabi-v7a", "armeabi", "armv7-a", "armv5te") then -- armv7-a/armv5te are deprecated
+                subdir = "android_armv7"
+            elseif package:is_arch("x86", "i386") then -- i386 is deprecated
+                subdir = "android_x86"
+            elseif package:is_arch("x86_64") then
+                subdir = "android_x86_64"
+            end
+            if subdir then
+                table.insert(subdirs, subdir)
+            end
+            table.insert(subdirs, "android")
+        elseif package:is_plat("wasm") then
+            table.insert(subdirs, "wasm_32")
+        else
+            table.insert(subdirs, "*")
+        end
+
+        local installeddir
+        for _, subdir in pairs(subdirs) do
+            local results = os.dirs(path.join(installdir, version, subdir), function (file, isdir) return false end)
+            if results and #results > 0 then
+                installeddir = results[1]
+                break
+            end
+        end
+        assert(installdir, "couldn't find where qt was installed!")
+
+        os.mv(path.join(installeddir, "*"), installdir)
+        os.rmdir(path.join(installdir, version))
+
+        package:data_set("qt", qt_table(installdir, version:shortstr()))
+    end)
+
+    on_test(function (package)
+        local qt = assert(package:data("qt"))
+        if not package:is_plat("mingw") then
+            os.vrun(path.join(qt.bindir, "moc") .. " -v")
+            os.vrun(path.join(qt.bindir, "rcc") .. " -v")
+        end
+    end)

+ 83 - 0
packages/q/qt5core/xmake.lua

@@ -0,0 +1,83 @@
+package("qt5core")
+    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("5.15.2", "dummy")
+    add_versions("5.12.5", "dummy")
+
+    on_load(function (package)
+        package:add("deps", "qt5base", {debug = package:is_debug(), version = package:version_str()})
+    end)
+
+    on_fetch(function (package)
+        local qt = package:dep("qt5base"):data("qt")
+        if not qt then
+            return
+        end
+
+        local syslinks
+        local linkname
+        local frameworks
+        local includedirs = {qt.includedir}
+        if package:is_plat("windows") then
+            linkname = "Qt5Core"
+            if package:is_debug() then
+                linkname = linkname .. "d"
+            end
+            table.insert(includedirs, path.join(qt.includedir, "QtCore"))
+        elseif package:is_plat("android") then
+            linkname = "Qt5Core"
+            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
+            syslinks = "z"
+            table.insert(includedirs, path.join(qt.includedir, "QtCore"))
+        elseif package:is_plat("macosx") then
+            table.insert(includedirs, path.join(qt.libdir, "QtCore.framework/Versions/5/Headers"))
+            frameworks = "QtCore"
+        elseif package:is_plat("iphoneos") then
+            linkname = "Qt5Core"
+            frameworks = {"UIKit", "CoreText", "CoreGraphics", "CoreServices", "CoreFoundation"}
+            syslinks = {"qtpcre2", "z"}
+            table.insert(includedirs, path.join(qt.includedir, "QtCore"))
+        else
+            linkname = "Qt5Core"
+            table.insert(includedirs, path.join(qt.includedir, "QtCore"))
+        end
+
+        return {
+            qtdir = qt,
+            version = qt.version,
+            includedirs = includedirs,
+            links = linkname,
+            linkdirs = qt.libdir,
+            frameworks = frameworks,
+            frameworkdirs = qt.libdir,
+            syslinks = syslinks
+        }
+    end)
+
+    on_install("windows", "linux", "macosx", "mingw", "android", "iphoneos", function (package)
+        local base = package:dep("qt5base")
+        local qt = base:data("qt")
+        assert(qt, "qt5base is required")
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QCoreApplication app (argc, argv);
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++14", cxflags = not package:is_plat("windows") and "-fPIC" or nil}, includes = {"QCoreApplication"}}))
+    end)

+ 81 - 0
packages/q/qt5gui/xmake.lua

@@ -0,0 +1,81 @@
+package("qt5gui")
+    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("5.15.2", "dummy")
+    add_versions("5.12.5", "dummy")
+
+    on_load(function (package)
+        package:add("deps", "qt5base", "qt5core", {debug = package:is_debug(), version = package:version_str()})
+    end)
+
+    on_fetch(function (package)
+        local qt = package:dep("qt5base"):data("qt")
+        if not qt then
+            return
+        end
+
+        local linkname
+        local syslinks
+        local frameworks
+        local includedirs = {qt.includedir}
+        if package:is_plat("windows") then
+            linkname = "Qt5Gui"
+            if package:is_debug() then
+                linkname = linkname .. "d"
+            end
+            table.insert(includedirs, path.join(qt.includedir, "QtGui"))
+        elseif package:is_plat("android") then
+            linkname = "Qt5Gui"
+            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
+            syslinks = "GLESv2"
+            table.insert(includedirs, path.join(qt.includedir, "QtGui"))
+        elseif package:is_plat("macosx") then
+            table.insert(includedirs, path.join(qt.libdir, "QtGui.framework/Versions/5/Headers"))
+            frameworks = "QtGui"
+        elseif package:is_plat("iphoneos") then
+            linkname = {"Qt5Gui", "qtharfbuzz"}
+            syslinks = {"qtlibpng", "z"}
+            table.insert(includedirs, path.join(qt.includedir, "QtGui"))
+        else
+            linkname = "Qt5Gui"
+            table.insert(includedirs, path.join(qt.includedir, "QtGui"))
+        end
+
+        return {
+            qtdir = qt,
+            version = qt.version,
+            includedirs = includedirs,
+            links = linkname,
+            linkdirs = qt.libdir,
+            frameworks = frameworks,
+            frameworkdirs = qt.libdir,
+            syslinks = syslinks
+        }
+    end)
+
+    on_install("windows", "linux", "macosx", "mingw", "android", "iphoneos", function (package)
+        local qt = package:dep("qt5base"):data("qt")
+        assert(qt, "qt5base is required")
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            int test(int argc, char** argv) {
+                QGuiApplication app (argc, argv);
+                return app.exec();
+            }
+        ]]}, {configs = {languages = "c++14", cxflags = not package:is_plat("windows") and "-fPIC" or nil}, includes = {"QGuiApplication"}}))
+    end)

+ 79 - 0
packages/q/qt5widgets/xmake.lua

@@ -0,0 +1,79 @@
+package("qt5widgets")
+    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("5.15.2", "dummy")
+    add_versions("5.12.5", "dummy")
+
+    on_load(function (package)
+        package:add("deps", "qt5base", "qt5core", "qt5gui", {debug = package:is_debug(), version = package:version_str()})
+    end)
+
+    on_fetch(function (package)
+        local qt = package:dep("qt5base"):data("qt")
+        if not qt then
+            return
+        end
+
+        local linkname
+        local syslinks
+        local frameworks
+        local includedirs = {qt.includedir}
+        if package:is_plat("windows") then
+            linkname = "Qt5Widgets"
+            if package:is_debug() then
+                linkname = linkname .. "d"
+            end
+            table.insert(includedirs, path.join(qt.includedir, "QtWidgets"))
+        elseif package:is_plat("android") then
+            linkname = "Qt5Widgets"
+            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, "QtWidgets"))
+        elseif package:is_plat("macosx") then
+            table.insert(includedirs, path.join(qt.libdir, "QtWidgets.framework/Versions/5/Headers"))
+            frameworks = "QtWidgets"
+        else
+            linkname = "Qt5Widgets"
+            table.insert(includedirs, path.join(qt.includedir, "QtWidgets"))
+        end
+
+        return {
+            qtdir = qt,
+            version = qt.version,
+            includedirs = includedirs,
+            links = linkname,
+            linkdirs = qt.libdir,
+            frameworks = frameworks,
+            frameworkdirs = qt.libdir,
+            syslinks = syslinks
+        }
+    end)
+
+    on_install("windows", "linux", "macosx", "mingw", "android", "iphoneos", function (package)
+        local base = package:dep("qt5base")
+        local qt = base:data("qt")
+        assert(qt, "qt5base is required")
+    end)
+
+    on_test(function (package)
+        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++14", cxflags = not package:is_plat("windows") and "-fPIC" or nil}, includes = {"QApplication", "QPushButton"}}))
+    end)