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

cmake: Fix checking compiler flags like -Wno-some-warning #1332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented May 30, 2023

Some compilers (GCC) produce no diagnostic for -Wno-some-warning unless other diagnostics are being produced:

$ git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 240557f..f976824 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -220,6 +220,7 @@ if(MSVC)
   add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
 else()
   # Keep the following commands ordered lexicographically.
+  try_append_c_flags(-Wno-some-warning)
   try_append_c_flags(-pedantic)
   try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
   try_append_c_flags(-Wcast-align) # GCC >= 2.95.
$ cmake -B build -DCMAKE_C_COMPILER=gcc 2>&1 | grep -i unknown
-- Performing Test C_SUPPORTS__WNO_SOME_WARNING
-- Performing Test C_SUPPORTS__WNO_SOME_WARNING - Success
Compile options ....................... -Wno-some-warning -pedantic -Wall -Wcast-align -Wcast-align=strict -Wextra -Wnested-externs -Wno-long-long -Wno-overlength-strings -Wno-unused-function -Wshadow -Wstrict-prototypes -Wundef

This PR fixes compiler flag check in CMake-based build system.

Let me know, if the same fix is desirable in Autotools-based build system.

@fanquake
Copy link
Member

fanquake commented Jul 1, 2024

Is this currently an issue for anything? If the check is broken, then it should be fixed before we start using it.

@real-or-random
Copy link
Contributor

Is this currently an issue for anything? If the check is broken, then it should be fixed before we start using it.

I think noone has run into this so far, but yeah, we should fix it.

Concept ACK

Comment on lines 14 to 16
# Some compilers (GCC) produce no diagnostic for -Wno-unknown-warning
# unless other diagnostics are being produced. Therefore, test the
# -Wsome-warning case instead of the -Wno-some-warning one.
Copy link
Contributor

@real-or-random real-or-random Jul 1, 2024

Choose a reason for hiding this comment

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

Suggested change
# Some compilers (GCC) produce no diagnostic for -Wno-unknown-warning
# unless other diagnostics are being produced. Therefore, test the
# -Wsome-warning case instead of the -Wno-some-warning one.
# Some compilers (GCC) produce no diagnostic for -Wno-some-warning,
# if "some-warning" is unknown to the compiler and no other diagnostics are being produced.
# Therefore, test the
# -Wsome-warning case instead of the -Wno-some-warning one.

Modulo paragraph formatting.

This confused me a lot because I thought -Wno-unknown-warning is a real flag that says "Don't warn on unknown warnings flags". (Clang has a real flag -Wno-unknown-warning-option for this!)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! Reworked.

@hebasto
Copy link
Member Author

hebasto commented Jul 1, 2024

Is this currently an issue for anything?

The newest current option---Wno-overlength-strings--is supported for GCC >=4.2. Only someone using an older compiler would be affected.

If the check is broken, then it should be fixed before we start using it.

The PR description mentions two checks, one per build system. The check in the Autotools-based build system:

dnl SECP_TRY_APPEND_CFLAGS(flags, VAR)
dnl Append flags to VAR if CC accepts them.
AC_DEFUN([SECP_TRY_APPEND_CFLAGS], [
AC_MSG_CHECKING([if ${CC} supports $1])
SECP_TRY_APPEND_CFLAGS_saved_CFLAGS="$CFLAGS"
CFLAGS="$1 $CFLAGS"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])], [flag_works=yes], [flag_works=no])
AC_MSG_RESULT($flag_works)
CFLAGS="$SECP_TRY_APPEND_CFLAGS_saved_CFLAGS"
if test x"$flag_works" = x"yes"; then
$2="$$2 $1"
fi
unset flag_works
AC_SUBST($2)
])
is broken.

The check in the CMake-based build system mirrored the behaviour of its Autotools' counterpart.

Therefore, both checks need to be fixed.

@hebasto hebasto marked this pull request as ready for review July 1, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants