What is a .cmake file?
CMake Script File · Code and data · Kitware · 2000
A .cmake file is a script for CMake, the de facto build-system generator for C and C++. It holds modules, toolchain settings or helper code included by a project's CMakeLists.txt.
What is a .cmake file used for?
CMake does not build code itself: it reads its scripts and generates native build files (Makefiles, Ninja, Visual Studio or Xcode projects). The main file of every project is called CMakeLists.txt; .cmake files are the reusable pieces around it.
Typical .cmake files are Find modules that locate libraries, toolchain files for cross-compiling, and shared macros. The language is CMake's own command syntax, plain text.
How to open a .cmake file
The .cmake format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list. For a step-by-step walkthrough, see how to open a .cmake file.
Windows
- VS Code (CMake Tools)
- Visual Studio
- any text editor
macOS
- VS Code (CMake Tools)
- CLion
- any text editor
Linux
- VS Code (CMake Tools)
- CLion
- any text editor
.cmake file signature (magic bytes)
Programs recognise a .cmake file by the bytes at the start of the file, not by its name. These are the signatures for CMake.
| Hex signature | Offset | Note |
|---|---|---|
| (no fixed signature) | 0 | plain text; no fixed magic bytes |
See the full magic-numbers reference for every format.
Frequently asked questions
What is a .cmake file?
A .cmake file is a script for CMake, the de facto build-system generator for C and C++. It holds modules, toolchain settings or helper code included by a project's CMakeLists.txt.
What is the difference between CMakeLists.txt and a .cmake file?
CMakeLists.txt is the entry point CMake looks for in each directory; .cmake files are modules, toolchains and helpers that those lists include() or that CMake loads as Find modules.
Does CMake compile my code?
No. It generates the build system (Ninja, Makefiles, IDE projects) that then compiles the code, which is why it is called a build-system generator.
How do I open a .cmake file?
Any text editor; VS Code with the CMake Tools extension adds highlighting, completion and configure/build integration.
Related formats
Sources
Details on this page were checked against authoritative references: