-
Notifications
You must be signed in to change notification settings - Fork 503
Make warnings errors #70
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmake/toolchain.cmake
Outdated
@@ -18,7 +18,7 @@ set(CMAKE_C_STANDARD 11) | |||
if(NOT WIN32) | |||
# Compiler options are set only on non-Windows, since these options | |||
# are not correct for MSVC. | |||
set(CMAKE_C_FLAGS_INIT "-Wall") | |||
set(CMAKE_C_FLAGS_INIT "-Wall -Werror") | |||
string(CONCAT CMAKE_C_FLAGS_DEBUG_INIT | |||
"-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types " | |||
"--coverage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally unrelated question, where did these flags come from? They look pretty specialized. Why not use defaults and append --coverage
to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK thanks. At some point it might be worth revisiting the flags here. I am not sure if they are the best options and if there is a better way to use the toolchain file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me.
Made an update to this PR, warnings as errors are still defaulted on, but also has an option to disable. edit: and once more for moving the option out of the toolchain file. |
CMakeLists.txt
Outdated
@@ -47,6 +47,14 @@ set(H3_SOVERSION 1) | |||
|
|||
project(h3 VERSION ${H3_VERSION}) | |||
|
|||
set(H3_FLAGS "") | |||
if(NOT WIN32) | |||
option(WARNINGS_AS_ERRORS "Warnings are treated as errors" ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
CMakeLists.txt
Outdated
@@ -47,6 +47,14 @@ set(H3_SOVERSION 1) | |||
|
|||
project(h3 VERSION ${H3_VERSION}) | |||
|
|||
set(H3_FLAGS "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the other flags? I'd remove them from cmake/toolchain.cmake
and put them here instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. I've moved the other flags here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more small change.
CMakeLists.txt
Outdated
# are not correct for MSVC. | ||
string(CONCAT H3_FLAGS ${H3_FLAGS} "-Wall ") | ||
|
||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I once thought this was a good idea too. Turns out, checking for "Debug" build might be done at build time instead of configuration time, so you need to use a generator expression here. Something like this should do it:
string(CONCAT H3_FLAGS "$<$<CONFIG:Debug>:-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types> ")
More on this topic here: https://stackoverflow.com/a/24470998/1930331.
For the record, I'm not convinced it's a good idea to use -O0
or -g
in these options because CMake will add them as the default debug flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, please remove the if statement entirely and you can append this generator expression to the earlier -Wall
if you'd like.
I see some of the tests are failing. I've had this issue too, and it has to do with |
CMakeLists.txt
Outdated
|
||
if(CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
list(APPEND H3_COMPILE_FLAGS | ||
-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the generator expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't been pushed yet, still running some tests locally
There was also a second issue that --coverage was no longer passed to the linker, which required adding an additional option there. |
CMakeLists.txt
Outdated
list(APPEND H3_COMPILE_FLAGS --coverage) | ||
# --coverage is not passed to the linker, so this option is needed | ||
# to fully enable coverage. | ||
list(APPEND H3_LINK_FLAGS -fprofile-arcs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think --coverage
would work here too (at least for GCC and clang). But you are right for adding the linker flags in general.
CMakeLists.txt
Outdated
# are not correct for MSVC. | ||
list(APPEND H3_COMPILE_FLAGS -Wall) | ||
|
||
list(APPEND H3_COMPILE_FLAGS $<$<CONFIG:Debug>:-g -gdwarf-2 -g3 -O0 -fno-inline -fno-eliminate-unused-debug-types>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove -O0
and -g
. They don't serve the same purpose here as in the toolchain file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see -g
is in the default flags for Debug, but I don't see -O0
. What is the reason for removing that option?
CMakeLists.txt
Outdated
@@ -147,6 +171,9 @@ set(ALL_SOURCE_FILES | |||
# Build the H3 library | |||
add_library(h3 ${LIB_SOURCE_FILES}) | |||
|
|||
target_compile_options(h3 PRIVATE ${H3_COMPILE_FLAGS}) | |||
target_link_libraries(h3 PUBLIC ${H3_LINK_FLAGS}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this PUBLIC
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking of writing this in a different way but didn't update, will fix it.
CHANGELOG.md
Outdated
@@ -10,6 +10,7 @@ The public API of this library consists of the functions declared in file | |||
- Generator for the faceCenterPoint table (#67) | |||
### Changed | |||
- Moved Vec3d structure to `vec3d.h` (#67) | |||
- Added CMake `WARNINGS_AS_ERRORS` option, defauled on, for Clang and GCC (#70) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo, should be defaulted on
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Make warnings errors
I think we're already at or near 0 warnings, so we could make warnings errors to preserve that. It's also possible some of the compilers in CI have warnings which we don't notice when developing.
Thoughts?