From 2bd21f8365eb0c199671d35acc64eb25552b2dc2 Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@qt.io> Date: Tue, 9 Apr 2019 10:02:48 +0200 Subject: [PATCH] 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: Tobias Hunger <tobias.hunger@qt.io> Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> --- doc/src/development/cmake-manual.qdoc | 7 ++++--- doc/src/snippets/cmake/CMakeLists.pro | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/src/development/cmake-manual.qdoc b/doc/src/development/cmake-manual.qdoc index b0f856ac..99b72cfe 100644 --- a/doc/src/development/cmake-manual.qdoc +++ b/doc/src/development/cmake-manual.qdoc @@ -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. diff --git a/doc/src/snippets/cmake/CMakeLists.pro b/doc/src/snippets/cmake/CMakeLists.pro index b2018342..6f66cabf 100644 --- a/doc/src/snippets/cmake/CMakeLists.pro +++ b/doc/src/snippets/cmake/CMakeLists.pro @@ -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") -- GitLab