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

adds -DMaCh3_WERROR_ENABLED=OFF options if you just can't even with GCC #195

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ N.B. that clang also understands these directives, so don't panic that they have

This will disable that diagnostic for the rest of the compilation unit (usually a .cc file). Note that this means if you include these in headerfiles, they will disable diagnostics more widely, please try and disable the diagnostics over as little code as possible.

If a specific error is really getting you down and its showing up everywhere, the nuclear option is to disable it repo-wide by modifying the `MaCh3Warnings` interface target, defined in the top-level project [CMakeLists.txt](../CMakeLists.txt) like so:
If a specific error is really getting you down and its showing up everywhere, the serious option is to disable it repo-wide by modifying the `MaCh3Warnings` interface target, defined in the top-level project [CMakeLists.txt](../CMakeLists.txt) like so:

```cmake
target_compile_options(MaCh3Warnings INTERFACE
Expand All @@ -126,6 +126,8 @@ target_compile_options(MaCh3Warnings INTERFACE

Please attempt more localised options before reaching for this, but sometimes this represents the best way to proceed with development without 'fixing' innocuous warnings.

The really serious option is to configure with: `-DMaCh3_WERROR_ENABLED=OFF`, which will disable the `-Werror` flag.

### An example

We got this compiler error:
Expand Down
38 changes: 22 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(MaCh3_VERSION ${PROJECT_VERSION})
#LP - This option name is confusing, but I wont change it now.
option(USE_CPU "Whether to *only* use the CPU (i.e. no GPU)" OFF)
option(MaCh3_PYTHON_ENABLED "Whether to build MaCh3 python bindings" OFF)
option(MaCh3_WERROR_ENABLED "Whether to build MaCh3 with heightened compiler pedancy" ON)

# Try to find CUDA
find_package(CUDAToolkit QUIET)
Expand Down Expand Up @@ -75,22 +76,22 @@ set( CMAKE_EXPORT_COMPILE_COMMANDS ON )
# KS: Compile and link options for more see https://github.com/cpp-best-practices/cppbestpractices/tree/master
add_library(MaCh3Warnings INTERFACE)
target_compile_options(MaCh3Warnings INTERFACE
-Wextra # Enable extra warning flags
-Wall # Enable all standard warning flags
-Wshadow # Warn when a variable declaration shadows one from an outer scope
-Wuninitialized # Warn about uninitialized variables
-Wnon-virtual-dtor # Warn when a class with virtual functions has a non-virtual destructor
-Woverloaded-virtual # Warn when a function declaration hides a virtual function from a base class
-Wformat=2 # Warn on security issues around functions that format output (ie printf)
-Wunused # Warn on anything being unused
-Wredundant-decls # Warn about multiple declarations of the same entity. Useful for code cleanup.
-Wstrict-aliasing=2 # Helps detect potential aliasing issues that could lead to undefined behavior.
-Wuseless-cast # Warn if you perform a cast to the same type (only in GCC >= 4.8)
# -Wpadded # Warn when padding is added to a structure or class for alignment
-Wnull-dereference # Warn if a null dereference is detected (only in GCC >= 6.0)
-Wold-style-cast # Warn for c-style casts
-Wconversion # Warn on type conversions that may lose data
-Werror # Treat Warnings as Errors
-Wextra # Enable extra warning flags
-Wall # Enable all standard warning flags
-Wshadow # Warn when a variable declaration shadows one from an outer scope
-Wuninitialized # Warn about uninitialized variables
-Wnon-virtual-dtor # Warn when a class with virtual functions has a non-virtual destructor
-Woverloaded-virtual # Warn when a function declaration hides a virtual function from a base class
-Wformat=2 # Warn on security issues around functions that format output (ie printf)
-Wunused # Warn on anything being unused
-Wredundant-decls # Warn about multiple declarations of the same entity. Useful for code cleanup.
-Wstrict-aliasing=2 # Helps detect potential aliasing issues that could lead to undefined behavior.
-Wuseless-cast # Warn if you perform a cast to the same type (only in GCC >= 4.8)
# -Wpadded # Warn when padding is added to a structure or class for alignment
-Wnull-dereference # Warn if a null dereference is detected (only in GCC >= 6.0)
-Wold-style-cast # Warn for c-style casts
-Wconversion # Warn on type conversions that may lose data
-Werror # Treat Warnings as Errors
)
# KS Some compiler options are only available in GCC, in case we move to other compilers we will have to expand this
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
Expand All @@ -100,6 +101,11 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
-Wduplicated-branches # Warn if if / else branches have duplicated code (only in GCC >= 7.0)
)
endif()
if(MaCh3_WERROR_ENABLED)
target_compile_options(MaCh3Warnings INTERFACE
-Werror # Treat Warnings as Errors
)
endif()

add_library(MaCh3CompilerOptions INTERFACE)
target_link_libraries(MaCh3CompilerOptions INTERFACE MaCh3CompileDefinitions)
Expand Down