Warning, /frameworks/extra-cmake-modules/modules/ECMQmlModule6.cmake is written in an unsupported language. File is not indexed.
0001 # 0002 # SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 # 0004 # SPDX-License-Identifier: BSD-3-Clause 0005 0006 # Qt 6 implementation of ECMQmlModule 0007 0008 set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON) 0009 find_package(Qt6 COMPONENTS Core Qml CONFIG) 0010 unset(QT_NO_CREATE_VERSIONLESS_FUNCTIONS) 0011 0012 if (NOT TARGET Qt6::Qml) 0013 message(WARNING "Target Qt6::Qml was not found. ECMQmlModule requires the QML module when building with Qt 6") 0014 return() 0015 endif() 0016 0017 # Match KDECMakeSettings' RUNTIME_OUTPUT_DIRECTORY so that we can load plugins from 0018 # the build directory when running tests. But only if we don't yet have an output directory. 0019 if (NOT QT_QML_OUTPUT_DIRECTORY) 0020 set(QT_QML_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0021 endif() 0022 0023 # Stop warning about a changed import prefix. 0024 qt6_policy(SET QTP0001 NEW) 0025 0026 function(ecm_add_qml_module ARG_TARGET) 0027 cmake_parse_arguments(PARSE_ARGV 1 ARG "NO_PLUGIN;QT_NO_PLUGIN;GENERATE_PLUGIN_SOURCE" "URI;VERSION;CLASSNAME" "") 0028 0029 if ("${ARG_TARGET}" STREQUAL "") 0030 message(FATAL_ERROR "ecm_add_qml_module called without a valid target name.") 0031 endif() 0032 0033 if ("${ARG_URI}" STREQUAL "") 0034 message(FATAL_ERROR "ecm_add_qml_module called without a valid module URI.") 0035 endif() 0036 0037 string(FIND "${ARG_URI}" " " "_space") 0038 if (${_space} GREATER_EQUAL 0) 0039 message(FATAL_ERROR "ecm_add_qml_module called without a valid module URI.") 0040 endif() 0041 0042 set(_arguments ${ARG_TARGET} URI ${ARG_URI}) 0043 0044 if (ARG_VERSION) 0045 list(APPEND _arguments VERSION ${ARG_VERSION}) 0046 endif() 0047 0048 if (ARG_CLASSNAME) 0049 message(AUTHOR_WARNING "The CLASSNAME argument to ecm_add_qml_module is deprecated for Qt 6; Use CLASS_NAME instead.") 0050 list(APPEND _arguments CLASS_NAME ${ARG_CLASSNAME}) 0051 endif() 0052 0053 if (ARG_NO_PLUGIN) 0054 message(AUTHOR_WARNING "The NO_PLUGIN argument to ecm_add_qml_module is deprecated for Qt 6; For Qt 6 QML modules always require a plugin library. Use GENERATE_PLUGIN_SOURCE instead. If you wish to use the NO_PLUGIN feature from qt_add_qml_module, use QT_NO_PLUGIN.") 0055 set(ARG_GENERATE_PLUGIN_SOURCE TRUE) 0056 endif() 0057 0058 if (ARG_QT_NO_PLUGIN) 0059 list(APPEND _arguments NO_PLUGIN) 0060 endif() 0061 0062 if (NOT ARG_GENERATE_PLUGIN_SOURCE) 0063 list(APPEND _arguments NO_GENERATE_PLUGIN_SOURCE) 0064 endif() 0065 0066 if (NOT TARGET ${ARG_TARGET}) 0067 list(APPEND _arguments PLUGIN_TARGET ${ARG_TARGET}) 0068 if (BUILD_SHARED_LIBS) 0069 list(APPEND _arguments SHARED) 0070 else() 0071 list(APPEND _arguments STATIC) 0072 endif() 0073 endif() 0074 0075 list(APPEND _arguments ${ARG_UNPARSED_ARGUMENTS}) 0076 0077 qt6_add_qml_module(${_arguments}) 0078 0079 # KDECMakeSettings sets the prefix of MODULE targets to empty but Qt will 0080 # not load a QML plugin without prefix. So we need to force it here. 0081 qt6_query_qml_module(${ARG_TARGET} PLUGIN_TARGET _plugin_target) 0082 if (NOT WIN32 AND TARGET ${_plugin_target}) 0083 set_target_properties(${_plugin_target} PROPERTIES PREFIX "lib") 0084 endif() 0085 endfunction() 0086 0087 function(ecm_add_qml_module_dependencies ARG_TARGET) 0088 message(AUTHOR_WARNING "ecm_add_qml_module_dependencies is deprecated for Qt 6; use the DEPENDENCIES argument to ecm_add_qml_module() instead.") 0089 endfunction() 0090 0091 function(ecm_target_qml_sources ARG_TARGET) 0092 cmake_parse_arguments(PARSE_ARGV 1 ARG "PRIVATE" "VERSION;PATH" "SOURCES") 0093 0094 if ("${ARG_SOURCES}" STREQUAL "") 0095 message(FATAL_ERROR "ecm_target_qml_sources called without required argument SOURCES") 0096 endif() 0097 0098 if (ARG_VERSION) 0099 set_source_files_properties(${ARG_SOURCES} PROPERTIES QT_QML_SOURCE_VERSIONS "${ARG_VERSION}") 0100 endif() 0101 0102 if (ARG_PRIVATE) 0103 set_source_files_properties(${ARG_SOURCES} PROPERTIES QT_QML_INTERNAL_TYPE TRUE) 0104 endif() 0105 0106 foreach(_path ${ARG_SOURCES}) 0107 get_filename_component(_file "${_path}" NAME) 0108 get_filename_component(_ext "${_path}" EXT) 0109 set(_resource_alias "${_file}") 0110 if (ARG_PATH) 0111 set(_resource_alias "${ARG_PATH}/${_file}") 0112 endif() 0113 set_source_files_properties("${_path}" PROPERTIES QT_RESOURCE_ALIAS "${_resource_alias}") 0114 if ("${_ext}" MATCHES "(.qml|.js|.mjs)") 0115 qt6_target_qml_sources(${ARG_TARGET} QML_FILES "${_path}" ${ARG_UNPARSED_ARGUMENTS}) 0116 else() 0117 qt6_target_qml_sources(${ARG_TARGET} RESOURCES "${_path}" ${ARG_UNPARSED_ARGUMENTS}) 0118 endif() 0119 endforeach() 0120 endfunction() 0121 0122 function(ecm_finalize_qml_module ARG_TARGET) 0123 cmake_parse_arguments(PARSE_ARGV 1 ARG "" "DESTINATION;VERSION" "") 0124 0125 if (NOT ARG_DESTINATION) 0126 set(ARG_DESTINATION "${KDE_INSTALL_QMLDIR}") 0127 endif() 0128 0129 if ("${ARG_DESTINATION}" STREQUAL "") 0130 message(FATAL_ERROR "ecm_finalize_qml_module called without required argument DESTINATION and KDE_INSTALL_QMLDIR is not set") 0131 endif() 0132 0133 if (NOT ARG_VERSION) 0134 set(ARG_VERSION "${PROJECT_VERSION}") 0135 endif() 0136 0137 # This is effectively a workaround for missing upstream API, see QTBUG-100102 0138 0139 qt6_query_qml_module(${ARG_TARGET} 0140 URI module_uri 0141 VERSION module_version 0142 PLUGIN_TARGET module_plugin_target 0143 TARGET_PATH module_target_path 0144 QMLDIR module_qmldir 0145 TYPEINFO module_typeinfo 0146 QML_FILES module_qml_files 0147 RESOURCES module_resources 0148 ) 0149 0150 set(module_dir "${ARG_DESTINATION}/${module_target_path}") 0151 0152 if (NOT TARGET "${module_plugin_target}") 0153 return() 0154 endif() 0155 0156 install(TARGETS "${module_plugin_target}" 0157 LIBRARY DESTINATION "${module_dir}" 0158 RUNTIME DESTINATION "${module_dir}" 0159 ) 0160 0161 # Install the QML module meta information. 0162 install(FILES "${module_qmldir}" DESTINATION "${module_dir}") 0163 install(FILES "${module_typeinfo}" DESTINATION "${module_dir}") 0164 0165 # Install QML files, possibly renamed. 0166 list(LENGTH module_qml_files num_files) 0167 if (NOT "${module_qml_files}" MATCHES "NOTFOUND" AND ${num_files} GREATER 0) 0168 qt6_query_qml_module(${ARG_TARGET} QML_FILES_DEPLOY_PATHS qml_files_deploy_paths) 0169 0170 math(EXPR last_index "${num_files} - 1") 0171 foreach(i RANGE 0 ${last_index}) 0172 list(GET module_qml_files ${i} src_file) 0173 list(GET qml_files_deploy_paths ${i} deploy_path) 0174 get_filename_component(dst_name "${deploy_path}" NAME) 0175 get_filename_component(dest_dir "${deploy_path}" DIRECTORY) 0176 install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}") 0177 endforeach() 0178 endif() 0179 0180 # Install resources, possibly renamed. 0181 list(LENGTH module_resources num_files) 0182 if (NOT "${module_resources}" MATCHES "NOTFOUND" AND ${num_files} GREATER 0) 0183 qt6_query_qml_module(${ARG_TARGET} RESOURCES_DEPLOY_PATHS resources_deploy_paths) 0184 0185 math(EXPR last_index "${num_files} - 1") 0186 foreach(i RANGE 0 ${last_index}) 0187 list(GET module_resources ${i} src_file) 0188 list(GET resources_deploy_paths ${i} deploy_path) 0189 get_filename_component(dst_name "${deploy_path}" NAME) 0190 get_filename_component(dest_dir "${deploy_path}" DIRECTORY) 0191 install(FILES "${src_file}" DESTINATION "${module_dir}/${dest_dir}" RENAME "${dst_name}") 0192 endforeach() 0193 endif() 0194 0195 file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}-kde-qmlmodule.version" CONTENT "${ARG_VERSION}\n") 0196 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${ARG_TARGET}-kde-qmlmodule.version" DESTINATION "${module_dir}" RENAME "kde-qmlmodule.version") 0197 endfunction()