
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 http://doc.qt.io/qt-5/deployment-android.html 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})
62 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 https://www.qt.io/download-open-source?hsCtaTracking=9f6a2170-a938-42df-a8e2-a9f0b1d6cdce%7C6cb0de4f-9bb5-4778-ab02-bfb62735f3e5
1In case if you are experiencing the same problem on Mac, here's what I added before find_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.
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobW5saGiDdoWOnKSao5VisLDBy51kp6ekYrOqusNmmGaokZi4orPEZpqoppaetLa%2BwK2gqKZdm7atsYypqaiumZmypXnBsmSqrA%3D%3D