aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/Qt6QmlBuildInternals.cmake
blob: ef2c1c4ac6a33c2e7620af4159becbdd0d865d7f (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# 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)

    _qt_internal_get_add_plugin_keywords(
        public_option_args
        public_single_args
        public_multi_args
    )
    qt_internal_get_internal_add_plugin_keywords(
        internal_option_args
        internal_single_args
        internal_multi_args
    )

    # We don't want to pass CLASS_NAME to qt_internal_add_plugin(), we will
    # pass it to qt6_add_qml_module() to handle instead. qt_internal_add_plugin()
    # would just ignore it anyway because we set TYPE to qml_plugin, but we have
    # to remove it to prevent duplicates in argument parsing.
    list(REMOVE_ITEM public_single_args CLASS_NAME)

    set(qml_module_option_args
        GENERATE_QMLTYPES
        INSTALL_QMLTYPES
        DESIGNER_SUPPORTED
        SKIP_TYPE_REGISTRATION
        PLUGIN_OPTIONAL
    )

    set(qml_module_single_args
        URI
        TARGET_PATH
        VERSION
        TYPEINFO
        CLASS_NAME
        CLASSNAME  # TODO: Remove once all other repos have been updated to use
                   #       CLASS_NAME instead.
    )

    set(qml_module_multi_args
        QML_FILES
        IMPORTS
        OPTIONAL_IMPORTS
        DEPENDENCIES
        PAST_MAJOR_VERSIONS
    )

    set(option_args
        ${public_option_args}
        ${internal_option_args}
        ${qml_module_option_args}
    )
    set(single_args
        ${public_single_args}
        ${internal_single_args}
        ${qml_module_single_args}
    )
    set(multi_args
        ${public_multi_args}
        ${internal_multi_args}
        ${qml_module_multi_args}
    )

    qt_parse_all_arguments(arg "qt_internal_add_qml_module"
        "${option_args}"
        "${single_args}"
        "${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_option_args}
            ${qml_module_single_args}
            ${qml_module_multi_args}
            OUTPUT_DIRECTORY
            INSTALL_DIRECTORY
        ALL_ARGS
            ${option_args}
            ${single_args}
            ${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_option_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()