Warnings in build systems are often useful: they alert you to deprecated features, suspicious patterns, or potential future breakage. But not every warning is something you can address - especially when it comes from a third-party project you don't control. In such cases, warnings can overwhelm the continuous integration (CI) logs, making it harder to notice the important messages. This tutorial demonstrates how to suppress CMake warnings.
Consider the following CMakeLists.txt
file:
cmake_minimum_required(VERSION 3.9)
project(myapp)
set(CMAKE_CXX_STANDARD 17)
add_executable(${PROJECT_NAME} main.cpp)
When generating build files with a modern CMake, you may see something like:
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.
Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
This is only a warning, so the build succeeds - but if the warning comes from code you cannot edit (such as 3rd-party libraries), you may want to silence it.
To turn off messages about deprecated CMake features, use the -Wno-deprecated
option:
cmake -S . -B build -Wno-deprecated
This keeps developer warnings visible, but hides notices about features that will be removed in future CMake versions.
To silence developer warnings (which usually point out questionable usage or bad practices), use the -Wno-dev
option:
cmake -S . -B build -Wno-dev
By default, the -Wno-dev
also turn off deprecation warnings.
Leave a Comment
Cancel reply