Format CMake files | Qt Creator Documentation

- Qt Creator Documentation
- Format CMake files
- Qt Creator 18.0.2

Edit CMake configuration files ◦ Manage files in CMake projects

# Format CMake files

You can use the cmake-format tool and local `.cmake-format`, `.py`, or `.json` configuration files to format any text in CMake files that you do not guard with a pair of fences. You must install the tool and tell Qt Creator where you installed it.

To automatically format CMake files upon file save:

1. Select Preferences > CMake > Formatter.

2. In CMakeFormat command, enter the path to `cmake-format.exe`.
3. Select Automatic formatting on file save to automatically format CMake files when you save them.

   To temporarily disable this setting while saving a file, go to File and select Save Without Formatting.

4. In Restrict to MIME types, add the MIME types of the files to format, separated by semicolons. The default value, `text/x-cmake` formats CMake files. If the field is empty, all files are formatted.
5. Select Restrict to files contained in the current project to only format CMake files that belong to the current project.

See also How To: Build with CMake, Edit MIME types, and CMake.

Edit CMake configuration files ◦ Manage files in CMake projects