CMake is an alternative to qmake for automating the generation of makefiles. It controls the software compilation process by using simple configuration files, called CMakeLists.txt files. CMake generates native makefiles and workspaces that you can use in the compiler environment of your choice.
Since Qt Creator 1.1, CMake configuration files are supported. Qt Creator 1.3 supports the Microsoft Toolchain if the CMake version is at least 2.8.
Setting the Path for CMake
You can set the path for the CMake executable in Tools > Options... > Projects > CMake.
Note: Before you open a CMake project it is necessary to modify the PATH environment variable to include the bin folders of mingw and Qt Creator in the SDK.
For instance, if you have the Qt Creator SDK installed in your C drive, use the following command to set the environment variables in the command line prompt:
Then start Qt Creator by typing:
Opening CMake Projects
To open a CMake project:
- Select File > Open File or Project....
- Select the CMakeLists.txt file from your CMake project.
A wizard guides you through the rest of the process.
Note: If the CMake project does not have an in-place build, Qt Creator lets you specify the directory in which the project is built (shadow build).
The screenshot below shows how you can specify command line arguments to CMake for your project.
Normally, there is no need to pass any command line arguments for projects that are already built, as CMake caches that information.
Building CMake Projects
Qt Creator builds CMake projects by running make, mingw32-make, or nmake depending on your platform. The build errors and warnings are parsed and displayed in the Build Issues output pane.
By default, Qt Creator builds the all target. You can specify which targets to build in Project mode, under Build Settings.
Qt Creator supports multiple build configurations. The build directory can also be modified after the initial import.
Running CMake Projects
Qt Creator automatically adds Run Configurations for all targets specified in the CMake project file.
Known issues for the current version can be found here.
Adding External Libraries to a CMake Project
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.
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.