diff options
author | Kai Koehne <kai.koehne@qt.io> | 2019-04-24 16:06:01 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2019-05-07 11:34:35 +0000 |
commit | 9dc3bd8fea81a8e1bba751215c7ff0ebacdd1b92 (patch) | |
tree | a9c52386cca84462482b5c1a461bd7119469dbfb | |
parent | 092e708a7c7333103c37a5c774ada27937bd1fe6 (diff) |
Doc: Improve CMake code example
Remove the comments, which are mostly superfluous or should
rather be put into the documentation.
Name the project and targets the same.
Guard CMAKE_INCLUDE_CURRENT_DIR with a version check:
This is only needed for CMake 3.6 and older.
Add a resource file to be able to show off CMAKE_AUTORCC.
Remove superfluous helloworld_SRCS variable indirection.
Remove WIN32 argument to add_executable; this seems
superfluous.
Task-number: QTBUG-72159
Change-Id: I39f0d51d23d5dfbbd7a009c0f70c94e5d6296dab
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r-- | doc/src/development/cmake-manual.qdoc | 8 | ||||
-rw-r--r-- | doc/src/snippets/cmake/examples.cmake (renamed from doc/src/snippets/cmake/CMakeLists.pro) | 20 |
2 files changed, 13 insertions, 15 deletions
diff --git a/doc/src/development/cmake-manual.qdoc b/doc/src/development/cmake-manual.qdoc index f0511eb80..6075c31cc 100644 --- a/doc/src/development/cmake-manual.qdoc +++ b/doc/src/development/cmake-manual.qdoc @@ -54,7 +54,7 @@ To build a helloworld GUI executable, typical usage would be: - \snippet snippets/cmake/CMakeLists.pro 0 + \snippet snippets/cmake/examples.cmake 0 In order for \c{find_package} to be successful, Qt 5 must be found below the CMAKE_PREFIX_PATH, or the \c{Qt5_DIR} must be set in the \c{CMake} cache to the location of the @@ -70,7 +70,7 @@ using a variable like Qt5<Module>_LIBRARIES in CMake commands such as \c{target_link_libraries}. The actual path to the library can be obtained using the \l{CMake LOCATION Documentation}{LOCATION property}: - \snippet snippets/cmake/CMakeLists.pro 1 + \snippet snippets/cmake/examples.cmake 1 Note however that it is rare to require the full location to the library in \c{CMake} code. Most \c{CMake} APIs are aware of imported targets and can automatically use them instead of the full path. @@ -87,14 +87,14 @@ If your project has custom CMake build configurations, it may be necessary to set a mapping from your custom configuration to either the debug or release Qt configuration. - \snippet snippets/cmake/CMakeLists.pro 2 + \snippet snippets/cmake/examples.cmake 2 Plugins are also available as \c IMPORTED targets in CMake. The \l{Qt Network}, \l{Qt SQL}, \l{Qt GUI}, and \l{Qt Widgets} modules have plugins associated. They provide a list of plugins in the \c{Qt5}\e{<Module>}\c{_PLUGINS} variable. - \snippet snippets/cmake/CMakeLists.pro 5 + \snippet snippets/cmake/examples.cmake 5 \section1 Variable Reference diff --git a/doc/src/snippets/cmake/CMakeLists.pro b/doc/src/snippets/cmake/examples.cmake index 6f66cabf9..264f3c05d 100644 --- a/doc/src/snippets/cmake/CMakeLists.pro +++ b/doc/src/snippets/cmake/examples.cmake @@ -1,27 +1,25 @@ #! [0] cmake_minimum_required(VERSION 3.1.0) -project(testproject) +project(helloworld) -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Instruct CMake to run moc automatically when needed set(CMAKE_AUTOMOC ON) -# Create code from a list of Qt designer ui files +set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) -# Find the QtWidgets library +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + find_package(Qt5 COMPONENTS Widgets REQUIRED) -# Populate a CMake variable with the sources -set(helloworld_SRCS +add_executable(helloworld mainwindow.ui mainwindow.cpp main.cpp + resources.qrc ) -# Tell CMake to create the helloworld executable -add_executable(helloworld WIN32 ${helloworld_SRCS}) -# Use the Widgets module from Qt 5 + target_link_libraries(helloworld Qt5::Widgets) #! [0] |