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

Remove -Werror from default flags or give cmake option to avoid it #3447

Closed
wjwwood opened this issue Jun 17, 2021 · 1 comment
Closed

Remove -Werror from default flags or give cmake option to avoid it #3447

wjwwood opened this issue Jun 17, 2021 · 1 comment
Assignees

Comments

@wjwwood
Copy link

wjwwood commented Jun 17, 2021

Does the feature exist in the most recent commit?

No, the -Werror flag is included by default on master as of now:

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(cxx_base_flags "-Wall -Wshadow -Werror -Wconversion")
set(cxx_exception_flags "-fexceptions")
set(cxx_no_exception_flags "-fno-exceptions")
set(cxx_strict_flags "-W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls")
set(cxx_no_rtti_flags "-fno-rtti")
elseif (CMAKE_COMPILER_IS_GNUCXX)
set(cxx_base_flags "-Wall -Wshadow -Werror")

Why do we need this feature?

When building googletest/googlemock as part of another project (recommended best practice AFAIK), if that project is built with extremely pedantic warning flags, e.g. clang's -Weverything, then googletest will fail with errors rather than warnings. It is desirable for the project to finish building so all warning can be collected. googletest failing part way through due to -Werror prevents this.

Describe the proposal

In my opinion, googletest should not set -Werror in its cmake logic. The user (developer on local machine, CI infrastructure, CD infrastructure) can enable this with export CXXFLAGS=-Werror (and export CFLAGS=-Werror if needed) or with an argument to cmake -DCMAKE_CXX_FLAGS=-Werror. The opposite is not true, however (AFAIK), because though you can disable individual warnings as errors with -Wno-error=..., there is no -werror or -Wno-error=all or something like that. If there is, then that would probably be a sufficient workaround, and I'd appreciate anyone who could point out how to do that to me.

However, if there is no desire to change existing infrastructure, then I'd request a way to influence googletest to not include this flag, likely by having a cmake build option like GOOGLE_TEST_INCLUDE_W_ERROR and have it default to true. This would allow a project to prevent google test from adding that flag when using ExternalProject_Add, for example.

Without either removing the flag altogether, or a build option to prevent it, the only alternative I can think of is patching googletest before compiling, again you could do this with ExternalProject_Add, but that is fragile when upgrading to newer versions of googletest, and therefore a burden to maintain.

Is the feature specific to an operating system, compiler, or build system version?

It was added in 1ded831.

It is specific to CMake, and it appears to be specific to clang and gcc:

@derekmauro
Copy link
Member

Thanks for pointing this out. I completely agree and will get it removed.

@derekmauro derekmauro self-assigned this Jun 18, 2021
dinord pushed a commit that referenced this issue Jun 21, 2021
Remove -Werror from the CMake compiler flags

We should not force warnings as errors on users.
Sometimes compilers introduce new warnings which
will break builds.

Instead, we manually turn this flag on in our continuous integration
scripts so we can catch these errors, but not force them on our users.

Fixes #3447

PiperOrigin-RevId: 380241852
dinord pushed a commit that referenced this issue Jun 22, 2021
Remove -Werror from the CMake compiler flags

We should not force warnings as errors on users.
Sometimes compilers introduce new warnings which
will break builds.

Instead, we manually turn this flag on in our continuous integration
scripts so we can catch these errors, but not force them on our users.

Fixes #3447

PiperOrigin-RevId: 380241852
@dinord dinord closed this as completed in f790280 Jun 22, 2021
kmikolaj pushed a commit to kmikolaj/googletest that referenced this issue Jun 28, 2022
Remove -Werror from the CMake compiler flags

We should not force warnings as errors on users.
Sometimes compilers introduce new warnings which
will break builds.

Instead, we manually turn this flag on in our continuous integration
scripts so we can catch these errors, but not force them on our users.

Fixes google#3447

PiperOrigin-RevId: 380241852
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants