diff options
31 files changed, 701 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2939fe51d2..83cea1d4c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,4 +10,7 @@ project(QtDeclarative find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core Gui Widgets Network OPTIONAL_COMPONENTS Sql Concurrent Test) +# export QT6_ADD_QML_MODULE to this project +include(src/qml/Qt6QmlMacros.cmake) + qt_build_repo() diff --git a/examples/.prev_CMakeLists.txt b/examples/.prev_CMakeLists.txt index 2209576c8c..c2ccea65c1 100644 --- a/examples/.prev_CMakeLists.txt +++ b/examples/.prev_CMakeLists.txt @@ -1,5 +1,7 @@ # Generated from examples.pro. +qt_examples_build_begin() + add_subdirectory(qml) if(TARGET Qt::QuickTest) add_subdirectory(qmltest) @@ -7,3 +9,5 @@ endif() if(TARGET Qt::Quick) add_subdirectory(quick) endif() + +qt_examples_build_end() diff --git a/examples/qml/tutorials/extending-qml/CMakeLists.txt b/examples/qml/tutorials/extending-qml/CMakeLists.txt index 8f8395ac95..8e41f3d77d 100644 --- a/examples/qml/tutorials/extending-qml/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/CMakeLists.txt @@ -5,7 +5,4 @@ add_subdirectory(chapter2-methods) add_subdirectory(chapter3-bindings) add_subdirectory(chapter4-customPropertyTypes) add_subdirectory(chapter5-listproperties) -# special case begin -# Needs public QML plugin API -# add_subdirectory(chapter6-plugins) -# special case end +add_subdirectory(chapter6-plugins) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt new file mode 100644 index 0000000000..33f79b03f5 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt @@ -0,0 +1,43 @@ +# Generated from chapter6-plugins.pro. + +cmake_minimum_required(VERSION 3.14) +project(chapter6-plugins LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(INSTALL_EXAMPLEDIR "examples") + +find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Quick) + +add_qt_gui_executable(chapter6-plugins + main.cpp +) +target_link_libraries(chapter6-plugins PUBLIC + Qt::Qml + Qt::Quick +) + +# Resources: +set(app_resource_files + "app.qml" +) + +QT6_ADD_RESOURCES(chapter6-plugins "app" + PREFIX + "/" + FILES + ${app_resource_files} +) + + +install(TARGETS chapter6-plugins + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) +add_subdirectory(import) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt new file mode 100644 index 0000000000..6a2b487009 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt @@ -0,0 +1,44 @@ +# Generated from chapter6-plugins.pro. + +cmake_minimum_required(VERSION 3.14) +project(chapter6-plugins LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(INSTALL_EXAMPLEDIR "examples") + +find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Quick) + +add_qt_gui_executable(chapter6-plugins + main.cpp +) +target_link_libraries(chapter6-plugins PUBLIC + Qt::Qml + Qt::Quick +) + +# Resources: +set(app_resource_files + "app.qml" +) + +QT6_ADD_RESOURCES(chapter6-plugins "app" + PREFIX + "/" + FILES + ${app_resource_files} +) + + +install(TARGETS chapter6-plugins + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) + +add_subdirectory(import) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt new file mode 100644 index 0000000000..938340eb87 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt @@ -0,0 +1,42 @@ +# Generated from import.pro. + +cmake_minimum_required(VERSION 3.14) +project(chartsplugin LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(INSTALL_EXAMPLEDIR "examples") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Quick) + +qt6_add_qml_module(chartsplugin + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../Charts" + VERSION 1.0 + URI "Charts" + INSTALL_LOCATION ${INSTALL_EXAMPLEDIR} +) + +target_sources(chartsplugin PRIVATE + chartsplugin.cpp chartsplugin.h + piechart.cpp piechart.h + pieslice.cpp pieslice.h +) +target_link_libraries(chartsplugin PUBLIC + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick +) + +install(TARGETS chartsplugin + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/quick/.prev_CMakeLists.txt b/examples/quick/.prev_CMakeLists.txt index 9ca9009184..5299e95ae2 100644 --- a/examples/quick/.prev_CMakeLists.txt +++ b/examples/quick/.prev_CMakeLists.txt @@ -35,6 +35,6 @@ endif() if(TARGET Qt::Widgets) add_subdirectory(embeddedinwidgets) endif() -if(QT_FEATURE_opengles2 OR (QT_FEATURE_opengl AND TARGET Qt::QuickWidgets) OR (QT_FEATURE_opengles3 AND TARGET Qt::Widgets)) +if(TARGET Qt::Widgets AND (QT_FEATURE_opengl OR QT_FEATURE_opengles2 OR QT_FEATURE_opengles3) AND (QT_FEATURE_opengles2 OR QT_FEATURE_opengles3 OR TARGET Qt::QuickWidgets)) add_subdirectory(quickwidgets) endif() diff --git a/examples/quick/CMakeLists.txt b/examples/quick/CMakeLists.txt index 889b46fa3e..a733e42f1c 100644 --- a/examples/quick/CMakeLists.txt +++ b/examples/quick/CMakeLists.txt @@ -38,6 +38,6 @@ endif() if(TARGET Qt::Widgets) add_subdirectory(embeddedinwidgets) endif() -if(QT_FEATURE_opengles2 OR (QT_FEATURE_opengl AND TARGET Qt::QuickWidgets) OR (QT_FEATURE_opengles3 AND TARGET Qt::Widgets)) +if(TARGET Qt::Widgets AND (QT_FEATURE_opengl OR QT_FEATURE_opengles2 OR QT_FEATURE_opengles3) AND (QT_FEATURE_opengles2 OR QT_FEATURE_opengles3 OR TARGET Qt::QuickWidgets)) add_subdirectory(quickwidgets) endif() diff --git a/examples/quick/customitems/CMakeLists.txt b/examples/quick/customitems/CMakeLists.txt index 86cb951940..4afbfe3f6b 100644 --- a/examples/quick/customitems/CMakeLists.txt +++ b/examples/quick/customitems/CMakeLists.txt @@ -1,7 +1,4 @@ # Generated from customitems.pro. -# special case begin -# Needs public QML Plugin API -#add_subdirectory(painteditem) -# special case end +add_subdirectory(painteditem) add_subdirectory(maskedmousearea) diff --git a/examples/quick/customitems/painteditem/CMakeLists.txt b/examples/quick/customitems/painteditem/CMakeLists.txt new file mode 100644 index 0000000000..48fb6bc3ea --- /dev/null +++ b/examples/quick/customitems/painteditem/CMakeLists.txt @@ -0,0 +1,55 @@ +# Generated from painteditem.pro. + +cmake_minimum_required(VERSION 3.14) +project(qmltextballoonplugin LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(INSTALL_EXAMPLEDIR "examples") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Quick) + +qt6_add_qml_module(qmltextballoonplugin + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/TextBalloonPlugin" + VERSION 1.0 + URI "TextBalloonPlugin" + INSTALL_LOCATION ${INSTALL_EXAMPLEDIR} +) + +target_sources(qmltextballoonplugin PRIVATE + TextBalloonPlugin/plugin.h + textballoon.cpp textballoon.h +) +target_link_libraries(qmltextballoonplugin PUBLIC + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick +) + +# Resources: +set(painteditem_resource_files + "textballoon.h" + "textballoons.qml" +) + +QT6_ADD_RESOURCES(qmltextballoonplugin "painteditem" + PREFIX + "/painteditem" + FILES + ${painteditem_resource_files} +) + + +install(TARGETS qmltextballoonplugin + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/quick/particles/CMakeLists.txt b/examples/quick/particles/CMakeLists.txt index 77ae5fad28..9bc4e894a5 100644 --- a/examples/quick/particles/CMakeLists.txt +++ b/examples/quick/particles/CMakeLists.txt @@ -4,7 +4,5 @@ add_subdirectory(affectors) add_subdirectory(customparticle) add_subdirectory(emitters) add_subdirectory(imageparticle) -# Needs public QML Plugin API -# add_subdirectory(itemparticle) -# special case begin +add_subdirectory(itemparticle) add_subdirectory(system) diff --git a/src/imports/folderlistmodel/CMakeLists.txt b/src/imports/folderlistmodel/CMakeLists.txt index aca79ab471..7fba885fd9 100644 --- a/src/imports/folderlistmodel/CMakeLists.txt +++ b/src/imports/folderlistmodel/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qmlfolderlistmodelplugin - CPP_PLUGIN URI "Qt.labs.folderlistmodel" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QmlFolderListModelPlugin SOURCES fileinfothread.cpp fileinfothread_p.h fileproperty_p.h diff --git a/src/imports/labsanimation/CMakeLists.txt b/src/imports/labsanimation/CMakeLists.txt index 972bbd72c5..9e3768ad75 100644 --- a/src/imports/labsanimation/CMakeLists.txt +++ b/src/imports/labsanimation/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(labsanimationplugin - CPP_PLUGIN URI "Qt.labs.animation" VERSION "1.0" + CLASSNAME QtLabsAnimationPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/labsmodels/CMakeLists.txt b/src/imports/labsmodels/CMakeLists.txt index a5f8670c46..84e778843f 100644 --- a/src/imports/labsmodels/CMakeLists.txt +++ b/src/imports/labsmodels/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(labsmodelsplugin - CPP_PLUGIN URI "Qt.labs.qmlmodels" VERSION "1.0" + CLASSNAME QtQmlLabsModelsPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/layouts/CMakeLists.txt b/src/imports/layouts/CMakeLists.txt index 1606740451..f75ec2eb9a 100644 --- a/src/imports/layouts/CMakeLists.txt +++ b/src/imports/layouts/CMakeLists.txt @@ -5,9 +5,10 @@ ##################################################################### add_qml_module(qquicklayoutsplugin - CPP_PLUGIN URI "QtQuick.Layouts" VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQuickLayoutsPlugin SOURCES plugin.cpp qquickgridlayoutengine.cpp qquickgridlayoutengine_p.h diff --git a/src/imports/localstorage/CMakeLists.txt b/src/imports/localstorage/CMakeLists.txt index 30830d66f4..2727b4dfa0 100644 --- a/src/imports/localstorage/CMakeLists.txt +++ b/src/imports/localstorage/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qmllocalstorageplugin - CPP_PLUGIN URI "QtQuick.LocalStorage" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QQmlLocalStoragePlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/models/CMakeLists.txt b/src/imports/models/CMakeLists.txt index 0eacd2d5e0..9b06e998c9 100644 --- a/src/imports/models/CMakeLists.txt +++ b/src/imports/models/CMakeLists.txt @@ -5,10 +5,11 @@ ##################################################################### add_qml_module(modelsplugin - CPP_PLUGIN TARGET_PATH "QtQml/Models.2" URI "QtQml.Models" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQmlModelsPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/particles/CMakeLists.txt b/src/imports/particles/CMakeLists.txt index 2643f6434e..f519891b49 100644 --- a/src/imports/particles/CMakeLists.txt +++ b/src/imports/particles/CMakeLists.txt @@ -5,10 +5,10 @@ ##################################################################### add_qml_module(particlesplugin - CPP_PLUGIN TARGET_PATH "QtQuick/Particles.2" URI "QtQuick.Particles" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QtQuick2ParticlesPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/qtqml/.prev_CMakeLists.txt b/src/imports/qtqml/.prev_CMakeLists.txt index 2f64891d2b..5e5be848bd 100644 --- a/src/imports/qtqml/.prev_CMakeLists.txt +++ b/src/imports/qtqml/.prev_CMakeLists.txt @@ -5,9 +5,13 @@ ##################################################################### add_qml_module(qmlplugin - CPP_PLUGIN URI "QtQml" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQmlPlugin + IMPORTS + QtQml.Models + QtQml.WorkerScript SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/qtqml/CMakeLists.txt b/src/imports/qtqml/CMakeLists.txt index 03ef5a353c..855be1b62b 100644 --- a/src/imports/qtqml/CMakeLists.txt +++ b/src/imports/qtqml/CMakeLists.txt @@ -5,9 +5,13 @@ ##################################################################### add_qml_module(qmlplugin - CPP_PLUGIN URI "QtQml" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQmlPlugin + IMPORTS + QtQml.Models + QtQml.WorkerScript SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/qtquick2/CMakeLists.txt b/src/imports/qtquick2/CMakeLists.txt index 8612327795..f9026d5774 100644 --- a/src/imports/qtquick2/CMakeLists.txt +++ b/src/imports/qtquick2/CMakeLists.txt @@ -5,10 +5,13 @@ ##################################################################### add_qml_module(qtquick2plugin - CPP_PLUGIN TARGET_PATH "QtQuick.2" URI "QtQuick" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQuick2Plugin + IMPORTS + QtQml SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/settings/CMakeLists.txt b/src/imports/settings/CMakeLists.txt index 0fc17698eb..f90b1a1040 100644 --- a/src/imports/settings/CMakeLists.txt +++ b/src/imports/settings/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qmlsettingsplugin - CPP_PLUGIN URI "Qt.labs.settings" VERSION "1.1" + CLASSNAME QmlSettingsPlugin SOURCES plugin.cpp qqmlsettings.cpp qqmlsettings_p.h diff --git a/src/imports/shapes/CMakeLists.txt b/src/imports/shapes/CMakeLists.txt index 6111f87d5e..9274fd14e7 100644 --- a/src/imports/shapes/CMakeLists.txt +++ b/src/imports/shapes/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qmlshapesplugin - CPP_PLUGIN URI "QtQuick.Shapes" VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QmlShapesPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/sharedimage/CMakeLists.txt b/src/imports/sharedimage/CMakeLists.txt index ef49189923..266faa6dc5 100644 --- a/src/imports/sharedimage/CMakeLists.txt +++ b/src/imports/sharedimage/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(sharedimageplugin - CPP_PLUGIN URI "Qt.labs.sharedimage" VERSION "1.0" + CLASSNAME QtQuickSharedImagePlugin SOURCES plugin.cpp qsharedimageloader.cpp qsharedimageloader_p.h diff --git a/src/imports/statemachine/CMakeLists.txt b/src/imports/statemachine/CMakeLists.txt index 02a1941b79..245c4aa681 100644 --- a/src/imports/statemachine/CMakeLists.txt +++ b/src/imports/statemachine/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qtqmlstatemachine - CPP_PLUGIN URI "QtQml.StateMachine" VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QtQmlStateMachinePlugin SOURCES childrenprivate.h finalstate.cpp finalstate.h diff --git a/src/imports/testlib/.prev_CMakeLists.txt b/src/imports/testlib/.prev_CMakeLists.txt new file mode 100644 index 0000000000..7674568e16 --- /dev/null +++ b/src/imports/testlib/.prev_CMakeLists.txt @@ -0,0 +1,53 @@ +# Generated from testlib.pro. + +##################################################################### +## qmltestplugin Plugin: +##################################################################### + +add_qml_module(qmltestplugin + URI "QtTest" + VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QTestQmlModule + DEPENDENCIES + QtQuick.Window/2.0 + SOURCES + main.cpp + LIBRARIES + Qt::CorePrivate + Qt::QmlPrivate + Qt::QuickTestPrivate + PUBLIC_LIBRARIES + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick + Qt::QuickTest + Qt::Test +) + +#### Keys ignored in scope 1:.:.:testlib.pro:<TRUE>: +# CXX_MODULE = "qml" +# IMPORT_VERSION = "1.$$QT_MINOR_VERSION" +# OTHER_FILES = "testlib.json" +# QML_FILES = "TestCase.qml" "SignalSpy.qml" "testlogger.js" +# TARGETPATH = "QtTest" +# _LOADED = "qml_plugin" + +set(qml_files + "TestCase.qml" + "SignalSpy.qml" + "testlogger.js" +) +set_source_files_properties(TestCase.qml PROPERTIES + QT_QML_SOURCE_VERSION "1.2" + QT_QML_SOURCE_INSTALL TRUE +) +set_source_files_properties(SignalSpy.qml PROPERTIES + QT_QML_SOURCE_VERSION "1.0" + QT_QML_SOURCE_INSTALL TRUE +) + +qt6_target_qml_files(qmltestplugin + FILES + ${qml_files} +) diff --git a/src/imports/testlib/CMakeLists.txt b/src/imports/testlib/CMakeLists.txt index 89dd13ca0a..bbff88e788 100644 --- a/src/imports/testlib/CMakeLists.txt +++ b/src/imports/testlib/CMakeLists.txt @@ -5,9 +5,11 @@ ##################################################################### add_qml_module(qmltestplugin - CPP_PLUGIN URI "QtTest" VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QTestQmlModule + DEPENDENCIES + QtQuick.Window/2.0 SOURCES main.cpp LIBRARIES @@ -23,24 +25,34 @@ add_qml_module(qmltestplugin Qt::Test ) +#### Keys ignored in scope 1:.:.:testlib.pro:<TRUE>: +# CXX_MODULE = "qml" +# IMPORT_VERSION = "1.$$QT_MINOR_VERSION" +# OTHER_FILES = "testlib.json" +# QML_FILES = "TestCase.qml" "SignalSpy.qml" "testlogger.js" +# TARGETPATH = "QtTest" +# _LOADED = "qml_plugin" + set(qml_files - TestCase.qml - SignalSpy.qml - testlogger.js + "TestCase.qml" + "SignalSpy.qml" + "testlogger.js" +) +set_source_files_properties(TestCase.qml PROPERTIES + QT_QML_SOURCE_VERSION "1.2" + QT_QML_SOURCE_INSTALL TRUE +) +set_source_files_properties(SignalSpy.qml PROPERTIES + QT_QML_SOURCE_VERSION "1.0" + QT_QML_SOURCE_INSTALL TRUE +) +# special case begin +set_source_files_properties(testlogger.js PROPERTIES + QT_QML_SOURCE_INSTALL TRUE ) +# special case end -add_qt_resource(qmltestplugin qmake_QtTest +qt6_target_qml_files(qmltestplugin FILES ${qml_files} ) - -qt_install_qml_files(qmltestplugin - FILES ${qml_files} -) - - -#### Keys ignored in scope 1:.:.:testlib.pro:<TRUE>: -# CXX_MODULE = "qml" -# IMPORT_VERSION = "1.$$QT_MINOR_VERSION" -# OTHER_FILES = "testlib.json" -# _LOADED = "qml_plugin" diff --git a/src/imports/wavefrontmesh/CMakeLists.txt b/src/imports/wavefrontmesh/CMakeLists.txt index 3162873b1a..8700cf9343 100644 --- a/src/imports/wavefrontmesh/CMakeLists.txt +++ b/src/imports/wavefrontmesh/CMakeLists.txt @@ -5,9 +5,9 @@ ##################################################################### add_qml_module(qmlwavefrontmeshplugin - CPP_PLUGIN URI "Qt.labs.wavefrontmesh" VERSION "1.${CMAKE_PROJECT_VERSION_MINOR}" + CLASSNAME QmlWavefrontMeshPlugin SOURCES plugin.cpp qwavefrontmesh.cpp qwavefrontmesh.h diff --git a/src/imports/window/CMakeLists.txt b/src/imports/window/CMakeLists.txt index 7dd022a385..3c42234360 100644 --- a/src/imports/window/CMakeLists.txt +++ b/src/imports/window/CMakeLists.txt @@ -5,10 +5,11 @@ ##################################################################### add_qml_module(windowplugin - CPP_PLUGIN TARGET_PATH "QtQuick/Window.2" URI "QtQuick.Window" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQuick2WindowPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/imports/workerscript/CMakeLists.txt b/src/imports/workerscript/CMakeLists.txt index 6a8efc4d38..c17b76edc6 100644 --- a/src/imports/workerscript/CMakeLists.txt +++ b/src/imports/workerscript/CMakeLists.txt @@ -5,10 +5,11 @@ ##################################################################### add_qml_module(workerscriptplugin - CPP_PLUGIN TARGET_PATH "QtQml/WorkerScript.2" URI "QtQml.WorkerScript" VERSION "2.${CMAKE_PROJECT_VERSION_MINOR}" + DESIGNER_SUPPORTED + CLASSNAME QtQmlWorkerScriptPlugin SOURCES plugin.cpp LIBRARIES diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake new file mode 100644 index 0000000000..f0235c9b41 --- /dev/null +++ b/src/qml/Qt6QmlMacros.cmake @@ -0,0 +1,392 @@ +# +# Q6QmlMacros +# + +# +# Create a Qml Module. Arguments: +# +# URI: Declares the module identifier of the module. The module identifier is +# the (dotted URI notation) identifier for the module, which must match the +# module's install path. (REQUIRED) +# +# VERSION: The module's version. (REQUIRED) +# +# TARGET_PATH: Overwrite the generated target path. By default the target path +# is generated from the URI by replacing the '.' with a '/'. However, under +# certain circumstance this may not be enough. Use this argument to provide +# a replacement. (OPTIONAL) +# +# RESOURCE_PREFIX: Resource Prefix to be used when generating a static library. +# When building a static library, the qmldir file is embedded into the library +# using rcc. It is is also used by the Qt Quick Compiler to embed compiled +# Qml files into a shared or static library. If none is supplied we will +# generate the following prefix: /org.qt-project/imports/${target_path}. +# (OPTIONAL) +# +# OUTPUT_DIRECTORY: If the module is not to be build under +# ${CMAKE_CURRENT_BINARY_DIR}. This ensures the qmldir file is copied to the +# right location. (OPTIONAL) +# +# INSTALL_LOCATION: Intended installation directory for this module. If no +# value is supplied, the default installation path will be ${Qt6_DIR}/qml. +# (OPTIONAL). +# +# DO_NOT_INSTALL: When present, will not install the supporting files. +# +# SOURCES: List of C++ sources. (OPTIONAL) +# +# DEPENDENCIES: List of QML Module depdencies and their versions. The module +# and its version must be separated via a slash(/). E.g. QtQuick/2.0 +# +# QML_FILES: List of Qml files. See qt6_target_qml_files for more information +# on how to specify additional properties on qml files. (OPTIONAL) +# +# CLASSNAME: Provides the class name of the C++ plugin used by the module. This +# information is required for all the QML modules that depend on a C++ plugin +# for additional functionality. Qt Quick applications built with static +# linking cannot resolve the module imports without this information. +# (REQUIRED for static targets) +# +# DESIGNER_SUPPORTED: Specify this argument if the plugin is supported by Qt +# Quick Designer. By default, the plugin will not be supported. (OPTIONAL) +# +# TYPEINFO: Path to a file which declares a type description file for the module +# that can be read by QML tools such as Qt Creator to access information about +# the types defined by the module's plugins. (OPTIONAL) +# +# IMPORTS: List of other Qml Modules that this module imports. (OPTIONAL) +# +# RESOURCE_EXPORT: In static builds, when Qml files are processed via the Qt +# Quick Compiler generate a separate static library that will be linked in +# as an Interface. Supply an output variable to perform any custom actions +# on these extra generated targets. +# + +function(qt6_add_qml_module target) + + set(args_optional + DESIGNER_SUPPORTED + DO_NOT_INSTALL + ) + + if (QT_BUILDING_QT) + list(APPEND args_optional DO_NOT_CREATE_TARGET) + endif() + + set(args_single + RESOURCE_PREFIX + URI + TARGET_PATH + VERSION + OUTPUT_DIRECTORY + INSTALL_LOCATION + CLASSNAME + TYPEINFO + RESOURCE_EXPORT + ) + + set(args_multi + SOURCES + QML_FILES + IMPORTS + DEPENDENCIES + ) + + cmake_parse_arguments(arg + "${args_optional}" + "${args_single}" + "${args_multi}" + ${ARGN} + ) + + if (NOT arg_URI) + message(FATAL_ERROR "qt6_add_qml_module called without a module URI. Please specify one using the URI argument.") + endif() + + if (NOT arg_VERSION) + message(FATAL_ERROR "qt6_add_qml_module called without a module version. Please specify one using the VERSION argument.") + endif() + + if (NOT "${arg_VERSION}" MATCHES "[0-9]+\\.[0-9]+") + message(FATAL_ERROR "qt6_add_qml_module called with an invalid version argument: '${arg_VERSION}'. Expected version style: VersionMajor.VersionMinor.") + endif() + + if (NOT BUILD_SHARED_LIBS AND NOT arg_CLASSNAME) + message(FATAL_ERROR "qt6_add_qml_module Static builds of Qml modules require a class name, none was provided. Please specify one using the CLASSNAME argument.") + endif() + + if (arg_DO_NOT_CREATE_TARGET AND NOT TARGET ${target}) + message(FATAL_ERROR "qt6_add_qml_module called with DO_NOT_CREATE_TARGET, but the given target '${target}' is not a cmake target") + endif() + + if (arg_DO_NOT_CREATE_TARGET) + get_target_property(target_type ${target} TYPE) + if (target_type STREQUAL "STATIC_LIBRARY") + set(is_static TRUE) + elseif(target_type STREQUAL "MODULE_LIBRARY") + set(is_static FALSE) + else() + message(FATAL_ERROR "qt6_add_qml_module called with DO_NOT_CREATE_TARGET, but target '${target}' is neither a static or a module library.") + endif() + else() + if(NOT BUILD_SHARED_LIBS) + add_library(${target} STATIC) + set(is_static TRUE) + else() + add_library(${target} MODULE) + set(is_static FALSE) + endif() + endif() + + if (NOT arg_TARGET_PATH) + string(REPLACE "." "/" arg_TARGET_PATH ${arg_URI}) + endif() + + if (NOT arg_RESOURCE_PREFIX) + set(arg_RESOURCE_PREFIX "/org.qt-project/imports") + endif() + + if (NOT arg_INSTALL_LOCATION) + set(arg_INSTALL_LOCATION "${Qt6_DIR}/../../../qml/${arg_TARGET_PATH}") + endif() + + set_target_properties(${target} + PROPERTIES + QT_QML_MODULE_TARGET_PATH ${arg_TARGET_PATH} + QT_QML_MODULE_URI ${arg_URI} + QT_RESOURCE_PREFIX ${arg_RESOURCE_PREFIX}/${arg_TARGET_PATH} + QT_QML_MODULE_VERSION ${arg_VERSION} + QT_QML_MODULE_INSTALL_DIR ${arg_INSTALL_LOCATION} + QT_QML_MODULE_RESOURCE_EXPORT "${arg_RESOURCE_EXPORT}" + ) + + if (arg_OUTPUT_DIRECTORY AND NOT DO_NOT_CREATE_TARGET) + set_target_properties(${target} + PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${arg_OUTPUT_DIRECTORY} + ARCHIVE_OUTPUT_DIRECTORY ${arg_OUTPUT_DIRECTORY} + ) + endif() + if (arg_OUTPUT_DIRECTORY) + set(target_output_dir ${arg_OUTPUT_DIRECTORY}) + else() + if(is_static) + get_target_property(target_output_dir ${target} ARCHIVE_OUTPUT_DIRECTORY) + else() + get_target_property(target_output_dir ${target} LIBRARY_OUTPUT_DIRECTORY) + endif() + endif() + + if (arg_SOURCES) + target_sources(${target} PRIVATE ${arg_SOURCES}) + endif() + + # Tracker so we can generate unique resource names for multiple + # target_qml_files() calls. + set_target_properties(${target} PROPERTIES QT6_QML_MODULE_ADD_QML_FILES_COUNT 1) + + # Generate qmldir file + set(qmldir_file "${CMAKE_CURRENT_BINARY_DIR}/qmldir") + set_target_properties(${target} PROPERTIES QT_QML_MODULE_QMLDIR_FILE ${qmldir_file}) + set(qmldir_file_contents "module ${arg_URI}\n") + string(APPEND qmldir_file_contents "plugin ${target}\n") + if (arg_CLASSNAME) + string(APPEND qmldir_file_contents "classname ${arg_CLASSNAME}\n") + endif() + if (arg_DESIGNER_SUPPORTED) + string(APPEND qmldir_file_contents "designersupported\n") + endif() + if (arg_TYPEINFO) + string(APPEND qmldir_file_contents "typeinfo ${arg_TYPEINFO}\n") + endif() + foreach(import IN LISTS arg_IMPORTS) + string(APPEND qmldir_file_contents "import ${import}\n") + endforeach() + + foreach(dependency IN LISTS arg_DEPENDENCIES) + string(FIND ${dependency} "/" slash_position REVERSE) + if (slash_position EQUAL -1) + message(FATAL_ERROR "Dependencies should follow the format 'ModuleName/VersionMajor.VersionMinor'") + endif() + string(SUBSTRING ${dependency} 0 ${slash_position} dep_module) + math(EXPR slash_position "${slash_position} + 1") + string(SUBSTRING ${dependency} ${slash_position} -1 dep_version) + if (NOT dep_version MATCHES "[0-9]+\\.[0-9]+") + message(FATAL_ERROR "Invalid module dependency version number. Expected VersionMajor.VersionMinor.") + endif() + string(APPEND qmldir_file_contents "dependency ${dep_module} ${dep_version}\n") + endforeach() + + file(WRITE ${qmldir_file} ${qmldir_file_contents}) + + # Process qml files + if (arg_QML_FILES) + qt6_target_qml_files(${target} FILES ${arg_QML_FILES}) + endif() + + # Embed qmldir in static builds + if (is_static) + string(REPLACE "/" "_" qmldir_resource_name ${arg_TARGET_PATH}) + string(APPEND qmldir_resource_name "_qmldir") + + set_source_files_properties("${qmldir_file}" + PROPERTIES QT_RESOURCE_ALIAS "qmldir" + ) + + set(resource_target "Foo") + QT6_ADD_RESOURCES(${target} ${qmldir_resource_name} + PREFIX ${target_resource_prefix} + FILES "${qmldir_file}" + OUTPUT_TARGETS resource_targets + ) + + if (resource_targets AND arg_RESOURCE_EXPORT) + install(TARGETS ${resource_targets} + EXPORT "${arg_RESOURCE_EXPORT}" + DESTINATION ${arg_INSTALL_LOCATION} + ) + endif() + else() + # Copy QMLDIR file to build directory + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${qmldir_file} + ${target_output_dir} + ) + + # Install QMLDIR file + if (NOT DO_NOT_INSTALL) + install(FILES ${qmldir_file} + DESTINATION ${arg_INSTALL_LOCATION} + ) + endif() + endif() + + # Install and Copy plugin.qmltypes if exists + set(target_plugin_qmltypes "${CMAKE_CURRENT_SOURCE_DIR}/plugins.qmltypes") + if (EXISTS ${target_plugin_qmltypes}) + file(APPEND ${qmldir_file} "typeinfo plugins.qmltypes\n") + if (NOT arg_DO_NOT_INSTALL) + install(FILES ${target_plugin_qmltypes} + DESTINATION ${arg_INSTALL_LOCATION} + ) + endif() + + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${target_plugin_qmltypes} + ${target_output_dir} + ) + endif() + + # Copy/Install type info file + if (EXISTS ${arg_TYPEINFO}) + if (NOT arg_DO_NOT_INSTALL) + install(FILES ${arg_TYPEINFO} + DESTINATION ${arg_INSTALL_LOCATION} + ) + endif() + + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${arg_TYPEINFO} + ${target_output_dir} + ) + endif() +endfunction() + + +# +# Add Qml files (.qml,.js,.mjs) to a Qml module. This will also append the +# qml files to the qmldir file of the module. Two source file properties can +# be used to control the generated qmldir entry. +# +# QT_QML_SOURCE_VERSION: Version for this qml file. If not present the module +# version will be used. +# QT_QML_SOURCE_TYPENAME: Override the file's type name. If not present the +# type name will be deduced using the file's basename. +# QT_QML_SINGLETON_TYPE: Set to true if this qml file contains a singleton +# type. +# QT_QML_SOURCE_INSTALL: When set to true, the file will be installed alongside +# the module. +# QT_QML_INTERNAL_TYPE: When set to true, the type specified by +# QT_QML_SOURCE_TYPENAME will not be available to users of this module. +# +# e.g.: +# set_source_files_properties(my_qml_file.qml +# PROPERTIES +# QT_QML_SOURCE_VERSION 2.0 +# QT_QML_SOURCE_TYPENAME MyQmlFile +# +# qt6_target_qml_files(my_qml_module +# FILES +# my_qml_file.qml +# ) +# +# Will produce the following entry in the qmldir file +# +# MyQmlFile 2.0 my_qml_file.qml +# +# +function(qt6_target_qml_files target) + + cmake_parse_arguments(arg "" "" "FILES" ${ARGN}) + get_target_property(resource_count ${target} QT6_QML_MODULE_ADD_QML_FILES_COUNT) + get_target_property(qmldir_file ${target} QT_QML_MODULE_QMLDIR_FILE) + if (NOT qmldir_file) + message(FATAL_ERROR "qt6_target_qml_file: ${target} is not a Qml module") + endif() + + if (NOT arg_FILES) + return() + endif() + math(EXPR new_count "${resource_count} + 1") + set_target_properties(${target} PROPERTIES QT6_QML_MODULE_ADD_QML_FILES_COUNT ${new_count}) + + qt6_add_resources(${target} "qml_files${new_count}" + FILES ${arg_FILES} + OUTPUT_TARGETS resource_targets + ) + get_target_property(target_resource_export ${target} QT_QML_MODULE_RESOURCE_EXPORT) + get_target_property(qml_module_install_dir ${target} QT_QML_MODULE_INSTALL_DIR) + if (resource_targets) + install(TARGETS ${resource_targets} + EXPORT "${target_resource_export}" + DESTINATION ${qm_module_install_dir} + ) + endif() + + set(file_contents "") + foreach(qml_file IN LISTS arg_FILES) + get_source_file_property(qml_file_version ${qml_file} QT_QML_SOURCE_VERSION) + get_source_file_property(qml_file_typename ${qml_file} QT_QML_SOURCE_TYPENAME) + get_source_file_property(qml_file_singleton ${qml_file} QT_QML_SINGLETON_TYPE) + get_source_file_property(qml_file_internal ${qml_file} QT_QML_INTERNAL_TYPE) + get_source_file_property(qml_file_install ${qml_file} QT_QML_SOURCE_INSTALL) + get_target_property(qml_module_version ${target} QT_QML_MODULE_VERSION) + + if (NOT qml_file_version) + set(qml_file_version ${qml_module_version}) + endif() + + if (NOT qml_file_typename) + get_filename_component(qml_file_typename ${qml_file} NAME_WLE) + endif() + + if (qml_file_singleton) + string(APPEND file_contents "[singleton] ") + endif() + + string(APPEND file_contents "${qml_file_typename} ${version} ${qml_file}\n") + + if (qml_file_internal) + string(APPEND file_contents "internal ${qml_file_typename} ${qml_file}\n") + endif() + + if (qml_file_install) + install(FILES ${qml_file} DESTINATION ${qml_module_install_dir}) + endif() + + endforeach() + file(APPEND ${qmldir_file} ${file_contents}) +endfunction() |