2017-02-21 10:01:34 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2022-02-03 15:11:15 +01:00
|
|
|
** Copyright (C) 2022 The Qt Company Ltd.
|
2017-02-21 10:01:34 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Creator documentation.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Free Documentation License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file included in the packaging of
|
|
|
|
|
** this file. Please review the following information to ensure
|
|
|
|
|
** the GNU Free Documentation License version 1.3 requirements
|
|
|
|
|
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*!
|
2021-03-26 16:31:13 +01:00
|
|
|
\previouspage creator-build-settings.html
|
|
|
|
|
\page creator-build-settings-cmake.html
|
|
|
|
|
\nextpage creator-build-settings-qmake.html
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\title CMake Build Configuration
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2020-08-18 13:59:21 +02:00
|
|
|
Configuring medium-sized to large CMake projects in \QC can be a
|
2022-02-03 15:11:15 +01:00
|
|
|
challenge due to the number of variables that you need to pass to
|
2021-03-26 16:31:13 +01:00
|
|
|
CMake to configure the project correctly. To make this easier,
|
|
|
|
|
\QC creates an initial configuration for you based on the kit
|
2022-02-03 15:11:15 +01:00
|
|
|
settings and displays it in \uicontrol {Initial Configuration} in
|
|
|
|
|
the \l{Specifying Build Settings}{Build Settings} of the project.
|
2021-03-26 16:31:13 +01:00
|
|
|
|
|
|
|
|
\image qtcreator-cmake-build-settings-initial.png "CMake build settings"
|
|
|
|
|
|
2022-02-21 16:39:54 +01:00
|
|
|
\uicontrol {Initial Configuration} lists the variables that are used to
|
|
|
|
|
configure the CMake project for the first time. The default values that
|
|
|
|
|
are inherited from the kit's CMake configuration are displayed in italic.
|
|
|
|
|
The initial configuration list of variables is saved in the project's source
|
|
|
|
|
directory as the \e CMakeLists.txt.user file.
|
|
|
|
|
|
|
|
|
|
\uicontrol {Current Configuration} lists the CMake variables in the
|
|
|
|
|
\c cmake-file-api JSON export in the \c {.cmake/api/v1/reply} directory.
|
|
|
|
|
The variables that are inherited from the initial configuration are
|
|
|
|
|
displayed in italic. Mismatched values are displayed in red.
|
|
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
You can view and edit the actual values of the variables that are passed
|
|
|
|
|
to CMake. Variable names are listed in the \uicontrol Key column and their
|
2022-02-10 14:34:29 +01:00
|
|
|
current values in the \uicontrol Value column. For more information about
|
|
|
|
|
the available variables, select \uicontrol Help in the context menu or see
|
|
|
|
|
\l{CMake: cmake-variables(7)}. For more information about Qt-specific
|
|
|
|
|
variables, see \l{CMake Variable Reference}.
|
2022-02-03 15:11:15 +01:00
|
|
|
|
|
|
|
|
You can specify additional CMake options, such as \c {--find-debug},
|
|
|
|
|
\c {--preset}, \c {--trace-expand}, or \c {--warn-uninitialized}, in
|
|
|
|
|
\uicontrol {Additional CMake options}. For more information about
|
2022-02-10 14:34:29 +01:00
|
|
|
the available options, click the link in the field name or see
|
|
|
|
|
\l{CMake: cmake(1)}.
|
2022-02-03 15:11:15 +01:00
|
|
|
|
|
|
|
|
After successfully running CMake, you can view and modify the current
|
|
|
|
|
configuration in \uicontrol {Current Configuration}.
|
|
|
|
|
|
|
|
|
|
Select \uicontrol {Kit Configuration} to edit the CMake settings for the
|
|
|
|
|
build and run kit selected for the project.
|
2020-08-18 13:59:21 +02:00
|
|
|
|
2021-04-16 08:00:46 +02:00
|
|
|
\section1 Multi-Config Support
|
|
|
|
|
|
|
|
|
|
\QC supports
|
|
|
|
|
\l{https://cmake.org/cmake/help/latest/prop_gbl/GENERATOR_IS_MULTI_CONFIG.html}
|
|
|
|
|
{Multi-config generators}, such as Xcode, Visual Studio, and Ninja
|
|
|
|
|
Multi-Config. This means that you need to configure CMake only once, have
|
|
|
|
|
only one build directory, and can switch between build types faster.
|
|
|
|
|
|
|
|
|
|
However, this means that \QC can no longer simply parse the first CMake
|
|
|
|
|
file-api JSON export. Therefore, the value of the \uicontrol {Build type}
|
|
|
|
|
field must match that of the \c CMAKE_BUILD_TYPE variable for the single
|
|
|
|
|
configuration generators (Ninja, Makefile) to determine, which generator
|
|
|
|
|
to use.
|
|
|
|
|
|
|
|
|
|
When developing with Qt 6 for iOS, only the Xcode generator is supported.
|
|
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
\section1 Modifying Variable Values
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
You can view and edit the actual values of the variables that
|
|
|
|
|
are passed to CMake in \uicontrol {Initial Configuration} or
|
|
|
|
|
\uicontrol {Current Configuration}.
|
2021-03-26 16:31:13 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
\image qtcreator-cmake-build-settings.png "CMake variables"
|
2021-03-26 16:31:13 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To view all variables, select the \uicontrol Advanced check box.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To add variables, select \uicontrol Add, and then select the type of
|
|
|
|
|
the variable that you are adding: \uicontrol Boolean, \uicontrol String,
|
2017-04-25 16:57:50 +02:00
|
|
|
\uicontrol Directory, or \uicontrol File.
|
|
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To change the type of the selected variable, right-click the
|
|
|
|
|
variable name in the \uicontrol Key column, and then select
|
2017-10-27 17:10:33 +02:00
|
|
|
\uicontrol {Force to bool}, \uicontrol {Force to file},
|
2020-10-08 12:15:14 +02:00
|
|
|
\uicontrol {Force to directory}, or \uicontrol {Force to string}
|
|
|
|
|
in the context menu.
|
2017-10-27 17:10:33 +02:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To copy the name or value of the selected variable to the clipboard,
|
2021-03-26 16:31:13 +01:00
|
|
|
select \uicontrol Copy in the context menu.
|
|
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To modify the value of a variable, double-click it, or select it,
|
2022-02-10 14:34:29 +01:00
|
|
|
and then select \uicontrol Edit. If the initial, current, and kit
|
|
|
|
|
configuration get out of sync, select \uicontrol {Apply Kit Value} or
|
|
|
|
|
\uicontrol {Apply Initial Configuration Value} in the context menu in
|
|
|
|
|
\uicontrol {Initial Configuration} or \uicontrol {Current Configuration}.
|
2017-10-27 17:10:33 +02:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
You can apply actions to multiple variables at a time. To clear
|
2020-10-08 12:15:14 +02:00
|
|
|
the selection, select \uicontrol {Clear Selection}.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To remove the selected variables, select \uicontrol Unset. To undo
|
2020-10-08 12:15:14 +02:00
|
|
|
the removal, select \uicontrol Set.
|
|
|
|
|
|
|
|
|
|
To reset all the changes that you made, select \uicontrol Reset.
|
|
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
To modify the environment variable values for the CMake build environment,
|
|
|
|
|
select \uicontrol {Batch Edit}. For more information, see \l{Batch Editing}.
|
|
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To build using the current configuration, select \uicontrol {Run CMake}.
|
|
|
|
|
While building, the button text changes to \uicontrol {Stop CMake}. Select
|
|
|
|
|
the button to cancel the current build.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
The variable values that you change are passed via \c -D<option>=<value>
|
2020-08-18 13:59:21 +02:00
|
|
|
to CMake, which stores the options in the CMakeCache.txt file. This means
|
2022-02-03 15:11:15 +01:00
|
|
|
that if you remove the build directory, all the custom variables that are
|
|
|
|
|
not part of the initial CMake configuration are also removed.
|
2020-08-18 13:59:21 +02:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To reconfigure a project using the modified variable values,
|
2020-08-18 13:59:21 +02:00
|
|
|
select \uicontrol Build > \uicontrol {Clear CMake Configuration}, which
|
|
|
|
|
removes the CMakeCache.txt file. This enables you to do a full rebuild.
|
2019-09-26 15:47:54 +02:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
\section1 Re-configuring with Initial Variables
|
2021-03-26 16:31:13 +01:00
|
|
|
|
2022-02-03 15:11:15 +01:00
|
|
|
To reset CMake variables to the initial ones, select
|
|
|
|
|
\uicontrol {Re-configure with Initial Variables} in
|
|
|
|
|
\uicontrol {Initial Configuration}. \QC deletes the current CMake
|
|
|
|
|
configuration and runs CMake. The initial configuration values are
|
|
|
|
|
stored in the CMakeLists.txt.user file, so deleting a build directory
|
|
|
|
|
does not delete the initial configuration.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
To be asked before \QC resets the changes, select \uicontrol Tools >
|
|
|
|
|
\uicontrol Options > \uicontrol {Build & Run} > \uicontrol CMake >
|
|
|
|
|
\uicontrol {Ask before re-configuring with initial parameters}.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\image qtcreator-build-run-options-cmake.png "CMake Build & Run options"
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-06-28 15:00:30 +02:00
|
|
|
\section1 Viewing CMake Output
|
|
|
|
|
|
|
|
|
|
Output from CMake is displayed next to the \uicontrol {Build Settings} and
|
|
|
|
|
\uicontrol {Run Settings} panes in the \uicontrol Projects mode.
|
|
|
|
|
|
|
|
|
|
\image qtcreator-build-cmake-output.png "CMake output in Projects mode"
|
|
|
|
|
|
2021-12-09 11:21:39 +01:00
|
|
|
To clear the search results, select the \inlineimage icons/clean_pane_small.png
|
2021-06-28 15:00:30 +02:00
|
|
|
(\uicontrol Clear) button.
|
|
|
|
|
|
|
|
|
|
You can enter a string in the \uicontrol Filter field to filter output.
|
2021-12-09 11:21:39 +01:00
|
|
|
To specify filtering options, select the
|
|
|
|
|
\inlineimage icons/magnifier.png "Filtering options menu"
|
2021-06-28 15:00:30 +02:00
|
|
|
button. You can filter output by using regular expressions or
|
|
|
|
|
case-sensitivity. Select \uicontrol {Show Non-matching Lines} to
|
|
|
|
|
hide the lines that match the filter.
|
|
|
|
|
|
2021-11-08 14:02:21 +01:00
|
|
|
Press \key {Ctrl+F} to \l{Finding and Replacing}{search} for a string from
|
|
|
|
|
the output.
|
|
|
|
|
|
2021-12-09 11:21:39 +01:00
|
|
|
To increase or decrease the output text size, select \inlineimage icons/plus.png
|
|
|
|
|
(\uicontrol {Zoom In}) or \inlineimage icons/minus.png
|
2021-06-28 15:00:30 +02:00
|
|
|
(\uicontrol {Zoom Out}), or press \key Ctrl++ or \key Ctrl+-.
|
|
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\section1 CMake Build Steps
|
2017-02-21 10:01:34 +01:00
|
|
|
|
|
|
|
|
\QC builds CMake projects by running \c {cmake . --build}, which then runs
|
2020-08-18 13:59:21 +02:00
|
|
|
the CMake generator specified in the project configuration: \c make,
|
|
|
|
|
\c mingw32-make, \c nmake, or \c ninja, for example. The CMake generator
|
2021-03-26 16:31:13 +01:00
|
|
|
produces project files for \QC. Multi-config generators are also supported.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2020-08-18 13:59:21 +02:00
|
|
|
You can add arguments to pass to CMake and the generator and targets for
|
|
|
|
|
the build command in \uicontrol {Build Steps}.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\image qtcreator-cmake-build-steps.png "CMake build steps"
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2019-09-02 17:01:24 +02:00
|
|
|
\note While the other CMake generators are installed together with Qt,
|
2021-03-26 16:31:13 +01:00
|
|
|
you usually need to install Ninja yourself.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\section1 Using Ninja as a CMake Generator
|
2019-09-02 17:01:24 +02:00
|
|
|
|
|
|
|
|
To use \l {https://ninja-build.org/}{Ninja} with CMake, you must install it
|
|
|
|
|
and select it as the CMake generator in the build and run kit:
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
\li Install Ninja.
|
|
|
|
|
\li Add the path to the Ninja executable to the value of the PATH system
|
|
|
|
|
variable.
|
2022-02-03 15:11:15 +01:00
|
|
|
\li In \uicontrol Projects > \uicontrol {Build & Run} > \uicontrol Build
|
|
|
|
|
> \uicontrol {Build Settings}, select \uicontrol {Kit Configuration}.
|
|
|
|
|
\image qtcreator-cmake-kit-configuration.png "Kit CMake Configuration dialog"
|
2019-09-02 17:01:24 +02:00
|
|
|
\li Select \uicontrol Change next to the \uicontrol {CMake generator}
|
|
|
|
|
field to open the \uicontrol {CMake Generator} dialog.
|
2022-02-03 15:11:15 +01:00
|
|
|
\image qtcreator-cmake-generator.png "CMake Generator dialog"
|
|
|
|
|
\li In \uicontrol Generator, select \uicontrol Ninja.
|
|
|
|
|
\li Select \uicontrol OK to save your changes and close the dialog.
|
2022-02-10 14:34:29 +01:00
|
|
|
\li Select \uicontrol Close to close the
|
|
|
|
|
\uicontrol {Kit CMake Configuration} dialog
|
|
|
|
|
and return to \uicontrol {Build Settings}.
|
2019-09-02 17:01:24 +02:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
\note To make sure that old build artifacts don't get in the way
|
|
|
|
|
the first time you build the project after the change, select
|
|
|
|
|
\uicontrol Build > \uicontrol {Rebuild Project}. This cleans up the
|
|
|
|
|
build directory and performs a new build.
|
|
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\section1 Using CMake with Conan
|
2019-09-02 17:01:24 +02:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\QC can automatically set up the \l {Setting Up Conan}
|
|
|
|
|
{Conan package manager} for use with CMake.
|
2019-09-02 17:01:24 +02:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
Select \uicontrol Tools > \uicontrol Options > \uicontrol {Build & Run} >
|
|
|
|
|
\uicontrol CMake > \uicontrol {Package manager auto setup} to set the
|
|
|
|
|
value of the \c CMAKE_PROJECT_INCLUDE_BEFORE variable to the path to a
|
|
|
|
|
CMake script that installs dependencies from a \c conanfile.txt,
|
|
|
|
|
\c conanfile.py, or \c vcpkg.json file in the project source directory.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2021-03-26 16:31:13 +01:00
|
|
|
\section1 CMake Clean Steps
|
2017-02-21 10:01:34 +01:00
|
|
|
|
2020-08-18 13:59:21 +02:00
|
|
|
When building with CMake, you can add arguments to pass to CMake and the
|
|
|
|
|
generator and targets for the clean command in \uicontrol {Clean Steps}.
|
2017-02-21 10:01:34 +01:00
|
|
|
|
|
|
|
|
\image qtcreator-cmake-clean-steps.png
|
|
|
|
|
|
2022-03-04 18:24:58 +01:00
|
|
|
The build errors and warnings are parsed and displayed in \l Issues.
|
2017-02-21 10:01:34 +01:00
|
|
|
*/
|