aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/Qt6QmlBuildInternals.cmake
blob: dc0204adacbcaa10bd07d5050131ab5d294dbee7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#
# QtDeclarative Specific extensions
#

include_guard(GLOBAL)

# This function is essentially a convenience wrapper around a pair of calls
# to qt_internal_add_plugin() and qt6_add_qml_module(). It ensures a consistent
# set of arguments are used for both. Most keywords for either command are
# supported, with a few exceptions:
#
# - RESOURCE_PREFIX and RESOURCE_EXPORT are both hard-coded and cannot be
#   overridden by the caller.
# - OUTPUT_DIRECTORY and INSTALL_DIRECTORY will be set if not provided.
# - SOURCES is only passed through to qt_internal_add_plugin() but not to
#   qt6_add_qml_module(). If SOURCES is not set, PURE_MODULE will be passed to
#   qt6_add_qml_module() so that a dummy plugin.cpp file will be generated.
#
# See qt_internal_add_plugin() and qt6_add_qml_module() for the full set of
# supported keywords.
function(qt_internal_add_qml_module target)

    set(qml_module_optional_args
        GENERATE_QMLTYPES
        INSTALL_QMLTYPES
        DESIGNER_SUPPORTED
        SKIP_TYPE_REGISTRATION
        PLUGIN_OPTIONAL
    )

    set(qml_module_single_args
        URI
        TARGET_PATH
        VERSION
        CLASSNAME
        TYPEINFO
    )

    set(qml_module_multi_args
        QML_FILES
        IMPORTS
        OPTIONAL_IMPORTS
        DEPENDENCIES
        PAST_MAJOR_VERSIONS
    )

    qt_parse_all_arguments(arg "qt_add_qml_module"
        "${__qt_add_plugin_optional_args};${qml_module_optional_args}"
        "${__qt_add_plugin_single_args};${qml_module_single_args}"
        "${__qt_add_plugin_multi_args};${qml_module_multi_args}" ${ARGN})

    if (NOT arg_TARGET_PATH)
        string(REPLACE "." "/" arg_TARGET_PATH ${arg_URI})
    endif()
    if (NOT arg_OUTPUT_DIRECTORY)
        set(arg_OUTPUT_DIRECTORY "${QT_BUILD_DIR}/${INSTALL_QMLDIR}/${arg_TARGET_PATH}")
    endif()
    if (NOT arg_INSTALL_DIRECTORY)
        set(arg_INSTALL_DIRECTORY "${INSTALL_QMLDIR}/${arg_TARGET_PATH}")
    endif()

    qt_remove_args(plugin_args
        ARGS_TO_REMOVE
            ${qml_module_optional_args}
            ${qml_module_single_args}
            ${qml_module_multi_args}
            OUTPUT_DIRECTORY
            INSTALL_DIRECTORY
        ALL_ARGS
            ${__qt_add_plugin_optional_args}
            ${__qt_add_plugin_single_args}
            ${__qt_add_plugin_multi_args}
            ${qml_module_optional_args}
            ${qml_module_single_args}
            ${qml_module_multi_args}
        ARGS
            ${ARGN}
    )

    qt_internal_add_plugin(${target}
        TYPE qml_plugin
        OUTPUT_DIRECTORY ${arg_OUTPUT_DIRECTORY}
        INSTALL_DIRECTORY ${arg_INSTALL_DIRECTORY}
        ${plugin_args}
    )

    if (arg_SOURCES AND NOT arg_TYPEINFO)
        set(arg_TYPEINFO "plugins.qmltypes")
    endif()

    set(add_qml_module_args DO_NOT_CREATE_TARGET)

    # Pass through options if given (these are present/absent, not true/false)
    foreach(opt IN LISTS qml_module_optional_args)
        if(arg_${opt})
            list(APPEND add_qml_module_args ${opt})
        endif()
    endforeach()

    # Pass through single and multi-value args as provided
    foreach(arg IN LISTS qml_module_single_args qml_module_multi_args)
        if(DEFINED arg_${arg})
            list(APPEND add_qml_module_args ${arg} ${arg_${arg}})
        endif()
    endforeach()


    # Because qt_internal_add_qml_module does not propagate its SOURCES option to
    # qt6_add_qml_module, but only to qt_internal_add_plugin, we need a way to tell
    # qt6_add_qml_module if it should generate a dummy plugin cpp file. Otherwise we'd generate
    # a dummy plugin.cpp file twice and thus cause duplicate symbol issues.
    if (NOT arg_SOURCES)
        list(APPEND add_qml_module_args PURE_MODULE)
    endif()

    qt6_add_qml_module(${target}
        ${add_qml_module_args}
        OUTPUT_DIRECTORY ${arg_OUTPUT_DIRECTORY}
        INSTALL_DIRECTORY ${arg_INSTALL_DIRECTORY}
        RESOURCE_PREFIX "/qt-project.org/imports"
        RESOURCE_EXPORT "${INSTALL_CMAKE_NAMESPACE}${target}Targets"
    )
endfunction()

if(NOT QT_NO_INTERNAL_COMPATIBILITY_FUNCTIONS)
    # Compatibility functions that should be removed once all their usages are removed.
    function(add_qml_module)
        qt_add_qml_module(${ARGV})
    endfunction()

    function(qt_add_qml_module)
        qt_internal_add_qml_module(${ARGV})
    endfunction()
endif()