aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2022-09-08 15:55:09 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-09-10 16:50:27 +0000
commit8148b3c04bc68c6c4d4b8e7bb6a6ba9e362967de (patch)
tree5de7f96fbcfbb790d7cd119974317e61ff1bfdea
parent121107c01d03107bd11b44724f461d3f455012b2 (diff)
CMake: Partially unify tooling import path handling
Add a function that returns all Qt import paths. It's intended to be used to pass the import paths to the various tooling invocations like qmlsc, qmltc, qmlimportscanner, qmllint, qmlcachegen. The order of the Qt prefixes returned is: - The build dir of the currently built qt repo (e.g qtdeclarative/qml) - Additional paths specified via _qt_additional_packages_prefix_paths - The main Qt installation prefix QT6_INSTALL_PREFIX Use this function for the various tooling invocations. Make sure the paths are only added if they exist on the file system, otherwise some of the tools might complain about non-existent paths, for example qmlimportscanner. This is only a partial unification, because we should still figure out how unify all the various target specific properties like QT_QML_IMPORT_PATH and QT_QML_MODULE_OUTPUT_DIRECTORY as well as the differences where in certain places the paths are specified via genexes like $<TARGET_PROPERTY:${target},BINARY_DIR> and _qt_internal_genex_getjoinedproperty and qmlcachegen custom import path computation done in qt6_target_qml_sources. Task-number: QTBUG-106365 Change-Id: Ia1297ebd57764068a4b8fbcb5ac70df6b380d3f6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 3a35b57269519bfed2418e27ed9daf69f27576a0) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/Qt6QmlMacros.cmake89
1 files changed, 60 insertions, 29 deletions
diff --git a/src/qml/Qt6QmlMacros.cmake b/src/qml/Qt6QmlMacros.cmake
index 4b4c9cc230..7443b6da25 100644
--- a/src/qml/Qt6QmlMacros.cmake
+++ b/src/qml/Qt6QmlMacros.cmake
@@ -715,16 +715,18 @@ macro(_qt_internal_genex_getoption var target property)
set(${var} "$<BOOL:$<TARGET_PROPERTY:${target},${property}>>")
endmacro()
+# Gets the Qt import paths, prepends -I, appends the values to the given import_paths_var output
+# variable.
function(_qt_internal_extend_qml_import_paths import_paths_var)
set(local_var ${${import_paths_var}})
- # prepend extra import path which is a current module's build dir: we need
- # this to ensure correct importing of QML modules when having a prefix-build
- # with QLibraryInfo::path(QLibraryInfo::QmlImportsPath) pointing to the
- # install location
- if(QT_BUILDING_QT AND QT_WILL_INSTALL)
- list(PREPEND local_var -I "${QT_BUILD_DIR}/${INSTALL_QMLDIR}")
- endif()
+ _qt_internal_get_main_qt_qml_import_paths(qt_import_paths)
+
+ # Append the paths instead of prepending them, to ensure Qt import paths are searched after
+ # any target or build dir specific import paths.
+ foreach(import_path IN LISTS qt_import_paths)
+ list(APPEND local_var -I "${import_path}")
+ endforeach()
set(${import_paths_var} ${local_var} PARENT_SCOPE)
endfunction()
@@ -2540,6 +2542,48 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
endfunction()
endif()
+# Get Qt provided QML import paths.
+# The appending order is important. Build dirs are preferred over install dirs.
+function(_qt_internal_get_main_qt_qml_import_paths out_var)
+ set(qml_import_paths "")
+
+ # When building a qml module as part of a prefix Qt build that is not yet installed, add an
+ # extra import path which is the current module's build dir: we need
+ # this to ensure correct importing of QML modules when having a prefix-build
+ # with QLibraryInfo::path(QLibraryInfo::QmlImportsPath) pointing to the
+ # install location.
+ if(QT_BUILDING_QT AND QT_WILL_INSTALL)
+ set(build_dir_import_path "${QT_BUILD_DIR}/${INSTALL_QMLDIR}")
+ if(IS_DIRECTORY "${build_dir_import_path}")
+ list(APPEND qml_import_paths "${build_dir_import_path}")
+ endif()
+ endif()
+
+ # We could have multiple additional installation prefixes: one per Qt repository (conan).
+ # Or just extra ones, that might be needed during cross-compilation or example building.
+ # Add those that have a "qml" subdirectory.
+ # The additional prefixes have priority over the main Qt prefix, so they come first.
+ if(NOT "${_qt_additional_packages_prefix_paths}" STREQUAL "")
+ __qt_internal_prefix_paths_to_roots(
+ additional_root_paths "${_qt_additional_packages_prefix_paths}")
+ foreach(root IN ITEMS ${additional_root_paths})
+ set(candidate "${root}/${QT6_INSTALL_QML}")
+ if(IS_DIRECTORY "${candidate}")
+ list(APPEND qml_import_paths "${candidate}")
+ endif()
+ endforeach()
+ endif()
+
+ # Add the main Qt "<prefix>/qml" import path.
+ if(QT6_INSTALL_PREFIX)
+ set(main_import_path "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_QML}")
+ if(IS_DIRECTORY "${main_import_path}")
+ list(APPEND qml_import_paths "${main_import_path}")
+ endif()
+ endif()
+
+ set(${out_var} "${qml_import_paths}" PARENT_SCOPE)
+endfunction()
function(_qt_internal_scan_qml_imports target imports_file_var when_to_scan)
if(NOT "${ARGN}" STREQUAL "")
@@ -2577,26 +2621,6 @@ but this file does not exist. Possible reasons include:
")
endif()
- # Find Qt provided QML import paths.
- if("${_qt_additional_packages_prefix_paths}" STREQUAL "")
- # We have one installation prefix for all Qt modules. Add the "<prefix>/qml" directory.
- set(qml_import_paths "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_QML}")
- else()
- # We have multiple installation prefixes: one per Qt repository (conan). Add those that have
- # a "qml" subdirectory.
- set(qml_import_paths)
- __qt_internal_prefix_paths_to_roots(
- additional_root_paths "${_qt_additional_packages_prefix_paths}")
- foreach(root IN ITEMS ${QT6_INSTALL_PREFIX} ${additional_root_paths})
- set(candidate "${root}/${QT6_INSTALL_QML}")
- if(IS_DIRECTORY "${candidate}")
- list(APPEND qml_import_paths "${candidate}")
- endif()
- endforeach()
- endif()
-
-
- # Run qmlimportscanner to generate the cmake file that records the import entries
get_target_property(target_source_dir ${target} SOURCE_DIR)
get_target_property(target_binary_dir ${target} BINARY_DIR)
set(out_dir "${target_binary_dir}/.qt_plugins")
@@ -2609,9 +2633,11 @@ but this file does not exist. Possible reasons include:
-cmake-output
-output-file "${imports_file}"
)
- get_target_property(qml_import_path ${target} QT_QML_IMPORT_PATH)
- if (qml_import_path)
+ set(qml_import_paths "")
+ # Get custom import paths provided during qt_add_qml_module call.
+ get_target_property(qml_import_path ${target} QT_QML_IMPORT_PATH)
+ if(qml_import_path)
list(APPEND cmd_args ${qml_import_path})
endif()
@@ -2630,6 +2656,10 @@ but this file does not exist. Possible reasons include:
list(APPEND qml_import_paths "${CMAKE_CURRENT_BINARY_DIR}")
endif()
+ # Add the Qt import paths last.
+ _qt_internal_get_main_qt_qml_import_paths(qt_import_paths)
+ list(APPEND qml_import_paths ${qt_import_paths})
+
# Construct the -importPath arguments.
set(import_path_arguments)
foreach(path IN LISTS qml_import_paths)
@@ -2659,6 +2689,7 @@ but this file does not exist. Possible reasons include:
set(import_scanner_args ${QT_TOOL_COMMAND_WRAPPER_PATH} ${tool_path} ${cmd_args})
+ # Run qmlimportscanner to generate the cmake file that records the import entries
if(scan_at_build_time)
add_custom_command(
OUTPUT "${imports_file}"