Skip to content

When using CMake >= 3.24 use CMAKE_COMPILE_WARNING_AS_ERROR variable instead of setting -Werror directly#390

Merged
christian-rauch merged 1 commit into
AprilRobotics:masterfrom
traversaro:patch-1
Jul 26, 2025
Merged

When using CMake >= 3.24 use CMAKE_COMPILE_WARNING_AS_ERROR variable instead of setting -Werror directly#390
christian-rauch merged 1 commit into
AprilRobotics:masterfrom
traversaro:patch-1

Conversation

@traversaro

Copy link
Copy Markdown
Contributor

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 view 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 it ON by default, while people packaging libraries can just set it to OFF 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.

@christian-rauch christian-rauch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CMakeLists.txt Outdated
@christian-rauch

Copy link
Copy Markdown
Collaborator

Can you rebase and squash your commits together?

@traversaro

Copy link
Copy Markdown
Contributor Author

Can you rebase and squash your commits together?

Done.

@christian-rauch christian-rauch self-requested a review July 26, 2025 17:14
@christian-rauch christian-rauch merged commit 41b39ef into AprilRobotics:master Jul 26, 2025
36 checks passed
@christian-rauch

Copy link
Copy Markdown
Collaborator

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants