CMake - Could not find a package configuration file provided by "QT"

I've got some problems with CMake. It shows me an error when I try to configure my build for Visual Studio 2019. Everything looks fine to me when I check the CMakeLists.txt, but something is still wrong. The file was auto created by Qt, I just added some things to connect some directories. What can I do to solve this problem?

Here is the error:

Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
The CXX compiler identification is MSVC 19.28.29334.0
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: D:/VS/VS-IDE/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
CMake Error at CMakeLists.txt:27 (find_package): Could not find a package configuration file provided by "QT" with any of the following names: Qt6Config.cmake qt6-config.cmake Qt5Config.cmake qt5-config.cmake Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to a directory containing one of the above files. If "QT" provides a separate development package or SDK, be sure it has been installed.
Configuring incomplete, errors occurred!

Here is my CMakeList.txt:

cmake_minimum_required(VERSION 3.5)
project(bacteria LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check for more information.
# They need to be set before the find_package(Qt5 ...) call.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets LinguistTools REQUIRED)
#Mine add
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
set(TS_FILES bacteria_ru_RU.ts)
#Mine add
set(CMAKE_PREFIX_PATH "D:/Qt/5.15.2/mingw81_64")
if(ANDROID) add_library(bacteria SHARED main.cpp mainwindow.cpp mainwindow.h mainwindow.ui #My add mainmatrix.cpp mainmatrix.h microbe.cpp microbe.h microbecontainer.cpp microbecontainer.h food.cpp food.h ${TS_FILES} )
else() add_executable(bacteria main.cpp mainwindow.cpp mainwindow.h mainwindow.ui #My add mainmatrix.cpp mainmatrix.h microbe.cpp microbe.h microbecontainer.cpp microbecontainer.h food.cpp food.h ${TS_FILES} )
endif()
target_link_libraries(bacteria PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
6

2 Answers

adding set(CMAKE_PREFIX_PATH "/Users/YOURPATH/Qt/6.1.0/clang_64")this line of code before the find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) solved the problem for me (macOS).Find the QT directory and copy the path of the /clang_64 file. If you have problems with QT then try to reinstall

1

In case if you are experiencing the same problem on Mac, here's what I added beforefind_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED):

set(CMAKE_PREFIX_PATH "/Users/MY_USER_NAME/Qt/6.1.2/macos/lib/cmake")

In my case cmake contained a lot of folders, many of which had .cmake files. Apparently CMake found the required packages there.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like