aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2020-05-25 19:21:05 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2020-05-29 10:01:28 +0200
commitdc6b76d85dc03d0a6866069169562f8d1942fe56 (patch)
treeafa0ecb4474190e0b689e352af9b6e5eabea8a77 /src
parent350a2f48c15d7766a58f13c9625e32e766ecdf80 (diff)
CMake: Explicitly require install location for plugin.qmltypes
If a user doesn't specify an explicit installation path for the plugin.qmltypes file, warn them about it, and make sure not to try and install the file. For internal Qt modules and plugins, we always set the path via the private qt_add_qml_module api call or by specifying the installation path explicitly via the QT_QML_MODULE_INSTALL_DIR property. Task-number: QTBUG-84403 Change-Id: I587fd70f9c767ae26f5268bb8fefc7ea678e170f Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/Qt6QmlMacros.cmake65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 3b384f5dae..fd3f73e97d 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -464,20 +464,7 @@ function(qt6_qml_type_registration target)
endif()
endif()
- cmake_parse_arguments(arg "COPY_OVER_INSTALL" "INSTALL_DIR" "" ${ARGN})
-
- set(meta_types_args)
- if (QT_BUILDING_QT AND NOT QT_WILL_INSTALL)
- set(arg_COPY_OVER_INSTALL TRUE)
- endif()
- if (arg_INSTALL_DIR)
- list(APPEND meta_types_args INSTALL_DIR "${arg_INSTALL_DIR}")
- endif()
- if (arg_COPY_OVER_INSTALL)
- list(APPEND meta_types_args COPY_OVER_INSTALL)
- endif()
-
- qt6_generate_meta_types_json_file(${target} ${meta_types_args})
+ qt6_generate_meta_types_json_file(${target})
get_target_property(import_version ${target} QT_QML_MODULE_VERSION)
get_target_property(target_source_dir ${target} SOURCE_DIR)
@@ -567,6 +554,7 @@ function(qt6_qml_type_registration target)
set(extra_env_command)
if (WIN32)
+ # TODO: FIXME: The env path is wrong when not building Qt, but a standalone example.
file(TO_NATIVE_PATH "${${PROJECT_NAME}_BINARY_DIR}/bin$<SEMICOLON>${CMAKE_INSTALL_PREFIX}/${INSTALL_BINDIR}$<SEMICOLON>%PATH%" env_path_native)
set(extra_env_command COMMAND set PATH=${env_path_native})
endif()
@@ -590,25 +578,44 @@ function(qt6_qml_type_registration target)
SKIP_AUTOGEN ON
)
- # Only install qml types if necessary
+ # Usually for Qt Qml-like modules and qml plugins, the installation destination of the .qmltypes
+ # file is somewhere under the ${qt_prefix}/qml (Qt qml import path).
+ #
+ # For user-written qml plugins, the file should be installed next to the
+ # binary / library, and not the Qt qml import path.
+ #
+ # Unfortunately CMake doesn't provide a way to query where a binary will be installed, so the
+ # only way to know where to install is to request the installation path via a property.
+ #
+ # Thus only install the qmltypes file if an explicit path via the QT_QML_MODULE_INSTALL_DIR
+ # property has been provided. Otherwise if installation is requested, and no path is provided,
+ # warn the user, and don't install the file.
get_target_property(install_qmltypes ${target} QT_QML_MODULE_INSTALL_QMLTYPES)
if (install_qmltypes)
get_target_property(qml_install_dir ${target} QT_QML_MODULE_INSTALL_DIR)
- if(NOT arg_COPY_OVER_INSTALL)
- install(FILES ${plugin_types_file} DESTINATION ${qml_install_dir})
- else()
- # For regular modules that have not been declared using
- # qt_add_qml_module (e.g: src/quick)
- if (DEFINED QT_WILL_INSTALL AND NOT QT_WILL_INSTALL
- AND NOT IS_ABSOLUTE "${qml_install_dir}")
- set(qml_install_dir "${QT_BUILD_DIR}/${qml_install_dir}")
+ if(qml_install_dir)
+ if(NOT DEFINED QT_WILL_INSTALL OR QT_WILL_INSTALL)
+ install(FILES ${plugin_types_file} DESTINATION "${qml_install_dir}")
+ else()
+ # Need to make the path absolute during a Qt non-prefix build, otherwise files are
+ # written to the source dir because the paths are relative to the source dir.
+ if(NOT IS_ABSOLUTE "${qml_install_dir}")
+ set(qml_install_dir "${CMAKE_INSTALL_PREFIX}/${qml_install_dir}")
+ endif()
+
+ add_custom_command(TARGET ${target} POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different
+ "${plugin_types_file}"
+ "${qml_install_dir}/${qmltypes_output_name}"
+ COMMENT "Copying ${plugin_types_file} to ${qml_install_dir}"
+ )
endif()
- add_custom_command(TARGET ${target} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy_if_different
- "${plugin_types_file}"
- "${qml_install_dir}/${qmltypes_output_name}"
- COMMENT "Copying ${plugin_types_file} to ${qml_install_dir}"
- )
+ else()
+ message(AUTHOR_WARNING
+ "No QT_QML_MODULE_INSTALL_DIR property value provided for the '${target}' target. "
+ "Please either provide a value, or don't set the "
+ "QT_QML_MODULE_INSTALL_QMLTYPES property. "
+ "Skipping installation of '${qmltypes_output_name}'.")
endif()
endif()