在 Mac OS 中将 QT 集成到 CMAKE 中

5

我正在尝试将我的QT项目集成到我的CLION项目中。 在这种情况下,我遇到了CMAKE和QT集成的问题。 我的CmakeList.txt文件内容如下:

    cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/")

find_package(Qt5Widgets REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui)
target_link_libraries(helloworld Qt5::Widgets)

但我遇到了以下错误:

CMake Error at CMakeLists.txt:8 (find_package):
  By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Qt5Widgets", but CMake did not find one.

  Could not find a package configuration file provided by "Qt5Widgets" with
  any of the following names:

    Qt5WidgetsConfig.cmake
    qt5widgets-config.cmake

  Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
  "Qt5Widgets_DIR" to a directory containing one of the above files.  If
  "Qt5Widgets" provides a separate development package or SDK, be sure it has
  been installed.

有人可以帮我吗?

谢谢


/Users/jonathanprieto/Qt5.13.0/5.13.0/lib/cmake吗?如果是这样,那么它应该是您的CMAKE_PREFIX_PATH。此外,您可以通过brew轻松安装Qt。 - Botje
无关:find_package(Qt5 COMPONENTS Widgets REQUIRED)允许您一次指定多个组件,如果需要的话。 - Botje
我没有lib目录,只有clang_64、ios、src和许多版本的android。 - Jonathan Prieto
我找到了解决方案!路径是:/Users/jonathanprieto/Qt5.13.0/5.13.0/clang_64/lib/cmake - Jonathan Prieto
1个回答

1

经过几次尝试,我找到了解决我的问题的方法。 因此,我发布了我的CMakeList.txt代码,以防您遇到相同的问题。

cmake_minimum_required(VERSION 3.12)
project(BD2_PROYECTO_1)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/Users/jonathanprieto/Qt5.13.0/5.13.0/clang_64/lib/cmake")

find_package(Qt5 COMPONENTS Widgets REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

add_executable(BD2_PROYECTO_1 parser.cpp parser.h main.cpp statichashing.cpp statichashing.h randomfile.cpp randomfile.h record.cpp record.h transactions.cpp transactions.h ui/input.cpp ui/input.h ui/ui_dialog.h ui/mainwindow.h ui/mainwindow.cpp ui/mainwindow.ui ui/ui_input.ui ui/input.h ui/dialog.ui ui/input.ui)
target_link_libraries(BD2_PROYECTO_1 Qt5::Widgets)

我希望这对你有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接