Merge bitcoin-core/secp256k1#1647: cmake: Adjust diagnostic flags for clang-cl
4c50d73dd9ci: Add new "Windows (clang-cl)" job (Hennadii Stepanov)84c0bd1f72cmake: Adjust diagnostic flags for clang-cl (Hennadii Stepanov) Pull request description: When building with `clang-cl` on Windows, the output is cluttered with warning messages because compiler diagnostic flags are not applied correctly: ``` > cmake -B build -G Ninja -DCMAKE_C_COMPILER="C:\Users\hebasto\Downloads\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin\clang-cl.exe" > cmake --build build [1/16] Building C object src\CMakeFiles\bench.dir\bench.c.obj In file included from C:\Users\hebasto\secp256k1\src\bench.c:11: C:\Users\hebasto\secp256k1\src\util.h(34,13): warning: unused function 'print_buf_plain' [-Wunused-function] 34 | static void print_buf_plain(const unsigned char *buf, size_t len) { | ^~~~~~~~~~~~~~~ 1 warning generated. [2/16] Building C object src\CMakeFiles\secp256k1_precomputed.dir\precomputed_ecmult_gen.c.obj In file included from C:\Users\hebasto\secp256k1\src\precomputed_ecmult_gen.c:3: In file included from C:\Users\hebasto\secp256k1\src\group.h:10: In file included from C:\Users\hebasto\secp256k1\src\field.h:10: C:\Users\hebasto\secp256k1\src\util.h(34,13): warning: unused function 'print_buf_plain' [-Wunused-function] 34 | static void print_buf_plain(const unsigned char *buf, size_t len) { | ^~~~~~~~~~~~~~~ ``` This PR resolves this issue. --- **Additional note for reviewers:** The VS builtin clang can also be used assuming that the following VS components are installed:  The user can generate a build system on Windows as follows: - Using the default "Visual Studio" generator: ``` cmake -B build -T ClangCL ``` - Using the "Ninja" generator: ``` cmake -B build -G Ninja -DCMAKE_C_COMPILER=clang-cl ``` --- Required for downstream projects which aim to build with `clang-cl` (see https://github.com/bitcoin/bitcoin/issues/31456). ACKs for top commit: real-or-random: utACK4c50d73dd9Tree-SHA512: 439eb53afd7be65d538cd569f3d095f58325bd26ffc5014ca5f94320689a45b20c9a5a963170578214a20fd3233ec15ef6ab75ab96ce3a4314c282b1b6229ca1
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -746,6 +746,8 @@ jobs:
|
|||||||
cpp_flags: '/DSECP256K1_MSVC_MULH_TEST_OVERRIDE'
|
cpp_flags: '/DSECP256K1_MSVC_MULH_TEST_OVERRIDE'
|
||||||
- job_name: 'x86 (MSVC): Windows (VS 2022)'
|
- job_name: 'x86 (MSVC): Windows (VS 2022)'
|
||||||
cmake_options: '-A Win32'
|
cmake_options: '-A Win32'
|
||||||
|
- job_name: 'x64 (MSVC): Windows (clang-cl)'
|
||||||
|
cmake_options: '-T ClangCL'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|||||||
@@ -242,17 +242,21 @@ endif()
|
|||||||
|
|
||||||
include(TryAppendCFlags)
|
include(TryAppendCFlags)
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
# Keep the following commands ordered lexicographically.
|
# For both cl and clang-cl compilers.
|
||||||
try_append_c_flags(/W3) # Production quality warning level.
|
try_append_c_flags(/W3) # Production quality warning level.
|
||||||
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
|
|
||||||
try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
|
|
||||||
try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
|
|
||||||
# Eliminate deprecation warnings for the older, less secure functions.
|
# Eliminate deprecation warnings for the older, less secure functions.
|
||||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
|
else()
|
||||||
|
try_append_c_flags(-Wall) # GCC >= 2.95 and probably many other compilers.
|
||||||
|
endif()
|
||||||
|
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||||
|
# Keep the following commands ordered lexicographically.
|
||||||
|
try_append_c_flags(/wd4146) # Disable warning C4146 "unary minus operator applied to unsigned type, result still unsigned".
|
||||||
|
try_append_c_flags(/wd4244) # Disable warning C4244 "'conversion' conversion from 'type1' to 'type2', possible loss of data".
|
||||||
|
try_append_c_flags(/wd4267) # Disable warning C4267 "'var' : conversion from 'size_t' to 'type', possible loss of data".
|
||||||
else()
|
else()
|
||||||
# Keep the following commands ordered lexicographically.
|
# Keep the following commands ordered lexicographically.
|
||||||
try_append_c_flags(-pedantic)
|
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.
|
try_append_c_flags(-Wcast-align) # GCC >= 2.95.
|
||||||
try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0.
|
try_append_c_flags(-Wcast-align=strict) # GCC >= 8.0.
|
||||||
try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only.
|
try_append_c_flags(-Wconditional-uninitialized) # Clang >= 3.0 only.
|
||||||
|
|||||||
Reference in New Issue
Block a user