2 Methods to Disable ANSI Color Escape Codes for CMake

2 Methods to Disable ANSI Color Escape Codes for CMake

By default, CMake can include ANSI color escape codes in terminal output to highlight messages, warnings, and errors. Colored output improve readability during interactive development, while plain text output can be preferable in some environments. This tutorial provides 2 methods how to disable ANSI color escape codes for CMake.

The following CMakeLists.txt file can be used as example:

cmake_minimum_required(VERSION 4.1)
project(myapp)

set(CMAKE_CXX_STANDARD 17)

add_executable(${PROJECT_NAME} main.cpp)

To generate an error message, keep the main.cpp file missing.

Method 1 - NO_COLOR

Since CMake 4.1, NO_COLOR environment variable is supported for disabling colored output. It is the preferred approach because the variable follows a standardized convention supported by many command-line tools. Setting NO_COLOR=1 disables colored terminal output for CMake commands.

Export the variable to affect all subsequent CMake commands in the current terminal session:

set NO_COLOR=1
export NO_COLOR=1

Now run any CMake command. For example:

cmake -S . -B build

The variable can also be applied only to a single command on Linux:

NO_COLOR=1 cmake -S . -B build

Method 2 - CLICOLOR

Another way to disable colored output is by using the CLICOLOR environment variable. Setting this variable to 0 prevents CMake from producing colored terminal messages.

Export environment variable:

set CLICOLOR=0
export CLICOLOR=0

Run CMake command:

cmake -S . -B build

For a single command execution on Linux:

CLICOLOR=0 cmake -S . -B build

Leave a Comment

Cancel reply

Your email address will not be published.