Skip to content
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

Error on all C/C++ compiler warnings in src/ and tests/ #292

Merged
merged 4 commits into from
Sep 22, 2022

Conversation

aloisklink
Copy link
Contributor

Enables the GCC/Clang -Werror flag on everything in the src/ and tests/ folder.

It's only enabled if -DCMAKE_BUILD_TYPE=Debug. This is so that any 3rd parties using edgesec (for example https://github.com/nqminds/manysecured-openwrt-packages or even the .deb build) should still be able to compile edgesec, even if they have a newer version of GCC/Clang that adds new warnings.

These warnings are usually pretty useful, so we probably want to fix them all. If we ever want to disable this, we can do:

add_compile_options(-Wno-error=foo) # too many -Wfoo warnings

Or better yet, we can use target_compile_options to disable them just in one file:

target_compile_options(my_library_with_warnings
  PUBLIC -Wno-error=foo # error is also disabled for all dependencies of this lib (e.g. error is in header file)
  PRIVATE -Wno-error=foo # error is not disable for dependencies of this lib (e.g. error is only in .c source file
)

There was only one minor warning left to fix in our code, see test(os): fix const correctness argv warning.

(OpenSSL, lib/libnetlink, sqlite3 and libpcap print a lot of warnings, but since they're not in src/ and tests/, they won't be converted to errors.

argv must not be `const`, since programs are allowed to modify argv.
Enables the GCC/Clang `-Werror` flag on everything in the src/
and tests/ folder, if -DCMAKE_BUILD_TYPE=Debug.
@aloisklink aloisklink added the enhancement New feature or request label Sep 20, 2022
@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Merging #292 (1a868b9) into main (146fc1c) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 1a868b9 differs from pull request most recent head bb72c63. Consider uploading reports for the commit bb72c63 to get more accurate results

@@            Coverage Diff             @@
##             main     #292      +/-   ##
==========================================
+ Coverage   49.25%   49.27%   +0.01%     
==========================================
  Files         116      116              
  Lines       18633    18633              
==========================================
+ Hits         9178     9181       +3     
+ Misses       9455     9452       -3     
Impacted Files Coverage Δ
tests/utils/test_os.c 98.38% <100.00%> (+0.01%) ⬆️
src/utils/sockctl.c 49.39% <0.00%> (+0.58%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@mereacre mereacre left a comment

Choose a reason for hiding this comment

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

Great. We need to document(write as comment) in the main CMakeLists file how to disable teh error for specific targets.

@mereacre mereacre merged commit 0bb4a20 into main Sep 22, 2022
@mereacre mereacre deleted the build/error-on-warnings branch September 22, 2022 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants