If CMake >= 3.24 use CMAKE_COMPILE_WARNING_AS_ERROR to enable Werror #117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
-Werror
option is typically enabled automatically by library authors, so they ensure that all contributors to the library early fail if new code they write contain a warning, ensuring as soon as possible that no new warnings are added to the library. On the other hand, people that package libraries for distributions prefer to disable the-Werror
option, as they may want to compile a given library with a new compilers (that may not have even existed when a given release of a library was tagged), that introduce new warnings, without having a failure. For a detailed discussion of this from the point of people packaging libraries, see https://youtu.be/_5weX5mx8hc?si=ZtiWaK7KPTfQ01_g&t=322 .Thanks to the
CMAKE_COMPILE_WARNING_AS_ERROR
CMake option available since CMake 3.24, it is possible to have the best of both worlds. Library authors can define this variable as an option and have itON
by default, while people packaging libraries can just set it toOFF
from CMake command line invocation (or pass--compile-no-warning-as-error
option to CMake) to have build scripts that will work also with more recent compilers.