diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-09-16 12:11:44 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2020-09-16 13:52:14 +0200 |
commit | 1d67ecd790fe08a7cea1327ee754a9b8e74d113f (patch) | |
tree | 1f3aea2903aaf65c5fcbf3521c77aca809e04702 /src | |
parent | a15840a8dfcd0baf0965422f9cb3eca14cc99cf9 (diff) |
CMake: Make reconfiguration work for in-source builds
Qml plugins can either use a plugins.qmltypes file from the source
repository, or opt into generating it if the file doesn't exist.
There is a use case for the file not to be generated for some Qml
tests.
To protect against accidentally overriding the source repo file,
an error is shown if the file exists in the source directory and we
also also try to generate it.
With an in-source build, all plugins.qmltypes files are generated in
the source directory, and this causes the above check to be triggered
on reconfiguration.
To avoid the false issue, create a new
"${CMAKE_CURRENT_BINARY_DIR}/.generated/plugins.qmltypes" file to
serve as a marker that the actual file was generated, and is not part
of the source repository.
If the marker file exists, don't error out.
Change-Id: Ieca28b4da0251f67f8c066cbac471c8e6e955758
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/Qt6QmlMacros.cmake | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake index 8f9b57cd0c..71d65ad27a 100644 --- a/src/qml/Qt6QmlMacros.cmake +++ b/src/qml/Qt6QmlMacros.cmake @@ -361,7 +361,13 @@ function(qt6_add_qml_module target) # Install and Copy plugin.qmltypes if exists set(target_plugin_qmltypes "${CMAKE_CURRENT_SOURCE_DIR}/plugins.qmltypes") - if (EXISTS ${target_plugin_qmltypes}) + + # For an in-source build, ensure that the file is not the one that was generated by + # qt6_qml_type_registration. + get_target_property(target_binary_dir ${target} BINARY_DIR) + set(generated_marker_file "${target_binary_dir}/.generated/plugins.qmltypes") + + if (EXISTS "${target_plugin_qmltypes}" AND NOT EXISTS "${generated_marker_file}") set_target_properties(${target} PROPERTIES QT_QML_MODULE_PLUGIN_TYPES_FILE "${target_plugin_qmltypes}" ) @@ -591,7 +597,9 @@ function(qt6_qml_type_registration target) endif() set(cmd_args) - set(plugin_types_file ${target_binary_dir}/${qmltypes_output_name}) + set(plugin_types_file "${target_binary_dir}/${qmltypes_output_name}") + set(generated_marker_dir "${target_binary_dir}/.generated") + set(generated_marker_file "${generated_marker_dir}/${qmltypes_output_name}") set_target_properties(${target} PROPERTIES QT_QML_MODULE_PLUGIN_TYPES_FILE ${plugin_types_file} ) @@ -662,6 +670,10 @@ function(qt6_qml_type_registration target) ${cmd_args} -o ${type_registration_cpp_file} ${target_metatypes_json_file} + COMMAND + ${CMAKE_COMMAND} -E make_directory "${generated_marker_dir}" + COMMAND + ${CMAKE_COMMAND} -E touch "${generated_marker_file}" ${registration_cpp_file_dep_args} COMMENT "Automatic QML type registration for target ${target}" ) |