mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-07-25 00:38:41 +08:00
refactor: rebuild desktop client with Slint
This commit is contained in:
+7
-2
@@ -30,6 +30,8 @@ function setup_options_and_dependencies()
|
||||
option_end()
|
||||
|
||||
add_rules("mode.release", "mode.debug")
|
||||
-- Preserve the existing codebase/toolchain contract. Slint targets opt in to
|
||||
-- C++20 locally because its generated C++ API requires it.
|
||||
set_languages("c++17")
|
||||
set_encodings("utf-8")
|
||||
|
||||
@@ -41,7 +43,9 @@ function setup_options_and_dependencies()
|
||||
add_defines("USE_CUDA=" .. (is_config("USE_CUDA", true) and "1" or "0"))
|
||||
add_defines("USE_WAYLAND=" .. (is_config("USE_WAYLAND", true) and "1" or "0"))
|
||||
add_defines("USE_DRM=" .. (is_config("USE_DRM", true) and "1" or "0"))
|
||||
add_defines("CROSSDESK_PORTABLE=" .. (is_config("CROSSDESK_PORTABLE", true) and "1" or "0"))
|
||||
if is_config("CROSSDESK_PORTABLE", true) then
|
||||
add_defines("CROSSDESK_PORTABLE=1")
|
||||
end
|
||||
|
||||
if is_mode("debug") then
|
||||
add_defines("CROSSDESK_DEBUG")
|
||||
@@ -49,7 +53,8 @@ function setup_options_and_dependencies()
|
||||
|
||||
add_requireconfs("*.python", {version = "3.12", override = true, configs = {pgo = false}})
|
||||
add_requires("spdlog 1.14.1", {system = false})
|
||||
add_requires("imgui v1.92.1-docking", {configs = {sdl3 = true, sdl3_renderer = true}})
|
||||
add_requires("slint 1.17.1", {configs = {shared = true}})
|
||||
add_requires("libsdl3 3.2.26", {configs = {shared = false}})
|
||||
add_requires("openssl3 3.3.2", {system = false})
|
||||
add_requires("nlohmann_json 3.11.3")
|
||||
add_requires("cpp-httplib v0.26.0", {configs = {ssl = true}})
|
||||
|
||||
+2
-3
@@ -27,7 +27,7 @@ function setup_platform_settings()
|
||||
if is_os("windows") then
|
||||
add_requires("libyuv", "miniaudio 0.11.21")
|
||||
add_links("Shell32", "dwmapi", "User32", "kernel32",
|
||||
"SDL3-static", "gdi32", "winmm", "setupapi", "version",
|
||||
"gdi32", "winmm", "setupapi", "version",
|
||||
"Imm32", "iphlpapi", "d3d11", "dxgi")
|
||||
add_cxflags("/WX")
|
||||
set_runtimes("MT")
|
||||
@@ -35,7 +35,7 @@ function setup_platform_settings()
|
||||
add_links("pulse-simple", "pulse")
|
||||
add_requires("libyuv")
|
||||
add_syslinks("pthread", "dl")
|
||||
add_links("SDL3", "asound", "X11", "Xext", "Xrender", "Xft", "Xtst",
|
||||
add_links("asound", "X11", "Xext", "Xrender", "Xft", "Xtst",
|
||||
"Xrandr", "Xfixes")
|
||||
add_existing_include_dirs({
|
||||
"/usr/include/freetype2",
|
||||
@@ -77,7 +77,6 @@ function setup_platform_settings()
|
||||
|
||||
add_cxflags("-Wno-unused-variable")
|
||||
elseif is_os("macosx") then
|
||||
add_links("SDL3")
|
||||
add_ldflags("-Wl,-ld_classic")
|
||||
add_cxflags("-Wno-unused-variable")
|
||||
add_frameworks("Cocoa", "OpenGL", "IOSurface", "ScreenCaptureKit",
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package("slint")
|
||||
set_homepage("https://slint.dev")
|
||||
set_description("Declarative GUI toolkit for C++")
|
||||
set_license("GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0")
|
||||
|
||||
add_urls("https://github.com/slint-ui/slint/archive/refs/tags/v$(version).tar.gz",
|
||||
"https://github.com/slint-ui/slint.git")
|
||||
add_versions("1.17.1", "68222567f8c70ff677cd4a98cd94fb4765ac0f797eb8f8608a646911c908dc2a")
|
||||
|
||||
add_configs("shared", {description = "Build the Slint runtime as a shared library", default = true, type = "boolean", readonly = true})
|
||||
|
||||
add_deps("cmake")
|
||||
|
||||
on_load(function(package)
|
||||
package:add("includedirs", "include/slint")
|
||||
package:add("links", "slint_cpp")
|
||||
end)
|
||||
|
||||
on_install("windows", "linux", "macosx", function(package)
|
||||
local configs = {
|
||||
"-DSLINT_BUILD_TESTING=OFF",
|
||||
"-DSLINT_BUILD_EXAMPLES=OFF",
|
||||
"-DSLINT_COMPILER=download",
|
||||
"-DSLINT_FEATURE_INTERPRETER=OFF",
|
||||
"-DSLINT_FEATURE_LIVE_PREVIEW=OFF",
|
||||
"-DSLINT_FEATURE_TESTING=OFF",
|
||||
"-DSLINT_FEATURE_SYSTEM_TESTING=OFF",
|
||||
"-DSLINT_FEATURE_MCP=OFF",
|
||||
"-DSLINT_FEATURE_BACKEND_QT=OFF",
|
||||
"-DSLINT_FEATURE_RENDERER_SKIA=OFF",
|
||||
"-DSLINT_FEATURE_RENDERER_SKIA_OPENGL=OFF",
|
||||
"-DSLINT_FEATURE_RENDERER_SKIA_VULKAN=OFF",
|
||||
"-DSLINT_FEATURE_RENDERER_FEMTOVG=ON",
|
||||
"-DSLINT_FEATURE_RENDERER_SOFTWARE=ON",
|
||||
"-DSLINT_STYLE=fluent",
|
||||
"-DBUILD_SHARED_LIBS=ON"
|
||||
}
|
||||
import("package.tools.cmake").install(package, configs)
|
||||
|
||||
-- SLINT_COMPILER=download only configures downstream CMake projects.
|
||||
-- xmake's native Slint rule needs the matching host executable here.
|
||||
import("net.http")
|
||||
import("utils.archive")
|
||||
local host_system = is_host("windows") and "windows" or (is_host("macosx") and "Darwin" or "Linux")
|
||||
local host_arch = os.arch()
|
||||
if host_arch == "x64" then
|
||||
host_arch = "x86_64"
|
||||
end
|
||||
local suffix = host_system .. "-" .. host_arch
|
||||
local archive_name = "slint-compiler-" .. suffix .. ".tar.gz"
|
||||
local archive_file = path.join(package:builddir(), archive_name)
|
||||
local download_url = "https://github.com/slint-ui/slint/releases/download/v" .. package:version_str() .. "/" .. archive_name
|
||||
http.download(download_url, archive_file)
|
||||
os.mkdir(path.join(package:installdir(), "bin"))
|
||||
archive.extract(archive_file, package:installdir())
|
||||
end)
|
||||
|
||||
on_test(function(package)
|
||||
assert(package:has_cxxincludes("slint.h", {configs = {languages = "c++20"}}), "Slint C++ headers are unusable")
|
||||
assert(os.isfile(path.join(package:installdir(), "bin", is_host("windows") and "slint-compiler.exe" or "slint-compiler")), "slint-compiler was not installed")
|
||||
end)
|
||||
package_end()
|
||||
@@ -0,0 +1,53 @@
|
||||
rule("slint")
|
||||
set_extensions(".slint")
|
||||
|
||||
on_config(function(target)
|
||||
local rule_name = "slint"
|
||||
if target:rule("c++.build") then
|
||||
local cpp_rule = target:rule("c++.build"):clone()
|
||||
cpp_rule:add("deps", rule_name, {order = true})
|
||||
target:rule_add(cpp_rule)
|
||||
end
|
||||
|
||||
local outputdir = path.join(target:autogendir(), "rules", "slint")
|
||||
os.mkdir(outputdir)
|
||||
target:add("includedirs", outputdir, {public = true})
|
||||
|
||||
local sourcebatch = target:sourcebatches()[rule_name]
|
||||
if sourcebatch and sourcebatch.sourcefiles then
|
||||
for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
|
||||
-- Make the generated include discoverable during C++ dependency
|
||||
-- scanning; the real contents are produced before compilation.
|
||||
os.touch(path.join(outputdir, path.basename(sourcefile) .. ".h"))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
before_buildcmd_file(function(target, batchcmds, sourcefile, opt)
|
||||
local package = assert(target:pkg("slint"), "the slint package is required by this target")
|
||||
local compiler = path.join(package:installdir(), "bin", is_host("windows") and "slint-compiler.exe" or "slint-compiler")
|
||||
local outputdir = path.join(target:autogendir(), "rules", "slint")
|
||||
local outputfile = path.join(outputdir, path.basename(sourcefile) .. ".h")
|
||||
local depfile = outputfile .. ".d"
|
||||
|
||||
batchcmds:show_progress(opt.progress, "${color.build.object}generating.slint %s", sourcefile)
|
||||
batchcmds:mkdir(outputdir)
|
||||
batchcmds:vrunv(compiler, {
|
||||
sourcefile,
|
||||
"-f", "cpp",
|
||||
"-o", outputfile,
|
||||
"--depfile", depfile,
|
||||
"--style", "fluent",
|
||||
"--embed-resources=embed-files",
|
||||
"--cpp-namespace", "crossdesk::ui"
|
||||
})
|
||||
-- The compiler's depfile is useful to external build systems, while
|
||||
-- xmake needs imported .slint files registered explicitly so editing a
|
||||
-- component regenerates the umbrella header without a forced rebuild.
|
||||
for _, dependency in ipairs(os.files(path.join(path.directory(sourcefile), "*.slint"))) do
|
||||
batchcmds:add_depfiles(dependency)
|
||||
end
|
||||
batchcmds:set_depmtime(os.mtime(outputfile))
|
||||
batchcmds:set_depcache(target:dependfile(outputfile))
|
||||
end)
|
||||
rule_end()
|
||||
+24
-6
@@ -1,5 +1,5 @@
|
||||
function setup_targets()
|
||||
add_packages("spdlog", "imgui", "nlohmann_json")
|
||||
add_packages("spdlog", "libsdl3", "nlohmann_json")
|
||||
|
||||
includes("submodules", "thirdparty")
|
||||
|
||||
@@ -18,6 +18,7 @@ function setup_targets()
|
||||
set_kind("object")
|
||||
add_deps("rd_log")
|
||||
add_files("src/common/*.cpp")
|
||||
remove_files("src/common/rounded_corner_button.cpp")
|
||||
if is_os("macosx") then
|
||||
add_files("src/common/*.mm")
|
||||
end
|
||||
@@ -33,6 +34,7 @@ function setup_targets()
|
||||
target("path_manager_portable_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
set_policy("build.ccache", false)
|
||||
add_defines("CROSSDESK_PORTABLE=1")
|
||||
add_includedirs("src/path_manager")
|
||||
add_files("tests/path_manager_portable_test.cpp",
|
||||
@@ -81,6 +83,15 @@ function setup_targets()
|
||||
set_default(false)
|
||||
add_files("tests/display_popup_hover_state_test.cpp")
|
||||
|
||||
target("slint_ui_smoke_test")
|
||||
set_kind("binary")
|
||||
set_languages("c++20")
|
||||
set_default(false)
|
||||
add_packages("slint")
|
||||
add_rules("slint")
|
||||
add_files("src/gui/ui/crossdesk_ui.slint")
|
||||
add_files("tests/slint_ui_smoke_test.cpp")
|
||||
|
||||
target("version_checker_test")
|
||||
set_kind("binary")
|
||||
set_default(false)
|
||||
@@ -209,24 +220,31 @@ function setup_targets()
|
||||
|
||||
target("gui")
|
||||
set_kind("object")
|
||||
set_languages("c++20")
|
||||
-- spdlog 1.14 bundles fmt 10, whose consteval parser is rejected by
|
||||
-- current Apple Clang in C++20 mode. Keep the established dependency
|
||||
-- version and use fmt's supported runtime-parser fallback here.
|
||||
add_defines("FMT_CONSTEVAL=")
|
||||
add_packages("slint", {public = true})
|
||||
add_packages("libyuv", "tinyfiledialogs")
|
||||
add_rules("slint")
|
||||
add_defines("CROSSDESK_VERSION=\"" .. (get_config("CROSSDESK_VERSION") or "Unknown") .. "\"")
|
||||
add_deps("rd_log", "common", "assets", "config_center", "minirtc",
|
||||
"path_manager", "screen_capturer", "speaker_capturer",
|
||||
"device_controller", "thumbnail", "version_checker", "tools")
|
||||
add_files("src/gui/render.cpp", "src/gui/application/*.cpp",
|
||||
add_files("src/gui/render.cpp", "src/gui/application/gui_application.cpp",
|
||||
"src/gui/application/portable_service_integration.cpp",
|
||||
"src/gui/runtime/*.cpp",
|
||||
"src/gui/features/devices/*.cpp", "src/gui/features/input/*.cpp",
|
||||
"src/gui/features/clipboard/*.cpp", "src/gui/features/file_transfer/*.cpp",
|
||||
"src/gui/features/settings/*.cpp", "src/gui/views/panels/*.cpp",
|
||||
"src/gui/views/toolbars/*.cpp", "src/gui/views/windows/*.cpp")
|
||||
"src/gui/features/settings/*.cpp", "src/gui/ui/crossdesk_ui.slint")
|
||||
add_includedirs("src/gui", {public = true})
|
||||
if is_os("windows") then
|
||||
add_files("src/gui/platform/tray/win_tray.cpp")
|
||||
add_includedirs("src/service/windows", {public = true})
|
||||
elseif is_os("macosx") then
|
||||
add_files("src/gui/runtime/*.mm", "src/gui/views/windows/*.mm",
|
||||
"src/gui/platform/tray/*.mm")
|
||||
add_files("src/gui/runtime/*.mm", "src/gui/platform/tray/*.mm",
|
||||
"src/gui/platform/window_drag_mac.mm")
|
||||
elseif is_os("linux") then
|
||||
add_files("src/gui/platform/tray/linux_tray.cpp")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user