c++ - MacOS Sierra - cmake 因 qt5 而失败

标签 c++ macos qt cmake qt5

我正在尝试使用 cmake 构建 cpp/qt5 项目,但编译返回有关 QT5 的错误。

我用 Homebrew 安装了 QT5,

当我这样做时:

brew --prefix qt5

我明白了

 /usr/local/Cellar/qt5/5.6.0

所以我在项目的 build 文件夹中,我这样做:

cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix qt5) -G Xcode -DBUILD_TESTS=ON -DBUILD_TESTS_COVERAGE=off

给我返回这个错误:

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

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

    Qt5Config.cmake
    qt5-config.cmake

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

CMakelist.txt 中的错误行:

    ## QT5 ##

find_package(Qt5 COMPONENTS Core Gui Widgets Concurrent Qml Quick REQUIRED)

set_target_properties(${BIN_NAME} PROPERTIES AUTOMOC ON)
set_target_properties(${BIN_NAME} PROPERTIES AUTOUIC ON)
target_link_libraries(${BIN_NAME} PUBLIC Qt5::Core PUBLIC Qt5::Widgets PUBLIC Qt5::Gui PUBLIC Qt5::Qml PUBLIC Qt5::Quick PUBLIC Qt5::Concurrent)

#########

我还尝试在命令中添加 -DQt5_DIR=$(brew --prefix qt5),结果相同。


有什么想法吗? 谢谢

最佳答案

尝试:

-DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5

请注意,您可以在使用set_target_properties 时指定多个属性,并在使用target_link_libraries 时为多个值指定PUBLIC 范围:

set_target_properties(${BIN_NAME}
    PROPERTIES
    AUTOMOC ON
    AUTOUIC ON
)
target_link_libraries(${BIN_NAME}
    PUBLIC
    Qt5::Core
    Qt5::Widgets
    Qt5::Gui
    Qt5::Qml
    Qt5::Quick
    Qt5::Concurrent
)

关于c++ - MacOS Sierra - cmake 因 qt5 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40081327/

相关文章:

c++ - 适用于 Linux 的 SDL 跨平台消息框

python - 如何通过Python执行任意shell脚本并传递多个变量?

objective-c - 无缝循环视频

c++ - QT 5.4 QPrinterInfo::printerName 返回空白

c++ - Qt 运行 C++ 和 C 代码

c++ - 为什么我程序中的一个变量使用了 60% 的执行时间?

c++ - 为什么将 boost::move() 的返回值分配给非常量引用在 C++0x 模式下失败,但在 C++03 模式下有效

C++:如何检查文件/目录是否可读? (相当于 PHP:is_readable)

Qt 绘图应用程序

c++ - mock_method 上的 gmock 编译错误(在 testing::internal::FunctionMocker 中)