Skip to content

Commit 09f3d71

Browse files
configure: Add a few CFLAGS for MSVC
1 parent 3b4f3d0 commit 09f3d71

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

configure.ac

+29-17
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,35 @@ esac
8686
#
8787
# TODO We should analogously not touch CPPFLAGS and LDFLAGS but currently there are no issues.
8888
AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [
89-
# Try to append -Werror=unknown-warning-option to CFLAGS temporarily. Otherwise clang will
90-
# not error out if it gets unknown warning flags and the checks here will always succeed
91-
# no matter if clang knows the flag or not.
92-
SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS"
93-
SECP_TRY_APPEND_CFLAGS([-Werror=unknown-warning-option], CFLAGS)
94-
95-
SECP_TRY_APPEND_CFLAGS([-std=c89 -pedantic -Wno-long-long -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef], $1) # GCC >= 3.0, -Wlong-long is implied by -pedantic.
96-
SECP_TRY_APPEND_CFLAGS([-Wno-overlength-strings], $1) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic.
97-
SECP_TRY_APPEND_CFLAGS([-Wall], $1) # GCC >= 2.95 and probably many other compilers
98-
SECP_TRY_APPEND_CFLAGS([-Wno-unused-function], $1) # GCC >= 3.0, -Wunused-function is implied by -Wall.
99-
SECP_TRY_APPEND_CFLAGS([-Wextra], $1) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions.
100-
SECP_TRY_APPEND_CFLAGS([-Wcast-align], $1) # GCC >= 2.95
101-
SECP_TRY_APPEND_CFLAGS([-Wcast-align=strict], $1) # GCC >= 8.0
102-
SECP_TRY_APPEND_CFLAGS([-Wconditional-uninitialized], $1) # Clang >= 3.0 only
103-
SECP_TRY_APPEND_CFLAGS([-fvisibility=hidden], $1) # GCC >= 4.0
104-
105-
CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS"
89+
# GCC and compatible (incl. clang)
90+
if test "x$GCC" = "xyes"; then
91+
# Try to append -Werror=unknown-warning-option to CFLAGS temporarily. Otherwise clang will
92+
# not error out if it gets unknown warning flags and the checks here will always succeed
93+
# no matter if clang knows the flag or not.
94+
SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS="$CFLAGS"
95+
SECP_TRY_APPEND_CFLAGS([-Werror=unknown-warning-option], CFLAGS)
96+
97+
SECP_TRY_APPEND_CFLAGS([-std=c89 -pedantic -Wno-long-long -Wnested-externs -Wshadow -Wstrict-prototypes -Wundef], $1) # GCC >= 3.0, -Wlong-long is implied by -pedantic.
98+
SECP_TRY_APPEND_CFLAGS([-Wno-overlength-strings], $1) # GCC >= 4.2, -Woverlength-strings is implied by -pedantic.
99+
SECP_TRY_APPEND_CFLAGS([-Wall], $1) # GCC >= 2.95 and probably many other compilers
100+
SECP_TRY_APPEND_CFLAGS([-Wno-unused-function], $1) # GCC >= 3.0, -Wunused-function is implied by -Wall.
101+
SECP_TRY_APPEND_CFLAGS([-Wextra], $1) # GCC >= 3.4, this is the newer name of -W, which we don't use because older GCCs will warn about unused functions.
102+
SECP_TRY_APPEND_CFLAGS([-Wcast-align], $1) # GCC >= 2.95
103+
SECP_TRY_APPEND_CFLAGS([-Wcast-align=strict], $1) # GCC >= 8.0
104+
SECP_TRY_APPEND_CFLAGS([-Wconditional-uninitialized], $1) # Clang >= 3.0 only
105+
SECP_TRY_APPEND_CFLAGS([-fvisibility=hidden], $1) # GCC >= 4.0
106+
107+
CFLAGS="$SECP_TRY_APPEND_DEFAULT_CFLAGS_saved_CFLAGS"
108+
fi
109+
110+
# MSVC
111+
# Assume MSVC if we're building for Windows but not with GCC or compatible;
112+
# libtool makes the same assumption internally.
113+
# Note that "/opt" and "-opt" are equivalent for MSVC; we use "-opt" because "/opt" looks like a path.
114+
if test x"$GCC" != x"yes" && test x"$build_windows" = x"yes"; then
115+
SECP_TRY_APPEND_CFLAGS([-W2 -wd4146], $1) # Moderate warning level, disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned"
116+
SECP_TRY_APPEND_CFLAGS([-external:anglebrackets -external:W0], $1) # Suppress warnings from #include <...> files
117+
fi
106118
])
107119
SECP_TRY_APPEND_DEFAULT_CFLAGS(SECP_CFLAGS)
108120

0 commit comments

Comments
 (0)