我正在尝试使用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)
,但结果相同。
有什么想法吗? 谢谢
Qt5Config.cmake
文件? - Tsyvarev/usr/local/Cellar/qt5/5.6.0
下搜索给定的文件即可:变量CMAKE_PREFIX_PATH
只是为搜索添加新的前缀。至于变量Qt5_DIR
,为了产生效果,此目录应直接包含所需文件。 - Tsyvarev