// Copyright (C) 2024 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only /*! \page creator-build-settings-cmake.html \previouspage creator-reference.html \ingroup creator-reference-build-configurations \title CMake Build Configuration \brief Settings for building applications with CMake. Specify build settings for the selected \l{Kits}{kit} in \uicontrol Projects > \uicontrol {Build & Run} > \uicontrol Build > \uicontrol {Build Settings}. Configuring medium-sized to large CMake projects in \QC can be a challenge due to the number of variables that you need to pass to CMake to configure the project correctly. To make this easier, \QC creates an initial configuration for you based on the \l{Kits} {kit preferences} and displays it in \uicontrol {Initial Configuration} in the \uicontrol {Build Settings} of the project. Or, you can use CMake presets to configure CMake. The \uicontrol Configure field displays the effective CMake call that \QC constructs using the values of the \uicontrol {Build directory} and \uicontrol {Build type} fields. \image qtcreator-build-settings-cmake-configure.webp {CMake configure command} You can specify additional CMake options, such as \c {--find-debug}, \c {--trace-expand}, or \c {--warn-uninitialized}, in \uicontrol {Additional CMake options}. For more information about the options, click the link in the field name or see \l{CMake: cmake(1)}. Select \uicontrol {Kit Configuration} to edit the CMake settings for the build and run kit selected for the project. You can use \l{CMake Presets}{CMake presets} files to specify common configure, build, and test options and share them with others. \section1 Initial Configuration \image qtcreator-build-settings-cmake-initial.webp {Initial CMake configuration} \uicontrol {Initial Configuration} lists the variables that \QC uses to configure the CMake project for the first time. It shows the default values that come from the kit's CMake configuration in italics. \QC saves the initial configuration list of variables in the project's source directory as the \e CMakeLists.txt.user file. \section1 Current Configuration \image qtcreator-build-settings-cmake-current.webp {Current CMake configuration} \uicontrol {Current Configuration} lists the CMake variables in the \c cmake-file-api JSON export in the \c {.cmake/api/v1/reply} directory. It shows the variables that come from the initial configuration in italics and mismatched values in red. After selecting the \uicontrol {Run CMake} button, you can view and change the actual values of the variables that \QC passes to CMake. The \uicontrol Key column lists variable names, and the \uicontrol Value column lists their current values. For more information about the 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}. \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. \section1 Modifying Variable Values You can view and edit the actual values of the variables that are passed to CMake in \uicontrol {Initial Configuration} or \uicontrol {Current Configuration}. \image qtcreator-build-settings-cmake-current.webp {Current CMake configuration} You can select several variables and apply an action to them. To clear the selection, click anywhere in the view. To batch edit variable values, select \uicontrol {Batch Edit}. \image qtcreator-edit-cmake-configuration.webp {Edit CMake Configuration dialog} 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. \section2 Adding Variables To add variables, select \uicontrol Add, and then select the type of the variable that you are adding: \uicontrol Boolean, \uicontrol String, \uicontrol Directory, or \uicontrol File. To change the type of the selected variable, right-click the variable name in the \uicontrol Key column, and then select \uicontrol {Force to bool}, \uicontrol {Force to file}, \uicontrol {Force to directory}, or \uicontrol {Force to string} in the context menu. To copy the name or value of the selected variable to the clipboard, select \uicontrol Copy in the context menu. \section2 Changing Variable Values To change the value of a variable, double-click it, or select it, 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}. To reset all the changes that you made, select \uicontrol Reset. The variable values that you change are passed via \c -D