QT_NO_CREATE_TARGETS getting set to True causing Qt6Core_FOUND to be False - help
-
I just built Qt6.2.4 for cross-compiling for QNX from a Windows host.
I had previously been building my project with Linux as a host and that worked fine. Now when I run CMake against my project with my Windows-based build of Qt for QNX it gives me errors around not finding Qt6Core. Specifically:
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR) CMake Warning at C:/Qt/6.2.4/qnx71_armv7/lib/cmake/Qt6/Qt6Config.cmake:209 (find_package): Found package configuration file: C:/Qt/6.2.4/qnx71_armv7/lib/cmake/Qt6Core/Qt6CoreConfig.cmake but it set Qt6Core_FOUND to FALSE so package "Qt6Core" is considered to be NOT FOUND.
I looked at the lib/cmake/Qt6Core/*.cmake files and the only way that Qt6Core_FOUND gets set to false is if the variable QT_NO_CREATE_TARGETS gets set to TRUE.
I'm not doing anything with QT_NO_CREATE_TARGETS, so I have to ask why would this be getting set at all? Why wouldn't I want a Qt6::Core target?
How can I even begin to debug this? So far I've verified that libQt6Core.so* files exist. I mentioned that the lib/cmake/Qt6Core/*.cmake files exist. The project is known to work with Qt6.2.1 when using a Linux host for development, so the project's CMake seems ok.
-
What I've also learned is that Qt6Core and several others will not be found unless QT_HOST_PATH is set. I found that this is a fairly recent introduction (still in technology preview), and I was not required to set it on Linux when cross-compiling there for QNX with Qt6.2.1. Somehow QT_HOST_PATH is set when I added (via -DCMAKE_TOOLCHAIN_FILE) the build-generated toolchain file ${Qt6_INSTALL_PATH}/lib/cmake/Qt6/qt.toolchain.cmake.
So I can choose one or the other but this seems like obscure undocumented information that I've not needed in the past.
-
Hi,
Could you try to set follow paths for configuring your qnx application on Windows?
"Qt installation path>\bin\qt-cmake.bat" CMakeLists.txt -GNinja
-DCMAKE_PREFIX_PATH="C:..........\targetbuild"
-DQt6_DIR="C:...........\targetbuild\lib\cmake\Qt6"
-DQt6Core_DIR="C:............\targetbuild\lib\cmake\Qt6Core"
-DQt6Gui_DIR="C:.....\targetbuild\lib\cmake\Qt6Gui"And after that build:
cmake --build . -
I imagine that would work, but let me share something that I learned in the last hour or so.
I was reducing my problem to a small example, which I then tried to build within QtCreator where I have a Qt6.2.4 kit established. I took note of the generation command that it used and I noticed that it added at the end this:
-DCMAKE_TOOLCHAIN_FILE:PATH=C:/Qt/6.2.4/qnx71_armv7/lib/cmake/Qt6/qt.toolchain.cmake
This addition removes any problem with Qt6<component>_FOUND being set to false. The components are all found and in fact any project for which I run cmake generation in this way succeeds.
My question is why does this work? I've never seen this used before and I don't understand it. It shouldn't be necessary, but QtCreator inserted it almost unnoticed by me. I googled around a bit and there's no official documentation for it.
-
Cmake uses CMAKE_TOOLCHAIN_FILE variable for cross compile builds.
It sets the path to a file which is read early in the CMake run and which specifies locations for compilers and toolchain utilities, and other target platform and compiler related information.With Qt 6 and CMake a toolchain file must be provided before configuring can happen. It is in this file where customization with regards to compiler and linker flags, and toolchain and sysroot specific quirks, happens.
There is a good description in docs: https://doc-snapshots.qt.io/qt6-dev/configure-linux-device.html#toolchain-files-versus-device-makespecs
-
Yes, that's toolchains 101.
I'm asking specifically about this autogenerated toolchain file in the install folder of Qt6 that I built for QNX. What magic is happening there that suddenly makes things work? Why does QtCreator auto-insert this in the CMake generation line?
FWIW I was specifying compilers and sysroot and system_name and all of that already. That isn't the problem.
EDIT: I'm leaving this open only because I plan to post the answer I get from Qt support when everything is resolved.
-
What I've also learned is that Qt6Core and several others will not be found unless QT_HOST_PATH is set. I found that this is a fairly recent introduction (still in technology preview), and I was not required to set it on Linux when cross-compiling there for QNX with Qt6.2.1. Somehow QT_HOST_PATH is set when I added (via -DCMAKE_TOOLCHAIN_FILE) the build-generated toolchain file ${Qt6_INSTALL_PATH}/lib/cmake/Qt6/qt.toolchain.cmake.
So I can choose one or the other but this seems like obscure undocumented information that I've not needed in the past.
-
I stand corrected. I didnt' realize it until now, but when I've been working on Linux and cross-compiling for QNX QtCreator is inserting a -DCMAKE_TOOLCHAIN_FILE:PATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake
Looking at that toolchain file one of the main things it does is make sure QT_HOST_PATH is defined.