SDK: make sure initial qt host path is absolute

__qt_toolchain_initial_qt_host_path is assigned to QT_HOST_PATH and then
to CMAKE_FIND_ROOT_PATH. Problems occurs if that path is relative.
CMake doesn't do relative path resolving by default in find_package,
when doing sub-prefix checking between find root path and prefix path.

Patch the qt.toochain.cmake so that it always uses absolute path for
__qt_toolchain_initial_qt_host_path, but make it still based on its
own location.

Fixes: QTBUG-103818
Change-Id: I1cce126c243c017b1cecd14a0fd616cb0328fe6d
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit ea541e308f)
Reviewed-by: Pasi Petäjäjärvi <pasi.petajajarvi@qt.io>
This commit is contained in:
Samuli Piippo 2022-06-02 04:36:49 +00:00
parent f9b57ed9d7
commit 08352251e6
3 changed files with 48 additions and 31 deletions

View File

@ -1,29 +0,0 @@
From c15033fd4df14b08fc28ec8da61c990801c7e411 Mon Sep 17 00:00:00 2001
From: Samuli Piippo <samuli.piippo@qt.io>
Date: Thu, 16 Dec 2021 13:10:48 +0200
Subject: [PATCH] Do not use QT_TOOLCHAIN_RELOCATABLE paths in
qt.toolchain.cmake
The calculated paths for QT_TOOLCHAIN_RELOCATABLE paths point to
host sysroot which must not be used when cross-compiling other projects.
Upstream-Status: Inappropriate [embedded specific]
---
cmake/qt.toolchain.cmake.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in
index 5e9acd66b8..451de99633 100644
--- a/cmake/qt.toolchain.cmake.in
+++ b/cmake/qt.toolchain.cmake.in
@@ -68,8 +68,8 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_
# Instead of collapsing the search prefix (which is the case when one is a subdir of the other),
# it concatenates them creating an invalid path. Workaround it by setting the root path to the
# Qt install prefix, and the prefix path to the lib/cmake subdir.
-list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
-list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
+#list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
+#list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
# Let CMake load our custom platform modules.
# CMake-provided platform modules take precedence.

View File

@ -0,0 +1,47 @@
From e3f59a24add346248842a8f28971621469c9161f Mon Sep 17 00:00:00 2001
From: Samuli Piippo <samuli.piippo@qt.io>
Date: Thu, 16 Dec 2021 13:10:48 +0200
Subject: [PATCH] Fix qt.toolchain.cmake for SDK use
Set initial host path based on the location of the qt.toolchain.cmake file.
This helps us avoid need to relocate the file in SDK.
The calculated paths for QT_TOOLCHAIN_RELOCATABLE paths point to
host sysroot which must not be used when cross-compiling other projects.
Change-Id: I52aa2a10d2a13fd27d6bf8b4af6dc1833c7a286a
Upstream-Status: Inappropriate [embedded specific]
---
cmake/qt.toolchain.cmake.in | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in
index c565e923ff..a917c65d89 100644
--- a/cmake/qt.toolchain.cmake.in
+++ b/cmake/qt.toolchain.cmake.in
@@ -70,8 +70,8 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_
# Instead of collapsing the search prefix (which is the case when one is a subdir of the other),
# it concatenates them creating an invalid path. Workaround it by setting the root path to the
# Qt install prefix, and the prefix path to the lib/cmake subdir.
-list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
-list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
+#list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
+#list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}")
# Let CMake load our custom platform modules.
# CMake-provided platform modules take precedence.
@@ -156,10 +156,10 @@ endif()
# Set up QT_HOST_PATH and do sanity checks.
# A host path is required when cross-compiling but optional when doing a native build.
set(__qt_toolchain_host_path_required "@qt_host_path_required@")
-set(__qt_toolchain_initial_qt_host_path
- "@qt_host_path_absolute@")
-set(__qt_toolchain_initial_qt_host_path_cmake_dir
- "@qt_host_path_cmake_dir_absolute@")
+get_filename_component(__qt_toolchain_initial_qt_host_path
+ "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE)
+get_filename_component(__qt_toolchain_initial_qt_host_path_cmake_dir
+ "${CMAKE_CURRENT_LIST_DIR}/../../../lib/cmake" ABSOLUTE)
# QT_HOST_PATH precedence:
# - cache variable / command line option

View File

@ -19,7 +19,7 @@ SRC_URI += "\
file://0001-Add-linux-oe-g-platform.patch \
file://0002-qlibraryinfo-allow-to-set-qt.conf-from-the-outside-u.patch \
file://0003-tests-disable-failing-tests.patch \
file://0004-Do-not-use-QT_TOOLCHAIN_RELOCATABLE-paths-in-qt.tool.patch \
file://0004-Fix-qt.toolchain.cmake-for-SDK-use.patch \
"
DEPENDS += "\
@ -168,7 +168,6 @@ EOF
RELPATH=${@os.path.relpath(d.getVar('prefix') + '/share/cmake/Qt6Toolchain.cmake', d.getVar('QT6_INSTALL_LIBDIR') + '/cmake/Qt6')}
sed -i ${D}${QT6_INSTALL_LIBDIR}/cmake/Qt6/qt.toolchain.cmake \
-e 's|${RECIPE_SYSROOT_NATIVE}|\${CMAKE_CURRENT_LIST_DIR}/../../../..|' \
-e "s|/.*/toolchain.cmake|\${CMAKE_CURRENT_LIST_DIR}/$RELPATH|"
}