我试图使用cmake构建cpp/qt5 5项目,但是编译返回一个有关QT5的错误。
我安装了国产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),结果是相同的。
有什么想法吗?谢谢
发布于 2016-10-17 08:39:38
尝试:
-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
)https://stackoverflow.com/questions/40081327
复制相似问题