When working with CMake, the default output during project configuration can be quite verbose. While this level of detail is helpful for debugging or initial setup, it can be excessive in clean CI pipelines or routine builds. This tutorial demonstrates how to set log level when generating build files using CMake.
We have a simple CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.27)
project(myapp)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} main.cpp)
By default, when generating the build files, CMake shows all configuration steps like this:
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/ubuntu/myproject/build
We can reduce the output by using the --log-level
option:
cmake -S . -B build --log-level=ERROR
The ERROR
log level displays only error messages and essential steps, while suppressing detection messages and other non-critical information. Output:
-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/ubuntu/myproject/build
CMake supports several log levels that determine which messages will appear in the output. These levels, from least to most verbose, are: ERROR < WARNING < NOTICE < STATUS (default) < VERBOSE < DEBUG < TRACE
.
When using --log-level=<level>
, only messages of that level or higher severity are shown.
Leave a Comment
Cancel reply