From 0b29c1b305b0d2681f049e338ae3ad4f57cc8337 Mon Sep 17 00:00:00 2001 From: Cloud Date: Thu, 23 Jul 2026 20:24:39 +0800 Subject: [PATCH 1/2] fix: build on MSYS2/MinGW Guard Linux-specific linker flags and platform assertions with appropriate #ifdefs so the project compiles on MinGW. Add DBus Qt dependency, export all symbols for MinGW, and add null checks in DSGBlendNode::render for OpenGL context/functions. --- CMakeLists.txt | 7 ++++++- examples/exhibition/CMakeLists.txt | 4 +++- src/dquickwindow.cpp | 3 ++- src/private/dqmlglobalobject.cpp | 5 +++-- src/private/dquickbehindwindowblur.cpp | 13 +++++++++---- src/targets.cmake | 1 - 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7140cb511..bcb41274a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,12 @@ set(MKSPECS_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/mkspecs/m set(QML_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_VERSION_MAJOR}/qml" CACHE STRING "Qml plugin install directory") set(USE_QQuickStylePluginPrivate OFF) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core QuickControls2) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core QuickControls2 DBus) + +# Export all symbols for MinGW since DTK classes lack export macros +if(WIN32 AND NOT MSVC) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--export-all-symbols") +endif() if (${QT_VERSION_MAJOR} STREQUAL "6") if (${Qt6QuickControls2_VERSION} VERSION_GREATER_EQUAL "6.10.0") diff --git a/examples/exhibition/CMakeLists.txt b/examples/exhibition/CMakeLists.txt index 1cd69e561..6b8ed6e2b 100644 --- a/examples/exhibition/CMakeLists.txt +++ b/examples/exhibition/CMakeLists.txt @@ -4,7 +4,9 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Quick QuickControls2) find_package(Dtk${DTK_NAME_SUFFIX}Core REQUIRED) find_package(Dtk${DTK_NAME_SUFFIX}Gui REQUIRED) -set(CMAKE_EXE_LINKER_FLAGS "-z relro -z now -z noexecstack -pie -Wl,--as-needed") +if(NOT WIN32) + set(CMAKE_EXE_LINKER_FLAGS "-z relro -z now -z noexecstack -pie -Wl,--as-needed") +endif() if (DTK5) set(QML_RCS ${CMAKE_CURRENT_LIST_DIR}/qml.qrc) diff --git a/src/dquickwindow.cpp b/src/dquickwindow.cpp index 64210d35b..de0a3bc08 100644 --- a/src/dquickwindow.cpp +++ b/src/dquickwindow.cpp @@ -144,8 +144,9 @@ bool DQuickWindowAttachedPrivate::ensurePlatformHandle() qWarning() << "Failed to enable NoTitlebar for the window:" << window; return false; } - +#ifndef Q_OS_WIN Q_ASSERT(DPlatformHandle::isEnabledNoTitlebar(window)); +#endif explicitEnable = Invalid; D_Q(DQuickWindowAttached); handle = new DPlatformHandle(window); diff --git a/src/private/dqmlglobalobject.cpp b/src/private/dqmlglobalobject.cpp index 3dff8ddaa..643e888c0 100644 --- a/src/private/dqmlglobalobject.cpp +++ b/src/private/dqmlglobalobject.cpp @@ -27,11 +27,12 @@ #include #endif +#include +#include + #ifdef Q_OS_UNIX #include #include -#include -#include #endif DGUI_USE_NAMESPACE diff --git a/src/private/dquickbehindwindowblur.cpp b/src/private/dquickbehindwindowblur.cpp index 9a65886b6..fa5eea268 100644 --- a/src/private/dquickbehindwindowblur.cpp +++ b/src/private/dquickbehindwindowblur.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -64,9 +64,14 @@ void DSGBlendNode::render(const QSGRenderNode::RenderState *state) p->setCompositionMode(QPainter::CompositionMode_Source); } else { #ifndef QT_NO_OPENGL - QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions(); - f->glEnable(GL_BLEND); - f->glBlendFunc(GL_ONE, GL_ZERO); + QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (ctx) { + QOpenGLFunctions *f = ctx->functions(); + if (f) { + f->glEnable(GL_BLEND); + f->glBlendFunc(GL_ONE, GL_ZERO); + } + } #endif } diff --git a/src/targets.cmake b/src/targets.cmake index 9f42cea7f..5c6ceda7a 100644 --- a/src/targets.cmake +++ b/src/targets.cmake @@ -33,7 +33,6 @@ target_sources(${LIB_NAME}_sources INTERFACE ${SRCS} ${HEADERS} ${D_HEADERS} - ${ASSETS_RCS} ) set(DTK_QML_APP_PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/${LIB_NAME}/qml-app" CACHE STRING "dtk qml app plugin path") From e317e1fca13f49905d9dacbc849a1444ac11f047 Mon Sep 17 00:00:00 2001 From: Cloud Date: Fri, 24 Jul 2026 12:04:04 +0800 Subject: [PATCH 2/2] fix(cmake): use qt_add_resources for MSYS2 compatibility use qt_add_resources for MSYS2 compatibility --- src/targets.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/targets.cmake b/src/targets.cmake index 5c6ceda7a..95fe9c81f 100644 --- a/src/targets.cmake +++ b/src/targets.cmake @@ -24,15 +24,20 @@ pkg_check_modules(GL REQUIRED IMPORTED_TARGET gl) include(${PROJECT_SOURCE_DIR}/src/src.cmake) -file(GLOB ASSETS_RCS ${PROJECT_SOURCE_DIR}/src/dtkdeclarative_assets.qrc) file(GLOB TS_FILES "${PROJECT_SOURCE_DIR}/src/translations/*.ts") +# Use qt_add_resources instead of file(GLOB) for better cross-platform compatibility +if(EXISTS ${PROJECT_SOURCE_DIR}/src/dtkdeclarative_assets.qrc) + qt_add_resources(ASSETS_BINARY ${PROJECT_SOURCE_DIR}/src/dtkdeclarative_assets.qrc) +endif() + add_library(${LIB_NAME}_properties INTERFACE) add_library(${LIB_NAME}_sources INTERFACE) target_sources(${LIB_NAME}_sources INTERFACE ${SRCS} ${HEADERS} ${D_HEADERS} + ${ASSETS_BINARY} ) set(DTK_QML_APP_PLUGIN_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/${LIB_NAME}/qml-app" CACHE STRING "dtk qml app plugin path")