-
Notifications
You must be signed in to change notification settings - Fork 24
feat(cmake): centralize and harden compiler warning flags #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bburda
wants to merge
8
commits into
main
Choose a base branch
from
feature/production-warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+287
−67
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f691a6a
feat(cmake): centralize compiler warnings with ROS2MedkitWarnings module
bburda 5e15467
fix(cmake): remove -Wnull-dereference due to GCC 13 STL false positives
bburda 451b6b2
fix(cmake): restore -Wnull-dereference, default ENABLE_WERROR to OFF
bburda 4028a53
feat(cmake): use selective -Werror for flags safe from external headers
bburda 2d75f67
fix(cmake): suppress all warnings on vendored and gtest code with -w
bburda a6ec484
fix(cmake): demote -Wuseless-cast from error to warning
bburda eadf4ae
fix(cmake): mark vendored cpp-httplib include as SYSTEM
bburda 385fe13
fix(gateway,fault_manager): fix format specifier portability issues
bburda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| # Copyright 2026 bburda | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| # Production-grade compiler warning configuration for ros2_medkit packages. | ||
| # Aligned with AUTOSAR C++14, MISRA C++, OpenSSF, and Airbus SecLab guidelines. | ||
| # | ||
| # Strategy: all warnings enabled, selective -Werror=<flag> only for warnings | ||
| # that don't false-positive on external headers (STL, ROS 2, gtest, nlohmann). | ||
| # Flags that DO fire on external code remain as warnings for visibility. | ||
| # | ||
| # Provides: | ||
| # option ENABLE_WERROR (default ON) - selective warnings-as-errors | ||
| # function ros2_medkit_relax_vendor_warnings() - call after ament_add_gtest/gmock | ||
| # | ||
| # Usage: | ||
| # find_package(ros2_medkit_cmake REQUIRED) | ||
| # include(ROS2MedkitWarnings) | ||
| # ... | ||
| # if(BUILD_TESTING) | ||
| # ament_add_gtest(...) | ||
| # ros2_medkit_relax_vendor_warnings() | ||
| # endif() | ||
|
|
||
| option(ENABLE_WERROR "Treat select compiler warnings as errors" ON) | ||
|
|
||
| if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
| # -- All warnings (report everything, some as errors, rest as warnings) ------ | ||
| add_compile_options( | ||
| # Core warnings | ||
| -Wall | ||
| -Wextra | ||
| -Wpedantic | ||
|
|
||
| # Type safety (MISRA, OpenSSF) | ||
| -Wconversion | ||
| -Wsign-conversion | ||
| -Wdouble-promotion | ||
| -Wfloat-equal # MISRA M6-2-2, AUTOSAR M6-2-2 | ||
|
|
||
| # Shadow / hiding | ||
| -Wshadow | ||
| -Woverloaded-virtual | ||
|
|
||
| # OOP correctness | ||
| -Wnon-virtual-dtor | ||
| -Wold-style-cast | ||
|
|
||
| # Const correctness (MISRA, Airbus SecLab) | ||
| -Wcast-qual | ||
|
|
||
| # Memory / alignment | ||
| -Wcast-align | ||
| -Wnull-dereference | ||
|
|
||
| # Control flow | ||
| -Wimplicit-fallthrough | ||
| -Wswitch-enum # AUTOSAR A6-4-6 | ||
|
|
||
| # Preprocessor (MISRA) | ||
| -Wundef | ||
|
|
||
| # Format strings (OpenSSF) | ||
| -Wformat=2 | ||
|
|
||
| # Modern C++ (AUTOSAR A4-10-1) | ||
| -Wzero-as-null-pointer-constant | ||
|
|
||
| # Code cleanliness (AUTOSAR) | ||
| -Wextra-semi | ||
| ) | ||
|
|
||
| # -- Selective -Werror for flags safe from external header false positives ---- | ||
| # NOT promoted: -Wconversion, -Wsign-conversion, -Wdouble-promotion, | ||
| # -Wnull-dereference, -Wcast-align (false positives on STL/ROS 2/nlohmann) | ||
| if(ENABLE_WERROR) | ||
| add_compile_options( | ||
| -Werror=shadow | ||
| -Werror=switch-enum | ||
| -Werror=old-style-cast | ||
| -Werror=float-equal | ||
| -Werror=cast-qual | ||
| -Werror=undef | ||
| -Werror=zero-as-null-pointer-constant | ||
| -Werror=extra-semi | ||
| -Werror=overloaded-virtual | ||
| -Werror=non-virtual-dtor | ||
| -Werror=implicit-fallthrough | ||
| -Werror=format=2 | ||
| ) | ||
| endif() | ||
|
|
||
| # GCC-only warnings | ||
| if(CMAKE_COMPILER_IS_GNUCXX) | ||
| add_compile_options( | ||
| -Wduplicated-cond | ||
| -Wduplicated-branches | ||
| -Wlogical-op | ||
| -Wuseless-cast | ||
| ) | ||
| # Note: -Wuseless-cast NOT promoted - type aliases (time_t, int64_t, size_t) | ||
| # resolve differently across distros, making casts useless on one but needed | ||
| # on another. | ||
| if(ENABLE_WERROR) | ||
| add_compile_options( | ||
| -Werror=duplicated-cond | ||
| -Werror=duplicated-branches | ||
| -Werror=logical-op | ||
| ) | ||
| endif() | ||
| endif() | ||
| endif() | ||
|
|
||
| # Suppress strict warnings on gtest/gmock vendor targets. | ||
| # ament_add_gtest/ament_add_gmock build gtest/gmock sources as subdirectory | ||
| # targets, which inherit add_compile_options flags. Vendored code may trigger | ||
| # promoted warnings (-Werror=switch-enum, -Werror=useless-cast, etc.). | ||
| # Call this once at the end of the BUILD_TESTING block. | ||
| function(ros2_medkit_relax_vendor_warnings) | ||
| foreach(_target gmock gmock_main gtest gtest_main) | ||
| if(TARGET ${_target}) | ||
| target_compile_options(${_target} PRIVATE -w) | ||
| endif() | ||
| endforeach() | ||
| endfunction() | ||
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
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.