CMake is an alternative to qmake for automating the generation of build configurations. It controls the software compilation process by using simple configuration files, called
CMakeLists.txt files. CMake generates native build configurations and workspaces that you can use in the compiler environment of your choice.
CMake automates the configuration of build systems. It controls the software compilation process by using simple configuration files, called CMakeLists.txt files. CMake generates native build configurations and workspaces that you can use in the compiler environment of your choice. Hey folks, today I ramble on about changing my build system, enjoy! Please let me know if you have any questions. Follow-up videos coming soon.https://www.pa. QMake support in Qt6? Customer still need to build QMake projects; Idea: Make QMake build outside qtbase.git Do a verbatim copy of mkspecs for Qt6; Let CMake generate the QMake module.pri files (via ECM's CMake modules) Qt Community: How do we communicate the progress to our community and get a community decision on the build system for Qt 6? Mar 09, 2017 Using QMake pretty much limits developers to Qt Creator to get decent support. Moving to CMake would allow developers to use CLion, XCode or Visual Studio C more easily, while keeping support for Qt Creator (although not as good support as with QMake). Bionus added the build label on Mar 9, 2017.
Qt Creator automatically detects the CMake executable specified in the
PATH. You can add paths to other CMake executables and use them in different build and run kits.
Adding CMake Tools
Qt Creator supports CMake version 3.0, or later.
To specify paths to CMake executables and to add them to kits:
- Select Tools > Options > Build & Run > CMake > Add.
- In the Name field, specify a name for the tool.
- In the Path field, specify the path to the CMake executable.
- Select Apply to save your changes.
- Select the Kits tab to add the CMake tool to a build and run kit. The kit also specifies the CMake Generator that is used for producing project files for Qt Creator and the configuration variables that are used:
For more information, see Adding Kits.
Creating CMake Projects
To create a CMake project:
- Select File > New File or Project > Non-Qt Project > Plain C Application or Plain C++ Application > Choose.
- In the Name field, enter a name for the project.
- In the Create in field, enter the path for the project files, and then select Next (or Continue on OS X).
- In the Build system field, select CMake, and then select Next.
- Select CMake kits for the platforms that you want to build the application for, and then select Next.
- Review the project settings, and click Finish (or Done on OS X).
- Select Run CMake to generate a .cbp file.
Some projects require command line arguments to the initial CMake call. CMake will remember the arguments during subsequent calls.
Qt Creator generates a
CMakeLists.txt file that you can modify in the Edit mode.
Opening CMake Projects
Qmake To Cmake Converter
To open an existing CMake project:
- Select File > Open File or Project.
- Select the
CMakeLists.txtfile from your CMake project.
- Select a kit that is configured to use CMake for building the project.
- In Projects, right-click the project name to open the context menu, and then select Run CMake to have the project contents listed in the view.
Editing CMake Configuration Files
To open a CMakeLists.txt file for editing, right-click it in the Projects view and select Open with > CMake Editor.
The following features are supported:
- Pressing F2 when the cursor is on a filename to open the file
- Keyword completion
- Matching parentheses and quotes
Building CMake Projects
To build CMake projects, select Build Project or press Ctrl+B (or Cmd+B Merging two cells in excel. on OS X).
Qt Creator builds CMake projects by running
ninja depending on the selected kit.
By default, Qt Creator uses the Defaultbuild configuration. You can select another build configuration in Projects > Build Settings > Edit build configuration. In addition to debug and release build configurations, you can create a release build that contains debug information or a release build with the smallest possible size.
In the Build directory field, you can specify the directory in which the project is built (shadow build).
To view all settings, select the Advanced check box.
To modify the value of a build setting, select it, and then select Edit. The new value is displayed in italics until you save the changes by selecting Apply Configuration Changes. Any configuration change might trigger a follow-up configuration change, so keep saving until no more values are displayed in italics.
You can add arguments and targets for the build command in Build Steps.
You can add arguments and targets for the clean command in Clean Steps.
The build errors and warnings are parsed and displayed in the Issues output pane.
Running CMake Projects
Qt Creator automatically adds Run Configurations for all targets specified in the CMake project file.
To run CMake projects, select Run or press Ctrl+R (or Cmd+R on OS X).
Deploying CMake Projects to Embedded Linux Devices
Qt Creator cannot extract files to be installed from a CMake project, and therefore, only executable targets are automatically added to deployment files. You must specify all other files in the
QtCreatorDeployment.txt file that you create and place in either the root directory of the CMake project or the build directory of the active build configuration. Currently, Qt Creator first checks the root directory and only if no
QtCreatorDeployment.txt exists it checks the active build directory.
Use the following syntax in the file:
<deployment/prefix>is the (absolute) path prefix to where files are copied on the remote machine.
<relative/source/file>is the file path relative to the CMake project root. No directories or wildcards are allowed in this value.
<relative/destination/dir>is the destination directory path relative to
To automate the creation of
- Define the following macros in the top level
add_deployment_file(<file/name>)to add files and
add_deployment_directory(<folder/name>)to add directories (including subdirectories) to the
cmakeafter you add or remove files using the macros.
Adding External Libraries to CMake Projects
Through external libraries, Qt Creator can support code completion and syntax highlighting as if they were part of the current project or the Qt library.
Qt Creator detects the external libraries using the
FIND_PACKAGE() macro. Some libraries come with the CMake installation. You can find those in the
Modules directory of your CMake installation.
Qmake To Cmake Transfer
Note: If you provide your own libraries, you also need to provide your own
FindFoo.cmake file. For more information, see CMake FAQ.
Syntax completion and highlighting work once your project successfully builds and links against the external library.
Qmake To Cmake Free
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.