What is MIME type "text/x-cmake"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

text/x-cmake is a MIME type for files that contain CMake scripting code. These files are written in plain text. They provide instructions to generate native build files on different platforms.

They are used primarily by the CMake build system. CMake reads these scripts to configure project builds and manage compilation processes.

Files with this MIME type may have names typical for build configuration. For example, you might see names like MAKE, CMAKE, MAKEFILE, MK, MAK, CMAKE.IN, or MKFILE.

For more details on how CMake functions, visit its official site at cmake.org.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-cmake    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-cmake">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-cmake');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

What programs can open files with the text/x-cmake MIME type?

Since these are plain text files, they can be opened and edited with any text editor. Popular choices for developers include Visual Studio Code, Sublime Text, and Notepad++, which often provide syntax highlighting for .cmake and Makefiles. Integrated Development Environments (IDEs) like CLion or Visual Studio also have native support.

How do I configure Apache to serve CMake files as viewable text?

To ensure browsers display the code inline rather than downloading it, map the extension to the MIME type in your .htaccess or httpd.conf file. Add the line: AddType text/plain .cmake .mak .mk. While you can use text/x-cmake, using text/plain ensures wider browser compatibility for immediate viewing.

Why does my browser download the file instead of displaying the code?

This happens if the web server sends the file with the generic application/octet-stream MIME type or sets a Content-Disposition: attachment header. To fix this, configure your web server (Nginx, Apache, or IIS) to serve extensions like .cmake or .mak with a text-based content type.

What does the 'x-' prefix mean in text/x-cmake?

The x- prefix indicates that this is a non-standard or experimental MIME type not officially registered with the IANA. While it is widely used by applications to identify CMake and Make scripts, some systems may prefer using text/plain to ensure the content is treated simply as text.

Is it a security risk to expose text/x-cmake files on a web server?

Exposing build configuration files like Makefiles or CMakeLists.txt can reveal directory structures, library dependencies, and compiler flags. While they rarely contain passwords, this information can help attackers map your infrastructure. It is best practice to block access to these files on production servers.

How do I configure Nginx to handle CMake extensions?

You can add the MIME type definition inside the types block of your nginx.conf file. Use the following configuration: types { text/plain cmake mak mk; }. Reload Nginx to apply the changes, allowing users to view the scripts directly in their browser.

Can text/x-cmake be used for standard Makefiles?

Yes, this MIME type is often associated with standard build files like .make and .mk. Although specifically named for CMake, the underlying format for both CMake scripts and Makefiles is plain text, making the MIME type functionally compatible for classification purposes.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.