Commit 2bd21f83 authored by Kai Koehne's avatar Kai Koehne
Browse files

CMake: Advocate find_packages(Qt5 COMPONENTS ...) style

This is the style cmake-qt documentation shows nowadays.
For motivation see also

https://blog.kitware.com/cmake-finding-qt5-the-right-way/



Change-Id: I47651c58387b8bf96a2235395f0321e54ad05a88
Reviewed-by: default avatarTobias Hunger <tobias.hunger@qt.io>
Reviewed-by: default avatarLeena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: default avatarAlexandru Croitor <alexandru.croitor@qt.io>
Showing with 7 additions and 6 deletions
......@@ -56,8 +56,8 @@
\snippet snippets/cmake/CMakeLists.pro 0
In order for \c{find_package} to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH,
or the Qt5<Module>_DIR must be set in the \c{CMake} cache to the location of the
Qt5WidgetsConfig.cmake file. The easiest way to use \c{CMake} is to set the CMAKE_PREFIX_PATH
or the \c{Qt5_DIR} must be set in the \c{CMake} cache to the location of the
\c{Qt5Config.cmake} file. The easiest way to use \c{CMake} is to set the CMAKE_PREFIX_PATH
environment variable to the install prefix of Qt 5.
The CMAKE_AUTOMOC setting runs moc automatically when required. For more on this feature see
......@@ -105,7 +105,8 @@
for use. The name of the imported target for each module matches the name of the module with a
prefix of 'Qt5::', for example Qt5::Widgets. All of the package-specific variables have a
consistent name with a prefix of the name of the package. For example,
\c{find_package}(Qt5Widgets) will make the following variables available if successfully found:
\c{find_package(Qt5 COMPONENTS Widgets)} will make the following variables available
if successfully found:
\list
\li Qt5Widgets_VERSION String describing the version of the module.
......
......@@ -11,7 +11,7 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
# Populate a CMake variable with the sources
set(helloworld_SRCS
......@@ -26,13 +26,13 @@ target_link_libraries(helloworld Qt5::Widgets)
#! [0]
#! [1]
find_package(Qt5Core)
find_package(Qt5 COMPONENTS Core REQUIRED)
get_target_property(QtCore_location Qt5::Core LOCATION)
#! [1]
#! [2]
find_package(Qt5Core)
find_package(Qt5 COMPONENTS Core REQUIRED)
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment