Cmake finds cross compiled Qt6 config files but Qt6_FOUND is set to FALSE
-
Hi,
I am experiencing a very annoying issue with cross compiled qt6 for the raspberry arm64 target.
Qt6 has been deployed by issuing the following command:cmake ../../qt-everywhere-src-6.3.1 -GNinja -DCMAKE_BUILD_TYPE=Release -DINPUT_opengl=es2 -DQT_BUILD_EXAMPLES=OFF -DQT_BUILD_TESTS=OFF -DQT_HOST_PATH=/home/michal/Qt/6.3.1/gcc_64 -DCMAKE_STAGING_PREFIX=/home/michal/rpi/qt6-raspi -DCMAKE_INSTALL_PREFIX=/home/michal/rpi/qt6 -DCMAKE_TOOLCHAIN_FILE=/home/michal/rpi/rpi-toolchain.cmake -DQT_QMAKE_TARGET_MKSPEC=devices/linux-rasp-pi4-v3d-g++ -DQT_FEATURE_xcb=ON -DFEATURE_xcb_xlib=ON -DQT_FEATURE_xlib=ON
After the installation step I have noticed that the staging dir has been used to store all the lib and binaries (/home/micha/rpi/qt6-raspi) instead of the install prefix: /home/michal/rpi/qt6
When cmake is trying to find the qt packages within the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.1)
project(user_interface LANGUAGES C CXX)
include(cmake/compilation_flags.cmake)
if(DEFINED ENV{Qt${QT_VERSION}_DIR})
SET(Qt6_DIR $ENV{Qt${QT_VERSION}_DIR})
else()
message(STATUS "not ok")
endif()find_package(Qt${QT_VERSION} COMPONENTS Core Qml Quick QuickControls2 Test Network REQUIRED)
#find_package(Qt6 HINTS "$ENV{Qt6_DIR}" COMPONENTS Core Qml Quick QuickControls2 Test Network REQUIRED)I get the following errors:
-- Could NOT find Qt6Core (missing: Qt6Core_DIR)
-- Could NOT find Qt6Qml (missing: Qt6Qml_DIR)
-- Could NOT find Qt6Quick (missing: Qt6Quick_DIR)
-- Could NOT find Qt6QuickControls2 (missing: Qt6QuickControls2_DIR)
-- Could NOT find Qt6Test (missing: Qt6Test_DIR)
-- Could NOT find Qt6Network (missing: Qt6Network_DIR)
CMake Error at CMakeLists.txt:17 (find_package):
Found package configuration file:/home/michal/rpi/qt6-raspi/lib/cmake/Qt6/Qt6Config.cmake
but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
FOUND. Reason given by package:Failed to find Qt component "Core".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6Core/Qt6CoreConfig.cmake" existsFailed to find Qt component "Qml".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6Qml/Qt6QmlConfig.cmake" existsFailed to find Qt component "Quick".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6Quick/Qt6QuickConfig.cmake" existsFailed to find Qt component "QuickControls2".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6QuickControls2/Qt6QuickControls2Config.cmake"
existsFailed to find Qt component "Test".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6Test/Qt6TestConfig.cmake" existsFailed to find Qt component "Network".
Expected Config file at
"/home/michal/rpi/qt6-raspi/lib/cmake/Qt6Network/Qt6NetworkConfig.cmake"
existsAll the config files are correctly settled at the paths written above.
Is the issue related to this:
https://cmake.org/cmake/help/latest/variable/CMAKE_STAGING_PREFIX.html
and if yes how it could be addressed?
Thanks -
Using this plain cmake file:
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0084 NEW)
project(test)
SET(Qt6_DIR "/home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6")
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(test INTERFACE Qt::Core)
add_executable(test main.cpp)
I am seeing the same issue as with the cross-compiled arm64 variant, this is the console output:
-- The C compiler identification is GNU 10.2.1
-- The CXX compiler identification is GNU 10.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR)
CMake Warning at /home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6/Qt6Config.cmake:213 (find_package):
Found package configuration file:/home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6Core/Qt6CoreConfig.cmake
but it set Qt6Core_FOUND to FALSE so package "Qt6Core" is considered to be
NOT FOUND. Reason given by package:Target "Qt6::Core" was not found.
Call Stack (most recent call first):
CMakeLists.txt:23 (find_package)CMake Error at CMakeLists.txt:23 (find_package):
Found package configuration file:/home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6/Qt6Config.cmake
but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
FOUND. Reason given by package:Failed to find Qt component "Core".
Expected Config file at
"/home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6Core/Qt6CoreConfig.cmake" existsThanks in advance.
-
There is a specular issue opened here:
https://forum.qt.io/topic/134586/installed-qt6-to-linux-cmake-target-qt6-core-was-not-found/4
for such cmake lists:cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0084 NEW)
project(test)
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(test INTERFACE Qt::Core)
add_executable(test main.cpp)
and by invoking:
cmake .. -DCMAKE_PREFIX_PATH=/home/michal/Qt/6.3.1/gcc_64/lib/cmake/Qt6the problem still persists.
Thanks. -
Finding Qt just by setting
Qt6_DIR
currently does not work.
That is tracked in https://bugreports.qt.io/browse/QTBUG-97615 and will be fixed in a future Qt version, but only for desktop platforms.Even with the fix proposed in the bug report above, setting
Qt6_DIR
will not be enough for cross-compilation.
You would also need to setQT_HOST_PATH
to the host Qt installation and adjustCMAKE_FIND_ROOT_PATH
to point the cross-compiled Qt installation.Rather than doing all that, I suggest you use Qt's cmake wrapper, which is located in
$path_to_installed_qt/bin/qt-cmake
.
That passes a Qt generated toolchain file toCMAKE_TOOLCHAIN_FILE
when calling CMake, which adjustsCMAKE_PREFIX_PATH
andCMAKE_FIND_ROOT_PATH
to ensure projects can find a cross-compiled Qt.If you don't want to use the
qt-cmake
wrapper, you can try using the toolchain file directly, by passing-DCMAKE_TOOLCHAIN_FILE=$path_to_installed_qt/lib/cmake/Qt6/qt.toolchain.cmake
-
@Croitor-Alexandru thanks a lot :) I did not reply before (my fault) - when I ve realized that passing the toolchain file in the qt6 install dir had solved the issue.