Skip to content

Commit 7755086

Browse files
committed
Adopt recommended QML module file layout
This implements the recommended file layout similar to commit e0633ff8cece18852e5d5ce9eb6f597bad589e60 in quartz, except this time we try it a bit different to the recommended file structure [0]. We still keep the file structure following the URI of the QML module, but instead of creating a separate CMakeLists.txt inside the inner most directory, we create everything from the root CMakeLists.txt. This still seems to work, but a quick look at the resources with Gammaray suggests that the source QML path structure is now redundantly duplicated for all QML resources. This can possibly be fixed by setting the resource output path for the QML module, but it is not really important for QML files that only we consume. Otherwise if we would use a second CMakeLists.txt inside the QML module path, we would also need to move the entire qt_add_executable() call to that CMakeLists.txt file as well to avoid weird errors with "debug_metatypes.json:: Failed to parse JSON: 5 illegal value" [1] [2]. [0] https://doc.qt.io/qt-6/qt-add-qml-module.html#separate-backing-and-plugin-targets [1] https://bugreports.qt.io/browse/QTBUG-122702 [2] https://bugreports.qt.io/browse/QTBUG-123574
1 parent 901046f commit 7755086

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.21)
1+
cmake_minimum_required(VERSION 3.31)
22
cmake_policy(SET CMP0048 NEW)
33
project(blobdrop VERSION 2.1 DESCRIPTION "Drag and drop files directly out of the terminal")
44

@@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
99
set(CMAKE_CXX_EXTENSIONS OFF)
1010

1111
list(APPEND QT_MODULES Core Qml Quick QuickControls2 DBus Svg)
12-
find_package(Qt6 6.8 COMPONENTS ${QT_MODULES} REQUIRED)
13-
qt_standard_project_setup()
12+
find_package(Qt6 6.9 COMPONENTS ${QT_MODULES} REQUIRED)
13+
qt_standard_project_setup(REQUIRES ${Qt6_VERSION})
1414
list(TRANSFORM QT_MODULES PREPEND "Qt6::")
1515

1616
list(APPEND LINK_LIBS ${QT_MODULES})
@@ -25,7 +25,7 @@ if (UNIX AND NOT APPLE)
2525
endif()
2626

2727
include(FetchContent)
28-
FetchContent_Declare(quartz GIT_REPOSITORY https://github.com/vimpostor/quartz.git GIT_TAG v0.8)
28+
FetchContent_Declare(quartz GIT_REPOSITORY https://github.com/vimpostor/quartz.git GIT_TAG v0.9.1)
2929
FetchContent_MakeAvailable(quartz)
3030

3131
list(APPEND LINK_LIBS ${PKGCONFIG_MODULES})
@@ -35,14 +35,13 @@ add_compile_definitions(BLOBDROP_VERSION="${PROJECT_VERSION}")
3535

3636
file(GLOB_RECURSE SRCS "src/*.cpp")
3737
file(GLOB_RECURSE HDRS "src/*.hpp")
38-
file(GLOB_RECURSE QMLS RELATIVE "${CMAKE_SOURCE_DIR}" "src/qml/*.qml")
38+
file(GLOB_RECURSE QMLS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.qml")
3939

40-
list(APPEND RSRC "icons.qrc")
41-
qt_add_resources(RESOURCES ${RSRC})
40+
qt_add_resources(RESOURCES "${CMAKE_SOURCE_DIR}/icons.qrc")
4241

4342
qt_add_executable(${PROJECT_NAME} ${SRCS} ${RESOURCES})
4443

45-
qt_add_qml_module(${PROJECT_NAME} URI "Blobdrop" VERSION "${PROJECT_VERSION}" NO_RESOURCE_TARGET_PATH QML_FILES ${QMLS} SOURCES "src/Models/path_model.cpp")
44+
qt_add_qml_module(${PROJECT_NAME} URI "Blobdrop" VERSION "${PROJECT_VERSION}" QML_FILES ${QMLS} SOURCES "src/Models/path_model.cpp")
4645
set_target_properties(${PROJECT_NAME} PROPERTIES QT_QMLCACHEGEN_ARGUMENTS "--only-bytecode")
4746

4847
target_link_libraries(${PROJECT_NAME} PRIVATE ${LINK_LIBS})

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ int main(int argc, char *argv[]) {
3232
QGuiApplication::setWindowIcon(QIcon::fromTheme("blobdrop", QIcon(":/blobdrop")));
3333

3434
QQmlApplicationEngine engine;
35-
engine.addImportPath(QStringLiteral(":/"));
3635

3736
engine.loadFromModule("Blobdrop", "Main");
3837
if (engine.rootObjects().isEmpty()) {
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)