I'm trying to build a cpp/qt5 project using cmake, but the compilation return an error regarding QT5.
I've installed QT5 with Homebrew,
When I do :
brew --prefix qt5
I get
/usr/local/Cellar/qt5/5.6.0
So I'm in the build
folder of my project, and I do :
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix qt5) -G Xcode -DBUILD_TESTS=ON -DBUILD_TESTS_COVERAGE=off
Return me this error :
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.
the lines of errors in the 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)
#########
I've also tried to add a -DQt5_DIR=$(brew --prefix qt5)
to the command, same result.
Any ideas ? thanks
Try:
-DQt5_DIR=$(brew --prefix qt5)/lib/cmake/Qt5
Note that you can specify multiple properties when using set_target_properties
, and specify PUBLIC
scope for multiple values when using target_link_libraries
:
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With