When using CMake >= 3.24 use CMAKE_COMPILE_WARNING_AS_ERROR variable instead of setting -Werror directly#390
Merged
Conversation
christian-rauch
requested changes
Jul 6, 2025
christian-rauch
left a comment
Collaborator
There was a problem hiding this comment.
This generally makes sense with the "support newer compilers" argument. But we can reuse the --compile-no-warning-as-error flag instead of adding a new option.
Collaborator
|
Can you rebase and squash your commits together? |
…instead of setting `-Werror` directly
Contributor
Author
Done. |
christian-rauch
approved these changes
Jul 26, 2025
Collaborator
|
Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
-Werroroption 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-Werroroption, 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 view of people packaging libraries, see https://youtu.be/_5weX5mx8hc?si=ZtiWaK7KPTfQ01_g&t=322 .Thanks to the
CMAKE_COMPILE_WARNING_AS_ERRORCMake 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 itONby default, while people packaging libraries can just set it toOFFfrom CMake command line invocation (or pass--compile-no-warning-as-erroroption to CMake) to have build scripts that will work also with more recent compilers.