CMake - 找不到“QT”提供的包配置文件

时间:2020-12-28 20:27:02

标签: c++ qt cmake

我在使用 CMake 时遇到了一些问题。当我尝试为 Visual Studio 2019 配置我的构建时,它向我显示一个错误。当我检查 CMakeLists.txt 时,一切看起来都很好,但仍然有问题。该文件是由 Qt 自动创建的,我只是添加了一些东西来连接一些目录。我该怎么做才能解决这个问题?

这里是错误:

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!

这是我的 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})

1 个答案:

答案 0 :(得分:1)

添加 set(CMAKE_PREFIX_PATH "/Users/YOURPATH/Qt/6.1.0/clang_64") find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)之前的这行代码为我解决了这个问题(macOS)。找到QT目录,复制/clang_64文件的路径。如果您在使用 QT 时遇到问题,请尝试重新安装 https://www.qt.io/download-open-source?hsCtaTracking=9f6a2170-a938-42df-a8e2-a9f0b1d6cdce%7C6cb0de4f-9bb5-4778-ab02-bfb62735f3e5