StreakerOne
StreakerOne

Reputation: 103

Qt example project fails to build (No CMake configuration found)

I am trying to simply open Qt6.4.1 sensors example project, but it says that no CMake configuration found. I already made some simple Qt6 applications for Windows, and i have entire Qt6.4.1 package installed, so cant blame on bad installation. There is an error on line find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Sensors Svg) in CMakeLists.txt. Full error message:

C:\Qt\Examples\Qt-6.4.1\sensors\sensorsshowcase\CMakeLists.txt:12: error: By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6", but CMake did not find one. Could not find a package configuration file provided by "Qt6" with any of the following names: Qt6Config.cmake qt6-config.cmake Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR" to a directory containing one of the above files. If "Qt6" provides a separate development package or SDK, be sure it has been installed.

Upvotes: 4

Views: 4237

Answers (1)

fabian
fabian

Reputation: 82461

Pass the path to the directory containing the Qt6 files via CMAKE_PREFIX_PATH cache variable during configuration.

Note: Make sure to specify the type of the variable as PATH or use forward slashes as path separator for this to work properly.

E.g. for me I'd need to pass

-D CMAKE_PREFIX_PATH=D:/Qt/6.4.1/msvc2019_64

to tell CMake to look into the directory containing the Qt6.4.1 files compiled with MSVC.

Make sure that the directory you pass contains the file lib/cmake/Qt6/Qt6Config.cmake; this is the file find_package(Qt6 REQUIRED COMPONENTS ...) is looking for.

You can also fix your project setup that previously failed by adding the cache variable.

cmake -D CMAKE_PREFIX_PATH=D:/Qt/6.4.1/msvc2019_64 path/to/build_dir

Note: Don't forget to add the -A ... option when configuring a VS project; CMake defaults to Win32 as architecture, at least on my system.

You could add this info to a CMAKE_PREFIX_PATH environment variable, if you don't want to specify the info cache variable for every single project using qt 6 that you want to set up on your machine.

Upvotes: 0

Related Questions