.cmake

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.

Category
Code and data
MIME type
Type
Plain text
Is a .cmake file safe to open? Caution. CMake scripts execute commands during configuration and can run arbitrary processes. Review third-party build scripts before configuring a project with them.

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.

What opens 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.

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

Open a .cmake file step by step

  1. Confirm the file really is a .cmake. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with VS Code (CMake Tools) or Visual Studio.
  3. On Mac, use VS Code (CMake Tools) or CLion.
  4. On Linux, try VS Code (CMake Tools) or CLion.
  5. Still stuck? Search for a dedicated CMake viewer rather than a generic one.

Why can't I open my .cmake file?

Almost always because no installed app understands CMake. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .cmake at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

CMake has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

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. How sources are ranked and what is deliberately left out is set out in the methodology.