Skip to content

Commit cfbec63

Browse files
committed
build: Level up MSVC warnings
1 parent 20a5da5 commit cfbec63

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ endif()
212212
include(TryAppendCFlags)
213213
if(MSVC)
214214
# Keep the following commands ordered lexicographically.
215-
try_append_c_flags(/W2) # Moderate warning level.
215+
try_append_c_flags(/W3) # Production quality warning level.
216216
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
217+
try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
218+
try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
217219
else()
218220
# Keep the following commands ordered lexicographically.
219221
try_append_c_flags(-pedantic)

configure.ac

+6-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ AC_DEFUN([SECP_TRY_APPEND_DEFAULT_CFLAGS], [
121121
# libtool makes the same assumption internally.
122122
# Note that "/opt" and "-opt" are equivalent for MSVC; we use "-opt" because "/opt" looks like a path.
123123
if test x"$GCC" != x"yes" && test x"$build_windows" = x"yes"; then
124-
SECP_TRY_APPEND_CFLAGS([-W2 -wd4146], $1) # Moderate warning level, disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned"
124+
SECP_TRY_APPEND_CFLAGS([-W3], $1) # Production quality warning level.
125+
SECP_TRY_APPEND_CFLAGS([-wd4146], $1) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
126+
SECP_TRY_APPEND_CFLAGS([-wd4244], $1) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
127+
SECP_TRY_APPEND_CFLAGS([-wd4267], $1) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
128+
# The following warning is relevant to benchmarks and tests only.
129+
SECP_TRY_APPEND_CFLAGS([-wd4996], $1) # Disable warning C4996 for the usage of a function, class member, variable, or typedef that's marked deprecated.
125130
# We pass -ignore:4217 to the MSVC linker to suppress warning 4217 when
126131
# importing variables from a statically linked secp256k1.
127132
# (See the libtool manual, section "Windows DLLs" for background.)

src/CMakeLists.txt

+12-6
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,37 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
7575
endif()
7676
unset(${PROJECT_NAME}_soversion)
7777

78+
add_library(secp256k1_warning_suppression INTERFACE)
79+
target_compile_options(secp256k1_warning_suppression INTERFACE
80+
# Disable warning C4996 for the usage of a function, class member, variable, or typedef that's marked deprecated.
81+
$<$<C_COMPILER_ID:MSVC>:/wd4996>
82+
)
83+
7884
if(SECP256K1_BUILD_BENCHMARK)
7985
add_executable(bench bench.c)
80-
target_link_libraries(bench secp256k1)
86+
target_link_libraries(bench secp256k1 secp256k1_warning_suppression)
8187
add_executable(bench_internal bench_internal.c)
82-
target_link_libraries(bench_internal secp256k1_precomputed secp256k1_asm)
88+
target_link_libraries(bench_internal secp256k1_precomputed secp256k1_asm secp256k1_warning_suppression)
8389
add_executable(bench_ecmult bench_ecmult.c)
84-
target_link_libraries(bench_ecmult secp256k1_precomputed secp256k1_asm)
90+
target_link_libraries(bench_ecmult secp256k1_precomputed secp256k1_asm secp256k1_warning_suppression)
8591
endif()
8692

8793
if(SECP256K1_BUILD_TESTS)
8894
add_executable(noverify_tests tests.c)
89-
target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm)
95+
target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm secp256k1_warning_suppression)
9096
add_test(NAME noverify_tests COMMAND noverify_tests)
9197
if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
9298
add_executable(tests tests.c)
9399
target_compile_definitions(tests PRIVATE VERIFY)
94-
target_link_libraries(tests secp256k1_precomputed secp256k1_asm)
100+
target_link_libraries(tests secp256k1_precomputed secp256k1_asm secp256k1_warning_suppression)
95101
add_test(NAME tests COMMAND tests)
96102
endif()
97103
endif()
98104

99105
if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)
100106
# Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables).
101107
add_executable(exhaustive_tests tests_exhaustive.c)
102-
target_link_libraries(exhaustive_tests secp256k1_asm)
108+
target_link_libraries(exhaustive_tests secp256k1_asm secp256k1_warning_suppression)
103109
target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
104110
add_test(NAME exhaustive_tests COMMAND exhaustive_tests)
105111
endif()

0 commit comments

Comments
 (0)