From 7ebf46e96c6f65e78911d25843c240463d7dbafb Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Fri, 26 Dec 2025 16:49:20 -0500 Subject: [PATCH] Use qt_add_qml_module for QML AOT compilation Eliminates runtime qmlcache by compiling webview.qml ahead of time. Fixes portable mode cache leak where qmlcache was written to system dir. --- CMakeModules/GenerateQtResources.cmake | 2 +- src/CMakeLists.txt | 15 +++++++++++++-- src/main.cpp | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeModules/GenerateQtResources.cmake b/CMakeModules/GenerateQtResources.cmake index 3fc1d03..bcccb3a 100644 --- a/CMakeModules/GenerateQtResources.cmake +++ b/CMakeModules/GenerateQtResources.cmake @@ -12,7 +12,7 @@ foreach(_file ${_files}) string(APPEND qrc "${_file}\n") endforeach() -string(APPEND qrc "${WEBVIEW_QML}\n") +# webview.qml is now compiled via qt_add_qml_module (AOT) file(GLOB_RECURSE _files "${NATIVE_DIR}/*") list(SORT _files) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3df2221..28e6a8a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,13 +60,13 @@ file(GLOB_RECURSE RESOURCE_FILES CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/resources file(GLOB_RECURSE NATIVE_FILES CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/native/*) # Generate resources - runs rcc, only writes output if changed +# Note: webview.qml is handled separately via qt_add_qml_module for AOT compilation add_custom_target(generate_resources ALL COMMAND ${CMAKE_COMMAND} -DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/qrc_resources.cpp -DRCC=${Qt6Core_RCC_EXECUTABLE} -DRESOURCES_DIR=${CMAKE_SOURCE_DIR}/resources -DNATIVE_DIR=${CMAKE_SOURCE_DIR}/native - -DWEBVIEW_QML=${CMAKE_SOURCE_DIR}/src/ui/webview.qml -P ${CMAKE_SOURCE_DIR}/CMakeModules/GenerateQtResources.cmake BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/qrc_resources.cpp VERBATIM @@ -141,6 +141,17 @@ set_target_properties(${MAIN_TARGET} PROPERTIES copy_resources(${MAIN_TARGET}) clang_tidy(${MAIN_TARGET}) +# QML module for AOT compilation (eliminates runtime qmlcache) +set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/ui/webview.qml + PROPERTIES QT_RESOURCE_ALIAS webview.qml +) +qt_add_qml_module(${MAIN_TARGET} + URI Konvergo + VERSION 1.0 + QML_FILES ${CMAKE_CURRENT_SOURCE_DIR}/ui/webview.qml + NO_RESOURCE_TARGET_PATH +) + find_library(MINIZIP_LIBRARY minizip) if(WIN32) # FindZLIB doesn't find this. (It might be possible to fix the minizip build @@ -207,7 +218,7 @@ if(WIN32) target_link_options(jmp_core PRIVATE /DELAYLOAD:libmpv-2.dll) endif() -target_link_libraries(${MAIN_TARGET} jmp_core) +target_link_libraries(${MAIN_TARGET} PRIVATE jmp_core) install(TARGETS ${MAIN_TARGET} DESTINATION ${INSTALL_BIN_DIR}) set(EXE "${MAIN_NAME}.app") diff --git a/src/main.cpp b/src/main.cpp index abbc909..3d825fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -692,7 +692,7 @@ int main(int argc, char *argv[]) WindowManager::Get().raiseWindow(); }); }); - engine->load(QUrl(QStringLiteral("qrc:/ui/webview.qml"))); + engine->load(QUrl(QStringLiteral("qrc:/webview.qml"))); // run our application int ret = app.exec();